mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
feat(cli): setup (#3267)
* commander * commander * selber! * move to packages * fix(errors): implement Is interface * test: command * test: commands * add init steps * setup tenant * add default step yaml * possibility to set password * merge v2 into v2-commander * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: search query builder can filter events in memory * fix: filters for add member * fix(setup): add `ExternalSecure` to config * chore: name iam to instance * fix: matching * remove unsued func * base url * base url * test(command): filter funcs * test: commands * fix: rename orgiampolicy to domain policy * start from init * commands * config * fix indexes and add constraints * fixes * fix: merge conflicts * fix: protos * fix: md files * setup * add deprecated org iam policy again * typo * fix search query * fix filter * Apply suggestions from code review * remove custom org from org setup * add todos for verification * change apps creation * simplify package structure * fix error * move preparation helper for tests * fix unique constraints * fix config mapping in setup * fix error handling in encryption_keys.go * fix projection config * fix query from old views to projection * fix setup of mgmt api * set iam project and fix instance projection * imports Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: fabi <fabienne.gerschwiler@gmail.com>
This commit is contained in:
@@ -50,22 +50,44 @@ func NewSearchQueryBuilder(columns Columns) *SearchQueryBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
func (builder *SearchQueryBuilder) Matches(event Event, existingLen int) (matches bool) {
|
||||
if builder.limit > 0 && uint64(existingLen) >= builder.limit {
|
||||
return false
|
||||
}
|
||||
if builder.resourceOwner != "" && event.Aggregate().ResourceOwner != builder.resourceOwner {
|
||||
return false
|
||||
}
|
||||
if event.Aggregate().InstanceID != "" && builder.instanceID != "" && event.Aggregate().InstanceID != builder.instanceID {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(builder.queries) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, query := range builder.queries {
|
||||
if query.matches(event) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//Columns defines which fields are set
|
||||
func (factory *SearchQueryBuilder) Columns(columns Columns) *SearchQueryBuilder {
|
||||
factory.columns = repository.Columns(columns)
|
||||
return factory
|
||||
func (builder *SearchQueryBuilder) Columns(columns Columns) *SearchQueryBuilder {
|
||||
builder.columns = repository.Columns(columns)
|
||||
return builder
|
||||
}
|
||||
|
||||
//Limit defines how many events are returned maximally.
|
||||
func (factory *SearchQueryBuilder) Limit(limit uint64) *SearchQueryBuilder {
|
||||
factory.limit = limit
|
||||
return factory
|
||||
func (builder *SearchQueryBuilder) Limit(limit uint64) *SearchQueryBuilder {
|
||||
builder.limit = limit
|
||||
return builder
|
||||
}
|
||||
|
||||
//ResourceOwner defines the resource owner (org) of the events
|
||||
func (factory *SearchQueryBuilder) ResourceOwner(resourceOwner string) *SearchQueryBuilder {
|
||||
factory.resourceOwner = resourceOwner
|
||||
return factory
|
||||
func (builder *SearchQueryBuilder) ResourceOwner(resourceOwner string) *SearchQueryBuilder {
|
||||
builder.resourceOwner = resourceOwner
|
||||
return builder
|
||||
}
|
||||
|
||||
//InstanceID defines the instanceID (system) of the events
|
||||
@@ -75,25 +97,25 @@ func (factory *SearchQueryBuilder) InstanceID(instanceID string) *SearchQueryBui
|
||||
}
|
||||
|
||||
//OrderDesc changes the sorting order of the returned events to descending
|
||||
func (factory *SearchQueryBuilder) OrderDesc() *SearchQueryBuilder {
|
||||
factory.desc = true
|
||||
return factory
|
||||
func (builder *SearchQueryBuilder) OrderDesc() *SearchQueryBuilder {
|
||||
builder.desc = true
|
||||
return builder
|
||||
}
|
||||
|
||||
//OrderAsc changes the sorting order of the returned events to ascending
|
||||
func (factory *SearchQueryBuilder) OrderAsc() *SearchQueryBuilder {
|
||||
factory.desc = false
|
||||
return factory
|
||||
func (builder *SearchQueryBuilder) OrderAsc() *SearchQueryBuilder {
|
||||
builder.desc = false
|
||||
return builder
|
||||
}
|
||||
|
||||
//AddQuery creates a new sub query.
|
||||
//All fields in the sub query are AND-connected in the storage request.
|
||||
//Multiple sub queries are OR-connected in the storage request.
|
||||
func (factory *SearchQueryBuilder) AddQuery() *SearchQuery {
|
||||
func (builder *SearchQueryBuilder) AddQuery() *SearchQuery {
|
||||
query := &SearchQuery{
|
||||
builder: factory,
|
||||
builder: builder,
|
||||
}
|
||||
factory.queries = append(factory.queries, query)
|
||||
builder.queries = append(builder.queries, query)
|
||||
|
||||
return query
|
||||
}
|
||||
@@ -145,6 +167,25 @@ func (query *SearchQuery) Builder() *SearchQueryBuilder {
|
||||
return query.builder
|
||||
}
|
||||
|
||||
func (query *SearchQuery) matches(event Event) bool {
|
||||
if query.eventSequenceLess > 0 && event.Sequence() >= query.eventSequenceLess {
|
||||
return false
|
||||
}
|
||||
if query.eventSequenceGreater > 0 && event.Sequence() <= query.eventSequenceGreater {
|
||||
return false
|
||||
}
|
||||
if ok := isAggreagteTypes(event.Aggregate(), query.aggregateTypes...); len(query.aggregateTypes) > 0 && !ok {
|
||||
return false
|
||||
}
|
||||
if ok := isAggregateIDs(event.Aggregate(), query.aggregateIDs...); len(query.aggregateIDs) > 0 && !ok {
|
||||
return false
|
||||
}
|
||||
if ok := isEventTypes(event, query.eventTypes...); len(query.eventTypes) > 0 && !ok {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (builder *SearchQueryBuilder) build(instanceID string) (*repository.SearchQuery, error) {
|
||||
if builder == nil ||
|
||||
len(builder.queries) < 1 ||
|
||||
|
Reference in New Issue
Block a user