fix: change to repository event types and removed unused code (#3386)

* fix: change to repository event types and removed unused code

* some fixes

* remove unused code
This commit is contained in:
Livio Amstutz
2022-03-31 11:36:26 +02:00
committed by GitHub
parent 55af4a18a2
commit 87560157c1
170 changed files with 999 additions and 9581 deletions

View File

@@ -5,7 +5,6 @@ import (
"github.com/caos/zitadel/internal/api/grpc/object"
"github.com/caos/zitadel/internal/domain"
key_model "github.com/caos/zitadel/internal/key/model"
"github.com/caos/zitadel/internal/query"
"github.com/caos/zitadel/pkg/grpc/authn"
)
@@ -34,7 +33,7 @@ func KeyToPb(key *query.AuthNKey) *authn.Key {
func KeyTypeToPb(typ domain.AuthNKeyType) authn.KeyType {
switch typ {
case key_model.AuthNKeyTypeJSON:
case domain.AuthNKeyTypeJSON:
return authn.KeyType_KEY_TYPE_JSON
default:
return authn.KeyType_KEY_TYPE_UNSPECIFIED

View File

@@ -6,7 +6,6 @@ import (
object_grpc "github.com/caos/zitadel/internal/api/grpc/object"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
proj_model "github.com/caos/zitadel/internal/project/model"
"github.com/caos/zitadel/internal/query"
app_pb "github.com/caos/zitadel/pkg/grpc/app"
message_pb "github.com/caos/zitadel/pkg/grpc/message"
@@ -292,11 +291,3 @@ func AppQueryToModel(appQuery *app_pb.AppQuery) (query.SearchQuery, error) {
return nil, errors.ThrowInvalidArgument(nil, "APP-Add46", "List.Query.Invalid")
}
}
func AppQueryNameToModel(query *app_pb.AppNameQuery) *proj_model.ApplicationSearchQuery {
return &proj_model.ApplicationSearchQuery{
Key: proj_model.AppSearchKeyName,
Method: object_grpc.TextMethodToModel(query.Method),
Value: query.Name,
}
}

View File

@@ -5,7 +5,6 @@ import (
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/query"
usr_grant_model "github.com/caos/zitadel/internal/usergrant/model"
user_pb "github.com/caos/zitadel/pkg/grpc/user"
)
@@ -148,17 +147,6 @@ func UserStateToPb(state domain.UserState) user_pb.UserState {
}
}
func ModelUserGrantStateToPb(state usr_grant_model.UserGrantState) user_pb.UserGrantState {
switch state {
case usr_grant_model.UserGrantStateActive:
return user_pb.UserGrantState_USER_GRANT_STATE_ACTIVE
case usr_grant_model.UserGrantStateInactive:
return user_pb.UserGrantState_USER_GRANT_STATE_INACTIVE
default:
return user_pb.UserGrantState_USER_GRANT_STATE_UNSPECIFIED
}
}
func GenderToPb(gender domain.Gender) user_pb.Gender {
switch gender {
case domain.GenderDiverse:

View File

@@ -2,7 +2,7 @@ package user
import (
"github.com/caos/zitadel/internal/api/grpc/object"
auth_req_model "github.com/caos/zitadel/internal/auth_request/model"
"github.com/caos/zitadel/internal/domain"
user_model "github.com/caos/zitadel/internal/user/model"
"github.com/caos/zitadel/pkg/grpc/user"
)
@@ -34,11 +34,11 @@ func UserSessionToPb(session *user_model.UserSessionView) *user.Session {
}
}
func SessionStateToPb(state auth_req_model.UserSessionState) user.SessionState {
func SessionStateToPb(state domain.UserSessionState) user.SessionState {
switch state {
case auth_req_model.UserSessionStateActive:
case domain.UserSessionStateActive:
return user.SessionState_SESSION_STATE_ACTIVE
case auth_req_model.UserSessionStateTerminated:
case domain.UserSessionStateTerminated:
return user.SessionState_SESSION_STATE_TERMINATED
default:
return user.SessionState_SESSION_STATE_UNSPECIFIED

View File

@@ -51,9 +51,9 @@ func setInstance(r *http.Request, verifier authz.InstanceVerifier, headerName st
authCtx, span := tracing.NewServerInterceptorSpan(ctx)
defer func() { span.EndWithError(err) }()
host := r.Header.Get(headerName)
if host == "" {
return nil, fmt.Errorf("host header %s not found", headerName)
host, err := getHost(r, headerName)
if err != nil {
return nil, err
}
instance, err := verifier.InstanceByHost(authCtx, host)
@@ -63,3 +63,14 @@ func setInstance(r *http.Request, verifier authz.InstanceVerifier, headerName st
span.End()
return authz.WithInstance(ctx, instance), nil
}
func getHost(r *http.Request, headerName string) (string, error) {
host := r.Host
if headerName != "host" {
host = r.Header.Get(headerName)
}
if host == "" {
return "", fmt.Errorf("host header `%s` not found", headerName)
}
return host, nil
}

View File

@@ -2,7 +2,6 @@ package oidc
import (
"context"
"fmt"
"strings"
"time"
@@ -16,7 +15,6 @@ import (
"github.com/caos/zitadel/internal/query"
"github.com/caos/zitadel/internal/telemetry/tracing"
"github.com/caos/zitadel/internal/user/model"
grant_model "github.com/caos/zitadel/internal/usergrant/model"
)
func (o *OPStorage) CreateAuthRequest(ctx context.Context, req *oidc.AuthRequest, userID string) (_ op.AuthRequest, err error) {
@@ -102,16 +100,6 @@ func (o *OPStorage) CreateAccessToken(ctx context.Context, req op.TokenRequest)
return resp.TokenID, resp.Expiration, nil
}
func grantsToScopes(grants []*grant_model.UserGrantView) []string {
scopes := make([]string, 0)
for _, grant := range grants {
for _, role := range grant.RoleKeys {
scopes = append(scopes, fmt.Sprintf("%v:%v", grant.ResourceOwner, role))
}
}
return scopes
}
func (o *OPStorage) CreateAccessAndRefreshTokens(ctx context.Context, req op.TokenRequest, refreshToken string) (_, _ string, _ time.Time, err error) {
ctx, span := tracing.NewSpan(ctx)
defer func() { span.EndWithError(err) }()

View File

@@ -12,7 +12,6 @@ import (
"github.com/caos/zitadel/internal/api/authz"
http_utils "github.com/caos/zitadel/internal/api/http"
model2 "github.com/caos/zitadel/internal/auth_request/model"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/user/model"
@@ -207,8 +206,8 @@ func UILocalesToBusiness(tags []language.Tag) []string {
func GetSelectedIDPIDFromScopes(scopes oidc.SpaceDelimitedArray) string {
for _, scope := range scopes {
if strings.HasPrefix(scope, model2.SelectIDPScope) {
return strings.TrimPrefix(scope, model2.SelectIDPScope)
if strings.HasPrefix(scope, domain.SelectIDPScope) {
return strings.TrimPrefix(scope, domain.SelectIDPScope)
}
}
return ""

View File

@@ -11,7 +11,6 @@ import (
"github.com/caos/zitadel/internal/api/authz"
"github.com/caos/zitadel/internal/api/http"
authreq_model "github.com/caos/zitadel/internal/auth_request/model"
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
@@ -84,9 +83,9 @@ func (o *OPStorage) ValidateJWTProfileScopes(ctx context.Context, subject string
}
for i := len(scopes) - 1; i >= 0; i-- {
scope := scopes[i]
if strings.HasPrefix(scope, authreq_model.OrgDomainPrimaryScope) {
if strings.HasPrefix(scope, domain.OrgDomainPrimaryScope) {
var orgID string
org, err := o.query.OrgByDomainGlobal(ctx, strings.TrimPrefix(scope, authreq_model.OrgDomainPrimaryScope))
org, err := o.query.OrgByDomainGlobal(ctx, strings.TrimPrefix(scope, domain.OrgDomainPrimaryScope))
if err == nil {
orgID = org.ID
}
@@ -242,8 +241,8 @@ func (o *OPStorage) setUserinfo(ctx context.Context, userInfo oidc.UserInfoSette
if strings.HasPrefix(scope, ScopeProjectRolePrefix) {
roles = append(roles, strings.TrimPrefix(scope, ScopeProjectRolePrefix))
}
if strings.HasPrefix(scope, authreq_model.OrgDomainPrimaryScope) {
userInfo.AppendClaims(authreq_model.OrgDomainPrimaryClaim, strings.TrimPrefix(scope, authreq_model.OrgDomainPrimaryScope))
if strings.HasPrefix(scope, domain.OrgDomainPrimaryScope) {
userInfo.AppendClaims(domain.OrgDomainPrimaryClaim, strings.TrimPrefix(scope, domain.OrgDomainPrimaryScope))
}
}
}
@@ -283,8 +282,8 @@ func (o *OPStorage) GetPrivateClaimsFromScopes(ctx context.Context, userID, clie
}
if strings.HasPrefix(scope, ScopeProjectRolePrefix) {
roles = append(roles, strings.TrimPrefix(scope, ScopeProjectRolePrefix))
} else if strings.HasPrefix(scope, authreq_model.OrgDomainPrimaryScope) {
claims = appendClaim(claims, authreq_model.OrgDomainPrimaryClaim, strings.TrimPrefix(scope, authreq_model.OrgDomainPrimaryScope))
} else if strings.HasPrefix(scope, domain.OrgDomainPrimaryScope) {
claims = appendClaim(claims, domain.OrgDomainPrimaryClaim, strings.TrimPrefix(scope, domain.OrgDomainPrimaryScope))
}
}
if len(roles) == 0 || clientID == "" {

View File

@@ -7,7 +7,6 @@ import (
"github.com/caos/oidc/pkg/oidc"
"github.com/caos/oidc/pkg/op"
authreq_model "github.com/caos/zitadel/internal/auth_request/model"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/query"
@@ -101,13 +100,13 @@ func (c *Client) AccessTokenType() op.AccessTokenType {
}
func (c *Client) IsScopeAllowed(scope string) bool {
if strings.HasPrefix(scope, authreq_model.OrgDomainPrimaryScope) {
if strings.HasPrefix(scope, domain.OrgDomainPrimaryScope) {
return true
}
if strings.HasPrefix(scope, authreq_model.ProjectIDScope) {
if strings.HasPrefix(scope, domain.ProjectIDScope) {
return true
}
if strings.HasPrefix(scope, authreq_model.SelectIDPScope) {
if strings.HasPrefix(scope, domain.SelectIDPScope) {
return true
}
if strings.HasPrefix(scope, ScopeUserMetaData) {