From c919fd6f136e2dcff75ce7d6c42d3fea725c777e Mon Sep 17 00:00:00 2001 From: Silvan Date: Tue, 20 Apr 2021 22:17:37 +0200 Subject: [PATCH] fix: correct imports (#1630) * fix: correct import for errors * fix: add missing translations * fix(eventstore): index * fix(eventstore): use table instead of index * fix(proto): correct info * fix(migrations): use eventstore --- docs/docs/apis/proto/policy.md | 2 +- .../eventstore/token_verifier.go | 12 +++++------ .../eventsourcing/eventstore/user_grant.go | 6 +++--- internal/eventstore/repository/sql/crdb.go | 2 +- .../eventsourcing/eventstore/project.go | 20 +++++++++---------- .../eventsourcing/handler/user_grant.go | 19 ++++++++---------- .../eventsourcing/handler/user_membership.go | 18 +++++++---------- internal/static/i18n/de.yaml | 6 ++++++ internal/static/i18n/en.yaml | 6 ++++++ migrations/cockroach/V1.40__indexes.sql | 7 +++++++ proto/zitadel/admin.proto | 13 ++++++------ proto/zitadel/auth.proto | 11 ++++++++-- proto/zitadel/management.proto | 7 +++---- proto/zitadel/policy.proto | 2 +- proto/zitadel/user.proto | 1 - 15 files changed, 73 insertions(+), 59 deletions(-) create mode 100644 migrations/cockroach/V1.40__indexes.sql diff --git a/docs/docs/apis/proto/policy.md b/docs/docs/apis/proto/policy.md index ee7e1aea4b..532064ff99 100644 --- a/docs/docs/apis/proto/policy.md +++ b/docs/docs/apis/proto/policy.md @@ -17,7 +17,7 @@ title: zitadel/policy.proto | Name | Number | Description | | ---- | ------ | ----------- | | MULTI_FACTOR_TYPE_UNSPECIFIED | 0 | - | -| MULTI_FACTOR_TYPE_U2F_WITH_VERIFICATION | 1 | TODO: what does livio think after the weekend? :D | +| MULTI_FACTOR_TYPE_U2F_WITH_VERIFICATION | 1 | - | diff --git a/internal/authz/repository/eventsourcing/eventstore/token_verifier.go b/internal/authz/repository/eventsourcing/eventstore/token_verifier.go index 5993674c53..ba2b370c34 100644 --- a/internal/authz/repository/eventsourcing/eventstore/token_verifier.go +++ b/internal/authz/repository/eventsourcing/eventstore/token_verifier.go @@ -7,13 +7,11 @@ import ( "time" "github.com/caos/logging" - "k8s.io/apimachinery/pkg/api/errors" - "github.com/caos/zitadel/internal/authz/repository/eventsourcing/view" "github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" - "github.com/caos/zitadel/internal/eventstore/v1" + v1 "github.com/caos/zitadel/internal/eventstore/v1" "github.com/caos/zitadel/internal/eventstore/v1/models" es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" features_view_model "github.com/caos/zitadel/internal/features/repository/view/model" @@ -211,7 +209,7 @@ func (u *TokenVerifierRepo) getIAMByID(ctx context.Context) (*iam_model.IAM, err }, } err = es_sdk.Filter(ctx, u.Eventstore.FilterEvents, iam.AppendEvents, query) - if err != nil && errors.IsNotFound(err) && iam.Sequence == 0 { + if err != nil && caos_errs.IsNotFound(err) && iam.Sequence == 0 { return nil, err } return iam_es_model.IAMToModel(iam), nil @@ -219,14 +217,14 @@ func (u *TokenVerifierRepo) getIAMByID(ctx context.Context) (*iam_model.IAM, err func (repo *TokenVerifierRepo) checkDefaultFeatures(ctx context.Context, requiredFeatures ...string) error { features, viewErr := repo.View.FeaturesByAggregateID(domain.IAMID) - if viewErr != nil && !errors.IsNotFound(viewErr) { + if viewErr != nil && !caos_errs.IsNotFound(viewErr) { return viewErr } - if errors.IsNotFound(viewErr) { + if caos_errs.IsNotFound(viewErr) { features = new(features_view_model.FeaturesView) } events, esErr := repo.getIAMEvents(ctx, features.Sequence) - if errors.IsNotFound(viewErr) && len(events) == 0 { + if caos_errs.IsNotFound(viewErr) && len(events) == 0 { return checkFeatures(features, requiredFeatures...) } if esErr != nil { diff --git a/internal/authz/repository/eventsourcing/eventstore/user_grant.go b/internal/authz/repository/eventsourcing/eventstore/user_grant.go index 324da6df26..c58fbbb431 100644 --- a/internal/authz/repository/eventsourcing/eventstore/user_grant.go +++ b/internal/authz/repository/eventsourcing/eventstore/user_grant.go @@ -2,13 +2,13 @@ package eventstore import ( "context" - "github.com/caos/zitadel/internal/eventstore/v1" + + v1 "github.com/caos/zitadel/internal/eventstore/v1" "github.com/caos/zitadel/internal/eventstore/v1/models" es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" iam_model "github.com/caos/zitadel/internal/iam/model" iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model" iam_view "github.com/caos/zitadel/internal/iam/repository/view" - "k8s.io/apimachinery/pkg/api/errors" "github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/authz/repository/eventsourcing/view" @@ -134,7 +134,7 @@ func (u *UserGrantRepo) getIAMByID(ctx context.Context) (*iam_model.IAM, error) }, } err = es_sdk.Filter(ctx, u.Eventstore.FilterEvents, iam.AppendEvents, query) - if err != nil && errors.IsNotFound(err) && iam.Sequence == 0 { + if err != nil && caos_errs.IsNotFound(err) && iam.Sequence == 0 { return nil, err } return iam_es_model.IAMToModel(iam), nil diff --git a/internal/eventstore/repository/sql/crdb.go b/internal/eventstore/repository/sql/crdb.go index 20dd29fa6c..6d3253b4ae 100644 --- a/internal/eventstore/repository/sql/crdb.go +++ b/internal/eventstore/repository/sql/crdb.go @@ -4,7 +4,6 @@ import ( "context" "database/sql" "errors" - "github.com/lib/pq" "regexp" "strconv" @@ -12,6 +11,7 @@ import ( caos_errs "github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/eventstore/repository" "github.com/cockroachdb/cockroach-go/v2/crdb" + "github.com/lib/pq" //sql import for cockroach _ "github.com/lib/pq" diff --git a/internal/management/repository/eventsourcing/eventstore/project.go b/internal/management/repository/eventsourcing/eventstore/project.go index 5878d17a3d..ae3bd0e233 100644 --- a/internal/management/repository/eventsourcing/eventstore/project.go +++ b/internal/management/repository/eventsourcing/eventstore/project.go @@ -3,22 +3,19 @@ package eventstore import ( "context" "encoding/json" - "github.com/caos/zitadel/internal/domain" - "github.com/caos/zitadel/internal/eventstore/v1" - es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" - iam_model "github.com/caos/zitadel/internal/iam/model" - iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model" - iam_view "github.com/caos/zitadel/internal/iam/repository/view" "strings" "time" "github.com/caos/logging" - "github.com/golang/protobuf/ptypes" - "k8s.io/apimachinery/pkg/api/errors" - "github.com/caos/zitadel/internal/api/authz" + "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" + v1 "github.com/caos/zitadel/internal/eventstore/v1" "github.com/caos/zitadel/internal/eventstore/v1/models" + es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" + iam_model "github.com/caos/zitadel/internal/iam/model" + iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model" + iam_view "github.com/caos/zitadel/internal/iam/repository/view" key_model "github.com/caos/zitadel/internal/key/model" key_view_model "github.com/caos/zitadel/internal/key/repository/view/model" "github.com/caos/zitadel/internal/management/repository/eventsourcing/view" @@ -28,6 +25,7 @@ import ( usr_model "github.com/caos/zitadel/internal/user/model" usr_view "github.com/caos/zitadel/internal/user/repository/view" usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model" + "github.com/golang/protobuf/ptypes" ) type ProjectRepo struct { @@ -534,7 +532,7 @@ func (repo *ProjectRepo) userByID(ctx context.Context, id string) (*usr_model.Us user = new(usr_es_model.UserView) } events, esErr := repo.getUserEvents(ctx, id, user.Sequence) - if errors.IsNotFound(viewErr) && len(events) == 0 { + if caos_errs.IsNotFound(viewErr) && len(events) == 0 { return nil, caos_errs.ThrowNotFound(nil, "EVENT-4n8Fs", "Errors.User.NotFound") } if esErr != nil { @@ -674,7 +672,7 @@ func (u *ProjectRepo) GetIAMByID(ctx context.Context) (*iam_model.IAM, error) { }, } err = es_sdk.Filter(ctx, u.Eventstore.FilterEvents, iam.AppendEvents, query) - if err != nil && errors.IsNotFound(err) && iam.Sequence == 0 { + if err != nil && caos_errs.IsNotFound(err) && iam.Sequence == 0 { return nil, err } return iam_es_model.IAMToModel(iam), nil diff --git a/internal/management/repository/eventsourcing/handler/user_grant.go b/internal/management/repository/eventsourcing/handler/user_grant.go index f2fda5289b..c8781828d7 100644 --- a/internal/management/repository/eventsourcing/handler/user_grant.go +++ b/internal/management/repository/eventsourcing/handler/user_grant.go @@ -2,27 +2,24 @@ package handler import ( "context" - "github.com/caos/zitadel/internal/eventstore/v1" "github.com/caos/logging" - "k8s.io/apimachinery/pkg/api/errors" - caos_errs "github.com/caos/zitadel/internal/errors" - es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" - org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model" - org_view "github.com/caos/zitadel/internal/org/repository/view" - proj_view "github.com/caos/zitadel/internal/project/repository/view" - "github.com/caos/zitadel/internal/user/repository/view" - usr_view_model "github.com/caos/zitadel/internal/user/repository/view/model" - + v1 "github.com/caos/zitadel/internal/eventstore/v1" es_models "github.com/caos/zitadel/internal/eventstore/v1/models" "github.com/caos/zitadel/internal/eventstore/v1/query" + es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" "github.com/caos/zitadel/internal/eventstore/v1/spooler" org_model "github.com/caos/zitadel/internal/org/model" + org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model" + org_view "github.com/caos/zitadel/internal/org/repository/view" proj_model "github.com/caos/zitadel/internal/project/model" proj_es_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/model" + proj_view "github.com/caos/zitadel/internal/project/repository/view" usr_model "github.com/caos/zitadel/internal/user/model" usr_es_model "github.com/caos/zitadel/internal/user/repository/eventsourcing/model" + "github.com/caos/zitadel/internal/user/repository/view" + usr_view_model "github.com/caos/zitadel/internal/user/repository/view/model" grant_es_model "github.com/caos/zitadel/internal/usergrant/repository/eventsourcing/model" view_model "github.com/caos/zitadel/internal/usergrant/repository/view/model" ) @@ -297,7 +294,7 @@ func (u *UserGrant) getProjectByID(ctx context.Context, projID string) (*proj_mo }, } err = es_sdk.Filter(ctx, u.Eventstore().FilterEvents, esProject.AppendEvents, query) - if err != nil && !errors.IsNotFound(err) { + if err != nil && !caos_errs.IsNotFound(err) { return nil, err } if esProject.Sequence == 0 { diff --git a/internal/management/repository/eventsourcing/handler/user_membership.go b/internal/management/repository/eventsourcing/handler/user_membership.go index 3e7309ea71..164af8e3e5 100644 --- a/internal/management/repository/eventsourcing/handler/user_membership.go +++ b/internal/management/repository/eventsourcing/handler/user_membership.go @@ -2,25 +2,21 @@ package handler import ( "context" - "github.com/caos/zitadel/internal/eventstore/v1" - - "k8s.io/apimachinery/pkg/api/errors" - - caos_errs "github.com/caos/zitadel/internal/errors" - es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" - org_view "github.com/caos/zitadel/internal/org/repository/view" - proj_model "github.com/caos/zitadel/internal/project/model" - proj_view "github.com/caos/zitadel/internal/project/repository/view" "github.com/caos/logging" - + caos_errs "github.com/caos/zitadel/internal/errors" + v1 "github.com/caos/zitadel/internal/eventstore/v1" es_models "github.com/caos/zitadel/internal/eventstore/v1/models" "github.com/caos/zitadel/internal/eventstore/v1/query" + es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" "github.com/caos/zitadel/internal/eventstore/v1/spooler" iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model" org_model "github.com/caos/zitadel/internal/org/model" org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model" + org_view "github.com/caos/zitadel/internal/org/repository/view" + proj_model "github.com/caos/zitadel/internal/project/model" proj_es_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/model" + proj_view "github.com/caos/zitadel/internal/project/repository/view" usr_model "github.com/caos/zitadel/internal/user/model" "github.com/caos/zitadel/internal/user/repository/eventsourcing/model" usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model" @@ -295,7 +291,7 @@ func (u *UserMembership) getProjectByID(ctx context.Context, projID string) (*pr }, } err = es_sdk.Filter(ctx, u.Eventstore().FilterEvents, esProject.AppendEvents, query) - if err != nil && !errors.IsNotFound(err) { + if err != nil && !caos_errs.IsNotFound(err) { return nil, err } if esProject.Sequence == 0 { diff --git a/internal/static/i18n/de.yaml b/internal/static/i18n/de.yaml index bccf67bc06..aa9acc75a0 100644 --- a/internal/static/i18n/de.yaml +++ b/internal/static/i18n/de.yaml @@ -316,6 +316,8 @@ Errors: AlreadyExists: Schritt gestartet existiert bereits Done: AlreadyExists: Schritt ausgeführt existiert bereits + Features: + NotChanged: Feature hat nicht geändert EventTypes: user: added: Benutzer hinzugefügt @@ -556,6 +558,10 @@ EventTypes: added: Passwort Sperrungs Richtlinie hinzugefügt changed: Passwort Sperrungs Richtlinie geändert removed: Passwort Sperrungs Richtlinie gelöscht + label: + added: Label Richtline hinzugefügt + changed: Label Richtline geändert + removed: Label Richtline entfernt project: added: Projekt hinzugefügt changed: Project geändert diff --git a/internal/static/i18n/en.yaml b/internal/static/i18n/en.yaml index 64f83d8de0..25ab93341e 100644 --- a/internal/static/i18n/en.yaml +++ b/internal/static/i18n/en.yaml @@ -317,6 +317,8 @@ Errors: AlreadyExists: Step started already exists Done: AlreadyExists: Step done already exists + Features: + NotChanged: Feature hat nicht geändert EventTypes: user: added: User added @@ -557,6 +559,10 @@ EventTypes: added: Password lockout policy added changed: Password lockout policy changed removed: Password lockout policy removed + label: + added: Label Policy added + changed: Label Policy changed + removed: Label Policy removed project: added: Project added changed: Project changed diff --git a/migrations/cockroach/V1.40__indexes.sql b/migrations/cockroach/V1.40__indexes.sql new file mode 100644 index 0000000000..8f4edf41f2 --- /dev/null +++ b/migrations/cockroach/V1.40__indexes.sql @@ -0,0 +1,7 @@ +use auth; +CREATE INDEX IF NOT EXISTS auth_code on auth.auth_requests (code); + +use eventstore; +CREATE INDEX IF NOT EXISTS default_event_query on eventstore.events (aggregate_type, aggregate_id, event_type, resource_owner); +DROP INDEX IF EXISTS event_type; +DROP INDEX IF EXISTS resource_owner; \ No newline at end of file diff --git a/proto/zitadel/admin.proto b/proto/zitadel/admin.proto index 355f49fed5..2cc8e9b0e4 100644 --- a/proto/zitadel/admin.proto +++ b/proto/zitadel/admin.proto @@ -23,13 +23,14 @@ option go_package ="github.com/caos/zitadel/pkg/grpc/admin"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { - title: "Administrator API for ZITADEL"; - description: "This API provides all functions to administrate ZITADEL."; + title: "Administration API aka Admin"; version: "1.0"; - contact: { - name: "file an issue", - url: "https://github.com/caos/zitadel"; - }; + description: "This API is intended to configure and manage the IAM itself."; + contact:{ + name: "CAOS developers of ZITADEL" + url: "https://zitadel.ch" + email: "hi@zitadel.ch" + } license: { name: "Apache 2.0", url: "https://github.com/caos/zitadel/blob/main/LICENSE"; diff --git a/proto/zitadel/auth.proto b/proto/zitadel/auth.proto index 9beffbb76a..1c63902d80 100644 --- a/proto/zitadel/auth.proto +++ b/proto/zitadel/auth.proto @@ -18,10 +18,17 @@ option go_package ="github.com/caos/zitadel/pkg/grpc/auth"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { - title: "auth service"; + title: "Authentication API aka Auth"; version: "1.0"; + description: "The authentication API is used for all operations on the currently logged in user."; contact:{ - url: "https://github.com/caos/zitadel/api/auth" //TODO: should be swagger path + name: "CAOS developers of ZITADEL" + url: "https://zitadel.ch" + email: "hi@zitadel.ch" + } + license: { + name: "Apache License 2.0", + url: "https://github.com/caos/zitadel/blob/main/LICENSE" }; }; diff --git a/proto/zitadel/management.proto b/proto/zitadel/management.proto index 88722cc17e..bed448bffd 100644 --- a/proto/zitadel/management.proto +++ b/proto/zitadel/management.proto @@ -26,15 +26,14 @@ package zitadel.management.v1; option go_package ="github.com/caos/zitadel/pkg/grpc/management"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { - swagger: "2.0", info: { - title: "management api of ZITADEL"; + title: "Management API"; version: "1.0"; - description: "it's for managing organisation internal and extnernal objects."; + description: "The management API is as the name states the interface where systems can mutate IAM objects like, organisations, projects, clients, users and so on if they have the necessary access rights."; contact:{ name: "CAOS developers of ZITADEL" url: "https://zitadel.ch" - email: "hi@caos.ch" //TODO: is there a zitadel@caos.ch? + email: "hi@zitadel.ch" } license: { name: "Apache License 2.0", diff --git a/proto/zitadel/policy.proto b/proto/zitadel/policy.proto index bb51b6de86..ae98bb1b14 100644 --- a/proto/zitadel/policy.proto +++ b/proto/zitadel/policy.proto @@ -87,7 +87,7 @@ enum SecondFactorType { enum MultiFactorType { MULTI_FACTOR_TYPE_UNSPECIFIED = 0; - MULTI_FACTOR_TYPE_U2F_WITH_VERIFICATION = 1; //TODO: what does livio think after the weekend? :D + MULTI_FACTOR_TYPE_U2F_WITH_VERIFICATION = 1; } enum PasswordlessType { diff --git a/proto/zitadel/user.proto b/proto/zitadel/user.proto index 71d152f0be..7a6fe06c9c 100644 --- a/proto/zitadel/user.proto +++ b/proto/zitadel/user.proto @@ -350,7 +350,6 @@ message WebAuthNVerification { description: "json representation of public key credential issued by the webauthn client"; min_length: 55; max_length: 1048576; //1 mb - //TODO: add example validate max } ]; string token_name = 2 [