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
This commit is contained in:
Silvan 2021-04-20 22:17:37 +02:00 committed by GitHub
parent c223a9ed61
commit c919fd6f13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 73 additions and 59 deletions

View File

@ -17,7 +17,7 @@ title: zitadel/policy.proto
| Name | Number | Description | | Name | Number | Description |
| ---- | ------ | ----------- | | ---- | ------ | ----------- |
| MULTI_FACTOR_TYPE_UNSPECIFIED | 0 | - | | 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 | - |

View File

@ -7,13 +7,11 @@ import (
"time" "time"
"github.com/caos/logging" "github.com/caos/logging"
"k8s.io/apimachinery/pkg/api/errors"
"github.com/caos/zitadel/internal/authz/repository/eventsourcing/view" "github.com/caos/zitadel/internal/authz/repository/eventsourcing/view"
"github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" 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" "github.com/caos/zitadel/internal/eventstore/v1/models"
es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk"
features_view_model "github.com/caos/zitadel/internal/features/repository/view/model" 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) 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 nil, err
} }
return iam_es_model.IAMToModel(iam), nil 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 { func (repo *TokenVerifierRepo) checkDefaultFeatures(ctx context.Context, requiredFeatures ...string) error {
features, viewErr := repo.View.FeaturesByAggregateID(domain.IAMID) features, viewErr := repo.View.FeaturesByAggregateID(domain.IAMID)
if viewErr != nil && !errors.IsNotFound(viewErr) { if viewErr != nil && !caos_errs.IsNotFound(viewErr) {
return viewErr return viewErr
} }
if errors.IsNotFound(viewErr) { if caos_errs.IsNotFound(viewErr) {
features = new(features_view_model.FeaturesView) features = new(features_view_model.FeaturesView)
} }
events, esErr := repo.getIAMEvents(ctx, features.Sequence) 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...) return checkFeatures(features, requiredFeatures...)
} }
if esErr != nil { if esErr != nil {

View File

@ -2,13 +2,13 @@ package eventstore
import ( import (
"context" "context"
"github.com/caos/zitadel/internal/eventstore/v1"
v1 "github.com/caos/zitadel/internal/eventstore/v1"
"github.com/caos/zitadel/internal/eventstore/v1/models" "github.com/caos/zitadel/internal/eventstore/v1/models"
es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk"
iam_model "github.com/caos/zitadel/internal/iam/model" iam_model "github.com/caos/zitadel/internal/iam/model"
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model" iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
iam_view "github.com/caos/zitadel/internal/iam/repository/view" 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/api/authz"
"github.com/caos/zitadel/internal/authz/repository/eventsourcing/view" "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) 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 nil, err
} }
return iam_es_model.IAMToModel(iam), nil return iam_es_model.IAMToModel(iam), nil

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
"github.com/lib/pq"
"regexp" "regexp"
"strconv" "strconv"
@ -12,6 +11,7 @@ import (
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/repository" "github.com/caos/zitadel/internal/eventstore/repository"
"github.com/cockroachdb/cockroach-go/v2/crdb" "github.com/cockroachdb/cockroach-go/v2/crdb"
"github.com/lib/pq"
//sql import for cockroach //sql import for cockroach
_ "github.com/lib/pq" _ "github.com/lib/pq"

View File

@ -3,22 +3,19 @@ package eventstore
import ( import (
"context" "context"
"encoding/json" "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" "strings"
"time" "time"
"github.com/caos/logging" "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/api/authz"
"github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
v1 "github.com/caos/zitadel/internal/eventstore/v1"
"github.com/caos/zitadel/internal/eventstore/v1/models" "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_model "github.com/caos/zitadel/internal/key/model"
key_view_model "github.com/caos/zitadel/internal/key/repository/view/model" key_view_model "github.com/caos/zitadel/internal/key/repository/view/model"
"github.com/caos/zitadel/internal/management/repository/eventsourcing/view" "github.com/caos/zitadel/internal/management/repository/eventsourcing/view"
@ -28,6 +25,7 @@ import (
usr_model "github.com/caos/zitadel/internal/user/model" usr_model "github.com/caos/zitadel/internal/user/model"
usr_view "github.com/caos/zitadel/internal/user/repository/view" usr_view "github.com/caos/zitadel/internal/user/repository/view"
usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model" usr_es_model "github.com/caos/zitadel/internal/user/repository/view/model"
"github.com/golang/protobuf/ptypes"
) )
type ProjectRepo struct { 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) user = new(usr_es_model.UserView)
} }
events, esErr := repo.getUserEvents(ctx, id, user.Sequence) 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") return nil, caos_errs.ThrowNotFound(nil, "EVENT-4n8Fs", "Errors.User.NotFound")
} }
if esErr != nil { 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) 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 nil, err
} }
return iam_es_model.IAMToModel(iam), nil return iam_es_model.IAMToModel(iam), nil

View File

@ -2,27 +2,24 @@ package handler
import ( import (
"context" "context"
"github.com/caos/zitadel/internal/eventstore/v1"
"github.com/caos/logging" "github.com/caos/logging"
"k8s.io/apimachinery/pkg/api/errors"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
es_sdk "github.com/caos/zitadel/internal/eventstore/v1/sdk" v1 "github.com/caos/zitadel/internal/eventstore/v1"
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"
es_models "github.com/caos/zitadel/internal/eventstore/v1/models" es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/eventstore/v1/query" "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" "github.com/caos/zitadel/internal/eventstore/v1/spooler"
org_model "github.com/caos/zitadel/internal/org/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_model "github.com/caos/zitadel/internal/project/model"
proj_es_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/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_model "github.com/caos/zitadel/internal/user/model"
usr_es_model "github.com/caos/zitadel/internal/user/repository/eventsourcing/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" grant_es_model "github.com/caos/zitadel/internal/usergrant/repository/eventsourcing/model"
view_model "github.com/caos/zitadel/internal/usergrant/repository/view/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) 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 return nil, err
} }
if esProject.Sequence == 0 { if esProject.Sequence == 0 {

View File

@ -2,25 +2,21 @@ package handler
import ( import (
"context" "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" "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" es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/eventstore/v1/query" "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" "github.com/caos/zitadel/internal/eventstore/v1/spooler"
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model" iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
org_model "github.com/caos/zitadel/internal/org/model" org_model "github.com/caos/zitadel/internal/org/model"
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/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_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_model "github.com/caos/zitadel/internal/user/model"
"github.com/caos/zitadel/internal/user/repository/eventsourcing/model" "github.com/caos/zitadel/internal/user/repository/eventsourcing/model"
usr_es_model "github.com/caos/zitadel/internal/user/repository/view/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) 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 return nil, err
} }
if esProject.Sequence == 0 { if esProject.Sequence == 0 {

View File

@ -316,6 +316,8 @@ Errors:
AlreadyExists: Schritt gestartet existiert bereits AlreadyExists: Schritt gestartet existiert bereits
Done: Done:
AlreadyExists: Schritt ausgeführt existiert bereits AlreadyExists: Schritt ausgeführt existiert bereits
Features:
NotChanged: Feature hat nicht geändert
EventTypes: EventTypes:
user: user:
added: Benutzer hinzugefügt added: Benutzer hinzugefügt
@ -556,6 +558,10 @@ EventTypes:
added: Passwort Sperrungs Richtlinie hinzugefügt added: Passwort Sperrungs Richtlinie hinzugefügt
changed: Passwort Sperrungs Richtlinie geändert changed: Passwort Sperrungs Richtlinie geändert
removed: Passwort Sperrungs Richtlinie gelöscht removed: Passwort Sperrungs Richtlinie gelöscht
label:
added: Label Richtline hinzugefügt
changed: Label Richtline geändert
removed: Label Richtline entfernt
project: project:
added: Projekt hinzugefügt added: Projekt hinzugefügt
changed: Project geändert changed: Project geändert

View File

@ -317,6 +317,8 @@ Errors:
AlreadyExists: Step started already exists AlreadyExists: Step started already exists
Done: Done:
AlreadyExists: Step done already exists AlreadyExists: Step done already exists
Features:
NotChanged: Feature hat nicht geändert
EventTypes: EventTypes:
user: user:
added: User added added: User added
@ -557,6 +559,10 @@ EventTypes:
added: Password lockout policy added added: Password lockout policy added
changed: Password lockout policy changed changed: Password lockout policy changed
removed: Password lockout policy removed removed: Password lockout policy removed
label:
added: Label Policy added
changed: Label Policy changed
removed: Label Policy removed
project: project:
added: Project added added: Project added
changed: Project changed changed: Project changed

View File

@ -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;

View File

@ -23,13 +23,14 @@ option go_package ="github.com/caos/zitadel/pkg/grpc/admin";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: { info: {
title: "Administrator API for ZITADEL"; title: "Administration API aka Admin";
description: "This API provides all functions to administrate ZITADEL.";
version: "1.0"; version: "1.0";
contact: { description: "This API is intended to configure and manage the IAM itself.";
name: "file an issue", contact:{
url: "https://github.com/caos/zitadel"; name: "CAOS developers of ZITADEL"
}; url: "https://zitadel.ch"
email: "hi@zitadel.ch"
}
license: { license: {
name: "Apache 2.0", name: "Apache 2.0",
url: "https://github.com/caos/zitadel/blob/main/LICENSE"; url: "https://github.com/caos/zitadel/blob/main/LICENSE";

View File

@ -18,10 +18,17 @@ option go_package ="github.com/caos/zitadel/pkg/grpc/auth";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: { info: {
title: "auth service"; title: "Authentication API aka Auth";
version: "1.0"; version: "1.0";
description: "The authentication API is used for all operations on the currently logged in user.";
contact:{ 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"
}; };
}; };

View File

@ -26,15 +26,14 @@ package zitadel.management.v1;
option go_package ="github.com/caos/zitadel/pkg/grpc/management"; option go_package ="github.com/caos/zitadel/pkg/grpc/management";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
swagger: "2.0",
info: { info: {
title: "management api of ZITADEL"; title: "Management API";
version: "1.0"; 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:{ contact:{
name: "CAOS developers of ZITADEL" name: "CAOS developers of ZITADEL"
url: "https://zitadel.ch" url: "https://zitadel.ch"
email: "hi@caos.ch" //TODO: is there a zitadel@caos.ch? email: "hi@zitadel.ch"
} }
license: { license: {
name: "Apache License 2.0", name: "Apache License 2.0",

View File

@ -87,7 +87,7 @@ enum SecondFactorType {
enum MultiFactorType { enum MultiFactorType {
MULTI_FACTOR_TYPE_UNSPECIFIED = 0; 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 { enum PasswordlessType {

View File

@ -350,7 +350,6 @@ message WebAuthNVerification {
description: "json representation of public key credential issued by the webauthn client"; description: "json representation of public key credential issued by the webauthn client";
min_length: 55; min_length: 55;
max_length: 1048576; //1 mb max_length: 1048576; //1 mb
//TODO: add example validate max
} }
]; ];
string token_name = 2 [ string token_name = 2 [