mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
fix: rename iam to instance (#3345)
* 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: rename orgiampolicy to domain policy * fix: merge conflicts * fix: protos * fix: md files * implement deprecated org iam policy again Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
@@ -307,7 +307,7 @@ func shutdownServer(ctx context.Context, server *http.Server) error {
|
||||
|
||||
//TODO:!!??!!
|
||||
func consoleClientID(ctx context.Context, queries *query.Queries) (string, error) {
|
||||
iam, err := queries.IAM(ctx)
|
||||
iam, err := queries.Instance(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ and adds the user to the orgs members as ORG_OWNER
|
||||
> **rpc** GetIDPByID([GetIDPByIDRequest](#getidpbyidrequest))
|
||||
[GetIDPByIDResponse](#getidpbyidresponse)
|
||||
|
||||
Returns a identity provider configuration of the IAM
|
||||
Returns a identity provider configuration of the IAM instance
|
||||
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ Returns a identity provider configuration of the IAM
|
||||
> **rpc** ListIDPs([ListIDPsRequest](#listidpsrequest))
|
||||
[ListIDPsResponse](#listidpsresponse)
|
||||
|
||||
Returns all identity provider configurations of the IAM
|
||||
Returns all identity provider configurations of the IAM instance
|
||||
|
||||
|
||||
|
||||
@@ -315,7 +315,7 @@ Returns all identity provider configurations of the IAM
|
||||
> **rpc** AddOIDCIDP([AddOIDCIDPRequest](#addoidcidprequest))
|
||||
[AddOIDCIDPResponse](#addoidcidpresponse)
|
||||
|
||||
Adds a new oidc identity provider configuration the IAM
|
||||
Adds a new oidc identity provider configuration the IAM instance
|
||||
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ Adds a new oidc identity provider configuration the IAM
|
||||
> **rpc** AddJWTIDP([AddJWTIDPRequest](#addjwtidprequest))
|
||||
[AddJWTIDPResponse](#addjwtidpresponse)
|
||||
|
||||
Adds a new jwt identity provider configuration the IAM
|
||||
Adds a new jwt identity provider configuration the IAM instance
|
||||
|
||||
|
||||
|
||||
@@ -476,7 +476,8 @@ all fields are updated. If no value is provided the field will be empty afterwar
|
||||
> **rpc** GetOrgIAMPolicy([GetOrgIAMPolicyRequest](#getorgiampolicyrequest))
|
||||
[GetOrgIAMPolicyResponse](#getorgiampolicyresponse)
|
||||
|
||||
Returns the IAM policy defined by the administrators of ZITADEL
|
||||
deprecated: please use DomainPolicy instead
|
||||
Returns the Org IAM policy defined by the administrators of ZITADEL
|
||||
|
||||
|
||||
|
||||
@@ -488,7 +489,8 @@ Returns the IAM policy defined by the administrators of ZITADEL
|
||||
> **rpc** UpdateOrgIAMPolicy([UpdateOrgIAMPolicyRequest](#updateorgiampolicyrequest))
|
||||
[UpdateOrgIAMPolicyResponse](#updateorgiampolicyresponse)
|
||||
|
||||
Updates the default IAM policy.
|
||||
deprecated: please use DomainPolicy instead
|
||||
Updates the default OrgIAM policy.
|
||||
it impacts all organisations without a customised policy
|
||||
|
||||
|
||||
@@ -501,6 +503,7 @@ it impacts all organisations without a customised policy
|
||||
> **rpc** GetCustomOrgIAMPolicy([GetCustomOrgIAMPolicyRequest](#getcustomorgiampolicyrequest))
|
||||
[GetCustomOrgIAMPolicyResponse](#getcustomorgiampolicyresponse)
|
||||
|
||||
deprecated: please use DomainPolicy instead
|
||||
Returns the customised policy or the default if not customised
|
||||
|
||||
|
||||
@@ -513,7 +516,8 @@ Returns the customised policy or the default if not customised
|
||||
> **rpc** AddCustomOrgIAMPolicy([AddCustomOrgIAMPolicyRequest](#addcustomorgiampolicyrequest))
|
||||
[AddCustomOrgIAMPolicyResponse](#addcustomorgiampolicyresponse)
|
||||
|
||||
Defines a custom ORGIAM policy as specified
|
||||
deprecated: please use DomainPolicy instead
|
||||
Defines a custom OrgIAM policy as specified
|
||||
|
||||
|
||||
|
||||
@@ -525,7 +529,8 @@ Defines a custom ORGIAM policy as specified
|
||||
> **rpc** UpdateCustomOrgIAMPolicy([UpdateCustomOrgIAMPolicyRequest](#updatecustomorgiampolicyrequest))
|
||||
[UpdateCustomOrgIAMPolicyResponse](#updatecustomorgiampolicyresponse)
|
||||
|
||||
Updates a custom ORGIAM policy as specified
|
||||
deprecated: please use DomainPolicy instead
|
||||
Updates a custom OrgIAM policy as specified
|
||||
|
||||
|
||||
|
||||
@@ -537,6 +542,7 @@ Updates a custom ORGIAM policy as specified
|
||||
> **rpc** ResetCustomOrgIAMPolicyToDefault([ResetCustomOrgIAMPolicyToDefaultRequest](#resetcustomorgiampolicytodefaultrequest))
|
||||
[ResetCustomOrgIAMPolicyToDefaultResponse](#resetcustomorgiampolicytodefaultresponse)
|
||||
|
||||
deprecated: please use DomainPolicy instead
|
||||
Resets the org iam policy of the organisation to default
|
||||
ZITADEL will fallback to the default policy defined by the ZITADEL administrators
|
||||
|
||||
@@ -545,6 +551,80 @@ ZITADEL will fallback to the default policy defined by the ZITADEL administrator
|
||||
DELETE: /orgs/{org_id}/policies/orgiam
|
||||
|
||||
|
||||
### GetDomainPolicy
|
||||
|
||||
> **rpc** GetDomainPolicy([GetDomainPolicyRequest](#getdomainpolicyrequest))
|
||||
[GetDomainPolicyResponse](#getdomainpolicyresponse)
|
||||
|
||||
Returns the Domain policy defined by the administrators of ZITADEL
|
||||
|
||||
|
||||
|
||||
GET: /policies/domain
|
||||
|
||||
|
||||
### UpdateDomainPolicy
|
||||
|
||||
> **rpc** UpdateDomainPolicy([UpdateDomainPolicyRequest](#updatedomainpolicyrequest))
|
||||
[UpdateDomainPolicyResponse](#updatedomainpolicyresponse)
|
||||
|
||||
Updates the default Domain policy.
|
||||
it impacts all organisations without a customised policy
|
||||
|
||||
|
||||
|
||||
PUT: /policies/domain
|
||||
|
||||
|
||||
### GetCustomDomainPolicy
|
||||
|
||||
> **rpc** GetCustomDomainPolicy([GetCustomDomainPolicyRequest](#getcustomdomainpolicyrequest))
|
||||
[GetCustomDomainPolicyResponse](#getcustomdomainpolicyresponse)
|
||||
|
||||
Returns the customised policy or the default if not customised
|
||||
|
||||
|
||||
|
||||
GET: /orgs/{org_id}/policies/domain
|
||||
|
||||
|
||||
### AddCustomDomainPolicy
|
||||
|
||||
> **rpc** AddCustomDomainPolicy([AddCustomDomainPolicyRequest](#addcustomdomainpolicyrequest))
|
||||
[AddCustomDomainPolicyResponse](#addcustomdomainpolicyresponse)
|
||||
|
||||
Defines a custom Domain policy as specified
|
||||
|
||||
|
||||
|
||||
POST: /orgs/{org_id}/policies/domain
|
||||
|
||||
|
||||
### UpdateCustomDomainPolicy
|
||||
|
||||
> **rpc** UpdateCustomDomainPolicy([UpdateCustomDomainPolicyRequest](#updatecustomdomainpolicyrequest))
|
||||
[UpdateCustomDomainPolicyResponse](#updatecustomdomainpolicyresponse)
|
||||
|
||||
Updates a custom Domain policy as specified
|
||||
|
||||
|
||||
|
||||
PUT: /orgs/{org_id}/policies/domain
|
||||
|
||||
|
||||
### ResetCustomDomainPolicyToDefault
|
||||
|
||||
> **rpc** ResetCustomDomainPolicyToDefault([ResetCustomDomainPolicyToDefaultRequest](#resetcustomdomainpolicytodefaultrequest))
|
||||
[ResetCustomDomainPolicyToDefaultResponse](#resetcustomdomainpolicytodefaultresponse)
|
||||
|
||||
Resets the org iam policy of the organisation to default
|
||||
ZITADEL will fallback to the default policy defined by the ZITADEL administrators
|
||||
|
||||
|
||||
|
||||
DELETE: /orgs/{org_id}/policies/domain
|
||||
|
||||
|
||||
### GetLabelPolicy
|
||||
|
||||
> **rpc** GetLabelPolicy([GetLabelPolicyRequest](#getlabelpolicyrequest))
|
||||
@@ -1405,6 +1485,29 @@ This is an empty request
|
||||
|
||||
|
||||
|
||||
### AddCustomDomainPolicyRequest
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| org_id | string | - | string.min_len: 1<br /> string.max_len: 200<br /> |
|
||||
| user_login_must_be_domain | bool | the username has to end with the domain of it's organisation (uniqueness is organisation based) | |
|
||||
|
||||
|
||||
|
||||
|
||||
### AddCustomDomainPolicyResponse
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| details | zitadel.v1.ObjectDetails | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
### AddCustomOrgIAMPolicyRequest
|
||||
|
||||
|
||||
@@ -1679,6 +1782,29 @@ This is an empty response
|
||||
|
||||
|
||||
|
||||
### GetCustomDomainPolicyRequest
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| org_id | string | - | string.min_len: 1<br /> string.max_len: 200<br /> |
|
||||
|
||||
|
||||
|
||||
|
||||
### GetCustomDomainPolicyResponse
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| policy | zitadel.policy.v1.DomainPolicy | - | |
|
||||
| is_default | bool | deprecated: is_default is also defined in zitadel.policy.v1.DomainPolicy | |
|
||||
|
||||
|
||||
|
||||
|
||||
### GetCustomInitMessageTextRequest
|
||||
|
||||
|
||||
@@ -2022,6 +2148,23 @@ This is an empty request
|
||||
|
||||
|
||||
|
||||
### GetDomainPolicyRequest
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### GetDomainPolicyResponse
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| policy | zitadel.policy.v1.DomainPolicy | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
### GetFileSystemNotificationProviderRequest
|
||||
This is an empty request
|
||||
|
||||
@@ -2892,6 +3035,28 @@ This is an empty request
|
||||
|
||||
|
||||
|
||||
### ResetCustomDomainPolicyToDefaultRequest
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| org_id | string | - | string.min_len: 1<br /> string.max_len: 200<br /> |
|
||||
|
||||
|
||||
|
||||
|
||||
### ResetCustomDomainPolicyToDefaultResponse
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| details | zitadel.v1.ObjectDetails | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
### ResetCustomInitMessageTextToDefaultRequest
|
||||
|
||||
|
||||
@@ -3503,6 +3668,29 @@ This is an empty request
|
||||
|
||||
|
||||
|
||||
### UpdateCustomDomainPolicyRequest
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| org_id | string | - | string.min_len: 1<br /> string.max_len: 200<br /> |
|
||||
| user_login_must_be_domain | bool | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
### UpdateCustomDomainPolicyResponse
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| details | zitadel.v1.ObjectDetails | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
### UpdateCustomOrgIAMPolicyRequest
|
||||
|
||||
|
||||
@@ -3526,6 +3714,28 @@ This is an empty request
|
||||
|
||||
|
||||
|
||||
### UpdateDomainPolicyRequest
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| user_login_must_be_domain | bool | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
### UpdateDomainPolicyResponse
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| details | zitadel.v1.ObjectDetails | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
### UpdateIAMMemberRequest
|
||||
|
||||
|
||||
|
||||
@@ -1697,13 +1697,26 @@ remove a list of user grants in one request
|
||||
> **rpc** GetOrgIAMPolicy([GetOrgIAMPolicyRequest](#getorgiampolicyrequest))
|
||||
[GetOrgIAMPolicyResponse](#getorgiampolicyresponse)
|
||||
|
||||
Returns the org iam policy (this policy is managed by the iam administrator)
|
||||
deprecated: please use DomainPolicy instead
|
||||
Returns the domain policy (this policy is managed by the iam administrator)
|
||||
|
||||
|
||||
|
||||
GET: /policies/orgiam
|
||||
|
||||
|
||||
### GetDomainPolicy
|
||||
|
||||
> **rpc** GetDomainPolicy([GetDomainPolicyRequest](#getdomainpolicyrequest))
|
||||
[GetDomainPolicyResponse](#getdomainpolicyresponse)
|
||||
|
||||
Returns the domain policy (this policy is managed by the iam administrator)
|
||||
|
||||
|
||||
|
||||
GET: /policies/domain
|
||||
|
||||
|
||||
### GetLoginPolicy
|
||||
|
||||
> **rpc** GetLoginPolicy([GetLoginPolicyRequest](#getloginpolicyrequest))
|
||||
@@ -4540,6 +4553,23 @@ This is an empty request
|
||||
|
||||
|
||||
|
||||
### GetDomainPolicyRequest
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### GetDomainPolicyResponse
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| policy | zitadel.policy.v1.DomainPolicy | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
### GetFeaturesRequest
|
||||
|
||||
|
||||
@@ -4835,7 +4865,7 @@ This is an empty request
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| policy | zitadel.policy.v1.OrgIAMPolicy | - | |
|
||||
| policy | zitadel.policy.v1.DomainPolicy | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,19 @@ title: zitadel/policy.proto
|
||||
## Messages
|
||||
|
||||
|
||||
### DomainPolicy
|
||||
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
| ----- | ---- | ----------- | ----------- |
|
||||
| details | zitadel.v1.ObjectDetails | - | |
|
||||
| user_login_must_be_domain | bool | - | |
|
||||
| is_default | bool | - | |
|
||||
|
||||
|
||||
|
||||
|
||||
### LabelPolicy
|
||||
|
||||
|
||||
@@ -73,7 +86,7 @@ title: zitadel/policy.proto
|
||||
|
||||
|
||||
### OrgIAMPolicy
|
||||
|
||||
deprecated: please use DomainPolicy instead
|
||||
|
||||
|
||||
| Field | Type | Description | Validation |
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ type API struct {
|
||||
|
||||
type health interface {
|
||||
Health(ctx context.Context) error
|
||||
IAM(ctx context.Context) (*query.IAM, error)
|
||||
Instance(ctx context.Context) (*query.Instance, error)
|
||||
}
|
||||
|
||||
func New(
|
||||
@@ -107,7 +107,7 @@ func (a *API) healthHandler() http.Handler {
|
||||
return nil
|
||||
},
|
||||
func(ctx context.Context) error {
|
||||
iam, err := a.health.IAM(ctx)
|
||||
iam, err := a.health.Instance(ctx)
|
||||
if err != nil && !errors.IsNotFound(err) {
|
||||
return errors.ThrowPreconditionFailed(err, "API-dsgT2", "IAM SETUP CHECK FAILED")
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (s *Server) SetDefaultInitMessageText(ctx context.Context, req *admin_pb.Se
|
||||
}
|
||||
|
||||
func (s *Server) ResetCustomInitMessageTextToDefault(ctx context.Context, req *admin_pb.ResetCustomInitMessageTextToDefaultRequest) (*admin_pb.ResetCustomInitMessageTextToDefaultResponse, error) {
|
||||
result, err := s.command.RemoveIAMMessageTexts(ctx, domain.InitCodeMessageType, language.Make(req.Language))
|
||||
result, err := s.command.RemoveInstanceMessageTexts(ctx, domain.InitCodeMessageType, language.Make(req.Language))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func (s *Server) SetDefaultPasswordResetMessageText(ctx context.Context, req *ad
|
||||
}
|
||||
|
||||
func (s *Server) ResetCustomPasswordResetMessageTextToDefault(ctx context.Context, req *admin_pb.ResetCustomPasswordResetMessageTextToDefaultRequest) (*admin_pb.ResetCustomPasswordResetMessageTextToDefaultResponse, error) {
|
||||
result, err := s.command.RemoveIAMMessageTexts(ctx, domain.PasswordResetMessageType, language.Make(req.Language))
|
||||
result, err := s.command.RemoveInstanceMessageTexts(ctx, domain.PasswordResetMessageType, language.Make(req.Language))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func (s *Server) SetDefaultVerifyEmailMessageText(ctx context.Context, req *admi
|
||||
}
|
||||
|
||||
func (s *Server) ResetCustomVerifyEmailMessageTextToDefault(ctx context.Context, req *admin_pb.ResetCustomVerifyEmailMessageTextToDefaultRequest) (*admin_pb.ResetCustomVerifyEmailMessageTextToDefaultResponse, error) {
|
||||
result, err := s.command.RemoveIAMMessageTexts(ctx, domain.VerifyEmailMessageType, language.Make(req.Language))
|
||||
result, err := s.command.RemoveInstanceMessageTexts(ctx, domain.VerifyEmailMessageType, language.Make(req.Language))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -190,7 +190,7 @@ func (s *Server) SetDefaultVerifyPhoneMessageText(ctx context.Context, req *admi
|
||||
}
|
||||
|
||||
func (s *Server) ResetCustomVerifyPhoneMessageTextToDefault(ctx context.Context, req *admin_pb.ResetCustomVerifyPhoneMessageTextToDefaultRequest) (*admin_pb.ResetCustomVerifyPhoneMessageTextToDefaultResponse, error) {
|
||||
result, err := s.command.RemoveIAMMessageTexts(ctx, domain.VerifyPhoneMessageType, language.Make(req.Language))
|
||||
result, err := s.command.RemoveInstanceMessageTexts(ctx, domain.VerifyPhoneMessageType, language.Make(req.Language))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func (s *Server) SetDefaultDomainClaimedMessageText(ctx context.Context, req *ad
|
||||
}
|
||||
|
||||
func (s *Server) ResetCustomDomainClaimedMessageTextToDefault(ctx context.Context, req *admin_pb.ResetCustomDomainClaimedMessageTextToDefaultRequest) (*admin_pb.ResetCustomDomainClaimedMessageTextToDefaultResponse, error) {
|
||||
result, err := s.command.RemoveIAMMessageTexts(ctx, domain.DomainClaimedMessageType, language.Make(req.Language))
|
||||
result, err := s.command.RemoveInstanceMessageTexts(ctx, domain.DomainClaimedMessageType, language.Make(req.Language))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -286,7 +286,7 @@ func (s *Server) SetDefaultPasswordlessRegistrationMessageText(ctx context.Conte
|
||||
}
|
||||
|
||||
func (s *Server) ResetCustomPasswordlessRegistrationMessageTextToDefault(ctx context.Context, req *admin_pb.ResetCustomPasswordlessRegistrationMessageTextToDefaultRequest) (*admin_pb.ResetCustomPasswordlessRegistrationMessageTextToDefaultResponse, error) {
|
||||
result, err := s.command.RemoveIAMMessageTexts(ctx, domain.PasswordlessRegistrationMessageType, language.Make(req.Language))
|
||||
result, err := s.command.RemoveInstanceMessageTexts(ctx, domain.PasswordlessRegistrationMessageType, language.Make(req.Language))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -319,7 +319,7 @@ func (s *Server) GetCustomLoginTexts(ctx context.Context, req *admin_pb.GetCusto
|
||||
}
|
||||
|
||||
func (s *Server) SetCustomLoginText(ctx context.Context, req *admin_pb.SetCustomLoginTextsRequest) (*admin_pb.SetCustomLoginTextsResponse, error) {
|
||||
result, err := s.command.SetCustomIAMLoginText(ctx, SetLoginTextToDomain(req))
|
||||
result, err := s.command.SetCustomInstanceLoginText(ctx, SetLoginTextToDomain(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -333,7 +333,7 @@ func (s *Server) SetCustomLoginText(ctx context.Context, req *admin_pb.SetCustom
|
||||
}
|
||||
|
||||
func (s *Server) ResetCustomLoginTextToDefault(ctx context.Context, req *admin_pb.ResetCustomLoginTextsToDefaultRequest) (*admin_pb.ResetCustomLoginTextsToDefaultResponse, error) {
|
||||
result, err := s.command.RemoveCustomIAMLoginTexts(ctx, language.Make(req.Language))
|
||||
result, err := s.command.RemoveCustomInstanceLoginTexts(ctx, language.Make(req.Language))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/grpc/object"
|
||||
policy_grpc "github.com/caos/zitadel/internal/api/grpc/policy"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
admin_pb "github.com/caos/zitadel/pkg/grpc/admin"
|
||||
)
|
||||
|
||||
func (s *Server) GetDomainPolicy(ctx context.Context, _ *admin_pb.GetDomainPolicyRequest) (*admin_pb.GetDomainPolicyResponse, error) {
|
||||
policy, err := s.query.DefaultDomainPolicy(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.GetDomainPolicyResponse{Policy: policy_grpc.DomainPolicyToPb(policy)}, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetCustomDomainPolicy(ctx context.Context, req *admin_pb.GetCustomDomainPolicyRequest) (*admin_pb.GetCustomDomainPolicyResponse, error) {
|
||||
policy, err := s.query.DomainPolicyByOrg(ctx, req.OrgId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.GetCustomDomainPolicyResponse{Policy: policy_grpc.DomainPolicyToPb(policy)}, nil
|
||||
}
|
||||
|
||||
func (s *Server) AddCustomOrgIAMPolicy(ctx context.Context, req *admin_pb.AddCustomOrgIAMPolicyRequest) (*admin_pb.AddCustomOrgIAMPolicyResponse, error) {
|
||||
policy, err := s.command.AddOrgDomainPolicy(ctx, req.OrgId, domainPolicyToDomain(req.UserLoginMustBeDomain))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.AddCustomOrgIAMPolicyResponse{
|
||||
Details: object.AddToDetailsPb(
|
||||
policy.Sequence,
|
||||
policy.ChangeDate,
|
||||
policy.ResourceOwner,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateOrgIAMPolicy(ctx context.Context, req *admin_pb.UpdateOrgIAMPolicyRequest) (*admin_pb.UpdateOrgIAMPolicyResponse, error) {
|
||||
config, err := s.command.ChangeDefaultDomainPolicy(ctx, updateOrgIAMPolicyToDomain(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.UpdateOrgIAMPolicyResponse{
|
||||
Details: object.ChangeToDetailsPb(
|
||||
config.Sequence,
|
||||
config.ChangeDate,
|
||||
config.ResourceOwner,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateCustomOrgIAMPolicy(ctx context.Context, req *admin_pb.UpdateCustomOrgIAMPolicyRequest) (*admin_pb.UpdateCustomOrgIAMPolicyResponse, error) {
|
||||
config, err := s.command.ChangeOrgDomainPolicy(ctx, req.OrgId, updateCustomOrgIAMPolicyToDomain(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.UpdateCustomOrgIAMPolicyResponse{
|
||||
Details: object.ChangeToDetailsPb(
|
||||
config.Sequence,
|
||||
config.ChangeDate,
|
||||
config.ResourceOwner,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetOrgIAMPolicy(ctx context.Context, _ *admin_pb.GetOrgIAMPolicyRequest) (*admin_pb.GetOrgIAMPolicyResponse, error) {
|
||||
policy, err := s.query.DefaultDomainPolicy(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.GetOrgIAMPolicyResponse{Policy: policy_grpc.DomainPolicyToOrgIAMPb(policy)}, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetCustomOrgIAMPolicy(ctx context.Context, req *admin_pb.GetCustomOrgIAMPolicyRequest) (*admin_pb.GetCustomOrgIAMPolicyResponse, error) {
|
||||
policy, err := s.query.DomainPolicyByOrg(ctx, req.OrgId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.GetCustomOrgIAMPolicyResponse{Policy: policy_grpc.DomainPolicyToOrgIAMPb(policy)}, nil
|
||||
}
|
||||
|
||||
func (s *Server) AddCustomDomainPolicy(ctx context.Context, req *admin_pb.AddCustomDomainPolicyRequest) (*admin_pb.AddCustomDomainPolicyResponse, error) {
|
||||
policy, err := s.command.AddOrgDomainPolicy(ctx, req.OrgId, domainPolicyToDomain(req.UserLoginMustBeDomain))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.AddCustomDomainPolicyResponse{
|
||||
Details: object.AddToDetailsPb(
|
||||
policy.Sequence,
|
||||
policy.ChangeDate,
|
||||
policy.ResourceOwner,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateDomainPolicy(ctx context.Context, req *admin_pb.UpdateDomainPolicyRequest) (*admin_pb.UpdateDomainPolicyResponse, error) {
|
||||
config, err := s.command.ChangeDefaultDomainPolicy(ctx, updateDomainPolicyToDomain(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.UpdateDomainPolicyResponse{
|
||||
Details: object.ChangeToDetailsPb(
|
||||
config.Sequence,
|
||||
config.ChangeDate,
|
||||
config.ResourceOwner,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateCustomDomainPolicy(ctx context.Context, req *admin_pb.UpdateCustomDomainPolicyRequest) (*admin_pb.UpdateCustomDomainPolicyResponse, error) {
|
||||
config, err := s.command.ChangeOrgDomainPolicy(ctx, req.OrgId, updateCustomDomainPolicyToDomain(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.UpdateCustomDomainPolicyResponse{
|
||||
Details: object.ChangeToDetailsPb(
|
||||
config.Sequence,
|
||||
config.ChangeDate,
|
||||
config.ResourceOwner,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) ResetCustomDomainPolicyTo(ctx context.Context, req *admin_pb.ResetCustomDomainPolicyToDefaultRequest) (*admin_pb.ResetCustomDomainPolicyToDefaultResponse, error) {
|
||||
err := s.command.RemoveOrgDomainPolicy(ctx, req.OrgId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil //TOOD: return data
|
||||
}
|
||||
|
||||
func domainPolicyToDomain(userLoginMustBeDomain bool) *domain.DomainPolicy {
|
||||
return &domain.DomainPolicy{
|
||||
UserLoginMustBeDomain: userLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
|
||||
func updateDomainPolicyToDomain(req *admin_pb.UpdateDomainPolicyRequest) *domain.DomainPolicy {
|
||||
return &domain.DomainPolicy{
|
||||
// ObjectRoot: models.ObjectRoot{
|
||||
// // AggreagateID: //TODO: there should only be ONE default
|
||||
// },
|
||||
UserLoginMustBeDomain: req.UserLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
|
||||
func updateCustomDomainPolicyToDomain(req *admin_pb.UpdateCustomDomainPolicyRequest) *domain.DomainPolicy {
|
||||
return &domain.DomainPolicy{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: req.OrgId,
|
||||
},
|
||||
UserLoginMustBeDomain: req.UserLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
|
||||
func updateOrgIAMPolicyToDomain(req *admin_pb.UpdateOrgIAMPolicyRequest) *domain.DomainPolicy {
|
||||
return &domain.DomainPolicy{
|
||||
UserLoginMustBeDomain: req.UserLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
|
||||
func updateCustomOrgIAMPolicyToDomain(req *admin_pb.UpdateCustomOrgIAMPolicyRequest) *domain.DomainPolicy {
|
||||
return &domain.DomainPolicy{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: req.OrgId,
|
||||
},
|
||||
UserLoginMustBeDomain: req.UserLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func (s *Server) ListIAMMembers(ctx context.Context, req *admin_pb.ListIAMMember
|
||||
}
|
||||
|
||||
func (s *Server) AddIAMMember(ctx context.Context, req *admin_pb.AddIAMMemberRequest) (*admin_pb.AddIAMMemberResponse, error) {
|
||||
member, err := s.command.AddIAMMember(ctx, AddIAMMemberToDomain(req))
|
||||
member, err := s.command.AddInstanceMember(ctx, AddIAMMemberToDomain(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (s *Server) AddIAMMember(ctx context.Context, req *admin_pb.AddIAMMemberReq
|
||||
}
|
||||
|
||||
func (s *Server) UpdateIAMMember(ctx context.Context, req *admin_pb.UpdateIAMMemberRequest) (*admin_pb.UpdateIAMMemberResponse, error) {
|
||||
member, err := s.command.ChangeIAMMember(ctx, UpdateIAMMemberToDomain(req))
|
||||
member, err := s.command.ChangeInstanceMember(ctx, UpdateIAMMemberToDomain(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (s *Server) UpdateIAMMember(ctx context.Context, req *admin_pb.UpdateIAMMem
|
||||
}
|
||||
|
||||
func (s *Server) RemoveIAMMember(ctx context.Context, req *admin_pb.RemoveIAMMemberRequest) (*admin_pb.RemoveIAMMemberResponse, error) {
|
||||
objectDetails, err := s.command.RemoveIAMMember(ctx, req.UserId)
|
||||
objectDetails, err := s.command.RemoveInstanceMember(ctx, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/grpc/object"
|
||||
policy_grpc "github.com/caos/zitadel/internal/api/grpc/policy"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
admin_pb "github.com/caos/zitadel/pkg/grpc/admin"
|
||||
)
|
||||
|
||||
func (s *Server) GetOrgIAMPolicy(ctx context.Context, _ *admin_pb.GetOrgIAMPolicyRequest) (*admin_pb.GetOrgIAMPolicyResponse, error) {
|
||||
policy, err := s.query.DefaultOrgIAMPolicy(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.GetOrgIAMPolicyResponse{Policy: policy_grpc.OrgIAMPolicyToPb(policy)}, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetCustomOrgIAMPolicy(ctx context.Context, req *admin_pb.GetCustomOrgIAMPolicyRequest) (*admin_pb.GetCustomOrgIAMPolicyResponse, error) {
|
||||
policy, err := s.query.OrgIAMPolicyByOrg(ctx, req.OrgId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.GetCustomOrgIAMPolicyResponse{Policy: policy_grpc.OrgIAMPolicyToPb(policy)}, nil
|
||||
}
|
||||
|
||||
func (s *Server) AddCustomOrgIAMPolicy(ctx context.Context, req *admin_pb.AddCustomOrgIAMPolicyRequest) (*admin_pb.AddCustomOrgIAMPolicyResponse, error) {
|
||||
policy, err := s.command.AddOrgIAMPolicy(ctx, req.OrgId, toDomainOrgIAMPolicy(req.UserLoginMustBeDomain))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.AddCustomOrgIAMPolicyResponse{
|
||||
Details: object.AddToDetailsPb(
|
||||
policy.Sequence,
|
||||
policy.ChangeDate,
|
||||
policy.ResourceOwner,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateOrgIAMPolicy(ctx context.Context, req *admin_pb.UpdateOrgIAMPolicyRequest) (*admin_pb.UpdateOrgIAMPolicyResponse, error) {
|
||||
config, err := s.command.ChangeDefaultOrgIAMPolicy(ctx, updateOrgIAMPolicyToDomain(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.UpdateOrgIAMPolicyResponse{
|
||||
Details: object.ChangeToDetailsPb(
|
||||
config.Sequence,
|
||||
config.ChangeDate,
|
||||
config.ResourceOwner,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateCustomOrgIAMPolicy(ctx context.Context, req *admin_pb.UpdateCustomOrgIAMPolicyRequest) (*admin_pb.UpdateCustomOrgIAMPolicyResponse, error) {
|
||||
config, err := s.command.ChangeOrgIAMPolicy(ctx, req.OrgId, updateCustomOrgIAMPolicyToDomain(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &admin_pb.UpdateCustomOrgIAMPolicyResponse{
|
||||
Details: object.ChangeToDetailsPb(
|
||||
config.Sequence,
|
||||
config.ChangeDate,
|
||||
config.ResourceOwner,
|
||||
),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) ResetCustomOrgIAMPolicyTo(ctx context.Context, req *admin_pb.ResetCustomOrgIAMPolicyToDefaultRequest) (*admin_pb.ResetCustomOrgIAMPolicyToDefaultResponse, error) {
|
||||
err := s.command.RemoveOrgIAMPolicy(ctx, req.OrgId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil //TOOD: return data
|
||||
}
|
||||
|
||||
func toDomainOrgIAMPolicy(userLoginMustBeDomain bool) *domain.OrgIAMPolicy {
|
||||
return &domain.OrgIAMPolicy{
|
||||
UserLoginMustBeDomain: userLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
|
||||
func updateOrgIAMPolicyToDomain(req *admin_pb.UpdateOrgIAMPolicyRequest) *domain.OrgIAMPolicy {
|
||||
return &domain.OrgIAMPolicy{
|
||||
// ObjectRoot: models.ObjectRoot{
|
||||
// // AggreagateID: //TODO: there should only be ONE default
|
||||
// },
|
||||
UserLoginMustBeDomain: req.UserLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
|
||||
func updateCustomOrgIAMPolicyToDomain(req *admin_pb.UpdateCustomOrgIAMPolicyRequest) *domain.OrgIAMPolicy {
|
||||
return &domain.OrgIAMPolicy{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: req.OrgId,
|
||||
},
|
||||
UserLoginMustBeDomain: req.UserLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,7 @@ func (s *Server) ListMyProjectOrgs(ctx context.Context, req *auth_pb.ListMyProje
|
||||
return nil, err
|
||||
}
|
||||
|
||||
iam, err := s.query.IAM(ctx)
|
||||
iam, err := s.query.Instance(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Server) GetIAM(ctx context.Context, _ *mgmt_pb.GetIAMRequest) (*mgmt_pb.GetIAMResponse, error) {
|
||||
iam, err := s.query.IAM(ctx)
|
||||
iam, err := s.query.Instance(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -102,13 +102,13 @@ func (s *Server) ReactivateOrg(ctx context.Context, req *mgmt_pb.ReactivateOrgRe
|
||||
}, err
|
||||
}
|
||||
|
||||
func (s *Server) GetOrgIAMPolicy(ctx context.Context, req *mgmt_pb.GetOrgIAMPolicyRequest) (*mgmt_pb.GetOrgIAMPolicyResponse, error) {
|
||||
policy, err := s.query.OrgIAMPolicyByOrg(ctx, authz.GetCtxData(ctx).OrgID)
|
||||
func (s *Server) GetDomainPolicy(ctx context.Context, req *mgmt_pb.GetDomainPolicyRequest) (*mgmt_pb.GetDomainPolicyResponse, error) {
|
||||
policy, err := s.query.DomainPolicyByOrg(ctx, authz.GetCtxData(ctx).OrgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &mgmt_pb.GetOrgIAMPolicyResponse{
|
||||
Policy: policy_grpc.OrgIAMPolicyToPb(policy),
|
||||
return &mgmt_pb.GetDomainPolicyResponse{
|
||||
Policy: policy_grpc.DomainPolicyToPb(policy),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ func (s *Server) SetPrimaryOrgDomain(ctx context.Context, req *mgmt_pb.SetPrimar
|
||||
}
|
||||
|
||||
func (s *Server) ListOrgMemberRoles(ctx context.Context, _ *mgmt_pb.ListOrgMemberRolesRequest) (*mgmt_pb.ListOrgMemberRolesResponse, error) {
|
||||
iam, err := s.query.IAM(ctx)
|
||||
iam, err := s.query.Instance(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func (s *Server) ListUserChanges(ctx context.Context, req *mgmt_pb.ListUserChang
|
||||
|
||||
func (s *Server) IsUserUnique(ctx context.Context, req *mgmt_pb.IsUserUniqueRequest) (*mgmt_pb.IsUserUniqueResponse, error) {
|
||||
orgID := authz.GetCtxData(ctx).OrgID
|
||||
policy, err := s.query.OrgIAMPolicyByOrg(ctx, orgID)
|
||||
policy, err := s.query.DomainPolicyByOrg(ctx, orgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+14
-1
@@ -6,7 +6,20 @@ import (
|
||||
policy_pb "github.com/caos/zitadel/pkg/grpc/policy"
|
||||
)
|
||||
|
||||
func OrgIAMPolicyToPb(policy *query.OrgIAMPolicy) *policy_pb.OrgIAMPolicy {
|
||||
func DomainPolicyToPb(policy *query.DomainPolicy) *policy_pb.DomainPolicy {
|
||||
return &policy_pb.DomainPolicy{
|
||||
UserLoginMustBeDomain: policy.UserLoginMustBeDomain,
|
||||
IsDefault: policy.IsDefault,
|
||||
Details: object.ToViewDetailsPb(
|
||||
policy.Sequence,
|
||||
policy.CreationDate,
|
||||
policy.ChangeDate,
|
||||
policy.ResourceOwner,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func DomainPolicyToOrgIAMPb(policy *query.DomainPolicy) *policy_pb.OrgIAMPolicy {
|
||||
return &policy_pb.OrgIAMPolicy{
|
||||
UserLoginMustBeDomain: policy.UserLoginMustBeDomain,
|
||||
IsDefault: policy.IsDefault,
|
||||
@@ -16,7 +16,7 @@ func (l *Login) customExternalUserMapping(ctx context.Context, user *domain.Exte
|
||||
resourceOwner = config.AggregateID
|
||||
}
|
||||
if resourceOwner == domain.IAMID {
|
||||
iam, err := l.query.IAM(ctx)
|
||||
iam, err := l.query.Instance(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ func (l *Login) handleExternalUserAuthenticated(w http.ResponseWriter, r *http.R
|
||||
if errors.IsNotFound(err) {
|
||||
err = nil
|
||||
}
|
||||
iam, err := l.query.IAM(r.Context())
|
||||
iam, err := l.query.Instance(r.Context())
|
||||
if err != nil {
|
||||
l.renderExternalNotFoundOption(w, r, authReq, nil, nil, nil, nil, err)
|
||||
return
|
||||
@@ -220,7 +220,7 @@ func (l *Login) handleExternalUserAuthenticated(w http.ResponseWriter, r *http.R
|
||||
resourceOwner = authReq.RequestedOrgID
|
||||
}
|
||||
|
||||
orgIAMPolicy, err := l.getOrgIamPolicy(r, resourceOwner)
|
||||
orgIAMPolicy, err := l.getOrgDomainPolicy(r, resourceOwner)
|
||||
if err != nil {
|
||||
l.renderExternalNotFoundOption(w, r, authReq, nil, nil, nil, nil, err)
|
||||
return
|
||||
@@ -253,13 +253,13 @@ func (l *Login) handleExternalUserAuthenticated(w http.ResponseWriter, r *http.R
|
||||
l.renderNextStep(w, r, authReq)
|
||||
}
|
||||
|
||||
func (l *Login) renderExternalNotFoundOption(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, iam *query.IAM, orgIAMPolicy *query.OrgIAMPolicy, human *domain.Human, externalIDP *domain.UserIDPLink, err error) {
|
||||
func (l *Login) renderExternalNotFoundOption(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, iam *query.Instance, orgIAMPolicy *query.DomainPolicy, human *domain.Human, externalIDP *domain.UserIDPLink, err error) {
|
||||
var errID, errMessage string
|
||||
if err != nil {
|
||||
errID, errMessage = l.getErrorMessage(r, err)
|
||||
}
|
||||
if orgIAMPolicy == nil {
|
||||
iam, err = l.query.IAM(r.Context())
|
||||
iam, err = l.query.Instance(r.Context())
|
||||
if err != nil {
|
||||
l.renderError(w, r, authReq, err)
|
||||
return
|
||||
@@ -270,7 +270,7 @@ func (l *Login) renderExternalNotFoundOption(w http.ResponseWriter, r *http.Requ
|
||||
resourceOwner = authReq.RequestedOrgID
|
||||
}
|
||||
|
||||
orgIAMPolicy, err = l.getOrgIamPolicy(r, resourceOwner)
|
||||
orgIAMPolicy, err = l.getOrgDomainPolicy(r, resourceOwner)
|
||||
if err != nil {
|
||||
l.renderError(w, r, authReq, err)
|
||||
return
|
||||
@@ -341,7 +341,7 @@ func (l *Login) handleExternalNotFoundOptionCheck(w http.ResponseWriter, r *http
|
||||
}
|
||||
|
||||
func (l *Login) handleAutoRegister(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest) {
|
||||
iam, err := l.query.IAM(r.Context())
|
||||
iam, err := l.query.Instance(r.Context())
|
||||
if err != nil {
|
||||
l.renderExternalNotFoundOption(w, r, authReq, nil, nil, nil, nil, err)
|
||||
return
|
||||
@@ -355,7 +355,7 @@ func (l *Login) handleAutoRegister(w http.ResponseWriter, r *http.Request, authR
|
||||
resourceOwner = authReq.RequestedOrgID
|
||||
}
|
||||
|
||||
orgIamPolicy, err := l.getOrgIamPolicy(r, resourceOwner)
|
||||
orgIamPolicy, err := l.getOrgDomainPolicy(r, resourceOwner)
|
||||
if err != nil {
|
||||
l.renderExternalNotFoundOption(w, r, authReq, nil, nil, nil, nil, err)
|
||||
return
|
||||
@@ -433,7 +433,7 @@ func (l *Login) mapTokenToLoginUser(tokens *oidc.Tokens, idpConfig *iam_model.ID
|
||||
}
|
||||
return externalUser
|
||||
}
|
||||
func (l *Login) mapExternalUserToLoginUser(orgIamPolicy *query.OrgIAMPolicy, linkingUser *domain.ExternalUser, idpConfig *iam_model.IDPConfigView) (*domain.Human, *domain.UserIDPLink, []*domain.Metadata) {
|
||||
func (l *Login) mapExternalUserToLoginUser(orgIamPolicy *query.DomainPolicy, linkingUser *domain.ExternalUser, idpConfig *iam_model.IDPConfigView) (*domain.Human, *domain.UserIDPLink, []*domain.Metadata) {
|
||||
username := linkingUser.PreferredUsername
|
||||
switch idpConfig.OIDCUsernameMapping {
|
||||
case iam_model.OIDCMappingFieldEmail:
|
||||
|
||||
@@ -114,7 +114,7 @@ func (l *Login) handleExternalRegisterCallback(w http.ResponseWriter, r *http.Re
|
||||
}
|
||||
|
||||
func (l *Login) handleExternalUserRegister(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, idpConfig *iam_model.IDPConfigView, userAgentID string, tokens *oidc.Tokens) {
|
||||
iam, err := l.query.IAM(r.Context())
|
||||
iam, err := l.query.Instance(r.Context())
|
||||
if err != nil {
|
||||
l.renderRegisterOption(w, r, authReq, err)
|
||||
return
|
||||
@@ -123,7 +123,7 @@ func (l *Login) handleExternalUserRegister(w http.ResponseWriter, r *http.Reques
|
||||
if authReq.RequestedOrgID != "" {
|
||||
resourceOwner = authReq.RequestedOrgID
|
||||
}
|
||||
orgIamPolicy, err := l.getOrgIamPolicy(r, resourceOwner)
|
||||
orgIamPolicy, err := l.getOrgDomainPolicy(r, resourceOwner)
|
||||
if err != nil {
|
||||
l.renderRegisterOption(w, r, authReq, err)
|
||||
return
|
||||
@@ -140,7 +140,7 @@ func (l *Login) handleExternalUserRegister(w http.ResponseWriter, r *http.Reques
|
||||
l.registerExternalUser(w, r, authReq, iam, user, externalIDP)
|
||||
}
|
||||
|
||||
func (l *Login) registerExternalUser(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, iam *query.IAM, user *domain.Human, externalIDP *domain.UserIDPLink) {
|
||||
func (l *Login) registerExternalUser(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, iam *query.Instance, user *domain.Human, externalIDP *domain.UserIDPLink) {
|
||||
resourceOwner := iam.GlobalOrgID
|
||||
memberRoles := []string{domain.RoleSelfManagementGlobal}
|
||||
|
||||
@@ -166,7 +166,7 @@ func (l *Login) registerExternalUser(w http.ResponseWriter, r *http.Request, aut
|
||||
l.renderNextStep(w, r, authReq)
|
||||
}
|
||||
|
||||
func (l *Login) renderExternalRegisterOverview(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, orgIAMPolicy *query.OrgIAMPolicy, human *domain.Human, idp *domain.UserIDPLink, err error) {
|
||||
func (l *Login) renderExternalRegisterOverview(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, orgIAMPolicy *query.DomainPolicy, human *domain.Human, idp *domain.UserIDPLink, err error) {
|
||||
var errID, errMessage string
|
||||
if err != nil {
|
||||
errID, errMessage = l.getErrorMessage(r, err)
|
||||
@@ -207,7 +207,7 @@ func (l *Login) handleExternalRegisterCheck(w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
iam, err := l.query.IAM(r.Context())
|
||||
iam, err := l.query.Instance(r.Context())
|
||||
if err != nil {
|
||||
l.renderRegisterOption(w, r, authReq, err)
|
||||
return
|
||||
@@ -247,7 +247,7 @@ func (l *Login) handleExternalRegisterCheck(w http.ResponseWriter, r *http.Reque
|
||||
l.renderNextStep(w, r, authReq)
|
||||
}
|
||||
|
||||
func (l *Login) mapTokenToLoginHumanAndExternalIDP(orgIamPolicy *query.OrgIAMPolicy, tokens *oidc.Tokens, idpConfig *iam_model.IDPConfigView) (*domain.Human, *domain.UserIDPLink) {
|
||||
func (l *Login) mapTokenToLoginHumanAndExternalIDP(orgIamPolicy *query.DomainPolicy, tokens *oidc.Tokens, idpConfig *iam_model.IDPConfigView) (*domain.Human, *domain.UserIDPLink) {
|
||||
username := tokens.IDTokenClaims.GetPreferredUsername()
|
||||
switch idpConfig.OIDCUsernameMapping {
|
||||
case iam_model.OIDCMappingFieldEmail:
|
||||
|
||||
@@ -123,7 +123,7 @@ func (l *Login) jwtExtractionUserNotFound(w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
resourceOwner := l.getOrgID(authReq)
|
||||
orgIamPolicy, err := l.getOrgIamPolicy(r, resourceOwner)
|
||||
orgIamPolicy, err := l.getOrgDomainPolicy(r, resourceOwner)
|
||||
if err != nil {
|
||||
l.renderError(w, r, authReq, err)
|
||||
return
|
||||
|
||||
@@ -7,15 +7,15 @@ import (
|
||||
"github.com/caos/zitadel/internal/query"
|
||||
)
|
||||
|
||||
func (l *Login) getDefaultOrgIamPolicy(r *http.Request) (*query.OrgIAMPolicy, error) {
|
||||
return l.query.DefaultOrgIAMPolicy(r.Context())
|
||||
func (l *Login) getDefaultDomainPolicy(r *http.Request) (*query.DomainPolicy, error) {
|
||||
return l.query.DefaultDomainPolicy(r.Context())
|
||||
}
|
||||
|
||||
func (l *Login) getOrgIamPolicy(r *http.Request, orgID string) (*query.OrgIAMPolicy, error) {
|
||||
func (l *Login) getOrgDomainPolicy(r *http.Request, orgID string) (*query.DomainPolicy, error) {
|
||||
if orgID == "" {
|
||||
return l.query.DefaultOrgIAMPolicy(r.Context())
|
||||
return l.query.DefaultDomainPolicy(r.Context())
|
||||
}
|
||||
return l.query.OrgIAMPolicyByOrg(r.Context(), orgID)
|
||||
return l.query.DomainPolicyByOrg(r.Context(), orgID)
|
||||
}
|
||||
|
||||
func (l *Login) getIDPConfigByID(r *http.Request, idpConfigID string) (*iam_model.IDPConfigView, error) {
|
||||
|
||||
@@ -62,7 +62,7 @@ func (l *Login) handleRegisterCheck(w http.ResponseWriter, r *http.Request) {
|
||||
l.renderRegister(w, r, authRequest, data, err)
|
||||
return
|
||||
}
|
||||
iam, err := l.query.IAM(r.Context())
|
||||
iam, err := l.query.Instance(r.Context())
|
||||
if err != nil {
|
||||
l.renderRegister(w, r, authRequest, data, err)
|
||||
return
|
||||
@@ -127,7 +127,7 @@ func (l *Login) renderRegister(w http.ResponseWriter, r *http.Request, authReque
|
||||
}
|
||||
|
||||
if resourceOwner == "" {
|
||||
iam, err := l.query.IAM(r.Context())
|
||||
iam, err := l.query.Instance(r.Context())
|
||||
if err != nil {
|
||||
l.renderRegister(w, r, authRequest, formData, err)
|
||||
return
|
||||
@@ -153,7 +153,7 @@ func (l *Login) renderRegister(w http.ResponseWriter, r *http.Request, authReque
|
||||
}
|
||||
}
|
||||
|
||||
orgIAMPolicy, err := l.getOrgIamPolicy(r, resourceOwner)
|
||||
orgIAMPolicy, err := l.getOrgDomainPolicy(r, resourceOwner)
|
||||
if err != nil {
|
||||
l.renderRegister(w, r, authRequest, formData, err)
|
||||
return
|
||||
|
||||
@@ -116,7 +116,7 @@ func (l *Login) renderRegisterOrg(w http.ResponseWriter, r *http.Request, authRe
|
||||
data.HasNumber = NumberRegex
|
||||
}
|
||||
}
|
||||
orgPolicy, _ := l.getDefaultOrgIamPolicy(r)
|
||||
orgPolicy, _ := l.getDefaultDomainPolicy(r)
|
||||
if orgPolicy != nil {
|
||||
data.UserLoginMustBeDomain = orgPolicy.UserLoginMustBeDomain
|
||||
data.IamDomain = l.iamDomain
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
iam_view_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/query"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type OrgRepository struct {
|
||||
@@ -53,5 +53,5 @@ func (repo *OrgRepository) GetLoginText(ctx context.Context, orgID string) ([]*d
|
||||
}
|
||||
|
||||
func (p *OrgRepository) getIAMEvents(ctx context.Context, sequence uint64) ([]*models.Event, error) {
|
||||
return p.Eventstore.FilterEvents(ctx, models.NewSearchQuery().AggregateIDFilter(domain.IAMID).AggregateTypeFilter(iam.AggregateType))
|
||||
return p.Eventstore.FilterEvents(ctx, models.NewSearchQuery().AggregateIDFilter(domain.IAMID).AggregateTypeFilter(instance.AggregateType))
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
iam_view_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
@@ -91,8 +91,8 @@ func (i *IDPConfig) processIdpConfig(providerType iam_model.IDPProviderType, eve
|
||||
case model.IDPConfigChanged, iam_es_model.IDPConfigChanged,
|
||||
model.OIDCIDPConfigAdded, iam_es_model.OIDCIDPConfigAdded,
|
||||
model.OIDCIDPConfigChanged, iam_es_model.OIDCIDPConfigChanged,
|
||||
es_models.EventType(org.IDPJWTConfigAddedEventType), es_models.EventType(iam.IDPJWTConfigAddedEventType),
|
||||
es_models.EventType(org.IDPJWTConfigChangedEventType), es_models.EventType(iam.IDPJWTConfigChangedEventType):
|
||||
es_models.EventType(org.IDPJWTConfigAddedEventType), es_models.EventType(instance.IDPJWTConfigAddedEventType),
|
||||
es_models.EventType(org.IDPJWTConfigChangedEventType), es_models.EventType(instance.IDPJWTConfigChangedEventType):
|
||||
err = idp.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
||||
"github.com/caos/zitadel/internal/org/repository/view"
|
||||
query2 "github.com/caos/zitadel/internal/query"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
user_repo "github.com/caos/zitadel/internal/repository/user"
|
||||
es_model "github.com/caos/zitadel/internal/user/repository/eventsourcing/model"
|
||||
view_model "github.com/caos/zitadel/internal/user/repository/view/model"
|
||||
@@ -186,9 +187,9 @@ func (u *User) ProcessOrg(event *es_models.Event) (err error) {
|
||||
switch event.Type {
|
||||
case org_es_model.OrgDomainVerified,
|
||||
org_es_model.OrgDomainRemoved,
|
||||
org_es_model.OrgIAMPolicyAdded,
|
||||
org_es_model.OrgIAMPolicyChanged,
|
||||
org_es_model.OrgIAMPolicyRemoved:
|
||||
es_models.EventType(org.OrgDomainPolicyAddedEventType),
|
||||
es_models.EventType(org.OrgDomainPolicyChangedEventType),
|
||||
es_models.EventType(org.OrgDomainPolicyRemovedEventType):
|
||||
return u.fillLoginNamesOnOrgUsers(event)
|
||||
case org_es_model.OrgDomainPrimarySet:
|
||||
return u.fillPreferredLoginNamesOnOrgUsers(event)
|
||||
@@ -266,8 +267,8 @@ func (u *User) loginNameInformation(ctx context.Context, orgID string) (userLogi
|
||||
if err != nil {
|
||||
return false, "", nil, err
|
||||
}
|
||||
if org.OrgIamPolicy == nil {
|
||||
policy, err := u.queries.DefaultOrgIAMPolicy(ctx)
|
||||
if org.DomainPolicy == nil {
|
||||
policy, err := u.queries.DefaultDomainPolicy(ctx)
|
||||
if err != nil {
|
||||
return false, "", nil, err
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ func (repo *TokenVerifierRepo) VerifierClientID(ctx context.Context, appName str
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
iam, err := repo.Query.IAM(ctx)
|
||||
iam, err := repo.Query.Instance(ctx)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/id"
|
||||
"github.com/caos/zitadel/internal/repository/action"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/keypair"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
proj_repo "github.com/caos/zitadel/internal/repository/project"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
@@ -1098,9 +1098,9 @@ func (c *Commands) createCustomLoginTextEvent(ctx context.Context, agg *eventsto
|
||||
}
|
||||
if defaultText {
|
||||
if newText != "" {
|
||||
return iam.NewCustomTextSetEvent(ctx, agg, domain.LoginCustomText, textKey, newText, lang)
|
||||
return instance.NewCustomTextSetEvent(ctx, agg, domain.LoginCustomText, textKey, newText, lang)
|
||||
}
|
||||
return iam.NewCustomTextRemovedEvent(ctx, agg, domain.LoginCustomText, textKey, lang)
|
||||
return instance.NewCustomTextRemovedEvent(ctx, agg, domain.LoginCustomText, textKey, lang)
|
||||
}
|
||||
if newText != "" {
|
||||
return org.NewCustomTextSetEvent(ctx, agg, domain.LoginCustomText, textKey, newText, lang)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ func (rm *ExistingLabelPoliciesReadModel) AppendEvents(events ...eventstore.Even
|
||||
func (rm *ExistingLabelPoliciesReadModel) Reduce() error {
|
||||
for _, event := range rm.Events {
|
||||
switch e := event.(type) {
|
||||
case *iam.LabelPolicyAddedEvent,
|
||||
case *instance.LabelPolicyAddedEvent,
|
||||
*org.LabelPolicyAddedEvent:
|
||||
rm.aggregateIDs = append(rm.aggregateIDs, e.Aggregate().ID)
|
||||
case *org.LabelPolicyRemovedEvent:
|
||||
@@ -44,8 +44,8 @@ func (rm *ExistingLabelPoliciesReadModel) Reduce() error {
|
||||
func (rm *ExistingLabelPoliciesReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
EventTypes(iam.LabelPolicyAddedEventType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
EventTypes(instance.LabelPolicyAddedEventType).
|
||||
Or().
|
||||
AggregateTypes(org.AggregateType).
|
||||
EventTypes(
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,123 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func (c *Commands) SetDefaultMessageText(ctx context.Context, messageText *domain.CustomMessageText) (*domain.ObjectDetails, error) {
|
||||
iamAgg := iam.NewAggregate()
|
||||
events, existingMessageText, err := c.setDefaultMessageText(ctx, &iamAgg.Aggregate, messageText)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pushedEvents, err := c.eventstore.Push(ctx, events...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(existingMessageText, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToObjectDetails(&existingMessageText.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) setDefaultMessageText(ctx context.Context, iamAgg *eventstore.Aggregate, msg *domain.CustomMessageText) ([]eventstore.Command, *IAMCustomMessageTextReadModel, error) {
|
||||
if !msg.IsValid() {
|
||||
return nil, nil, caos_errs.ThrowInvalidArgument(nil, "IAM-kd9fs", "Errors.CustomMessageText.Invalid")
|
||||
}
|
||||
|
||||
existingMessageText, err := c.defaultCustomMessageTextWriteModelByID(ctx, msg.MessageTextType, msg.Language)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
events := make([]eventstore.Command, 0)
|
||||
if existingMessageText.Greeting != msg.Greeting {
|
||||
if msg.Greeting != "" {
|
||||
events = append(events, iam.NewCustomTextSetEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageGreeting, msg.Greeting, msg.Language))
|
||||
} else {
|
||||
events = append(events, iam.NewCustomTextRemovedEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageGreeting, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.Subject != msg.Subject {
|
||||
if msg.Subject != "" {
|
||||
events = append(events, iam.NewCustomTextSetEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageSubject, msg.Subject, msg.Language))
|
||||
} else {
|
||||
events = append(events, iam.NewCustomTextRemovedEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageSubject, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.Title != msg.Title {
|
||||
if msg.Title != "" {
|
||||
events = append(events, iam.NewCustomTextSetEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageTitle, msg.Title, msg.Language))
|
||||
} else {
|
||||
events = append(events, iam.NewCustomTextRemovedEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageTitle, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.PreHeader != msg.PreHeader {
|
||||
if msg.PreHeader != "" {
|
||||
events = append(events, iam.NewCustomTextSetEvent(ctx, iamAgg, msg.MessageTextType, domain.MessagePreHeader, msg.PreHeader, msg.Language))
|
||||
} else {
|
||||
events = append(events, iam.NewCustomTextRemovedEvent(ctx, iamAgg, msg.MessageTextType, domain.MessagePreHeader, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.Text != msg.Text {
|
||||
if msg.Text != "" {
|
||||
events = append(events, iam.NewCustomTextSetEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageText, msg.Text, msg.Language))
|
||||
} else {
|
||||
events = append(events, iam.NewCustomTextRemovedEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageText, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.ButtonText != msg.ButtonText {
|
||||
if msg.ButtonText != "" {
|
||||
events = append(events, iam.NewCustomTextSetEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageButtonText, msg.ButtonText, msg.Language))
|
||||
} else {
|
||||
events = append(events, iam.NewCustomTextRemovedEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageButtonText, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.FooterText != msg.FooterText {
|
||||
if msg.FooterText != "" {
|
||||
events = append(events, iam.NewCustomTextSetEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageFooterText, msg.FooterText, msg.Language))
|
||||
} else {
|
||||
events = append(events, iam.NewCustomTextRemovedEvent(ctx, iamAgg, msg.MessageTextType, domain.MessageFooterText, msg.Language))
|
||||
}
|
||||
}
|
||||
return events, existingMessageText, nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveIAMMessageTexts(ctx context.Context, messageTextType string, lang language.Tag) (*domain.ObjectDetails, error) {
|
||||
if messageTextType == "" || lang == language.Und {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-fjw9b", "Errors.CustomMessageText.Invalid")
|
||||
}
|
||||
customText, err := c.defaultCustomMessageTextWriteModelByID(ctx, messageTextType, lang)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if customText.State == domain.PolicyStateUnspecified || customText.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "Org-fju90", "Errors.CustomMessageText.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&customText.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam.NewCustomTextTemplateRemovedEvent(ctx, iamAgg, messageTextType, lang))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(customText, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToObjectDetails(&customText.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultCustomMessageTextWriteModelByID(ctx context.Context, messageType string, lang language.Tag) (*IAMCustomMessageTextReadModel, error) {
|
||||
writeModel := NewIAMCustomMessageTextWriteModel(messageType, lang)
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModel, nil
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddIAMMember(ctx context.Context, member *domain.Member) (*domain.Member, error) {
|
||||
if member.UserID == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-Mf83b", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
addedMember := NewIAMMemberWriteModel(member.UserID)
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedMember.MemberWriteModel.WriteModel)
|
||||
err := c.checkUserExists(ctx, addedMember.UserID, "")
|
||||
if err != nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(err, "IAM-5N9vs", "Errors.User.NotFound")
|
||||
}
|
||||
event, err := c.addIAMMember(ctx, iamAgg, addedMember, member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(addedMember, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return memberWriteModelToMember(&addedMember.MemberWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addIAMMember(ctx context.Context, iamAgg *eventstore.Aggregate, addedMember *IAMMemberWriteModel, member *domain.Member) (eventstore.Command, error) {
|
||||
if !member.IsIAMValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-GR34U", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
if len(domain.CheckForInvalidRoles(member.Roles, domain.IAMRolePrefix, c.zitadelRoles)) > 0 {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-4m0fS", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedMember)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedMember.State == domain.MemberStateActive {
|
||||
return nil, errors.ThrowAlreadyExists(nil, "IAM-sdgQ4", "Errors.IAM.Member.AlreadyExists")
|
||||
}
|
||||
|
||||
return iam_repo.NewMemberAddedEvent(ctx, iamAgg, member.UserID, member.Roles...), nil
|
||||
}
|
||||
|
||||
//ChangeIAMMember updates an existing member
|
||||
func (c *Commands) ChangeIAMMember(ctx context.Context, member *domain.Member) (*domain.Member, error) {
|
||||
if !member.IsIAMValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-LiaZi", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
if len(domain.CheckForInvalidRoles(member.Roles, domain.IAMRolePrefix, c.zitadelRoles)) > 0 {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-3m9fs", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
|
||||
existingMember, err := c.iamMemberWriteModelByID(ctx, member.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(existingMember.Roles, member.Roles) {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-LiaZi", "Errors.IAM.Member.RolesNotChanged")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingMember.MemberWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewMemberChangedEvent(ctx, iamAgg, member.UserID, member.Roles...))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(existingMember, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return memberWriteModelToMember(&existingMember.MemberWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveIAMMember(ctx context.Context, userID string) (*domain.ObjectDetails, error) {
|
||||
if userID == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-LiaZi", "Errors.IDMissing")
|
||||
}
|
||||
memberWriteModel, err := c.iamMemberWriteModelByID(ctx, userID)
|
||||
if err != nil && !errors.IsNotFound(err) {
|
||||
return nil, err
|
||||
}
|
||||
if errors.IsNotFound(err) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&memberWriteModel.MemberWriteModel.WriteModel)
|
||||
removeEvent := c.removeIAMMember(ctx, iamAgg, userID, false)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, removeEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(memberWriteModel, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return writeModelToObjectDetails(&memberWriteModel.MemberWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) removeIAMMember(ctx context.Context, iamAgg *eventstore.Aggregate, userID string, cascade bool) eventstore.Command {
|
||||
if cascade {
|
||||
return iam_repo.NewMemberCascadeRemovedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
userID)
|
||||
} else {
|
||||
return iam_repo.NewMemberRemovedEvent(ctx, iamAgg, userID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Commands) iamMemberWriteModelByID(ctx context.Context, userID string) (member *IAMMemberWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMMemberWriteModel(userID)
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if writeModel.State == domain.MemberStateUnspecified || writeModel.State == domain.MemberStateRemoved {
|
||||
return nil, errors.ThrowNotFound(nil, "IAM-D8JxR", "Errors.NotFound")
|
||||
}
|
||||
|
||||
return writeModel, nil
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDefaultOrgIAMPolicy(ctx context.Context, policy *domain.OrgIAMPolicy) (*domain.OrgIAMPolicy, error) {
|
||||
addedPolicy := NewIAMOrgIAMPolicyWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
event, err := c.addDefaultOrgIAMPolicy(ctx, iamAgg, addedPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(addedPolicy, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToOrgIAMPolicy(addedPolicy), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultOrgIAMPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, addedPolicy *IAMOrgIAMPolicyWriteModel, policy *domain.OrgIAMPolicy) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedPolicy.State == domain.PolicyStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-Lk0dS", "Errors.IAM.OrgIAMPolicy.AlreadyExists")
|
||||
}
|
||||
return iam_repo.NewOrgIAMPolicyAddedEvent(ctx, iamAgg, policy.UserLoginMustBeDomain), nil
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultOrgIAMPolicy(ctx context.Context, policy *domain.OrgIAMPolicy) (*domain.OrgIAMPolicy, error) {
|
||||
existingPolicy, err := c.defaultOrgIAMPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !existingPolicy.State.Exists() {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-0Pl0d", "Errors.IAM.OrgIAMPolicy.NotFound")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.PolicyOrgIAMWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, iamAgg, policy.UserLoginMustBeDomain)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(existingPolicy, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToOrgIAMPolicy(existingPolicy), nil
|
||||
}
|
||||
|
||||
func (c *Commands) getDefaultOrgIAMPolicy(ctx context.Context) (*domain.OrgIAMPolicy, error) {
|
||||
policyWriteModel, err := c.defaultOrgIAMPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !policyWriteModel.State.Exists() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-3n8fs", "Errors.IAM.PasswordComplexityPolicy.NotFound")
|
||||
}
|
||||
policy := writeModelToOrgIAMPolicy(policyWriteModel)
|
||||
policy.Default = true
|
||||
return policy, nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultOrgIAMPolicyWriteModelByID(ctx context.Context) (policy *IAMOrgIAMPolicyWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMOrgIAMPolicyWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModel, nil
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type IAMOrgIAMPolicyWriteModel struct {
|
||||
PolicyOrgIAMWriteModel
|
||||
}
|
||||
|
||||
func NewIAMOrgIAMPolicyWriteModel() *IAMOrgIAMPolicyWriteModel {
|
||||
return &IAMOrgIAMPolicyWriteModel{
|
||||
PolicyOrgIAMWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
ResourceOwner: domain.IAMID,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMOrgIAMPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.OrgIAMPolicyAddedEvent:
|
||||
wm.PolicyOrgIAMWriteModel.AppendEvents(&e.OrgIAMPolicyAddedEvent)
|
||||
case *iam.OrgIAMPolicyChangedEvent:
|
||||
wm.PolicyOrgIAMWriteModel.AppendEvents(&e.OrgIAMPolicyChangedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMOrgIAMPolicyWriteModel) Reduce() error {
|
||||
return wm.PolicyOrgIAMWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMOrgIAMPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateIDs(wm.PolicyOrgIAMWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.OrgIAMPolicyAddedEventType,
|
||||
iam.OrgIAMPolicyChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMOrgIAMPolicyWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
userLoginMustBeDomain bool) (*iam.OrgIAMPolicyChangedEvent, bool) {
|
||||
changes := make([]policy.OrgIAMPolicyChanges, 0)
|
||||
if wm.UserLoginMustBeDomain != userLoginMustBeDomain {
|
||||
changes = append(changes, policy.ChangeUserLoginMustBeDomain(userLoginMustBeDomain))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewOrgIAMPolicyChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
return changedEvent, true
|
||||
}
|
||||
+15
-15
@@ -6,16 +6,16 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type IAMPasswordAgePolicyWriteModel struct {
|
||||
type InstancePasswordAgePolicyWriteModel struct {
|
||||
PasswordAgePolicyWriteModel
|
||||
}
|
||||
|
||||
func NewIAMPasswordAgePolicyWriteModel() *IAMPasswordAgePolicyWriteModel {
|
||||
return &IAMPasswordAgePolicyWriteModel{
|
||||
func NewInstancePasswordAgePolicyWriteModel() *InstancePasswordAgePolicyWriteModel {
|
||||
return &InstancePasswordAgePolicyWriteModel{
|
||||
PasswordAgePolicyWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -25,38 +25,38 @@ func NewIAMPasswordAgePolicyWriteModel() *IAMPasswordAgePolicyWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMPasswordAgePolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstancePasswordAgePolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.PasswordAgePolicyAddedEvent:
|
||||
case *instance.PasswordAgePolicyAddedEvent:
|
||||
wm.PasswordAgePolicyWriteModel.AppendEvents(&e.PasswordAgePolicyAddedEvent)
|
||||
case *iam.PasswordAgePolicyChangedEvent:
|
||||
case *instance.PasswordAgePolicyChangedEvent:
|
||||
wm.PasswordAgePolicyWriteModel.AppendEvents(&e.PasswordAgePolicyChangedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMPasswordAgePolicyWriteModel) Reduce() error {
|
||||
func (wm *InstancePasswordAgePolicyWriteModel) Reduce() error {
|
||||
return wm.PasswordAgePolicyWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMPasswordAgePolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstancePasswordAgePolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.PasswordAgePolicyWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.PasswordAgePolicyAddedEventType,
|
||||
iam.PasswordAgePolicyChangedEventType).
|
||||
instance.PasswordAgePolicyAddedEventType,
|
||||
instance.PasswordAgePolicyChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMPasswordAgePolicyWriteModel) NewChangedEvent(
|
||||
func (wm *InstancePasswordAgePolicyWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
expireWarnDays,
|
||||
maxAgeDays uint64) (*iam.PasswordAgePolicyChangedEvent, bool) {
|
||||
maxAgeDays uint64) (*instance.PasswordAgePolicyChangedEvent, bool) {
|
||||
changes := make([]policy.PasswordAgePolicyChanges, 0)
|
||||
if wm.ExpireWarnDays != expireWarnDays {
|
||||
changes = append(changes, policy.ChangeExpireWarnDays(expireWarnDays))
|
||||
@@ -67,7 +67,7 @@ func (wm *IAMPasswordAgePolicyWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewPasswordAgePolicyChangedEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewPasswordAgePolicyChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
@@ -6,22 +6,22 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
//TODO: private as soon as setup uses query
|
||||
func (c *Commands) GetIAM(ctx context.Context) (*domain.IAM, error) {
|
||||
iamWriteModel := NewIAMWriteModel()
|
||||
func (c *Commands) GetInstance(ctx context.Context) (*domain.Instance, error) {
|
||||
iamWriteModel := NewInstanceWriteModel()
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, iamWriteModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToIAM(iamWriteModel), nil
|
||||
return writeModelToInstance(iamWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) setGlobalOrg(ctx context.Context, iamAgg *eventstore.Aggregate, iamWriteModel *IAMWriteModel, orgID string) (eventstore.Command, error) {
|
||||
func (c *Commands) setGlobalOrg(ctx context.Context, iamAgg *eventstore.Aggregate, iamWriteModel *InstanceWriteModel, orgID string) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, iamWriteModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -29,10 +29,10 @@ func (c *Commands) setGlobalOrg(ctx context.Context, iamAgg *eventstore.Aggregat
|
||||
if iamWriteModel.GlobalOrgID != "" {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-HGG24", "Errors.IAM.GlobalOrgAlreadySet")
|
||||
}
|
||||
return iam.NewGlobalOrgSetEventEvent(ctx, iamAgg, orgID), nil
|
||||
return instance.NewGlobalOrgSetEventEvent(ctx, iamAgg, orgID), nil
|
||||
}
|
||||
|
||||
func (c *Commands) setIAMProject(ctx context.Context, iamAgg *eventstore.Aggregate, iamWriteModel *IAMWriteModel, projectID string) (eventstore.Command, error) {
|
||||
func (c *Commands) setIAMProject(ctx context.Context, iamAgg *eventstore.Aggregate, iamWriteModel *InstanceWriteModel, projectID string) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, iamWriteModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -40,7 +40,7 @@ func (c *Commands) setIAMProject(ctx context.Context, iamAgg *eventstore.Aggrega
|
||||
if iamWriteModel.ProjectID != "" {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-EGbw2", "Errors.IAM.IAMProjectAlreadySet")
|
||||
}
|
||||
return iam.NewIAMProjectSetEvent(ctx, iamAgg, projectID), nil
|
||||
return instance.NewIAMProjectSetEvent(ctx, iamAgg, projectID), nil
|
||||
}
|
||||
|
||||
func (c *Commands) SetDefaultLanguage(ctx context.Context, language language.Tag) (*domain.ObjectDetails, error) {
|
||||
@@ -48,8 +48,8 @@ func (c *Commands) SetDefaultLanguage(ctx context.Context, language language.Tag
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&iamWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam.NewDefaultLanguageSetEvent(ctx, iamAgg, language))
|
||||
iamAgg := InstanceAggregateFromWriteModel(&iamWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewDefaultLanguageSetEvent(ctx, iamAgg, language))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,11 +60,11 @@ func (c *Commands) SetDefaultLanguage(ctx context.Context, language language.Tag
|
||||
return writeModelToObjectDetails(&iamWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) getIAMWriteModel(ctx context.Context) (_ *IAMWriteModel, err error) {
|
||||
func (c *Commands) getIAMWriteModel(ctx context.Context) (_ *InstanceWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMWriteModel()
|
||||
writeModel := NewInstanceWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -15,8 +15,8 @@ func writeModelToObjectRoot(writeModel eventstore.WriteModel) models.ObjectRoot
|
||||
}
|
||||
}
|
||||
|
||||
func writeModelToIAM(wm *IAMWriteModel) *domain.IAM {
|
||||
return &domain.IAM{
|
||||
func writeModelToInstance(wm *InstanceWriteModel) *domain.Instance {
|
||||
return &domain.Instance{
|
||||
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
||||
SetUpStarted: wm.SetUpStarted,
|
||||
SetUpDone: wm.SetUpDone,
|
||||
@@ -74,9 +74,9 @@ func writeModelToMailTemplate(wm *MailTemplateWriteModel) *domain.MailTemplate {
|
||||
}
|
||||
}
|
||||
|
||||
func writeModelToOrgIAMPolicy(wm *IAMOrgIAMPolicyWriteModel) *domain.OrgIAMPolicy {
|
||||
return &domain.OrgIAMPolicy{
|
||||
ObjectRoot: writeModelToObjectRoot(wm.PolicyOrgIAMWriteModel.WriteModel),
|
||||
func writeModelToDomainPolicy(wm *InstanceDomainPolicyWriteModel) *domain.DomainPolicy {
|
||||
return &domain.DomainPolicy{
|
||||
ObjectRoot: writeModelToObjectRoot(wm.PolicyDomainWriteModel.WriteModel),
|
||||
UserLoginMustBeDomain: wm.UserLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
+12
-12
@@ -8,12 +8,12 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func (c *Commands) SetCustomIAMLoginText(ctx context.Context, loginText *domain.CustomLoginText) (*domain.ObjectDetails, error) {
|
||||
iamAgg := iam.NewAggregate()
|
||||
events, existingMailText, err := c.setCustomIAMLoginText(ctx, &iamAgg.Aggregate, loginText)
|
||||
func (c *Commands) SetCustomInstanceLoginText(ctx context.Context, loginText *domain.CustomLoginText) (*domain.ObjectDetails, error) {
|
||||
iamAgg := instance.NewAggregate()
|
||||
events, existingMailText, err := c.setCustomInstanceLoginText(ctx, &iamAgg.Aggregate, loginText)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func (c *Commands) SetCustomIAMLoginText(ctx context.Context, loginText *domain.
|
||||
return writeModelToObjectDetails(&existingMailText.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveCustomIAMLoginTexts(ctx context.Context, lang language.Tag) (*domain.ObjectDetails, error) {
|
||||
func (c *Commands) RemoveCustomInstanceLoginTexts(ctx context.Context, lang language.Tag) (*domain.ObjectDetails, error) {
|
||||
if lang == language.Und {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-Gfbg3", "Errors.CustomText.Invalid")
|
||||
}
|
||||
@@ -39,8 +39,8 @@ func (c *Commands) RemoveCustomIAMLoginTexts(ctx context.Context, lang language.
|
||||
if customText.State == domain.PolicyStateUnspecified || customText.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-fru44", "Errors.CustomText.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&customText.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam.NewCustomTextTemplateRemovedEvent(ctx, iamAgg, domain.LoginCustomText, lang))
|
||||
iamAgg := InstanceAggregateFromWriteModel(&customText.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewCustomTextTemplateRemovedEvent(ctx, iamAgg, domain.LoginCustomText, lang))
|
||||
err = AppendAndReduce(customText, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -48,21 +48,21 @@ func (c *Commands) RemoveCustomIAMLoginTexts(ctx context.Context, lang language.
|
||||
return writeModelToObjectDetails(&customText.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) setCustomIAMLoginText(ctx context.Context, iamAgg *eventstore.Aggregate, text *domain.CustomLoginText) ([]eventstore.Command, *IAMCustomLoginTextReadModel, error) {
|
||||
func (c *Commands) setCustomInstanceLoginText(ctx context.Context, instanceAgg *eventstore.Aggregate, text *domain.CustomLoginText) ([]eventstore.Command, *InstanceCustomLoginTextReadModel, error) {
|
||||
if !text.IsValid() {
|
||||
return nil, nil, caos_errs.ThrowInvalidArgument(nil, "IAM-kd9fs", "Errors.CustomText.Invalid")
|
||||
return nil, nil, caos_errs.ThrowInvalidArgument(nil, "Instance-kd9fs", "Errors.CustomText.Invalid")
|
||||
}
|
||||
|
||||
existingLoginText, err := c.defaultLoginTextWriteModelByID(ctx, text.Language)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
events := c.createAllLoginTextEvents(ctx, iamAgg, &existingLoginText.CustomLoginTextReadModel, text, true)
|
||||
events := c.createAllLoginTextEvents(ctx, instanceAgg, &existingLoginText.CustomLoginTextReadModel, text, true)
|
||||
return events, existingLoginText, nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultLoginTextWriteModelByID(ctx context.Context, lang language.Tag) (*IAMCustomLoginTextReadModel, error) {
|
||||
writeModel := NewIAMCustomLoginTextReadModel(lang)
|
||||
func (c *Commands) defaultLoginTextWriteModelByID(ctx context.Context, lang language.Tag) (*InstanceCustomLoginTextReadModel, error) {
|
||||
writeModel := NewInstanceCustomLoginTextReadModel(lang)
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+14
-14
@@ -5,15 +5,15 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMCustomLoginTextReadModel struct {
|
||||
type InstanceCustomLoginTextReadModel struct {
|
||||
CustomLoginTextReadModel
|
||||
}
|
||||
|
||||
func NewIAMCustomLoginTextReadModel(lang language.Tag) *IAMCustomLoginTextReadModel {
|
||||
return &IAMCustomLoginTextReadModel{
|
||||
func NewInstanceCustomLoginTextReadModel(lang language.Tag) *InstanceCustomLoginTextReadModel {
|
||||
return &InstanceCustomLoginTextReadModel{
|
||||
CustomLoginTextReadModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -24,32 +24,32 @@ func NewIAMCustomLoginTextReadModel(lang language.Tag) *IAMCustomLoginTextReadMo
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMCustomLoginTextReadModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceCustomLoginTextReadModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.CustomTextSetEvent:
|
||||
case *instance.CustomTextSetEvent:
|
||||
wm.CustomLoginTextReadModel.AppendEvents(&e.CustomTextSetEvent)
|
||||
case *iam.CustomTextRemovedEvent:
|
||||
case *instance.CustomTextRemovedEvent:
|
||||
wm.CustomLoginTextReadModel.AppendEvents(&e.CustomTextRemovedEvent)
|
||||
case *iam.CustomTextTemplateRemovedEvent:
|
||||
case *instance.CustomTextTemplateRemovedEvent:
|
||||
wm.CustomLoginTextReadModel.AppendEvents(&e.CustomTextTemplateRemovedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMCustomLoginTextReadModel) Reduce() error {
|
||||
func (wm *InstanceCustomLoginTextReadModel) Reduce() error {
|
||||
return wm.CustomLoginTextReadModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMCustomLoginTextReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceCustomLoginTextReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateIDs(wm.CustomLoginTextReadModel.AggregateID).
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
EventTypes(
|
||||
iam.CustomTextSetEventType,
|
||||
iam.CustomTextRemovedEventType,
|
||||
iam.CustomTextTemplateRemovedEventType).
|
||||
instance.CustomTextSetEventType,
|
||||
instance.CustomTextRemovedEventType,
|
||||
instance.CustomTextTemplateRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,123 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func (c *Commands) SetDefaultMessageText(ctx context.Context, messageText *domain.CustomMessageText) (*domain.ObjectDetails, error) {
|
||||
instanceAgg := instance.NewAggregate()
|
||||
events, existingMessageText, err := c.setDefaultMessageText(ctx, &instanceAgg.Aggregate, messageText)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pushedEvents, err := c.eventstore.Push(ctx, events...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(existingMessageText, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToObjectDetails(&existingMessageText.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) setDefaultMessageText(ctx context.Context, instanceAgg *eventstore.Aggregate, msg *domain.CustomMessageText) ([]eventstore.Command, *InstanceCustomMessageTextReadModel, error) {
|
||||
if !msg.IsValid() {
|
||||
return nil, nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-kd9fs", "Errors.CustomMessageText.Invalid")
|
||||
}
|
||||
|
||||
existingMessageText, err := c.defaultCustomMessageTextWriteModelByID(ctx, msg.MessageTextType, msg.Language)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
events := make([]eventstore.Command, 0)
|
||||
if existingMessageText.Greeting != msg.Greeting {
|
||||
if msg.Greeting != "" {
|
||||
events = append(events, instance.NewCustomTextSetEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageGreeting, msg.Greeting, msg.Language))
|
||||
} else {
|
||||
events = append(events, instance.NewCustomTextRemovedEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageGreeting, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.Subject != msg.Subject {
|
||||
if msg.Subject != "" {
|
||||
events = append(events, instance.NewCustomTextSetEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageSubject, msg.Subject, msg.Language))
|
||||
} else {
|
||||
events = append(events, instance.NewCustomTextRemovedEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageSubject, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.Title != msg.Title {
|
||||
if msg.Title != "" {
|
||||
events = append(events, instance.NewCustomTextSetEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageTitle, msg.Title, msg.Language))
|
||||
} else {
|
||||
events = append(events, instance.NewCustomTextRemovedEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageTitle, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.PreHeader != msg.PreHeader {
|
||||
if msg.PreHeader != "" {
|
||||
events = append(events, instance.NewCustomTextSetEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessagePreHeader, msg.PreHeader, msg.Language))
|
||||
} else {
|
||||
events = append(events, instance.NewCustomTextRemovedEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessagePreHeader, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.Text != msg.Text {
|
||||
if msg.Text != "" {
|
||||
events = append(events, instance.NewCustomTextSetEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageText, msg.Text, msg.Language))
|
||||
} else {
|
||||
events = append(events, instance.NewCustomTextRemovedEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageText, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.ButtonText != msg.ButtonText {
|
||||
if msg.ButtonText != "" {
|
||||
events = append(events, instance.NewCustomTextSetEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageButtonText, msg.ButtonText, msg.Language))
|
||||
} else {
|
||||
events = append(events, instance.NewCustomTextRemovedEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageButtonText, msg.Language))
|
||||
}
|
||||
}
|
||||
if existingMessageText.FooterText != msg.FooterText {
|
||||
if msg.FooterText != "" {
|
||||
events = append(events, instance.NewCustomTextSetEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageFooterText, msg.FooterText, msg.Language))
|
||||
} else {
|
||||
events = append(events, instance.NewCustomTextRemovedEvent(ctx, instanceAgg, msg.MessageTextType, domain.MessageFooterText, msg.Language))
|
||||
}
|
||||
}
|
||||
return events, existingMessageText, nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveInstanceMessageTexts(ctx context.Context, messageTextType string, lang language.Tag) (*domain.ObjectDetails, error) {
|
||||
if messageTextType == "" || lang == language.Und {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-fjw9b", "Errors.CustomMessageText.Invalid")
|
||||
}
|
||||
customText, err := c.defaultCustomMessageTextWriteModelByID(ctx, messageTextType, lang)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if customText.State == domain.PolicyStateUnspecified || customText.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-fju90", "Errors.CustomMessageText.NotFound")
|
||||
}
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&customText.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewCustomTextTemplateRemovedEvent(ctx, instanceAgg, messageTextType, lang))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(customText, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToObjectDetails(&customText.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultCustomMessageTextWriteModelByID(ctx context.Context, messageType string, lang language.Tag) (*InstanceCustomMessageTextReadModel, error) {
|
||||
writeModel := NewInstanceCustomMessageTextWriteModel(messageType, lang)
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModel, nil
|
||||
}
|
||||
+12
-12
@@ -5,15 +5,15 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMCustomMessageTextReadModel struct {
|
||||
type InstanceCustomMessageTextReadModel struct {
|
||||
CustomMessageTextReadModel
|
||||
}
|
||||
|
||||
func NewIAMCustomMessageTextWriteModel(messageTextType string, lang language.Tag) *IAMCustomMessageTextReadModel {
|
||||
return &IAMCustomMessageTextReadModel{
|
||||
func NewInstanceCustomMessageTextWriteModel(messageTextType string, lang language.Tag) *InstanceCustomMessageTextReadModel {
|
||||
return &InstanceCustomMessageTextReadModel{
|
||||
CustomMessageTextReadModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -25,29 +25,29 @@ func NewIAMCustomMessageTextWriteModel(messageTextType string, lang language.Tag
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMCustomMessageTextReadModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceCustomMessageTextReadModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.CustomTextSetEvent:
|
||||
case *instance.CustomTextSetEvent:
|
||||
wm.CustomMessageTextReadModel.AppendEvents(&e.CustomTextSetEvent)
|
||||
case *iam.CustomTextRemovedEvent:
|
||||
case *instance.CustomTextRemovedEvent:
|
||||
wm.CustomMessageTextReadModel.AppendEvents(&e.CustomTextRemovedEvent)
|
||||
case *iam.CustomTextTemplateRemovedEvent:
|
||||
case *instance.CustomTextTemplateRemovedEvent:
|
||||
wm.CustomMessageTextReadModel.AppendEvents(&e.CustomTextTemplateRemovedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMCustomMessageTextReadModel) Reduce() error {
|
||||
func (wm *InstanceCustomMessageTextReadModel) Reduce() error {
|
||||
return wm.CustomMessageTextReadModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMCustomMessageTextReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceCustomMessageTextReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.CustomMessageTextReadModel.AggregateID).
|
||||
EventTypes(iam.CustomTextSetEventType, iam.CustomTextRemovedEventType, iam.CustomTextTemplateRemovedEventType).
|
||||
EventTypes(instance.CustomTextSetEventType, instance.CustomTextRemovedEventType, instance.CustomTextTemplateRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
+15
-15
@@ -11,7 +11,7 @@ import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func TestCommandSide_SetDefaultMessageText(t *testing.T) {
|
||||
@@ -56,8 +56,8 @@ func TestCommandSide_SetDefaultMessageText(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewCustomTextSetEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"Template",
|
||||
domain.MessageGreeting,
|
||||
"Greeting",
|
||||
@@ -65,8 +65,8 @@ func TestCommandSide_SetDefaultMessageText(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewCustomTextSetEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"Template",
|
||||
domain.MessageSubject,
|
||||
"Subject",
|
||||
@@ -74,8 +74,8 @@ func TestCommandSide_SetDefaultMessageText(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewCustomTextSetEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"Template",
|
||||
domain.MessageTitle,
|
||||
"Title",
|
||||
@@ -83,8 +83,8 @@ func TestCommandSide_SetDefaultMessageText(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewCustomTextSetEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"Template",
|
||||
domain.MessagePreHeader,
|
||||
"PreHeader",
|
||||
@@ -92,8 +92,8 @@ func TestCommandSide_SetDefaultMessageText(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewCustomTextSetEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"Template",
|
||||
domain.MessageText,
|
||||
"Text",
|
||||
@@ -101,8 +101,8 @@ func TestCommandSide_SetDefaultMessageText(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewCustomTextSetEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"Template",
|
||||
domain.MessageButtonText,
|
||||
"ButtonText",
|
||||
@@ -110,8 +110,8 @@ func TestCommandSide_SetDefaultMessageText(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewCustomTextSetEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"Template",
|
||||
domain.MessageFooterText,
|
||||
"Footer",
|
||||
@@ -8,14 +8,14 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) SetIAMCustomText(ctx context.Context, customText *domain.CustomText) (*domain.CustomText, error) {
|
||||
setText := NewIAMCustomTextWriteModel(customText.Key, customText.Language)
|
||||
iamAgg := IAMAggregateFromWriteModel(&setText.CustomTextWriteModel.WriteModel)
|
||||
event, err := c.setDefaultCustomText(ctx, iamAgg, setText, customText)
|
||||
func (c *Commands) SetInstanceCustomText(ctx context.Context, customText *domain.CustomText) (*domain.CustomText, error) {
|
||||
setText := NewInstanceCustomTextWriteModel(customText.Key, customText.Language)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&setText.CustomTextWriteModel.WriteModel)
|
||||
event, err := c.setDefaultCustomText(ctx, instanceAgg, setText, customText)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -31,28 +31,28 @@ func (c *Commands) SetIAMCustomText(ctx context.Context, customText *domain.Cust
|
||||
return writeModelToCustomText(&setText.CustomTextWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) setDefaultCustomText(ctx context.Context, iamAgg *eventstore.Aggregate, addedPolicy *IAMCustomTextWriteModel, text *domain.CustomText) (eventstore.Command, error) {
|
||||
func (c *Commands) setDefaultCustomText(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstanceCustomTextWriteModel, text *domain.CustomText) (eventstore.Command, error) {
|
||||
if !text.IsValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-3MN0s", "Errors.CustomText.Invalid")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-3MN0s", "Errors.CustomText.Invalid")
|
||||
}
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iam_repo.NewCustomTextSetEvent(
|
||||
return instance.NewCustomTextSetEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
text.Template,
|
||||
text.Key,
|
||||
text.Text,
|
||||
text.Language), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultCustomTextWriteModelByID(ctx context.Context, key string, language language.Tag) (policy *IAMCustomTextWriteModel, err error) {
|
||||
func (c *Commands) defaultCustomTextWriteModelByID(ctx context.Context, key string, language language.Tag) (policy *InstanceCustomTextWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMCustomTextWriteModel(key, language)
|
||||
writeModel := NewInstanceCustomTextWriteModel(key, language)
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+10
-10
@@ -5,15 +5,15 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMCustomTextWriteModel struct {
|
||||
type InstanceCustomTextWriteModel struct {
|
||||
CustomTextWriteModel
|
||||
}
|
||||
|
||||
func NewIAMCustomTextWriteModel(key string, language language.Tag) *IAMCustomTextWriteModel {
|
||||
return &IAMCustomTextWriteModel{
|
||||
func NewInstanceCustomTextWriteModel(key string, language language.Tag) *InstanceCustomTextWriteModel {
|
||||
return &InstanceCustomTextWriteModel{
|
||||
CustomTextWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -25,26 +25,26 @@ func NewIAMCustomTextWriteModel(key string, language language.Tag) *IAMCustomTex
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMCustomTextWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceCustomTextWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.CustomTextSetEvent:
|
||||
case *instance.CustomTextSetEvent:
|
||||
wm.CustomTextWriteModel.AppendEvents(&e.CustomTextSetEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMCustomTextWriteModel) Reduce() error {
|
||||
func (wm *InstanceCustomTextWriteModel) Reduce() error {
|
||||
return wm.CustomTextWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMCustomTextWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceCustomTextWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateIDs(wm.CustomTextWriteModel.AggregateID).
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
EventTypes(
|
||||
iam.CustomTextSetEventType).
|
||||
instance.CustomTextSetEventType).
|
||||
Builder()
|
||||
}
|
||||
+19
-19
@@ -7,14 +7,14 @@ import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/notification/channels/fs"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDebugNotificationProviderFile(ctx context.Context, fileSystemProvider *fs.FSConfig) (*domain.ObjectDetails, error) {
|
||||
writeModel := NewIAMDebugNotificationFileWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&writeModel.WriteModel)
|
||||
events, err := c.addDefaultDebugNotificationFile(ctx, iamAgg, writeModel, fileSystemProvider)
|
||||
writeModel := NewInstanceDebugNotificationFileWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&writeModel.WriteModel)
|
||||
events, err := c.addDefaultDebugNotificationFile(ctx, instanceAgg, writeModel, fileSystemProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -29,27 +29,27 @@ func (c *Commands) AddDebugNotificationProviderFile(ctx context.Context, fileSys
|
||||
return writeModelToObjectDetails(&writeModel.DebugNotificationWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultDebugNotificationFile(ctx context.Context, iamAgg *eventstore.Aggregate, addedWriteModel *IAMDebugNotificationFileWriteModel, fileSystemProvider *fs.FSConfig) ([]eventstore.Command, error) {
|
||||
func (c *Commands) addDefaultDebugNotificationFile(ctx context.Context, instanceAgg *eventstore.Aggregate, addedWriteModel *InstanceDebugNotificationFileWriteModel, fileSystemProvider *fs.FSConfig) ([]eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedWriteModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedWriteModel.State.Exists() {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-d93nfs", "Errors.IAM.DebugNotificationProvider.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-d93nfs", "Errors.IAM.DebugNotificationProvider.AlreadyExists")
|
||||
}
|
||||
|
||||
events := []eventstore.Command{
|
||||
iam_repo.NewDebugNotificationProviderFileAddedEvent(ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
fileSystemProvider.Compact),
|
||||
}
|
||||
return events, nil
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultNotificationFile(ctx context.Context, fileSystemProvider *fs.FSConfig) (*domain.ObjectDetails, error) {
|
||||
writeModel := NewIAMDebugNotificationFileWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&writeModel.WriteModel)
|
||||
events, err := c.changeDefaultDebugNotificationProviderFile(ctx, iamAgg, writeModel, fileSystemProvider)
|
||||
writeModel := NewInstanceDebugNotificationFileWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&writeModel.WriteModel)
|
||||
events, err := c.changeDefaultDebugNotificationProviderFile(ctx, instanceAgg, writeModel, fileSystemProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -64,40 +64,40 @@ func (c *Commands) ChangeDefaultNotificationFile(ctx context.Context, fileSystem
|
||||
return writeModelToObjectDetails(&writeModel.DebugNotificationWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) changeDefaultDebugNotificationProviderFile(ctx context.Context, iamAgg *eventstore.Aggregate, existingProvider *IAMDebugNotificationFileWriteModel, fileSystemProvider *fs.FSConfig) ([]eventstore.Command, error) {
|
||||
func (c *Commands) changeDefaultDebugNotificationProviderFile(ctx context.Context, instanceAgg *eventstore.Aggregate, existingProvider *InstanceDebugNotificationFileWriteModel, fileSystemProvider *fs.FSConfig) ([]eventstore.Command, error) {
|
||||
err := c.defaultDebugNotificationProviderFileWriteModelByID(ctx, existingProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !existingProvider.State.Exists() {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-fm9wl", "Errors.IAM.DebugNotificationProvider.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-fm9wl", "Errors.IAM.DebugNotificationProvider.NotFound")
|
||||
}
|
||||
events := make([]eventstore.Command, 0)
|
||||
changedEvent, hasChanged := existingProvider.NewChangedEvent(ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
fileSystemProvider.Compact)
|
||||
if hasChanged {
|
||||
events = append(events, changedEvent)
|
||||
}
|
||||
if len(events) == 0 {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-5M9vdd", "Errors.IAM.LoginPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-5M9vdd", "Errors.IAM.LoginPolicy.NotChanged")
|
||||
|
||||
}
|
||||
return events, nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveDefaultNotificationFile(ctx context.Context) (*domain.ObjectDetails, error) {
|
||||
existingProvider := NewIAMDebugNotificationFileWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingProvider.WriteModel)
|
||||
existingProvider := NewInstanceDebugNotificationFileWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingProvider.WriteModel)
|
||||
err := c.defaultDebugNotificationProviderFileWriteModelByID(ctx, existingProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !existingProvider.State.Exists() {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-dj9ew", "Errors.IAM.DebugNotificationProvider.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-dj9ew", "Errors.IAM.DebugNotificationProvider.NotFound")
|
||||
}
|
||||
|
||||
events, err := c.eventstore.Push(ctx, iam_repo.NewDebugNotificationProviderFileRemovedEvent(ctx, iamAgg))
|
||||
events, err := c.eventstore.Push(ctx, iam_repo.NewDebugNotificationProviderFileRemovedEvent(ctx, instanceAgg))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (c *Commands) RemoveDefaultNotificationFile(ctx context.Context) (*domain.O
|
||||
return writeModelToObjectDetails(&existingProvider.DebugNotificationWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultDebugNotificationProviderFileWriteModelByID(ctx context.Context, writeModel *IAMDebugNotificationFileWriteModel) (err error) {
|
||||
func (c *Commands) defaultDebugNotificationProviderFileWriteModelByID(ctx context.Context, writeModel *InstanceDebugNotificationFileWriteModel) (err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
+18
-18
@@ -7,15 +7,15 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/settings"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMDebugNotificationFileWriteModel struct {
|
||||
type InstanceDebugNotificationFileWriteModel struct {
|
||||
DebugNotificationWriteModel
|
||||
}
|
||||
|
||||
func NewIAMDebugNotificationFileWriteModel() *IAMDebugNotificationFileWriteModel {
|
||||
return &IAMDebugNotificationFileWriteModel{
|
||||
func NewInstanceDebugNotificationFileWriteModel() *InstanceDebugNotificationFileWriteModel {
|
||||
return &InstanceDebugNotificationFileWriteModel{
|
||||
DebugNotificationWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -25,44 +25,44 @@ func NewIAMDebugNotificationFileWriteModel() *IAMDebugNotificationFileWriteModel
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationFileWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceDebugNotificationFileWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.DebugNotificationProviderFileAddedEvent:
|
||||
case *instance.DebugNotificationProviderFileAddedEvent:
|
||||
wm.DebugNotificationWriteModel.AppendEvents(&e.DebugNotificationProviderAddedEvent)
|
||||
case *iam.DebugNotificationProviderFileChangedEvent:
|
||||
case *instance.DebugNotificationProviderFileChangedEvent:
|
||||
wm.DebugNotificationWriteModel.AppendEvents(&e.DebugNotificationProviderChangedEvent)
|
||||
case *iam.DebugNotificationProviderFileRemovedEvent:
|
||||
case *instance.DebugNotificationProviderFileRemovedEvent:
|
||||
wm.DebugNotificationWriteModel.AppendEvents(&e.DebugNotificationProviderRemovedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationFileWriteModel) IsValid() bool {
|
||||
func (wm *InstanceDebugNotificationFileWriteModel) IsValid() bool {
|
||||
return wm.AggregateID != ""
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationFileWriteModel) Reduce() error {
|
||||
func (wm *InstanceDebugNotificationFileWriteModel) Reduce() error {
|
||||
return wm.DebugNotificationWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationFileWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceDebugNotificationFileWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.DebugNotificationWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.DebugNotificationProviderFileAddedEventType,
|
||||
iam.DebugNotificationProviderFileChangedEventType,
|
||||
iam.DebugNotificationProviderFileRemovedEventType).
|
||||
instance.DebugNotificationProviderFileAddedEventType,
|
||||
instance.DebugNotificationProviderFileChangedEventType,
|
||||
instance.DebugNotificationProviderFileRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationFileWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceDebugNotificationFileWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
compact bool) (*iam.DebugNotificationProviderFileChangedEvent, bool) {
|
||||
compact bool) (*instance.DebugNotificationProviderFileChangedEvent, bool) {
|
||||
|
||||
changes := make([]settings.DebugNotificationProviderChanges, 0)
|
||||
if wm.Compact != compact {
|
||||
@@ -71,7 +71,7 @@ func (wm *IAMDebugNotificationFileWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewDebugNotificationProviderFileChangedEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewDebugNotificationProviderFileChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
+18
-18
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/notification/channels/fs"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/settings"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -40,8 +40,8 @@ func TestCommandSide_AddDefaultDebugNotificationProviderFile(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -68,8 +68,8 @@ func TestCommandSide_AddDefaultDebugNotificationProviderFile(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -153,8 +153,8 @@ func TestCommandSide_ChangeDebugNotificationProviderFile(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -179,8 +179,8 @@ func TestCommandSide_ChangeDebugNotificationProviderFile(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -205,8 +205,8 @@ func TestCommandSide_ChangeDebugNotificationProviderFile(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -293,8 +293,8 @@ func TestCommandSide_RemoveDebugNotificationProviderFile(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderFileAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -302,8 +302,8 @@ func TestCommandSide_RemoveDebugNotificationProviderFile(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderFileRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate),
|
||||
instance.NewDebugNotificationProviderFileRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate),
|
||||
),
|
||||
},
|
||||
),
|
||||
@@ -337,9 +337,9 @@ func TestCommandSide_RemoveDebugNotificationProviderFile(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
func newDefaultDebugNotificationFileChangedEvent(ctx context.Context, compact bool) *iam.DebugNotificationProviderFileChangedEvent {
|
||||
event, _ := iam.NewDebugNotificationProviderFileChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultDebugNotificationFileChangedEvent(ctx context.Context, compact bool) *instance.DebugNotificationProviderFileChangedEvent {
|
||||
event, _ := instance.NewDebugNotificationProviderFileChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]settings.DebugNotificationProviderChanges{
|
||||
settings.ChangeCompact(compact),
|
||||
},
|
||||
+20
-20
@@ -7,14 +7,14 @@ import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/notification/channels/fs"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDebugNotificationProviderLog(ctx context.Context, fileSystemProvider *fs.FSConfig) (*domain.ObjectDetails, error) {
|
||||
writeModel := NewIAMDebugNotificationLogWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&writeModel.WriteModel)
|
||||
events, err := c.addDefaultDebugNotificationLog(ctx, iamAgg, writeModel, fileSystemProvider)
|
||||
writeModel := NewInstanceDebugNotificationLogWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&writeModel.WriteModel)
|
||||
events, err := c.addDefaultDebugNotificationLog(ctx, instanceAgg, writeModel, fileSystemProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -29,27 +29,27 @@ func (c *Commands) AddDebugNotificationProviderLog(ctx context.Context, fileSyst
|
||||
return writeModelToObjectDetails(&writeModel.DebugNotificationWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultDebugNotificationLog(ctx context.Context, iamAgg *eventstore.Aggregate, addedWriteModel *IAMDebugNotificationLogWriteModel, fileSystemProvider *fs.FSConfig) ([]eventstore.Command, error) {
|
||||
func (c *Commands) addDefaultDebugNotificationLog(ctx context.Context, instanceAgg *eventstore.Aggregate, addedWriteModel *InstanceDebugNotificationLogWriteModel, fileSystemProvider *fs.FSConfig) ([]eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedWriteModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedWriteModel.State.Exists() {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-3h0fs", "Errors.IAM.DebugNotificationProvider.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-3h0fs", "Errors.IAM.DebugNotificationProvider.AlreadyExists")
|
||||
}
|
||||
|
||||
events := []eventstore.Command{
|
||||
iam_repo.NewDebugNotificationProviderLogAddedEvent(ctx,
|
||||
iamAgg,
|
||||
instance.NewDebugNotificationProviderLogAddedEvent(ctx,
|
||||
instanceAgg,
|
||||
fileSystemProvider.Compact),
|
||||
}
|
||||
return events, nil
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultNotificationLog(ctx context.Context, fileSystemProvider *fs.FSConfig) (*domain.ObjectDetails, error) {
|
||||
writeModel := NewIAMDebugNotificationLogWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&writeModel.WriteModel)
|
||||
event, err := c.changeDefaultDebugNotificationProviderLog(ctx, iamAgg, writeModel, fileSystemProvider)
|
||||
writeModel := NewInstanceDebugNotificationLogWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&writeModel.WriteModel)
|
||||
event, err := c.changeDefaultDebugNotificationProviderLog(ctx, instanceAgg, writeModel, fileSystemProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -64,35 +64,35 @@ func (c *Commands) ChangeDefaultNotificationLog(ctx context.Context, fileSystemP
|
||||
return writeModelToObjectDetails(&writeModel.DebugNotificationWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) changeDefaultDebugNotificationProviderLog(ctx context.Context, iamAgg *eventstore.Aggregate, existingProvider *IAMDebugNotificationLogWriteModel, fileSystemProvider *fs.FSConfig) (eventstore.Command, error) {
|
||||
func (c *Commands) changeDefaultDebugNotificationProviderLog(ctx context.Context, instanceAgg *eventstore.Aggregate, existingProvider *InstanceDebugNotificationLogWriteModel, fileSystemProvider *fs.FSConfig) (eventstore.Command, error) {
|
||||
err := c.defaultDebugNotificationProviderLogWriteModelByID(ctx, existingProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !existingProvider.State.Exists() {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-2h0s3", "Errors.IAM.DebugNotificationProvider.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-2h0s3", "Errors.IAM.DebugNotificationProvider.NotFound")
|
||||
}
|
||||
changedEvent, hasChanged := existingProvider.NewChangedEvent(ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
fileSystemProvider.Compact)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-fn9p3", "Errors.IAM.LoginPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-fn9p3", "Errors.IAM.LoginPolicy.NotChanged")
|
||||
}
|
||||
return changedEvent, nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveDefaultNotificationLog(ctx context.Context) (*domain.ObjectDetails, error) {
|
||||
existingProvider := NewIAMDebugNotificationLogWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingProvider.WriteModel)
|
||||
existingProvider := NewInstanceDebugNotificationLogWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingProvider.WriteModel)
|
||||
err := c.defaultDebugNotificationProviderLogWriteModelByID(ctx, existingProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !existingProvider.State.Exists() {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-39lse", "Errors.IAM.DebugNotificationProvider.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-39lse", "Errors.IAM.DebugNotificationProvider.NotFound")
|
||||
}
|
||||
|
||||
events, err := c.eventstore.Push(ctx, iam_repo.NewDebugNotificationProviderLogRemovedEvent(ctx, iamAgg))
|
||||
events, err := c.eventstore.Push(ctx, instance.NewDebugNotificationProviderLogRemovedEvent(ctx, instanceAgg))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func (c *Commands) RemoveDefaultNotificationLog(ctx context.Context) (*domain.Ob
|
||||
return writeModelToObjectDetails(&existingProvider.DebugNotificationWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultDebugNotificationProviderLogWriteModelByID(ctx context.Context, writeModel *IAMDebugNotificationLogWriteModel) (err error) {
|
||||
func (c *Commands) defaultDebugNotificationProviderLogWriteModelByID(ctx context.Context, writeModel *InstanceDebugNotificationLogWriteModel) (err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
+20
-20
@@ -7,15 +7,15 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/settings"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMDebugNotificationLogWriteModel struct {
|
||||
type InstanceDebugNotificationLogWriteModel struct {
|
||||
DebugNotificationWriteModel
|
||||
}
|
||||
|
||||
func NewIAMDebugNotificationLogWriteModel() *IAMDebugNotificationLogWriteModel {
|
||||
return &IAMDebugNotificationLogWriteModel{
|
||||
func NewInstanceDebugNotificationLogWriteModel() *InstanceDebugNotificationLogWriteModel {
|
||||
return &InstanceDebugNotificationLogWriteModel{
|
||||
DebugNotificationWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -25,46 +25,46 @@ func NewIAMDebugNotificationLogWriteModel() *IAMDebugNotificationLogWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationLogWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceDebugNotificationLogWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.DebugNotificationProviderLogAddedEvent:
|
||||
case *instance.DebugNotificationProviderLogAddedEvent:
|
||||
wm.DebugNotificationWriteModel.AppendEvents(&e.DebugNotificationProviderAddedEvent)
|
||||
case *iam.DebugNotificationProviderLogChangedEvent:
|
||||
case *instance.DebugNotificationProviderLogChangedEvent:
|
||||
wm.DebugNotificationWriteModel.AppendEvents(&e.DebugNotificationProviderChangedEvent)
|
||||
case *iam.DebugNotificationProviderLogRemovedEvent:
|
||||
case *instance.DebugNotificationProviderLogRemovedEvent:
|
||||
wm.DebugNotificationWriteModel.AppendEvents(&e.DebugNotificationProviderRemovedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationLogWriteModel) IsValid() bool {
|
||||
func (wm *InstanceDebugNotificationLogWriteModel) IsValid() bool {
|
||||
return wm.AggregateID != ""
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationLogWriteModel) Reduce() error {
|
||||
func (wm *InstanceDebugNotificationLogWriteModel) Reduce() error {
|
||||
return wm.DebugNotificationWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationLogWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceDebugNotificationLogWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.DebugNotificationWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.DebugNotificationProviderLogAddedEventType,
|
||||
iam.DebugNotificationProviderLogChangedEventType,
|
||||
iam.DebugNotificationProviderLogEnabledEventType,
|
||||
iam.DebugNotificationProviderLogDisabledEventType,
|
||||
iam.DebugNotificationProviderLogRemovedEventType).
|
||||
instance.DebugNotificationProviderLogAddedEventType,
|
||||
instance.DebugNotificationProviderLogChangedEventType,
|
||||
instance.DebugNotificationProviderLogEnabledEventType,
|
||||
instance.DebugNotificationProviderLogDisabledEventType,
|
||||
instance.DebugNotificationProviderLogRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMDebugNotificationLogWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceDebugNotificationLogWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
compact bool) (*iam.DebugNotificationProviderLogChangedEvent, bool) {
|
||||
compact bool) (*instance.DebugNotificationProviderLogChangedEvent, bool) {
|
||||
|
||||
changes := make([]settings.DebugNotificationProviderChanges, 0)
|
||||
if wm.Compact != compact {
|
||||
@@ -73,7 +73,7 @@ func (wm *IAMDebugNotificationLogWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewDebugNotificationProviderLogChangedEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewDebugNotificationProviderLogChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
+20
-20
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/notification/channels/fs"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/settings"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -40,8 +40,8 @@ func TestCommandSide_AddDefaultDebugNotificationProviderLog(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -68,8 +68,8 @@ func TestCommandSide_AddDefaultDebugNotificationProviderLog(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -98,8 +98,8 @@ func TestCommandSide_AddDefaultDebugNotificationProviderLog(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -184,8 +184,8 @@ func TestCommandSide_ChangeDebugNotificationProviderLog(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -210,8 +210,8 @@ func TestCommandSide_ChangeDebugNotificationProviderLog(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -246,8 +246,8 @@ func TestCommandSide_ChangeDebugNotificationProviderLog(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -334,8 +334,8 @@ func TestCommandSide_RemoveDebugNotificationProviderLog(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -343,8 +343,8 @@ func TestCommandSide_RemoveDebugNotificationProviderLog(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewDebugNotificationProviderLogRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate),
|
||||
instance.NewDebugNotificationProviderLogRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate),
|
||||
),
|
||||
},
|
||||
),
|
||||
@@ -378,9 +378,9 @@ func TestCommandSide_RemoveDebugNotificationProviderLog(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
func newDefaultDebugNotificationLogChangedEvent(ctx context.Context, compact bool) *iam.DebugNotificationProviderLogChangedEvent {
|
||||
event, _ := iam.NewDebugNotificationProviderLogChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultDebugNotificationLogChangedEvent(ctx context.Context, compact bool) *instance.DebugNotificationProviderLogChangedEvent {
|
||||
event, _ := instance.NewDebugNotificationProviderLogChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]settings.DebugNotificationProviderChanges{
|
||||
settings.ChangeCompact(compact),
|
||||
},
|
||||
@@ -4,13 +4,13 @@ import (
|
||||
"context"
|
||||
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
func (c *Commands) SetDefaultFeatures(ctx context.Context, features *domain.Features) (*domain.ObjectDetails, error) {
|
||||
existingFeatures := NewIAMFeaturesWriteModel()
|
||||
existingFeatures := NewInstanceFeaturesWriteModel()
|
||||
setEvent, err := c.setDefaultFeatures(ctx, existingFeatures, features)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -27,14 +27,14 @@ func (c *Commands) SetDefaultFeatures(ctx context.Context, features *domain.Feat
|
||||
return writeModelToObjectDetails(&existingFeatures.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) setDefaultFeatures(ctx context.Context, existingFeatures *IAMFeaturesWriteModel, features *domain.Features) (*iam.FeaturesSetEvent, error) {
|
||||
func (c *Commands) setDefaultFeatures(ctx context.Context, existingFeatures *InstanceFeaturesWriteModel, features *domain.Features) (*instance.FeaturesSetEvent, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, existingFeatures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
setEvent, hasChanged := existingFeatures.NewSetEvent(
|
||||
ctx,
|
||||
IAMAggregateFromWriteModel(&existingFeatures.FeaturesWriteModel.WriteModel),
|
||||
InstanceAggregateFromWriteModel(&existingFeatures.FeaturesWriteModel.WriteModel),
|
||||
features.TierName,
|
||||
features.TierDescription,
|
||||
features.State,
|
||||
@@ -65,7 +65,7 @@ func (c *Commands) setDefaultFeatures(ctx context.Context, existingFeatures *IAM
|
||||
}
|
||||
|
||||
func (c *Commands) getDefaultFeatures(ctx context.Context) (*domain.Features, error) {
|
||||
existingFeatures := NewIAMFeaturesWriteModel()
|
||||
existingFeatures := NewInstanceFeaturesWriteModel()
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, existingFeatures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+14
-14
@@ -7,15 +7,15 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/features"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMFeaturesWriteModel struct {
|
||||
type InstanceFeaturesWriteModel struct {
|
||||
FeaturesWriteModel
|
||||
}
|
||||
|
||||
func NewIAMFeaturesWriteModel() *IAMFeaturesWriteModel {
|
||||
return &IAMFeaturesWriteModel{
|
||||
func NewInstanceFeaturesWriteModel() *InstanceFeaturesWriteModel {
|
||||
return &InstanceFeaturesWriteModel{
|
||||
FeaturesWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -25,33 +25,33 @@ func NewIAMFeaturesWriteModel() *IAMFeaturesWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMFeaturesWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceFeaturesWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.FeaturesSetEvent:
|
||||
case *instance.FeaturesSetEvent:
|
||||
wm.FeaturesWriteModel.AppendEvents(&e.FeaturesSetEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMFeaturesWriteModel) IsValid() bool {
|
||||
func (wm *InstanceFeaturesWriteModel) IsValid() bool {
|
||||
return wm.AggregateID != ""
|
||||
}
|
||||
|
||||
func (wm *IAMFeaturesWriteModel) Reduce() error {
|
||||
func (wm *InstanceFeaturesWriteModel) Reduce() error {
|
||||
return wm.FeaturesWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMFeaturesWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceFeaturesWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
EventTypes(iam.FeaturesSetEventType).
|
||||
AggregateTypes(iam.AggregateType).
|
||||
EventTypes(instance.FeaturesSetEventType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMFeaturesWriteModel) NewSetEvent(
|
||||
func (wm *InstanceFeaturesWriteModel) NewSetEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
tierName, tierDescription string,
|
||||
@@ -75,7 +75,7 @@ func (wm *IAMFeaturesWriteModel) NewSetEvent(
|
||||
lockoutPolicy bool,
|
||||
actionsAllowed domain.ActionsAllowed,
|
||||
maxActions int,
|
||||
) (*iam.FeaturesSetEvent, bool) {
|
||||
) (*instance.FeaturesSetEvent, bool) {
|
||||
|
||||
changes := make([]features.FeaturesChanges, 0)
|
||||
|
||||
@@ -148,7 +148,7 @@ func (wm *IAMFeaturesWriteModel) NewSetEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewFeaturesSetEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewFeaturesSetEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDefaultIDPConfig(ctx context.Context, config *domain.IDPConfig) (*domain.IDPConfig, error) {
|
||||
@@ -21,13 +21,13 @@ func (c *Commands) AddDefaultIDPConfig(ctx context.Context, config *domain.IDPCo
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
addedConfig := NewIAMIDPConfigWriteModel(idpConfigID)
|
||||
addedConfig := NewInstanceIDPConfigWriteModel(idpConfigID)
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedConfig.WriteModel)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedConfig.WriteModel)
|
||||
events := []eventstore.Command{
|
||||
iam_repo.NewIDPConfigAddedEvent(
|
||||
instance.NewIDPConfigAddedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
idpConfigID,
|
||||
config.Name,
|
||||
config.Type,
|
||||
@@ -41,9 +41,9 @@ func (c *Commands) AddDefaultIDPConfig(ctx context.Context, config *domain.IDPCo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
events = append(events, iam_repo.NewIDPOIDCConfigAddedEvent(
|
||||
events = append(events, instance.NewIDPOIDCConfigAddedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
config.OIDCConfig.ClientID,
|
||||
idpConfigID,
|
||||
config.OIDCConfig.Issuer,
|
||||
@@ -55,9 +55,9 @@ func (c *Commands) AddDefaultIDPConfig(ctx context.Context, config *domain.IDPCo
|
||||
config.OIDCConfig.Scopes...,
|
||||
))
|
||||
} else if config.JWTConfig != nil {
|
||||
events = append(events, iam_repo.NewIDPJWTConfigAddedEvent(
|
||||
events = append(events, instance.NewIDPJWTConfigAddedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
idpConfigID,
|
||||
config.JWTConfig.JWTEndpoint,
|
||||
config.JWTConfig.Issuer,
|
||||
@@ -78,20 +78,20 @@ func (c *Commands) AddDefaultIDPConfig(ctx context.Context, config *domain.IDPCo
|
||||
|
||||
func (c *Commands) ChangeDefaultIDPConfig(ctx context.Context, config *domain.IDPConfig) (*domain.IDPConfig, error) {
|
||||
if config.IDPConfigID == "" {
|
||||
return nil, errors.ThrowInvalidArgument(nil, "IAM-4m9gs", "Errors.IDMissing")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "INSTANCE-4m9gs", "Errors.IDMissing")
|
||||
}
|
||||
existingIDP, err := c.iamIDPConfigWriteModelByID(ctx, config.IDPConfigID)
|
||||
existingIDP, err := c.isntanceIDPConfigWriteModelByID(ctx, config.IDPConfigID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existingIDP.State == domain.IDPConfigStateRemoved || existingIDP.State == domain.IDPConfigStateUnspecified {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-m0e3r", "Errors.IDPConfig.NotExisting")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-m0e3r", "Errors.IDPConfig.NotExisting")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingIDP.WriteModel)
|
||||
changedEvent, hasChanged := existingIDP.NewChangedEvent(ctx, iamAgg, config.IDPConfigID, config.Name, config.StylingType, config.AutoRegister)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingIDP.WriteModel)
|
||||
changedEvent, hasChanged := existingIDP.NewChangedEvent(ctx, instanceAgg, config.IDPConfigID, config.Name, config.StylingType, config.AutoRegister)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
}
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
if err != nil {
|
||||
@@ -105,15 +105,15 @@ func (c *Commands) ChangeDefaultIDPConfig(ctx context.Context, config *domain.ID
|
||||
}
|
||||
|
||||
func (c *Commands) DeactivateDefaultIDPConfig(ctx context.Context, idpID string) (*domain.ObjectDetails, error) {
|
||||
existingIDP, err := c.iamIDPConfigWriteModelByID(ctx, idpID)
|
||||
existingIDP, err := c.isntanceIDPConfigWriteModelByID(ctx, idpID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existingIDP.State != domain.IDPConfigStateActive {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-2n0fs", "Errors.IAM.IDPConfig.NotActive")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-2n0fs", "Errors.IAM.IDPConfig.NotActive")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingIDP.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewIDPConfigDeactivatedEvent(ctx, iamAgg, idpID))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingIDP.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewIDPConfigDeactivatedEvent(ctx, instanceAgg, idpID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -125,15 +125,15 @@ func (c *Commands) DeactivateDefaultIDPConfig(ctx context.Context, idpID string)
|
||||
}
|
||||
|
||||
func (c *Commands) ReactivateDefaultIDPConfig(ctx context.Context, idpID string) (*domain.ObjectDetails, error) {
|
||||
existingIDP, err := c.iamIDPConfigWriteModelByID(ctx, idpID)
|
||||
existingIDP, err := c.isntanceIDPConfigWriteModelByID(ctx, idpID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existingIDP.State != domain.IDPConfigStateInactive {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-5Mo0d", "Errors.IAM.IDPConfig.NotInactive")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-5Mo0d", "Errors.IAM.IDPConfig.NotInactive")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingIDP.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewIDPConfigReactivatedEvent(ctx, iamAgg, idpID))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingIDP.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewIDPConfigReactivatedEvent(ctx, instanceAgg, idpID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -145,22 +145,22 @@ func (c *Commands) ReactivateDefaultIDPConfig(ctx context.Context, idpID string)
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveDefaultIDPConfig(ctx context.Context, idpID string, idpProviders []*domain.IDPProvider, externalIDPs ...*domain.UserIDPLink) (*domain.ObjectDetails, error) {
|
||||
existingIDP, err := c.iamIDPConfigWriteModelByID(ctx, idpID)
|
||||
existingIDP, err := c.isntanceIDPConfigWriteModelByID(ctx, idpID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existingIDP.State == domain.IDPConfigStateRemoved || existingIDP.State == domain.IDPConfigStateUnspecified {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-4M0xy", "Errors.IDPConfig.NotExisting")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-4M0xy", "Errors.IDPConfig.NotExisting")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingIDP.WriteModel)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingIDP.WriteModel)
|
||||
events := []eventstore.Command{
|
||||
iam_repo.NewIDPConfigRemovedEvent(ctx, iamAgg, idpID, existingIDP.Name),
|
||||
instance.NewIDPConfigRemovedEvent(ctx, instanceAgg, idpID, existingIDP.Name),
|
||||
}
|
||||
|
||||
for _, idpProvider := range idpProviders {
|
||||
if idpProvider.AggregateID == domain.IAMID {
|
||||
userEvents := c.removeIDPProviderFromDefaultLoginPolicy(ctx, iamAgg, idpProvider, true, externalIDPs...)
|
||||
userEvents := c.removeIDPProviderFromDefaultLoginPolicy(ctx, instanceAgg, idpProvider, true, externalIDPs...)
|
||||
events = append(events, userEvents...)
|
||||
}
|
||||
orgAgg := OrgAggregateFromWriteModel(&NewOrgIdentityProviderWriteModel(idpProvider.AggregateID, idpID).WriteModel)
|
||||
@@ -179,22 +179,22 @@ func (c *Commands) RemoveDefaultIDPConfig(ctx context.Context, idpID string, idp
|
||||
return writeModelToObjectDetails(&existingIDP.IDPConfigWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) getIAMIDPConfigByID(ctx context.Context, idpID string) (*domain.IDPConfig, error) {
|
||||
config, err := c.iamIDPConfigWriteModelByID(ctx, idpID)
|
||||
func (c *Commands) getInstanceIDPConfigByID(ctx context.Context, idpID string) (*domain.IDPConfig, error) {
|
||||
config, err := c.isntanceIDPConfigWriteModelByID(ctx, idpID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !config.State.Exists() {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-p0pFF", "Errors.IDPConfig.NotExisting")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-p0pFF", "Errors.IDPConfig.NotExisting")
|
||||
}
|
||||
return writeModelToIDPConfig(&config.IDPConfigWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) iamIDPConfigWriteModelByID(ctx context.Context, idpID string) (policy *IAMIDPConfigWriteModel, err error) {
|
||||
func (c *Commands) isntanceIDPConfigWriteModelByID(ctx context.Context, idpID string) (policy *InstanceIDPConfigWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMIDPConfigWriteModel(idpID)
|
||||
writeModel := NewInstanceIDPConfigWriteModel(idpID)
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+26
-26
@@ -6,16 +6,16 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/idpconfig"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMIDPConfigWriteModel struct {
|
||||
type InstanceIDPConfigWriteModel struct {
|
||||
IDPConfigWriteModel
|
||||
}
|
||||
|
||||
func NewIAMIDPConfigWriteModel(configID string) *IAMIDPConfigWriteModel {
|
||||
return &IAMIDPConfigWriteModel{
|
||||
func NewInstanceIDPConfigWriteModel(configID string) *InstanceIDPConfigWriteModel {
|
||||
return &InstanceIDPConfigWriteModel{
|
||||
IDPConfigWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -26,57 +26,57 @@ func NewIAMIDPConfigWriteModel(configID string) *IAMIDPConfigWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMIDPConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceIDPConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
EventTypes(
|
||||
iam.IDPConfigAddedEventType,
|
||||
iam.IDPConfigChangedEventType,
|
||||
iam.IDPConfigDeactivatedEventType,
|
||||
iam.IDPConfigReactivatedEventType,
|
||||
iam.IDPConfigRemovedEventType,
|
||||
iam.IDPOIDCConfigAddedEventType,
|
||||
iam.IDPOIDCConfigChangedEventType).
|
||||
instance.IDPConfigAddedEventType,
|
||||
instance.IDPConfigChangedEventType,
|
||||
instance.IDPConfigDeactivatedEventType,
|
||||
instance.IDPConfigReactivatedEventType,
|
||||
instance.IDPConfigRemovedEventType,
|
||||
instance.IDPOIDCConfigAddedEventType,
|
||||
instance.IDPOIDCConfigChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMIDPConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceIDPConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.IDPConfigAddedEvent:
|
||||
case *instance.IDPConfigAddedEvent:
|
||||
if wm.ConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigAddedEvent)
|
||||
case *iam.IDPConfigChangedEvent:
|
||||
case *instance.IDPConfigChangedEvent:
|
||||
if wm.ConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigChangedEvent)
|
||||
case *iam.IDPConfigDeactivatedEvent:
|
||||
case *instance.IDPConfigDeactivatedEvent:
|
||||
if wm.ConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigDeactivatedEvent)
|
||||
case *iam.IDPConfigReactivatedEvent:
|
||||
case *instance.IDPConfigReactivatedEvent:
|
||||
if wm.ConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigReactivatedEvent)
|
||||
case *iam.IDPConfigRemovedEvent:
|
||||
case *instance.IDPConfigRemovedEvent:
|
||||
if wm.ConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigRemovedEvent)
|
||||
case *iam.IDPOIDCConfigAddedEvent:
|
||||
case *instance.IDPOIDCConfigAddedEvent:
|
||||
if wm.ConfigID != e.IDPConfigID {
|
||||
continue
|
||||
}
|
||||
wm.IDPConfigWriteModel.AppendEvents(&e.OIDCConfigAddedEvent)
|
||||
case *iam.IDPOIDCConfigChangedEvent:
|
||||
case *instance.IDPOIDCConfigChangedEvent:
|
||||
if wm.ConfigID != e.IDPConfigID {
|
||||
continue
|
||||
}
|
||||
@@ -85,23 +85,23 @@ func (wm *IAMIDPConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMIDPConfigWriteModel) Reduce() error {
|
||||
func (wm *InstanceIDPConfigWriteModel) Reduce() error {
|
||||
return wm.IDPConfigWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMIDPConfigWriteModel) AppendAndReduce(events ...eventstore.Event) error {
|
||||
func (wm *InstanceIDPConfigWriteModel) AppendAndReduce(events ...eventstore.Event) error {
|
||||
wm.AppendEvents(events...)
|
||||
return wm.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMIDPConfigWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceIDPConfigWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
configID,
|
||||
name string,
|
||||
stylingType domain.IDPConfigStylingType,
|
||||
autoRegister bool,
|
||||
) (*iam.IDPConfigChangedEvent, bool) {
|
||||
) (*instance.IDPConfigChangedEvent, bool) {
|
||||
|
||||
changes := make([]idpconfig.IDPConfigChanges, 0)
|
||||
oldName := ""
|
||||
@@ -118,7 +118,7 @@ func (wm *IAMIDPConfigWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changeEvent, err := iam.NewIDPConfigChangedEvent(ctx, aggregate, configID, oldName, changes)
|
||||
changeEvent, err := instance.NewIDPConfigChangedEvent(ctx, aggregate, configID, oldName, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
+16
-16
@@ -15,8 +15,8 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/id"
|
||||
id_mock "github.com/caos/zitadel/internal/id/mock"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/idpconfig"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func TestCommandSide_AddDefaultIDPConfig(t *testing.T) {
|
||||
@@ -62,8 +62,8 @@ func TestCommandSide_AddDefaultIDPConfig(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name1",
|
||||
domain.IDPConfigTypeOIDC,
|
||||
@@ -72,8 +72,8 @@ func TestCommandSide_AddDefaultIDPConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"clientid1",
|
||||
"config1",
|
||||
"issuer",
|
||||
@@ -137,8 +137,8 @@ func TestCommandSide_AddDefaultIDPConfig(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name1",
|
||||
domain.IDPConfigTypeOIDC,
|
||||
@@ -147,8 +147,8 @@ func TestCommandSide_AddDefaultIDPConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPJWTConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPJWTConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"jwt-endpoint",
|
||||
"issuer",
|
||||
@@ -268,8 +268,8 @@ func TestCommandSide_ChangeDefaultIDPConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name1",
|
||||
domain.IDPConfigTypeOIDC,
|
||||
@@ -278,8 +278,8 @@ func TestCommandSide_ChangeDefaultIDPConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"clientid1",
|
||||
"config1",
|
||||
"issuer",
|
||||
@@ -351,9 +351,9 @@ func TestCommandSide_ChangeDefaultIDPConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultIDPConfigChangedEvent(ctx context.Context, configID, oldName, newName string, stylingType domain.IDPConfigStylingType, autoRegister bool) *iam.IDPConfigChangedEvent {
|
||||
event, _ := iam.NewIDPConfigChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultIDPConfigChangedEvent(ctx context.Context, configID, oldName, newName string, stylingType domain.IDPConfigStylingType, autoRegister bool) *instance.IDPConfigChangedEvent {
|
||||
event, _ := instance.NewIDPConfigChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
configID,
|
||||
oldName,
|
||||
[]idpconfig.IDPConfigChanges{
|
||||
+6
-6
@@ -9,22 +9,22 @@ import (
|
||||
|
||||
func (c *Commands) ChangeDefaultIDPJWTConfig(ctx context.Context, config *domain.JWTIDPConfig) (*domain.JWTIDPConfig, error) {
|
||||
if config.IDPConfigID == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-m9322", "Errors.IDMissing")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-m9322", "Errors.IDMissing")
|
||||
}
|
||||
existingConfig := NewIAMIDPJWTConfigWriteModel(config.IDPConfigID)
|
||||
existingConfig := NewInstanceIDPJWTConfigWriteModel(config.IDPConfigID)
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, existingConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if existingConfig.State == domain.IDPConfigStateRemoved || existingConfig.State == domain.IDPConfigStateUnspecified {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-2m00d", "Errors.IAM.IDPConfig.AlreadyExists")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-2m00d", "Errors.IAM.IDPConfig.AlreadyExists")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingConfig.WriteModel)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingConfig.WriteModel)
|
||||
changedEvent, hasChanged, err := existingConfig.NewChangedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
config.IDPConfigID,
|
||||
config.JWTEndpoint,
|
||||
config.Issuer,
|
||||
@@ -34,7 +34,7 @@ func (c *Commands) ChangeDefaultIDPJWTConfig(ctx context.Context, config *domain
|
||||
return nil, err
|
||||
}
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-3n9gg", "Errors.IAM.IDPConfig.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-3n9gg", "Errors.IAM.IDPConfig.NotChanged")
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
+21
-21
@@ -6,16 +6,16 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/idpconfig"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMIDPJWTConfigWriteModel struct {
|
||||
type InstanceIDPJWTConfigWriteModel struct {
|
||||
JWTConfigWriteModel
|
||||
}
|
||||
|
||||
func NewIAMIDPJWTConfigWriteModel(idpConfigID string) *IAMIDPJWTConfigWriteModel {
|
||||
return &IAMIDPJWTConfigWriteModel{
|
||||
func NewInstanceIDPJWTConfigWriteModel(idpConfigID string) *InstanceIDPJWTConfigWriteModel {
|
||||
return &InstanceIDPJWTConfigWriteModel{
|
||||
JWTConfigWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -26,30 +26,30 @@ func NewIAMIDPJWTConfigWriteModel(idpConfigID string) *IAMIDPJWTConfigWriteModel
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMIDPJWTConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceIDPJWTConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.IDPJWTConfigAddedEvent:
|
||||
case *instance.IDPJWTConfigAddedEvent:
|
||||
if wm.IDPConfigID != e.IDPConfigID {
|
||||
continue
|
||||
}
|
||||
wm.JWTConfigWriteModel.AppendEvents(&e.JWTConfigAddedEvent)
|
||||
case *iam.IDPJWTConfigChangedEvent:
|
||||
case *instance.IDPJWTConfigChangedEvent:
|
||||
if wm.IDPConfigID != e.IDPConfigID {
|
||||
continue
|
||||
}
|
||||
wm.JWTConfigWriteModel.AppendEvents(&e.JWTConfigChangedEvent)
|
||||
case *iam.IDPConfigReactivatedEvent:
|
||||
case *instance.IDPConfigReactivatedEvent:
|
||||
if wm.IDPConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
wm.JWTConfigWriteModel.AppendEvents(&e.IDPConfigReactivatedEvent)
|
||||
case *iam.IDPConfigDeactivatedEvent:
|
||||
case *instance.IDPConfigDeactivatedEvent:
|
||||
if wm.IDPConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
wm.JWTConfigWriteModel.AppendEvents(&e.IDPConfigDeactivatedEvent)
|
||||
case *iam.IDPConfigRemovedEvent:
|
||||
case *instance.IDPConfigRemovedEvent:
|
||||
if wm.IDPConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
@@ -60,29 +60,29 @@ func (wm *IAMIDPJWTConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMIDPJWTConfigWriteModel) Reduce() error {
|
||||
func (wm *InstanceIDPJWTConfigWriteModel) Reduce() error {
|
||||
if err := wm.JWTConfigWriteModel.Reduce(); err != nil {
|
||||
return err
|
||||
}
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMIDPJWTConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceIDPJWTConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
EventTypes(
|
||||
iam.IDPJWTConfigAddedEventType,
|
||||
iam.IDPJWTConfigChangedEventType,
|
||||
iam.IDPConfigReactivatedEventType,
|
||||
iam.IDPConfigDeactivatedEventType,
|
||||
iam.IDPConfigRemovedEventType).
|
||||
instance.IDPJWTConfigAddedEventType,
|
||||
instance.IDPJWTConfigChangedEventType,
|
||||
instance.IDPConfigReactivatedEventType,
|
||||
instance.IDPConfigDeactivatedEventType,
|
||||
instance.IDPConfigRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMIDPJWTConfigWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceIDPJWTConfigWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
idpConfigID,
|
||||
@@ -90,7 +90,7 @@ func (wm *IAMIDPJWTConfigWriteModel) NewChangedEvent(
|
||||
issuer,
|
||||
keysEndpoint,
|
||||
headerName string,
|
||||
) (*iam.IDPJWTConfigChangedEvent, bool, error) {
|
||||
) (*instance.IDPJWTConfigChangedEvent, bool, error) {
|
||||
|
||||
changes := make([]idpconfig.JWTConfigChanges, 0)
|
||||
if wm.JWTEndpoint != jwtEndpoint {
|
||||
@@ -108,7 +108,7 @@ func (wm *IAMIDPJWTConfigWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
changeEvent, err := iam.NewIDPJWTConfigChangedEvent(ctx, aggregate, idpConfigID, changes)
|
||||
changeEvent, err := instance.NewIDPJWTConfigChangedEvent(ctx, aggregate, idpConfigID, changes)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
+18
-18
@@ -13,8 +13,8 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/idpconfig"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
|
||||
@@ -78,8 +78,8 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name1",
|
||||
domain.IDPConfigTypeJWT,
|
||||
@@ -88,8 +88,8 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPJWTConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPJWTConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"jwt-endpoint",
|
||||
"issuer",
|
||||
@@ -98,8 +98,8 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name",
|
||||
),
|
||||
@@ -124,8 +124,8 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name1",
|
||||
domain.IDPConfigTypeJWT,
|
||||
@@ -134,8 +134,8 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPJWTConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPJWTConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"jwt-endpoint",
|
||||
"issuer",
|
||||
@@ -168,8 +168,8 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name1",
|
||||
domain.IDPConfigTypeJWT,
|
||||
@@ -178,8 +178,8 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPJWTConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPJWTConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"jwt-endpoint",
|
||||
"issuer",
|
||||
@@ -249,9 +249,9 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultIDPJWTConfigChangedEvent(ctx context.Context, configID, jwtEndpoint, issuer, keysEndpoint, headerName string) *iam.IDPJWTConfigChangedEvent {
|
||||
event, _ := iam.NewIDPJWTConfigChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultIDPJWTConfigChangedEvent(ctx context.Context, configID, jwtEndpoint, issuer, keysEndpoint, headerName string) *instance.IDPJWTConfigChangedEvent {
|
||||
event, _ := instance.NewIDPJWTConfigChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
configID,
|
||||
[]idpconfig.JWTConfigChanges{
|
||||
idpconfig.ChangeJWTEndpoint(jwtEndpoint),
|
||||
+6
-6
@@ -9,22 +9,22 @@ import (
|
||||
|
||||
func (c *Commands) ChangeDefaultIDPOIDCConfig(ctx context.Context, config *domain.OIDCIDPConfig) (*domain.OIDCIDPConfig, error) {
|
||||
if config.IDPConfigID == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-9djf8", "Errors.IDMissing")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-9djf8", "Errors.IDMissing")
|
||||
}
|
||||
existingConfig := NewIAMIDPOIDCConfigWriteModel(config.IDPConfigID)
|
||||
existingConfig := NewInstanceIDPOIDCConfigWriteModel(config.IDPConfigID)
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, existingConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if existingConfig.State == domain.IDPConfigStateRemoved || existingConfig.State == domain.IDPConfigStateUnspecified {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-67J9d", "Errors.IAM.IDPConfig.AlreadyExists")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-67J9d", "Errors.IAM.IDPConfig.AlreadyExists")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingConfig.WriteModel)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingConfig.WriteModel)
|
||||
changedEvent, hasChanged, err := existingConfig.NewChangedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
config.IDPConfigID,
|
||||
config.ClientID,
|
||||
config.Issuer,
|
||||
@@ -39,7 +39,7 @@ func (c *Commands) ChangeDefaultIDPOIDCConfig(ctx context.Context, config *domai
|
||||
return nil, err
|
||||
}
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
+21
-21
@@ -8,16 +8,16 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/idpconfig"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMIDPOIDCConfigWriteModel struct {
|
||||
type InstanceIDPOIDCConfigWriteModel struct {
|
||||
OIDCConfigWriteModel
|
||||
}
|
||||
|
||||
func NewIAMIDPOIDCConfigWriteModel(idpConfigID string) *IAMIDPOIDCConfigWriteModel {
|
||||
return &IAMIDPOIDCConfigWriteModel{
|
||||
func NewInstanceIDPOIDCConfigWriteModel(idpConfigID string) *InstanceIDPOIDCConfigWriteModel {
|
||||
return &InstanceIDPOIDCConfigWriteModel{
|
||||
OIDCConfigWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -28,30 +28,30 @@ func NewIAMIDPOIDCConfigWriteModel(idpConfigID string) *IAMIDPOIDCConfigWriteMod
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMIDPOIDCConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceIDPOIDCConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.IDPOIDCConfigAddedEvent:
|
||||
case *instance.IDPOIDCConfigAddedEvent:
|
||||
if wm.IDPConfigID != e.IDPConfigID {
|
||||
continue
|
||||
}
|
||||
wm.OIDCConfigWriteModel.AppendEvents(&e.OIDCConfigAddedEvent)
|
||||
case *iam.IDPOIDCConfigChangedEvent:
|
||||
case *instance.IDPOIDCConfigChangedEvent:
|
||||
if wm.IDPConfigID != e.IDPConfigID {
|
||||
continue
|
||||
}
|
||||
wm.OIDCConfigWriteModel.AppendEvents(&e.OIDCConfigChangedEvent)
|
||||
case *iam.IDPConfigReactivatedEvent:
|
||||
case *instance.IDPConfigReactivatedEvent:
|
||||
if wm.IDPConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
wm.OIDCConfigWriteModel.AppendEvents(&e.IDPConfigReactivatedEvent)
|
||||
case *iam.IDPConfigDeactivatedEvent:
|
||||
case *instance.IDPConfigDeactivatedEvent:
|
||||
if wm.IDPConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
wm.OIDCConfigWriteModel.AppendEvents(&e.IDPConfigDeactivatedEvent)
|
||||
case *iam.IDPConfigRemovedEvent:
|
||||
case *instance.IDPConfigRemovedEvent:
|
||||
if wm.IDPConfigID != e.ConfigID {
|
||||
continue
|
||||
}
|
||||
@@ -62,29 +62,29 @@ func (wm *IAMIDPOIDCConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMIDPOIDCConfigWriteModel) Reduce() error {
|
||||
func (wm *InstanceIDPOIDCConfigWriteModel) Reduce() error {
|
||||
if err := wm.OIDCConfigWriteModel.Reduce(); err != nil {
|
||||
return err
|
||||
}
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMIDPOIDCConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceIDPOIDCConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
EventTypes(
|
||||
iam.IDPOIDCConfigAddedEventType,
|
||||
iam.IDPOIDCConfigChangedEventType,
|
||||
iam.IDPConfigReactivatedEventType,
|
||||
iam.IDPConfigDeactivatedEventType,
|
||||
iam.IDPConfigRemovedEventType).
|
||||
instance.IDPOIDCConfigAddedEventType,
|
||||
instance.IDPOIDCConfigChangedEventType,
|
||||
instance.IDPConfigReactivatedEventType,
|
||||
instance.IDPConfigDeactivatedEventType,
|
||||
instance.IDPConfigRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMIDPOIDCConfigWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceIDPOIDCConfigWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
idpConfigID,
|
||||
@@ -97,7 +97,7 @@ func (wm *IAMIDPOIDCConfigWriteModel) NewChangedEvent(
|
||||
idpDisplayNameMapping,
|
||||
userNameMapping domain.OIDCMappingField,
|
||||
scopes ...string,
|
||||
) (*iam.IDPOIDCConfigChangedEvent, bool, error) {
|
||||
) (*instance.IDPOIDCConfigChangedEvent, bool, error) {
|
||||
|
||||
changes := make([]idpconfig.OIDCConfigChanges, 0)
|
||||
var clientSecret *crypto.CryptoValue
|
||||
@@ -133,7 +133,7 @@ func (wm *IAMIDPOIDCConfigWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
changeEvent, err := iam.NewIDPOIDCConfigChangedEvent(ctx, aggregate, idpConfigID, changes)
|
||||
changeEvent, err := instance.NewIDPOIDCConfigChangedEvent(ctx, aggregate, idpConfigID, changes)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
+18
-18
@@ -13,8 +13,8 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/idpconfig"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
|
||||
@@ -78,8 +78,8 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name1",
|
||||
domain.IDPConfigTypeOIDC,
|
||||
@@ -88,8 +88,8 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"clientid1",
|
||||
"config1",
|
||||
"issuer",
|
||||
@@ -107,8 +107,8 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name",
|
||||
),
|
||||
@@ -133,8 +133,8 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name1",
|
||||
domain.IDPConfigTypeOIDC,
|
||||
@@ -143,8 +143,8 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"clientid1",
|
||||
"config1",
|
||||
"issuer",
|
||||
@@ -189,8 +189,8 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name1",
|
||||
domain.IDPConfigTypeOIDC,
|
||||
@@ -199,8 +199,8 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPOIDCConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"clientid1",
|
||||
"config1",
|
||||
"issuer",
|
||||
@@ -295,9 +295,9 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultIDPOIDCConfigChangedEvent(ctx context.Context, configID, clientID, issuer, authorizationEndpoint, tokenEndpoint string, secret *crypto.CryptoValue, displayMapping, usernameMapping domain.OIDCMappingField, scopes []string) *iam.IDPOIDCConfigChangedEvent {
|
||||
event, _ := iam.NewIDPOIDCConfigChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultIDPOIDCConfigChangedEvent(ctx context.Context, configID, clientID, issuer, authorizationEndpoint, tokenEndpoint string, secret *crypto.CryptoValue, displayMapping, usernameMapping domain.OIDCMappingField, scopes []string) *instance.IDPOIDCConfigChangedEvent {
|
||||
event, _ := instance.NewIDPOIDCConfigChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
configID,
|
||||
[]idpconfig.OIDCConfigChanges{
|
||||
idpconfig.ChangeClientID(clientID),
|
||||
@@ -0,0 +1,142 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddInstanceMember(ctx context.Context, member *domain.Member) (*domain.Member, error) {
|
||||
if member.UserID == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-Mf83b", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
addedMember := NewInstanceMemberWriteModel(member.UserID)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedMember.MemberWriteModel.WriteModel)
|
||||
err := c.checkUserExists(ctx, addedMember.UserID, "")
|
||||
if err != nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(err, "INSTANCE-5N9vs", "Errors.User.NotFound")
|
||||
}
|
||||
event, err := c.addInstanceMember(ctx, instanceAgg, addedMember, member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(addedMember, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return memberWriteModelToMember(&addedMember.MemberWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addInstanceMember(ctx context.Context, instanceAgg *eventstore.Aggregate, addedMember *InstanceMemberWriteModel, member *domain.Member) (eventstore.Command, error) {
|
||||
if !member.IsIAMValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-GR34U", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
if len(domain.CheckForInvalidRoles(member.Roles, domain.IAMRolePrefix, c.zitadelRoles)) > 0 {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-4m0fS", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedMember)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedMember.State == domain.MemberStateActive {
|
||||
return nil, errors.ThrowAlreadyExists(nil, "INSTANCE-sdgQ4", "Errors.IAM.Member.AlreadyExists")
|
||||
}
|
||||
|
||||
return instance.NewMemberAddedEvent(ctx, instanceAgg, member.UserID, member.Roles...), nil
|
||||
}
|
||||
|
||||
//ChangeInstanceMember updates an existing member
|
||||
func (c *Commands) ChangeInstanceMember(ctx context.Context, member *domain.Member) (*domain.Member, error) {
|
||||
if !member.IsIAMValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-LiaZi", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
if len(domain.CheckForInvalidRoles(member.Roles, domain.IAMRolePrefix, c.zitadelRoles)) > 0 {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-3m9fs", "Errors.IAM.MemberInvalid")
|
||||
}
|
||||
|
||||
existingMember, err := c.instanceMemberWriteModelByID(ctx, member.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(existingMember.Roles, member.Roles) {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-LiaZi", "Errors.IAM.Member.RolesNotChanged")
|
||||
}
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingMember.MemberWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewMemberChangedEvent(ctx, instanceAgg, member.UserID, member.Roles...))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(existingMember, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return memberWriteModelToMember(&existingMember.MemberWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveInstanceMember(ctx context.Context, userID string) (*domain.ObjectDetails, error) {
|
||||
if userID == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-LiaZi", "Errors.IDMissing")
|
||||
}
|
||||
memberWriteModel, err := c.instanceMemberWriteModelByID(ctx, userID)
|
||||
if err != nil && !errors.IsNotFound(err) {
|
||||
return nil, err
|
||||
}
|
||||
if errors.IsNotFound(err) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&memberWriteModel.MemberWriteModel.WriteModel)
|
||||
removeEvent := c.removeInstanceMember(ctx, instanceAgg, userID, false)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, removeEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(memberWriteModel, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return writeModelToObjectDetails(&memberWriteModel.MemberWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) removeInstanceMember(ctx context.Context, instanceAgg *eventstore.Aggregate, userID string, cascade bool) eventstore.Command {
|
||||
if cascade {
|
||||
return instance.NewMemberCascadeRemovedEvent(
|
||||
ctx,
|
||||
instanceAgg,
|
||||
userID)
|
||||
} else {
|
||||
return instance.NewMemberRemovedEvent(ctx, instanceAgg, userID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Commands) instanceMemberWriteModelByID(ctx context.Context, userID string) (member *InstanceMemberWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewInstanceMemberWriteModel(userID)
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if writeModel.State == domain.MemberStateUnspecified || writeModel.State == domain.MemberStateRemoved {
|
||||
return nil, errors.ThrowNotFound(nil, "INSTANCE-D8JxR", "Errors.NotFound")
|
||||
}
|
||||
|
||||
return writeModel, nil
|
||||
}
|
||||
@@ -3,15 +3,15 @@ package command
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMMemberWriteModel struct {
|
||||
type InstanceMemberWriteModel struct {
|
||||
MemberWriteModel
|
||||
}
|
||||
|
||||
func NewIAMMemberWriteModel(userID string) *IAMMemberWriteModel {
|
||||
return &IAMMemberWriteModel{
|
||||
func NewInstanceMemberWriteModel(userID string) *InstanceMemberWriteModel {
|
||||
return &InstanceMemberWriteModel{
|
||||
MemberWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -22,25 +22,25 @@ func NewIAMMemberWriteModel(userID string) *IAMMemberWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMMemberWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceMemberWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.MemberAddedEvent:
|
||||
case *instance.MemberAddedEvent:
|
||||
if e.UserID != wm.MemberWriteModel.UserID {
|
||||
continue
|
||||
}
|
||||
wm.MemberWriteModel.AppendEvents(&e.MemberAddedEvent)
|
||||
case *iam.MemberChangedEvent:
|
||||
case *instance.MemberChangedEvent:
|
||||
if e.UserID != wm.MemberWriteModel.UserID {
|
||||
continue
|
||||
}
|
||||
wm.MemberWriteModel.AppendEvents(&e.MemberChangedEvent)
|
||||
case *iam.MemberRemovedEvent:
|
||||
case *instance.MemberRemovedEvent:
|
||||
if e.UserID != wm.MemberWriteModel.UserID {
|
||||
continue
|
||||
}
|
||||
wm.MemberWriteModel.AppendEvents(&e.MemberRemovedEvent)
|
||||
case *iam.MemberCascadeRemovedEvent:
|
||||
case *instance.MemberCascadeRemovedEvent:
|
||||
if e.UserID != wm.MemberWriteModel.UserID {
|
||||
continue
|
||||
}
|
||||
@@ -49,20 +49,20 @@ func (wm *IAMMemberWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMMemberWriteModel) Reduce() error {
|
||||
func (wm *InstanceMemberWriteModel) Reduce() error {
|
||||
return wm.MemberWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMMemberWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceMemberWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.MemberWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.MemberAddedEventType,
|
||||
iam.MemberChangedEventType,
|
||||
iam.MemberRemovedEventType,
|
||||
iam.MemberCascadeRemovedEventType).
|
||||
instance.MemberAddedEventType,
|
||||
instance.MemberChangedEventType,
|
||||
instance.MemberRemovedEventType,
|
||||
instance.MemberCascadeRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/member"
|
||||
"github.com/caos/zitadel/internal/repository/user"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -126,8 +126,8 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
|
||||
),
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewMemberAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewMemberAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"user1",
|
||||
),
|
||||
),
|
||||
@@ -174,8 +174,8 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
|
||||
expectFilter(),
|
||||
expectPushFailed(caos_errs.ThrowAlreadyExists(nil, "ERROR", "internal"),
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(iam.NewMemberAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
eventFromEventPusher(instance.NewMemberAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"user1",
|
||||
[]string{"IAM_OWNER"}...,
|
||||
)),
|
||||
@@ -224,8 +224,8 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
|
||||
expectFilter(),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(iam.NewMemberAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
eventFromEventPusher(instance.NewMemberAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"user1",
|
||||
[]string{"IAM_OWNER"}...,
|
||||
)),
|
||||
@@ -264,7 +264,7 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
|
||||
eventstore: tt.fields.eventstore,
|
||||
zitadelRoles: tt.fields.zitadelRoles,
|
||||
}
|
||||
got, err := r.AddIAMMember(tt.args.ctx, tt.args.member)
|
||||
got, err := r.AddInstanceMember(tt.args.ctx, tt.args.member)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -361,8 +361,8 @@ func TestCommandSide_ChangeIAMMember(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewMemberAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewMemberAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"user1",
|
||||
[]string{"IAM_OWNER"}...,
|
||||
),
|
||||
@@ -393,8 +393,8 @@ func TestCommandSide_ChangeIAMMember(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewMemberAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewMemberAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"user1",
|
||||
[]string{"IAM_OWNER"}...,
|
||||
),
|
||||
@@ -402,8 +402,8 @@ func TestCommandSide_ChangeIAMMember(t *testing.T) {
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(iam.NewMemberChangedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
eventFromEventPusher(instance.NewMemberChangedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"user1",
|
||||
[]string{"IAM_OWNER", "IAM_OWNER_VIEWER"}...,
|
||||
)),
|
||||
@@ -444,7 +444,7 @@ func TestCommandSide_ChangeIAMMember(t *testing.T) {
|
||||
eventstore: tt.fields.eventstore,
|
||||
zitadelRoles: tt.fields.zitadelRoles,
|
||||
}
|
||||
got, err := r.ChangeIAMMember(tt.args.ctx, tt.args.member)
|
||||
got, err := r.ChangeInstanceMember(tt.args.ctx, tt.args.member)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -514,8 +514,8 @@ func TestCommandSide_RemoveIAMMember(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewMemberAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewMemberAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"user1",
|
||||
[]string{"IAM_OWNER"}...,
|
||||
),
|
||||
@@ -523,8 +523,8 @@ func TestCommandSide_RemoveIAMMember(t *testing.T) {
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(iam.NewMemberRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
eventFromEventPusher(instance.NewMemberRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"user1",
|
||||
)),
|
||||
},
|
||||
@@ -548,7 +548,7 @@ func TestCommandSide_RemoveIAMMember(t *testing.T) {
|
||||
r := &Commands{
|
||||
eventstore: tt.fields.eventstore,
|
||||
}
|
||||
got, err := r.RemoveIAMMember(tt.args.ctx, tt.args.userID)
|
||||
got, err := r.RemoveInstanceMember(tt.args.ctx, tt.args.userID)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -3,11 +3,11 @@ package command
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
type IAMWriteModel struct {
|
||||
type InstanceWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
SetUpStarted domain.Step
|
||||
@@ -18,8 +18,8 @@ type IAMWriteModel struct {
|
||||
DefaultLanguage language.Tag
|
||||
}
|
||||
|
||||
func NewIAMWriteModel() *IAMWriteModel {
|
||||
return &IAMWriteModel{
|
||||
func NewInstanceWriteModel() *InstanceWriteModel {
|
||||
return &InstanceWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
ResourceOwner: domain.IAMID,
|
||||
@@ -27,16 +27,16 @@ func NewIAMWriteModel() *IAMWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMWriteModel) Reduce() error {
|
||||
func (wm *InstanceWriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
switch e := event.(type) {
|
||||
case *iam.ProjectSetEvent:
|
||||
case *instance.ProjectSetEvent:
|
||||
wm.ProjectID = e.ProjectID
|
||||
case *iam.GlobalOrgSetEvent:
|
||||
case *instance.GlobalOrgSetEvent:
|
||||
wm.GlobalOrgID = e.OrgID
|
||||
case *iam.DefaultLanguageSetEvent:
|
||||
case *instance.DefaultLanguageSetEvent:
|
||||
wm.DefaultLanguage = e.Language
|
||||
case *iam.SetupStepEvent:
|
||||
case *instance.SetupStepEvent:
|
||||
if e.Done {
|
||||
wm.SetUpDone = e.Step
|
||||
} else {
|
||||
@@ -47,21 +47,21 @@ func (wm *IAMWriteModel) Reduce() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wm *IAMWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
EventTypes(
|
||||
iam.ProjectSetEventType,
|
||||
iam.GlobalOrgSetEventType,
|
||||
iam.DefaultLanguageSetEventType,
|
||||
iam.SetupStartedEventType,
|
||||
iam.SetupDoneEventType).
|
||||
instance.ProjectSetEventType,
|
||||
instance.GlobalOrgSetEventType,
|
||||
instance.DefaultLanguageSetEventType,
|
||||
instance.SetupStartedEventType,
|
||||
instance.SetupDoneEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func IAMAggregateFromWriteModel(wm *eventstore.WriteModel) *eventstore.Aggregate {
|
||||
return eventstore.AggregateFromWriteModel(wm, iam.AggregateType, iam.AggregateVersion)
|
||||
func InstanceAggregateFromWriteModel(wm *eventstore.WriteModel) *eventstore.Aggregate {
|
||||
return eventstore.AggregateFromWriteModel(wm, instance.AggregateType, instance.AggregateVersion)
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func (c *Commands) AddOIDCSettings(ctx context.Context, settings *domain.OIDCSettings) (*domain.ObjectDetails, error) {
|
||||
@@ -16,10 +16,10 @@ func (c *Commands) AddOIDCSettings(ctx context.Context, settings *domain.OIDCSet
|
||||
if oidcSettingWriteModel.State.Exists() {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "COMMAND-d9nlw", "Errors.OIDCSettings.AlreadyExists")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&oidcSettingWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam.NewOIDCSettingsAddedEvent(
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&oidcSettingWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewOIDCSettingsAddedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
settings.AccessTokenLifetime,
|
||||
settings.IdTokenLifetime,
|
||||
settings.RefreshTokenIdleExpiration,
|
||||
@@ -42,11 +42,11 @@ func (c *Commands) ChangeOIDCSettings(ctx context.Context, settings *domain.OIDC
|
||||
if !oidcSettingWriteModel.State.Exists() {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "COMMAND-8snEr", "Errors.OIDCSettings.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&oidcSettingWriteModel.WriteModel)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&oidcSettingWriteModel.WriteModel)
|
||||
|
||||
changedEvent, hasChanged, err := oidcSettingWriteModel.NewChangedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
settings.AccessTokenLifetime,
|
||||
settings.IdTokenLifetime,
|
||||
settings.RefreshTokenIdleExpiration,
|
||||
@@ -68,8 +68,8 @@ func (c *Commands) ChangeOIDCSettings(ctx context.Context, settings *domain.OIDC
|
||||
return writeModelToObjectDetails(&oidcSettingWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) getOIDCSettings(ctx context.Context) (_ *IAMOIDCSettingsWriteModel, err error) {
|
||||
writeModel := NewIAMOIDCSettingsWriteModel()
|
||||
func (c *Commands) getOIDCSettings(ctx context.Context) (_ *InstanceOIDCSettingsWriteModel, err error) {
|
||||
writeModel := NewInstanceOIDCSettingsWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+19
-19
@@ -6,10 +6,10 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMOIDCSettingsWriteModel struct {
|
||||
type InstanceOIDCSettingsWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
AccessTokenLifetime time.Duration
|
||||
@@ -19,8 +19,8 @@ type IAMOIDCSettingsWriteModel struct {
|
||||
State domain.OIDCSettingsState
|
||||
}
|
||||
|
||||
func NewIAMOIDCSettingsWriteModel() *IAMOIDCSettingsWriteModel {
|
||||
return &IAMOIDCSettingsWriteModel{
|
||||
func NewInstanceOIDCSettingsWriteModel() *InstanceOIDCSettingsWriteModel {
|
||||
return &InstanceOIDCSettingsWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
ResourceOwner: domain.IAMID,
|
||||
@@ -28,16 +28,16 @@ func NewIAMOIDCSettingsWriteModel() *IAMOIDCSettingsWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMOIDCSettingsWriteModel) Reduce() error {
|
||||
func (wm *InstanceOIDCSettingsWriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
switch e := event.(type) {
|
||||
case *iam.OIDCSettingsAddedEvent:
|
||||
case *instance.OIDCSettingsAddedEvent:
|
||||
wm.AccessTokenLifetime = e.AccessTokenLifetime
|
||||
wm.IdTokenLifetime = e.IdTokenLifetime
|
||||
wm.RefreshTokenIdleExpiration = e.RefreshTokenIdleExpiration
|
||||
wm.RefreshTokenExpiration = e.RefreshTokenExpiration
|
||||
wm.State = domain.OIDCSettingsStateActive
|
||||
case *iam.OIDCSettingsChangedEvent:
|
||||
case *instance.OIDCSettingsChangedEvent:
|
||||
if e.AccessTokenLifetime != nil {
|
||||
wm.AccessTokenLifetime = *e.AccessTokenLifetime
|
||||
}
|
||||
@@ -55,45 +55,45 @@ func (wm *IAMOIDCSettingsWriteModel) Reduce() error {
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMOIDCSettingsWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceOIDCSettingsWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
EventTypes(
|
||||
iam.OIDCSettingsAddedEventType,
|
||||
iam.OIDCSettingsChangedEventType).
|
||||
instance.OIDCSettingsAddedEventType,
|
||||
instance.OIDCSettingsChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMOIDCSettingsWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceOIDCSettingsWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
accessTokenLifetime,
|
||||
idTokenLifetime,
|
||||
refreshTokenIdleExpiration,
|
||||
refreshTokenExpiration time.Duration,
|
||||
) (*iam.OIDCSettingsChangedEvent, bool, error) {
|
||||
changes := make([]iam.OIDCSettingsChanges, 0, 4)
|
||||
) (*instance.OIDCSettingsChangedEvent, bool, error) {
|
||||
changes := make([]instance.OIDCSettingsChanges, 0, 4)
|
||||
var err error
|
||||
|
||||
if wm.AccessTokenLifetime != accessTokenLifetime {
|
||||
changes = append(changes, iam.ChangeOIDCSettingsAccessTokenLifetime(accessTokenLifetime))
|
||||
changes = append(changes, instance.ChangeOIDCSettingsAccessTokenLifetime(accessTokenLifetime))
|
||||
}
|
||||
if wm.IdTokenLifetime != idTokenLifetime {
|
||||
changes = append(changes, iam.ChangeOIDCSettingsIdTokenLifetime(idTokenLifetime))
|
||||
changes = append(changes, instance.ChangeOIDCSettingsIdTokenLifetime(idTokenLifetime))
|
||||
}
|
||||
if wm.RefreshTokenIdleExpiration != refreshTokenIdleExpiration {
|
||||
changes = append(changes, iam.ChangeOIDCSettingsRefreshTokenIdleExpiration(refreshTokenIdleExpiration))
|
||||
changes = append(changes, instance.ChangeOIDCSettingsRefreshTokenIdleExpiration(refreshTokenIdleExpiration))
|
||||
}
|
||||
if wm.RefreshTokenExpiration != refreshTokenExpiration {
|
||||
changes = append(changes, iam.ChangeOIDCSettingsRefreshTokenExpiration(refreshTokenExpiration))
|
||||
changes = append(changes, instance.ChangeOIDCSettingsRefreshTokenExpiration(refreshTokenExpiration))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
changeEvent, err := iam.NewOIDCSettingsChangeEvent(ctx, aggregate, changes)
|
||||
changeEvent, err := instance.NewOIDCSettingsChangeEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
+17
-17
@@ -11,7 +11,7 @@ import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func TestCommandSide_AddOIDCConfig(t *testing.T) {
|
||||
@@ -39,8 +39,8 @@ func TestCommandSide_AddOIDCConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewOIDCSettingsAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewOIDCSettingsAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
time.Hour*1,
|
||||
time.Hour*1,
|
||||
time.Hour*1,
|
||||
@@ -71,9 +71,9 @@ func TestCommandSide_AddOIDCConfig(t *testing.T) {
|
||||
expectFilter(),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(iam.NewOIDCSettingsAddedEvent(
|
||||
eventFromEventPusher(instance.NewOIDCSettingsAddedEvent(
|
||||
context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
time.Hour*1,
|
||||
time.Hour*1,
|
||||
time.Hour*1,
|
||||
@@ -159,9 +159,9 @@ func TestCommandSide_ChangeOIDCConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewOIDCSettingsAddedEvent(
|
||||
instance.NewOIDCSettingsAddedEvent(
|
||||
context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
time.Hour*1,
|
||||
time.Hour*1,
|
||||
time.Hour*1,
|
||||
@@ -191,9 +191,9 @@ func TestCommandSide_ChangeOIDCConfig(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewOIDCSettingsAddedEvent(
|
||||
instance.NewOIDCSettingsAddedEvent(
|
||||
context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
time.Hour*1,
|
||||
time.Hour*1,
|
||||
time.Hour*1,
|
||||
@@ -249,15 +249,15 @@ func TestCommandSide_ChangeOIDCConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newOIDCConfigChangedEvent(ctx context.Context, accessTokenLifetime, idTokenLifetime, refreshTokenIdleExpiration, refreshTokenExpiration time.Duration) *iam.OIDCSettingsChangedEvent {
|
||||
changes := []iam.OIDCSettingsChanges{
|
||||
iam.ChangeOIDCSettingsAccessTokenLifetime(accessTokenLifetime),
|
||||
iam.ChangeOIDCSettingsIdTokenLifetime(idTokenLifetime),
|
||||
iam.ChangeOIDCSettingsRefreshTokenIdleExpiration(refreshTokenIdleExpiration),
|
||||
iam.ChangeOIDCSettingsRefreshTokenExpiration(refreshTokenExpiration),
|
||||
func newOIDCConfigChangedEvent(ctx context.Context, accessTokenLifetime, idTokenLifetime, refreshTokenIdleExpiration, refreshTokenExpiration time.Duration) *instance.OIDCSettingsChangedEvent {
|
||||
changes := []instance.OIDCSettingsChanges{
|
||||
instance.ChangeOIDCSettingsAccessTokenLifetime(accessTokenLifetime),
|
||||
instance.ChangeOIDCSettingsIdTokenLifetime(idTokenLifetime),
|
||||
instance.ChangeOIDCSettingsRefreshTokenIdleExpiration(refreshTokenIdleExpiration),
|
||||
instance.ChangeOIDCSettingsRefreshTokenExpiration(refreshTokenExpiration),
|
||||
}
|
||||
event, _ := iam.NewOIDCSettingsChangeEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
event, _ := instance.NewOIDCSettingsChangeEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
changes,
|
||||
)
|
||||
return event
|
||||
@@ -0,0 +1,92 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDefaultDomainPolicy(ctx context.Context, policy *domain.DomainPolicy) (*domain.DomainPolicy, error) {
|
||||
addedPolicy := NewInstanceDomainPolicyWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
event, err := c.addDefaultDomainPolicy(ctx, instanceAgg, addedPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(addedPolicy, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToDomainPolicy(addedPolicy), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultDomainPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstanceDomainPolicyWriteModel, policy *domain.DomainPolicy) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedPolicy.State == domain.PolicyStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-Lk0dS", "Errors.IAM.DomainPolicy.AlreadyExists")
|
||||
}
|
||||
return iam_repo.NewInstnaceDomainPolicyAddedEvent(ctx, instanceAgg, policy.UserLoginMustBeDomain), nil
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultDomainPolicy(ctx context.Context, policy *domain.DomainPolicy) (*domain.DomainPolicy, error) {
|
||||
existingPolicy, err := c.defaultDomainPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !existingPolicy.State.Exists() {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-0Pl0d", "Errors.IAM.DomainPolicy.NotFound")
|
||||
}
|
||||
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.PolicyDomainWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, instanceAgg, policy.UserLoginMustBeDomain)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(existingPolicy, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToDomainPolicy(existingPolicy), nil
|
||||
}
|
||||
|
||||
func (c *Commands) getDefaultDomainPolicy(ctx context.Context) (*domain.DomainPolicy, error) {
|
||||
policyWriteModel, err := c.defaultDomainPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !policyWriteModel.State.Exists() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-3n8fs", "Errors.IAM.PasswordComplexityPolicy.NotFound")
|
||||
}
|
||||
policy := writeModelToDomainPolicy(policyWriteModel)
|
||||
policy.Default = true
|
||||
return policy, nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultDomainPolicyWriteModelByID(ctx context.Context) (policy *InstanceDomainPolicyWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewInstanceDomainPolicyWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModel, nil
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type InstanceDomainPolicyWriteModel struct {
|
||||
PolicyDomainWriteModel
|
||||
}
|
||||
|
||||
func NewInstanceDomainPolicyWriteModel() *InstanceDomainPolicyWriteModel {
|
||||
return &InstanceDomainPolicyWriteModel{
|
||||
PolicyDomainWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
ResourceOwner: domain.IAMID,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *InstanceDomainPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *instance.InstanceDomainPolicyAddedEvent:
|
||||
wm.PolicyDomainWriteModel.AppendEvents(&e.DomainPolicyAddedEvent)
|
||||
case *instance.InstanceDomainPolicyChangedEvent:
|
||||
wm.PolicyDomainWriteModel.AppendEvents(&e.DomainPolicyChangedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *InstanceDomainPolicyWriteModel) Reduce() error {
|
||||
return wm.PolicyDomainWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *InstanceDomainPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.PolicyDomainWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
instance.InstanceDomainPolicyAddedEventType,
|
||||
instance.InstanceDomainPolicyChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *InstanceDomainPolicyWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
userLoginMustBeDomain bool) (*instance.InstanceDomainPolicyChangedEvent, bool) {
|
||||
changes := make([]policy.OrgPolicyChanges, 0)
|
||||
if wm.UserLoginMustBeDomain != userLoginMustBeDomain {
|
||||
changes = append(changes, policy.ChangeUserLoginMustBeDomain(userLoginMustBeDomain))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := instance.NewInstanceDomainPolicyChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
return changedEvent, true
|
||||
}
|
||||
+29
-28
@@ -2,27 +2,28 @@ package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCommandSide_AddDefaultOrgIAMPolicy(t *testing.T) {
|
||||
func TestCommandSide_AddDefaultDomainPolicy(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore *eventstore.Eventstore
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
policy *domain.OrgIAMPolicy
|
||||
policy *domain.DomainPolicy
|
||||
}
|
||||
type res struct {
|
||||
want *domain.OrgIAMPolicy
|
||||
want *domain.DomainPolicy
|
||||
err func(error) bool
|
||||
}
|
||||
tests := []struct {
|
||||
@@ -38,8 +39,8 @@ func TestCommandSide_AddDefaultOrgIAMPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewOrgIAMPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewInstnaceDomainPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -48,7 +49,7 @@ func TestCommandSide_AddDefaultOrgIAMPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.OrgIAMPolicy{
|
||||
policy: &domain.DomainPolicy{
|
||||
UserLoginMustBeDomain: true,
|
||||
},
|
||||
},
|
||||
@@ -65,8 +66,8 @@ func TestCommandSide_AddDefaultOrgIAMPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewOrgIAMPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewInstnaceDomainPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -76,12 +77,12 @@ func TestCommandSide_AddDefaultOrgIAMPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.OrgIAMPolicy{
|
||||
policy: &domain.DomainPolicy{
|
||||
UserLoginMustBeDomain: true,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
want: &domain.OrgIAMPolicy{
|
||||
want: &domain.DomainPolicy{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: "IAM",
|
||||
ResourceOwner: "IAM",
|
||||
@@ -96,7 +97,7 @@ func TestCommandSide_AddDefaultOrgIAMPolicy(t *testing.T) {
|
||||
r := &Commands{
|
||||
eventstore: tt.fields.eventstore,
|
||||
}
|
||||
got, err := r.AddDefaultOrgIAMPolicy(tt.args.ctx, tt.args.policy)
|
||||
got, err := r.AddDefaultDomainPolicy(tt.args.ctx, tt.args.policy)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -116,10 +117,10 @@ func TestCommandSide_ChangeDefaultOrgIAMPolicy(t *testing.T) {
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
policy *domain.OrgIAMPolicy
|
||||
policy *domain.DomainPolicy
|
||||
}
|
||||
type res struct {
|
||||
want *domain.OrgIAMPolicy
|
||||
want *domain.DomainPolicy
|
||||
err func(error) bool
|
||||
}
|
||||
tests := []struct {
|
||||
@@ -138,7 +139,7 @@ func TestCommandSide_ChangeDefaultOrgIAMPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.OrgIAMPolicy{
|
||||
policy: &domain.DomainPolicy{
|
||||
UserLoginMustBeDomain: true,
|
||||
},
|
||||
},
|
||||
@@ -153,8 +154,8 @@ func TestCommandSide_ChangeDefaultOrgIAMPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewOrgIAMPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewInstnaceDomainPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -163,7 +164,7 @@ func TestCommandSide_ChangeDefaultOrgIAMPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.OrgIAMPolicy{
|
||||
policy: &domain.DomainPolicy{
|
||||
UserLoginMustBeDomain: true,
|
||||
},
|
||||
},
|
||||
@@ -178,8 +179,8 @@ func TestCommandSide_ChangeDefaultOrgIAMPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewOrgIAMPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewInstnaceDomainPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
),
|
||||
),
|
||||
@@ -195,12 +196,12 @@ func TestCommandSide_ChangeDefaultOrgIAMPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.OrgIAMPolicy{
|
||||
policy: &domain.DomainPolicy{
|
||||
UserLoginMustBeDomain: false,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
want: &domain.OrgIAMPolicy{
|
||||
want: &domain.DomainPolicy{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: "IAM",
|
||||
ResourceOwner: "IAM",
|
||||
@@ -215,7 +216,7 @@ func TestCommandSide_ChangeDefaultOrgIAMPolicy(t *testing.T) {
|
||||
r := &Commands{
|
||||
eventstore: tt.fields.eventstore,
|
||||
}
|
||||
got, err := r.ChangeDefaultOrgIAMPolicy(tt.args.ctx, tt.args.policy)
|
||||
got, err := r.ChangeDefaultDomainPolicy(tt.args.ctx, tt.args.policy)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -229,10 +230,10 @@ func TestCommandSide_ChangeDefaultOrgIAMPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultOrgIAMPolicyChangedEvent(ctx context.Context, userLoginMustBeDomain bool) *iam.OrgIAMPolicyChangedEvent {
|
||||
event, _ := iam.NewOrgIAMPolicyChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
[]policy.OrgIAMPolicyChanges{
|
||||
func newDefaultOrgIAMPolicyChangedEvent(ctx context.Context, userLoginMustBeDomain bool) *instance.InstanceDomainPolicyChangedEvent {
|
||||
event, _ := instance.NewInstanceDomainPolicyChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]policy.OrgPolicyChanges{
|
||||
policy.ChangeUserLoginMustBeDomain(userLoginMustBeDomain),
|
||||
},
|
||||
)
|
||||
@@ -6,14 +6,14 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDefaultLabelPolicy(ctx context.Context, policy *domain.LabelPolicy) (*domain.LabelPolicy, error) {
|
||||
addedPolicy := NewIAMLabelPolicyWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
event, err := c.addDefaultLabelPolicy(ctx, iamAgg, addedPolicy, policy)
|
||||
addedPolicy := NewInstanceLabelPolicyWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
event, err := c.addDefaultLabelPolicy(ctx, instanceAgg, addedPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -29,7 +29,7 @@ func (c *Commands) AddDefaultLabelPolicy(ctx context.Context, policy *domain.Lab
|
||||
return writeModelToLabelPolicy(&addedPolicy.LabelPolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultLabelPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, addedPolicy *IAMLabelPolicyWriteModel, policy *domain.LabelPolicy) (eventstore.Command, error) {
|
||||
func (c *Commands) addDefaultLabelPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstanceLabelPolicyWriteModel, policy *domain.LabelPolicy) (eventstore.Command, error) {
|
||||
if err := policy.IsValid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -38,12 +38,12 @@ func (c *Commands) addDefaultLabelPolicy(ctx context.Context, iamAgg *eventstore
|
||||
return nil, err
|
||||
}
|
||||
if addedPolicy.State == domain.PolicyStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-2B0ps", "Errors.IAM.LabelPolicy.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-2B0ps", "Errors.IAM.LabelPolicy.AlreadyExists")
|
||||
}
|
||||
|
||||
return iam_repo.NewLabelPolicyAddedEvent(
|
||||
return instance.NewLabelPolicyAddedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
policy.PrimaryColor,
|
||||
policy.BackgroundColor,
|
||||
policy.WarnColor,
|
||||
@@ -68,12 +68,12 @@ func (c *Commands) ChangeDefaultLabelPolicy(ctx context.Context, policy *domain.
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-0K9dq", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-0K9dq", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
policy.PrimaryColor,
|
||||
policy.BackgroundColor,
|
||||
policy.WarnColor,
|
||||
@@ -86,7 +86,7 @@ func (c *Commands) ChangeDefaultLabelPolicy(ctx context.Context, policy *domain.
|
||||
policy.ErrorMsgPopup,
|
||||
policy.DisableWatermark)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
@@ -107,11 +107,11 @@ func (c *Commands) ActivateDefaultLabelPolicy(ctx context.Context) (*domain.Obje
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-6M23e", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-6M23e", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyActivatedEvent(ctx, iamAgg))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyActivatedEvent(ctx, instanceAgg))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (c *Commands) ActivateDefaultLabelPolicy(ctx context.Context) (*domain.Obje
|
||||
|
||||
func (c *Commands) AddLogoDefaultLabelPolicy(ctx context.Context, storageKey string) (*domain.ObjectDetails, error) {
|
||||
if storageKey == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-3m20c", "Errors.Assets.EmptyKey")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-3m20c", "Errors.Assets.EmptyKey")
|
||||
}
|
||||
existingPolicy, err := c.defaultLabelPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
@@ -133,10 +133,10 @@ func (c *Commands) AddLogoDefaultLabelPolicy(ctx context.Context, storageKey str
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-Qw0pd", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-Qw0pd", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyLogoAddedEvent(ctx, iamAgg, storageKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyLogoAddedEvent(ctx, instanceAgg, storageKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -154,15 +154,15 @@ func (c *Commands) RemoveLogoDefaultLabelPolicy(ctx context.Context) (*domain.Ob
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-Xc8Kf", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-Xc8Kf", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
|
||||
err = c.RemoveAsset(ctx, domain.IAMID, existingPolicy.LogoKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyLogoRemovedEvent(ctx, iamAgg, existingPolicy.LogoKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyLogoRemovedEvent(ctx, instanceAgg, existingPolicy.LogoKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -175,7 +175,7 @@ func (c *Commands) RemoveLogoDefaultLabelPolicy(ctx context.Context) (*domain.Ob
|
||||
|
||||
func (c *Commands) AddIconDefaultLabelPolicy(ctx context.Context, storageKey string) (*domain.ObjectDetails, error) {
|
||||
if storageKey == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-yxE4f", "Errors.Assets.EmptyKey")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-yxE4f", "Errors.Assets.EmptyKey")
|
||||
}
|
||||
existingPolicy, err := c.defaultLabelPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
@@ -183,10 +183,10 @@ func (c *Commands) AddIconDefaultLabelPolicy(ctx context.Context, storageKey str
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-1yMx0", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-1yMx0", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyIconAddedEvent(ctx, iamAgg, storageKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyIconAddedEvent(ctx, instanceAgg, storageKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -204,14 +204,14 @@ func (c *Commands) RemoveIconDefaultLabelPolicy(ctx context.Context) (*domain.Ob
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-4M0qw", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-4M0qw", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
err = c.RemoveAsset(ctx, domain.IAMID, existingPolicy.IconKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyIconRemovedEvent(ctx, iamAgg, existingPolicy.IconKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyIconRemovedEvent(ctx, instanceAgg, existingPolicy.IconKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -224,7 +224,7 @@ func (c *Commands) RemoveIconDefaultLabelPolicy(ctx context.Context) (*domain.Ob
|
||||
|
||||
func (c *Commands) AddLogoDarkDefaultLabelPolicy(ctx context.Context, storageKey string) (*domain.ObjectDetails, error) {
|
||||
if storageKey == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-4fMs9", "Errors.Assets.EmptyKey")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-4fMs9", "Errors.Assets.EmptyKey")
|
||||
}
|
||||
existingPolicy, err := c.defaultLabelPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
@@ -232,10 +232,10 @@ func (c *Commands) AddLogoDarkDefaultLabelPolicy(ctx context.Context, storageKey
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-ZR9fs", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-ZR9fs", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyLogoDarkAddedEvent(ctx, iamAgg, storageKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyLogoDarkAddedEvent(ctx, instanceAgg, storageKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -253,14 +253,14 @@ func (c *Commands) RemoveLogoDarkDefaultLabelPolicy(ctx context.Context) (*domai
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-3FGds", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-3FGds", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
err = c.RemoveAsset(ctx, domain.IAMID, existingPolicy.LogoDarkKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyLogoDarkRemovedEvent(ctx, iamAgg, existingPolicy.LogoDarkKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyLogoDarkRemovedEvent(ctx, instanceAgg, existingPolicy.LogoDarkKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func (c *Commands) RemoveLogoDarkDefaultLabelPolicy(ctx context.Context) (*domai
|
||||
|
||||
func (c *Commands) AddIconDarkDefaultLabelPolicy(ctx context.Context, storageKey string) (*domain.ObjectDetails, error) {
|
||||
if storageKey == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-1cxM3", "Errors.Assets.EmptyKey")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-1cxM3", "Errors.Assets.EmptyKey")
|
||||
}
|
||||
existingPolicy, err := c.defaultLabelPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
@@ -281,10 +281,10 @@ func (c *Commands) AddIconDarkDefaultLabelPolicy(ctx context.Context, storageKey
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-vMsf9", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-vMsf9", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyIconDarkAddedEvent(ctx, iamAgg, storageKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyIconDarkAddedEvent(ctx, instanceAgg, storageKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -302,14 +302,14 @@ func (c *Commands) RemoveIconDarkDefaultLabelPolicy(ctx context.Context) (*domai
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-2nc7F", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-2nc7F", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
err = c.RemoveAsset(ctx, domain.IAMID, existingPolicy.IconDarkKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyIconDarkRemovedEvent(ctx, iamAgg, existingPolicy.IconDarkKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyIconDarkRemovedEvent(ctx, instanceAgg, existingPolicy.IconDarkKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -322,7 +322,7 @@ func (c *Commands) RemoveIconDarkDefaultLabelPolicy(ctx context.Context) (*domai
|
||||
|
||||
func (c *Commands) AddFontDefaultLabelPolicy(ctx context.Context, storageKey string) (*domain.ObjectDetails, error) {
|
||||
if storageKey == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-1N8fs", "Errors.Assets.EmptyKey")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-1N8fs", "Errors.Assets.EmptyKey")
|
||||
}
|
||||
existingPolicy, err := c.defaultLabelPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
@@ -330,10 +330,10 @@ func (c *Commands) AddFontDefaultLabelPolicy(ctx context.Context, storageKey str
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-1N8fE", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-1N8fE", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyFontAddedEvent(ctx, iamAgg, storageKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyFontAddedEvent(ctx, instanceAgg, storageKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -351,14 +351,14 @@ func (c *Commands) RemoveFontDefaultLabelPolicy(ctx context.Context) (*domain.Ob
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-Tk0gw", "Errors.IAM.LabelPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-Tk0gw", "Errors.IAM.LabelPolicy.NotFound")
|
||||
}
|
||||
err = c.RemoveAsset(ctx, domain.IAMID, existingPolicy.FontKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLabelPolicyFontRemovedEvent(ctx, iamAgg, existingPolicy.FontKey))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LabelPolicyWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLabelPolicyFontRemovedEvent(ctx, instanceAgg, existingPolicy.FontKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -369,11 +369,11 @@ func (c *Commands) RemoveFontDefaultLabelPolicy(ctx context.Context) (*domain.Ob
|
||||
return writeModelToObjectDetails(&existingPolicy.LabelPolicyWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultLabelPolicyWriteModelByID(ctx context.Context) (policy *IAMLabelPolicyWriteModel, err error) {
|
||||
func (c *Commands) defaultLabelPolicyWriteModelByID(ctx context.Context) (policy *InstanceLabelPolicyWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMLabelPolicyWriteModel()
|
||||
writeModel := NewInstanceLabelPolicyWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+36
-36
@@ -5,16 +5,16 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type IAMLabelPolicyWriteModel struct {
|
||||
type InstanceLabelPolicyWriteModel struct {
|
||||
LabelPolicyWriteModel
|
||||
}
|
||||
|
||||
func NewIAMLabelPolicyWriteModel() *IAMLabelPolicyWriteModel {
|
||||
return &IAMLabelPolicyWriteModel{
|
||||
func NewInstanceLabelPolicyWriteModel() *InstanceLabelPolicyWriteModel {
|
||||
return &InstanceLabelPolicyWriteModel{
|
||||
LabelPolicyWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -24,66 +24,66 @@ func NewIAMLabelPolicyWriteModel() *IAMLabelPolicyWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMLabelPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceLabelPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.LabelPolicyAddedEvent:
|
||||
case *instance.LabelPolicyAddedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyAddedEvent)
|
||||
case *iam.LabelPolicyChangedEvent:
|
||||
case *instance.LabelPolicyChangedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyChangedEvent)
|
||||
case *iam.LabelPolicyActivatedEvent:
|
||||
case *instance.LabelPolicyActivatedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyActivatedEvent)
|
||||
case *iam.LabelPolicyLogoAddedEvent:
|
||||
case *instance.LabelPolicyLogoAddedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyLogoAddedEvent)
|
||||
case *iam.LabelPolicyLogoRemovedEvent:
|
||||
case *instance.LabelPolicyLogoRemovedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyLogoRemovedEvent)
|
||||
case *iam.LabelPolicyLogoDarkAddedEvent:
|
||||
case *instance.LabelPolicyLogoDarkAddedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyLogoDarkAddedEvent)
|
||||
case *iam.LabelPolicyLogoDarkRemovedEvent:
|
||||
case *instance.LabelPolicyLogoDarkRemovedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyLogoDarkRemovedEvent)
|
||||
case *iam.LabelPolicyIconAddedEvent:
|
||||
case *instance.LabelPolicyIconAddedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyIconAddedEvent)
|
||||
case *iam.LabelPolicyIconRemovedEvent:
|
||||
case *instance.LabelPolicyIconRemovedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyIconRemovedEvent)
|
||||
case *iam.LabelPolicyIconDarkAddedEvent:
|
||||
case *instance.LabelPolicyIconDarkAddedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyIconDarkAddedEvent)
|
||||
case *iam.LabelPolicyIconDarkRemovedEvent:
|
||||
case *instance.LabelPolicyIconDarkRemovedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyIconDarkRemovedEvent)
|
||||
case *iam.LabelPolicyFontAddedEvent:
|
||||
case *instance.LabelPolicyFontAddedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyFontAddedEvent)
|
||||
case *iam.LabelPolicyFontRemovedEvent:
|
||||
case *instance.LabelPolicyFontRemovedEvent:
|
||||
wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyFontRemovedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMLabelPolicyWriteModel) Reduce() error {
|
||||
func (wm *InstanceLabelPolicyWriteModel) Reduce() error {
|
||||
return wm.LabelPolicyWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMLabelPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceLabelPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.LabelPolicyWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.LabelPolicyAddedEventType,
|
||||
iam.LabelPolicyChangedEventType,
|
||||
iam.LabelPolicyLogoAddedEventType,
|
||||
iam.LabelPolicyLogoRemovedEventType,
|
||||
iam.LabelPolicyIconAddedEventType,
|
||||
iam.LabelPolicyIconRemovedEventType,
|
||||
iam.LabelPolicyLogoDarkAddedEventType,
|
||||
iam.LabelPolicyLogoDarkRemovedEventType,
|
||||
iam.LabelPolicyIconDarkAddedEventType,
|
||||
iam.LabelPolicyIconDarkRemovedEventType,
|
||||
iam.LabelPolicyFontAddedEventType,
|
||||
iam.LabelPolicyFontRemovedEventType).
|
||||
instance.LabelPolicyAddedEventType,
|
||||
instance.LabelPolicyChangedEventType,
|
||||
instance.LabelPolicyLogoAddedEventType,
|
||||
instance.LabelPolicyLogoRemovedEventType,
|
||||
instance.LabelPolicyIconAddedEventType,
|
||||
instance.LabelPolicyIconRemovedEventType,
|
||||
instance.LabelPolicyLogoDarkAddedEventType,
|
||||
instance.LabelPolicyLogoDarkRemovedEventType,
|
||||
instance.LabelPolicyIconDarkAddedEventType,
|
||||
instance.LabelPolicyIconDarkRemovedEventType,
|
||||
instance.LabelPolicyFontAddedEventType,
|
||||
instance.LabelPolicyFontRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMLabelPolicyWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceLabelPolicyWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
primaryColor,
|
||||
@@ -97,7 +97,7 @@ func (wm *IAMLabelPolicyWriteModel) NewChangedEvent(
|
||||
hideLoginNameSuffix,
|
||||
errorMsgPopup,
|
||||
disableWatermark bool,
|
||||
) (*iam.LabelPolicyChangedEvent, bool) {
|
||||
) (*instance.LabelPolicyChangedEvent, bool) {
|
||||
changes := make([]policy.LabelPolicyChanges, 0)
|
||||
if wm.PrimaryColor != primaryColor {
|
||||
changes = append(changes, policy.ChangePrimaryColor(primaryColor))
|
||||
@@ -135,7 +135,7 @@ func (wm *IAMLabelPolicyWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewLabelPolicyChangedEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewLabelPolicyChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
+82
-82
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
"github.com/caos/zitadel/internal/static"
|
||||
"github.com/caos/zitadel/internal/static/mock"
|
||||
@@ -43,8 +43,8 @@ func TestCommandSide_AddDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -90,8 +90,8 @@ func TestCommandSide_AddDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -210,8 +210,8 @@ func TestCommandSide_ChangeDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -255,8 +255,8 @@ func TestCommandSide_ChangeDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -387,8 +387,8 @@ func TestCommandSide_ActivateDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -406,8 +406,8 @@ func TestCommandSide_ActivateDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyActivatedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyActivatedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -499,8 +499,8 @@ func TestCommandSide_AddLogoDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -518,8 +518,8 @@ func TestCommandSide_AddLogoDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyLogoAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyLogoAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -599,8 +599,8 @@ func TestCommandSide_RemoveLogoDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -615,8 +615,8 @@ func TestCommandSide_RemoveLogoDefaultLabelPolicy(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyLogoAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyLogoAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -638,8 +638,8 @@ func TestCommandSide_RemoveLogoDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -654,8 +654,8 @@ func TestCommandSide_RemoveLogoDefaultLabelPolicy(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyLogoAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyLogoAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -663,8 +663,8 @@ func TestCommandSide_RemoveLogoDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyLogoRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyLogoRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -757,8 +757,8 @@ func TestCommandSide_AddIconDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -776,8 +776,8 @@ func TestCommandSide_AddIconDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyIconAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyIconAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -856,8 +856,8 @@ func TestCommandSide_RemoveIconDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -872,8 +872,8 @@ func TestCommandSide_RemoveIconDefaultLabelPolicy(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyIconAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyIconAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -881,8 +881,8 @@ func TestCommandSide_RemoveIconDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyIconRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyIconRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -975,8 +975,8 @@ func TestCommandSide_AddLogoDarkDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -994,8 +994,8 @@ func TestCommandSide_AddLogoDarkDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1074,8 +1074,8 @@ func TestCommandSide_RemoveLogoDarkDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -1090,8 +1090,8 @@ func TestCommandSide_RemoveLogoDarkDefaultLabelPolicy(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1113,8 +1113,8 @@ func TestCommandSide_RemoveLogoDarkDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -1129,8 +1129,8 @@ func TestCommandSide_RemoveLogoDarkDefaultLabelPolicy(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1138,8 +1138,8 @@ func TestCommandSide_RemoveLogoDarkDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyLogoDarkRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyLogoDarkRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1232,8 +1232,8 @@ func TestCommandSide_AddIconDarkDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -1251,8 +1251,8 @@ func TestCommandSide_AddIconDarkDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyIconDarkAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyIconDarkAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1331,8 +1331,8 @@ func TestCommandSide_RemoveIconDarkDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -1347,8 +1347,8 @@ func TestCommandSide_RemoveIconDarkDefaultLabelPolicy(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyIconDarkAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyIconDarkAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1370,8 +1370,8 @@ func TestCommandSide_RemoveIconDarkDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -1386,8 +1386,8 @@ func TestCommandSide_RemoveIconDarkDefaultLabelPolicy(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyIconDarkAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyIconDarkAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1395,8 +1395,8 @@ func TestCommandSide_RemoveIconDarkDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyIconDarkRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyIconDarkRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1489,8 +1489,8 @@ func TestCommandSide_AddFontDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -1508,8 +1508,8 @@ func TestCommandSide_AddFontDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyFontAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyFontAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1588,8 +1588,8 @@ func TestCommandSide_RemoveFontDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -1604,8 +1604,8 @@ func TestCommandSide_RemoveFontDefaultLabelPolicy(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyFontAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyFontAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1627,8 +1627,8 @@ func TestCommandSide_RemoveFontDefaultLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
@@ -1643,8 +1643,8 @@ func TestCommandSide_RemoveFontDefaultLabelPolicy(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyFontAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyFontAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1652,8 +1652,8 @@ func TestCommandSide_RemoveFontDefaultLabelPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLabelPolicyFontRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLabelPolicyFontRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"key",
|
||||
),
|
||||
),
|
||||
@@ -1691,9 +1691,9 @@ func TestCommandSide_RemoveFontDefaultLabelPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultLabelPolicyChangedEvent(ctx context.Context, primaryColor, backgroundColor, warnColor, fontColor, primaryColorDark, backgroundColorDark, warnColorDark, fontColorDark string, hideLoginNameSuffix, errMsgPopup, disableWatermark bool) *iam.LabelPolicyChangedEvent {
|
||||
event, _ := iam.NewLabelPolicyChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultLabelPolicyChangedEvent(ctx context.Context, primaryColor, backgroundColor, warnColor, fontColor, primaryColorDark, backgroundColorDark, warnColorDark, fontColorDark string, hideLoginNameSuffix, errMsgPopup, disableWatermark bool) *instance.LabelPolicyChangedEvent {
|
||||
event, _ := instance.NewLabelPolicyChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]policy.LabelPolicyChanges{
|
||||
policy.ChangePrimaryColor(primaryColor),
|
||||
policy.ChangeBackgroundColor(backgroundColor),
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) getDefaultLoginPolicy(ctx context.Context) (*domain.LoginPolicy, error) {
|
||||
policyWriteModel := NewIAMLoginPolicyWriteModel()
|
||||
policyWriteModel := NewInstanceLoginPolicyWriteModel()
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, policyWriteModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -23,9 +23,9 @@ func (c *Commands) getDefaultLoginPolicy(ctx context.Context) (*domain.LoginPoli
|
||||
}
|
||||
|
||||
func (c *Commands) AddDefaultLoginPolicy(ctx context.Context, policy *domain.LoginPolicy) (*domain.LoginPolicy, error) {
|
||||
addedPolicy := NewIAMLoginPolicyWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
event, err := c.addDefaultLoginPolicy(ctx, iamAgg, addedPolicy, policy)
|
||||
addedPolicy := NewInstanceLoginPolicyWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
event, err := c.addDefaultLoginPolicy(ctx, instanceAgg, addedPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -40,17 +40,17 @@ func (c *Commands) AddDefaultLoginPolicy(ctx context.Context, policy *domain.Log
|
||||
return writeModelToLoginPolicy(&addedPolicy.LoginPolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultLoginPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, addedPolicy *IAMLoginPolicyWriteModel, policy *domain.LoginPolicy) (eventstore.Command, error) {
|
||||
func (c *Commands) addDefaultLoginPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstanceLoginPolicyWriteModel, policy *domain.LoginPolicy) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedPolicy.State == domain.PolicyStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-2B0ps", "Errors.IAM.LoginPolicy.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-2B0ps", "Errors.IAM.LoginPolicy.AlreadyExists")
|
||||
}
|
||||
|
||||
return iam_repo.NewLoginPolicyAddedEvent(ctx,
|
||||
iamAgg,
|
||||
return instance.NewLoginPolicyAddedEvent(ctx,
|
||||
instanceAgg,
|
||||
policy.AllowUsernamePassword,
|
||||
policy.AllowRegister,
|
||||
policy.AllowExternalIDP,
|
||||
@@ -65,9 +65,9 @@ func (c *Commands) addDefaultLoginPolicy(ctx context.Context, iamAgg *eventstore
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultLoginPolicy(ctx context.Context, policy *domain.LoginPolicy) (*domain.LoginPolicy, error) {
|
||||
existingPolicy := NewIAMLoginPolicyWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LoginPolicyWriteModel.WriteModel)
|
||||
event, err := c.changeDefaultLoginPolicy(ctx, iamAgg, existingPolicy, policy)
|
||||
existingPolicy := NewInstanceLoginPolicyWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LoginPolicyWriteModel.WriteModel)
|
||||
event, err := c.changeDefaultLoginPolicy(ctx, instanceAgg, existingPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -82,16 +82,16 @@ func (c *Commands) ChangeDefaultLoginPolicy(ctx context.Context, policy *domain.
|
||||
return writeModelToLoginPolicy(&existingPolicy.LoginPolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) changeDefaultLoginPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, existingPolicy *IAMLoginPolicyWriteModel, policy *domain.LoginPolicy) (eventstore.Command, error) {
|
||||
func (c *Commands) changeDefaultLoginPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, existingPolicy *InstanceLoginPolicyWriteModel, policy *domain.LoginPolicy) (eventstore.Command, error) {
|
||||
err := c.defaultLoginPolicyWriteModelByID(ctx, existingPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-M0sif", "Errors.IAM.LoginPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-M0sif", "Errors.IAM.LoginPolicy.NotFound")
|
||||
}
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
policy.AllowUsernamePassword,
|
||||
policy.AllowRegister,
|
||||
policy.AllowExternalIDP,
|
||||
@@ -104,39 +104,39 @@ func (c *Commands) changeDefaultLoginPolicy(ctx context.Context, iamAgg *eventst
|
||||
policy.SecondFactorCheckLifetime,
|
||||
policy.MultiFactorCheckLifetime)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-5M9vdd", "Errors.IAM.LoginPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-5M9vdd", "Errors.IAM.LoginPolicy.NotChanged")
|
||||
}
|
||||
return changedEvent, nil
|
||||
}
|
||||
|
||||
func (c *Commands) AddIDPProviderToDefaultLoginPolicy(ctx context.Context, idpProvider *domain.IDPProvider) (*domain.IDPProvider, error) {
|
||||
if !idpProvider.IsValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-9nf88", "Errors.IAM.LoginPolicy.IDP.Invalid")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-9nf88", "Errors.IAM.LoginPolicy.IDP.Invalid")
|
||||
}
|
||||
existingPolicy := NewIAMLoginPolicyWriteModel()
|
||||
existingPolicy := NewInstanceLoginPolicyWriteModel()
|
||||
err := c.defaultLoginPolicyWriteModelByID(ctx, existingPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-GVDfe", "Errors.IAM.LoginPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-GVDfe", "Errors.IAM.LoginPolicy.NotFound")
|
||||
}
|
||||
|
||||
_, err = c.getIAMIDPConfigByID(ctx, idpProvider.IDPConfigID)
|
||||
_, err = c.getInstanceIDPConfigByID(ctx, idpProvider.IDPConfigID)
|
||||
if err != nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(err, "IAM-m8fsd", "Errors.IDPConfig.NotExisting")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(err, "INSTANCE-m8fsd", "Errors.IDPConfig.NotExisting")
|
||||
}
|
||||
idpModel := NewIAMIdentityProviderWriteModel(idpProvider.IDPConfigID)
|
||||
idpModel := NewInstanceIdentityProviderWriteModel(idpProvider.IDPConfigID)
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, idpModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if idpModel.State == domain.IdentityProviderStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-2B0ps", "Errors.IAM.LoginPolicy.IDP.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-2B0ps", "Errors.IAM.LoginPolicy.IDP.AlreadyExists")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&idpModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewIdentityProviderAddedEvent(ctx, iamAgg, idpProvider.IDPConfigID))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&idpModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewIdentityProviderAddedEvent(ctx, instanceAgg, idpProvider.IDPConfigID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -149,28 +149,28 @@ func (c *Commands) AddIDPProviderToDefaultLoginPolicy(ctx context.Context, idpPr
|
||||
|
||||
func (c *Commands) RemoveIDPProviderFromDefaultLoginPolicy(ctx context.Context, idpProvider *domain.IDPProvider, cascadeExternalIDPs ...*domain.UserIDPLink) (*domain.ObjectDetails, error) {
|
||||
if !idpProvider.IsValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-66m9s", "Errors.IAM.LoginPolicy.IDP.Invalid")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-66m9s", "Errors.IAM.LoginPolicy.IDP.Invalid")
|
||||
}
|
||||
existingPolicy := NewIAMLoginPolicyWriteModel()
|
||||
existingPolicy := NewInstanceLoginPolicyWriteModel()
|
||||
err := c.defaultLoginPolicyWriteModelByID(ctx, existingPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-Dfg4t", "Errors.IAM.LoginPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-Dfg4t", "Errors.IAM.LoginPolicy.NotFound")
|
||||
}
|
||||
|
||||
idpModel := NewIAMIdentityProviderWriteModel(idpProvider.IDPConfigID)
|
||||
idpModel := NewInstanceIdentityProviderWriteModel(idpProvider.IDPConfigID)
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, idpModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if idpModel.State == domain.IdentityProviderStateUnspecified || idpModel.State == domain.IdentityProviderStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-39fjs", "Errors.IAM.LoginPolicy.IDP.NotExisting")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-39fjs", "Errors.IAM.LoginPolicy.IDP.NotExisting")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&idpModel.IdentityProviderWriteModel.WriteModel)
|
||||
events := c.removeIDPProviderFromDefaultLoginPolicy(ctx, iamAgg, idpProvider, false, cascadeExternalIDPs...)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&idpModel.IdentityProviderWriteModel.WriteModel)
|
||||
events := c.removeIDPProviderFromDefaultLoginPolicy(ctx, instanceAgg, idpProvider, false, cascadeExternalIDPs...)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, events...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -182,12 +182,12 @@ func (c *Commands) RemoveIDPProviderFromDefaultLoginPolicy(ctx context.Context,
|
||||
return writeModelToObjectDetails(&idpModel.IdentityProviderWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) removeIDPProviderFromDefaultLoginPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, idpProvider *domain.IDPProvider, cascade bool, cascadeExternalIDPs ...*domain.UserIDPLink) []eventstore.Command {
|
||||
func (c *Commands) removeIDPProviderFromDefaultLoginPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, idpProvider *domain.IDPProvider, cascade bool, cascadeExternalIDPs ...*domain.UserIDPLink) []eventstore.Command {
|
||||
var events []eventstore.Command
|
||||
if cascade {
|
||||
events = append(events, iam_repo.NewIdentityProviderCascadeRemovedEvent(ctx, iamAgg, idpProvider.IDPConfigID))
|
||||
events = append(events, instance.NewIdentityProviderCascadeRemovedEvent(ctx, instanceAgg, idpProvider.IDPConfigID))
|
||||
} else {
|
||||
events = append(events, iam_repo.NewIdentityProviderRemovedEvent(ctx, iamAgg, idpProvider.IDPConfigID))
|
||||
events = append(events, instance.NewIdentityProviderRemovedEvent(ctx, instanceAgg, idpProvider.IDPConfigID))
|
||||
}
|
||||
|
||||
for _, idp := range cascadeExternalIDPs {
|
||||
@@ -203,11 +203,11 @@ func (c *Commands) removeIDPProviderFromDefaultLoginPolicy(ctx context.Context,
|
||||
|
||||
func (c *Commands) AddSecondFactorToDefaultLoginPolicy(ctx context.Context, secondFactor domain.SecondFactorType) (domain.SecondFactorType, *domain.ObjectDetails, error) {
|
||||
if !secondFactor.Valid() {
|
||||
return domain.SecondFactorTypeUnspecified, nil, caos_errs.ThrowInvalidArgument(nil, "IAM-5m9fs", "Errors.IAM.LoginPolicy.MFA.Unspecified")
|
||||
return domain.SecondFactorTypeUnspecified, nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-5m9fs", "Errors.IAM.LoginPolicy.MFA.Unspecified")
|
||||
}
|
||||
secondFactorModel := NewIAMSecondFactorWriteModel(secondFactor)
|
||||
iamAgg := IAMAggregateFromWriteModel(&secondFactorModel.SecondFactorWriteModel.WriteModel)
|
||||
event, err := c.addSecondFactorToDefaultLoginPolicy(ctx, iamAgg, secondFactorModel, secondFactor)
|
||||
secondFactorModel := NewInstanceSecondFactorWriteModel(secondFactor)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&secondFactorModel.SecondFactorWriteModel.WriteModel)
|
||||
event, err := c.addSecondFactorToDefaultLoginPolicy(ctx, instanceAgg, secondFactorModel, secondFactor)
|
||||
if err != nil {
|
||||
return domain.SecondFactorTypeUnspecified, nil, err
|
||||
}
|
||||
@@ -223,32 +223,32 @@ func (c *Commands) AddSecondFactorToDefaultLoginPolicy(ctx context.Context, seco
|
||||
return secondFactorModel.MFAType, writeModelToObjectDetails(&secondFactorModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addSecondFactorToDefaultLoginPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, secondFactorModel *IAMSecondFactorWriteModel, secondFactor domain.SecondFactorType) (eventstore.Command, error) {
|
||||
func (c *Commands) addSecondFactorToDefaultLoginPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, secondFactorModel *InstanceSecondFactorWriteModel, secondFactor domain.SecondFactorType) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, secondFactorModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if secondFactorModel.State == domain.FactorStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-2B0ps", "Errors.IAM.LoginPolicy.MFA.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-2B0ps", "Errors.IAM.LoginPolicy.MFA.AlreadyExists")
|
||||
}
|
||||
return iam_repo.NewLoginPolicySecondFactorAddedEvent(ctx, iamAgg, secondFactor), nil
|
||||
return instance.NewLoginPolicySecondFactorAddedEvent(ctx, instanceAgg, secondFactor), nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveSecondFactorFromDefaultLoginPolicy(ctx context.Context, secondFactor domain.SecondFactorType) (*domain.ObjectDetails, error) {
|
||||
if !secondFactor.Valid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-55n8s", "Errors.IAM.LoginPolicy.MFA.Unspecified")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-55n8s", "Errors.IAM.LoginPolicy.MFA.Unspecified")
|
||||
}
|
||||
secondFactorModel := NewIAMSecondFactorWriteModel(secondFactor)
|
||||
secondFactorModel := NewInstanceSecondFactorWriteModel(secondFactor)
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, secondFactorModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if secondFactorModel.State == domain.FactorStateUnspecified || secondFactorModel.State == domain.FactorStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-3M9od", "Errors.IAM.LoginPolicy.MFA.NotExisting")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-3M9od", "Errors.IAM.LoginPolicy.MFA.NotExisting")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&secondFactorModel.SecondFactorWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLoginPolicySecondFactorRemovedEvent(ctx, iamAgg, secondFactor))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&secondFactorModel.SecondFactorWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLoginPolicySecondFactorRemovedEvent(ctx, instanceAgg, secondFactor))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -261,11 +261,11 @@ func (c *Commands) RemoveSecondFactorFromDefaultLoginPolicy(ctx context.Context,
|
||||
|
||||
func (c *Commands) AddMultiFactorToDefaultLoginPolicy(ctx context.Context, multiFactor domain.MultiFactorType) (domain.MultiFactorType, *domain.ObjectDetails, error) {
|
||||
if !multiFactor.Valid() {
|
||||
return domain.MultiFactorTypeUnspecified, nil, caos_errs.ThrowInvalidArgument(nil, "IAM-5m9fs", "Errors.IAM.LoginPolicy.MFA.Unspecified")
|
||||
return domain.MultiFactorTypeUnspecified, nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-5m9fs", "Errors.IAM.LoginPolicy.MFA.Unspecified")
|
||||
}
|
||||
multiFactorModel := NewIAMMultiFactorWriteModel(multiFactor)
|
||||
iamAgg := IAMAggregateFromWriteModel(&multiFactorModel.MultiFactorWriteModel.WriteModel)
|
||||
event, err := c.addMultiFactorToDefaultLoginPolicy(ctx, iamAgg, multiFactorModel, multiFactor)
|
||||
multiFactorModel := NewInstanceMultiFactorWriteModel(multiFactor)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&multiFactorModel.MultiFactorWriteModel.WriteModel)
|
||||
event, err := c.addMultiFactorToDefaultLoginPolicy(ctx, instanceAgg, multiFactorModel, multiFactor)
|
||||
if err != nil {
|
||||
return domain.MultiFactorTypeUnspecified, nil, err
|
||||
}
|
||||
@@ -281,32 +281,32 @@ func (c *Commands) AddMultiFactorToDefaultLoginPolicy(ctx context.Context, multi
|
||||
return multiFactorModel.MultiFactorWriteModel.MFAType, writeModelToObjectDetails(&multiFactorModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addMultiFactorToDefaultLoginPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, multiFactorModel *IAMMultiFactorWriteModel, multiFactor domain.MultiFactorType) (eventstore.Command, error) {
|
||||
func (c *Commands) addMultiFactorToDefaultLoginPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, multiFactorModel *InstanceMultiFactorWriteModel, multiFactor domain.MultiFactorType) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, multiFactorModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if multiFactorModel.State == domain.FactorStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-3M9od", "Errors.IAM.LoginPolicy.MFA.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-3M9od", "Errors.IAM.LoginPolicy.MFA.AlreadyExists")
|
||||
}
|
||||
|
||||
return iam_repo.NewLoginPolicyMultiFactorAddedEvent(ctx, iamAgg, multiFactor), nil
|
||||
return instance.NewLoginPolicyMultiFactorAddedEvent(ctx, instanceAgg, multiFactor), nil
|
||||
}
|
||||
|
||||
func (c *Commands) RemoveMultiFactorFromDefaultLoginPolicy(ctx context.Context, multiFactor domain.MultiFactorType) (*domain.ObjectDetails, error) {
|
||||
if !multiFactor.Valid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-33m9F", "Errors.IAM.LoginPolicy.MFA.Unspecified")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-33m9F", "Errors.IAM.LoginPolicy.MFA.Unspecified")
|
||||
}
|
||||
multiFactorModel := NewIAMMultiFactorWriteModel(multiFactor)
|
||||
multiFactorModel := NewInstanceMultiFactorWriteModel(multiFactor)
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, multiFactorModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if multiFactorModel.State == domain.FactorStateUnspecified || multiFactorModel.State == domain.FactorStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-3M9df", "Errors.IAM.LoginPolicy.MFA.NotExisting")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-3M9df", "Errors.IAM.LoginPolicy.MFA.NotExisting")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&multiFactorModel.MultiFactorWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam_repo.NewLoginPolicyMultiFactorRemovedEvent(ctx, iamAgg, multiFactor))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&multiFactorModel.MultiFactorWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewLoginPolicyMultiFactorRemovedEvent(ctx, instanceAgg, multiFactor))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -317,7 +317,7 @@ func (c *Commands) RemoveMultiFactorFromDefaultLoginPolicy(ctx context.Context,
|
||||
return writeModelToObjectDetails(&multiFactorModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultLoginPolicyWriteModelByID(ctx context.Context, writeModel *IAMLoginPolicyWriteModel) (err error) {
|
||||
func (c *Commands) defaultLoginPolicyWriteModelByID(ctx context.Context, writeModel *InstanceLoginPolicyWriteModel) (err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
+23
-23
@@ -3,15 +3,15 @@ package command
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMSecondFactorWriteModel struct {
|
||||
type InstanceSecondFactorWriteModel struct {
|
||||
SecondFactorWriteModel
|
||||
}
|
||||
|
||||
func NewIAMSecondFactorWriteModel(factorType domain.SecondFactorType) *IAMSecondFactorWriteModel {
|
||||
return &IAMSecondFactorWriteModel{
|
||||
func NewInstanceSecondFactorWriteModel(factorType domain.SecondFactorType) *InstanceSecondFactorWriteModel {
|
||||
return &InstanceSecondFactorWriteModel{
|
||||
SecondFactorWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -22,14 +22,14 @@ func NewIAMSecondFactorWriteModel(factorType domain.SecondFactorType) *IAMSecond
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMSecondFactorWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceSecondFactorWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.LoginPolicySecondFactorAddedEvent:
|
||||
case *instance.LoginPolicySecondFactorAddedEvent:
|
||||
if wm.MFAType == e.MFAType {
|
||||
wm.WriteModel.AppendEvents(&e.SecondFactorAddedEvent)
|
||||
}
|
||||
case *iam.LoginPolicySecondFactorRemovedEvent:
|
||||
case *instance.LoginPolicySecondFactorRemovedEvent:
|
||||
if wm.MFAType == e.MFAType {
|
||||
wm.WriteModel.AppendEvents(&e.SecondFactorRemovedEvent)
|
||||
}
|
||||
@@ -37,28 +37,28 @@ func (wm *IAMSecondFactorWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMSecondFactorWriteModel) Reduce() error {
|
||||
func (wm *InstanceSecondFactorWriteModel) Reduce() error {
|
||||
return wm.SecondFactorWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMSecondFactorWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceSecondFactorWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.WriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.LoginPolicySecondFactorAddedEventType,
|
||||
iam.LoginPolicySecondFactorRemovedEventType).
|
||||
instance.LoginPolicySecondFactorAddedEventType,
|
||||
instance.LoginPolicySecondFactorRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
type IAMMultiFactorWriteModel struct {
|
||||
type InstanceMultiFactorWriteModel struct {
|
||||
MultiFactorWriteModel
|
||||
}
|
||||
|
||||
func NewIAMMultiFactorWriteModel(factorType domain.MultiFactorType) *IAMMultiFactorWriteModel {
|
||||
return &IAMMultiFactorWriteModel{
|
||||
func NewInstanceMultiFactorWriteModel(factorType domain.MultiFactorType) *InstanceMultiFactorWriteModel {
|
||||
return &InstanceMultiFactorWriteModel{
|
||||
MultiFactorWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -69,14 +69,14 @@ func NewIAMMultiFactorWriteModel(factorType domain.MultiFactorType) *IAMMultiFac
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMMultiFactorWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceMultiFactorWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.LoginPolicyMultiFactorAddedEvent:
|
||||
case *instance.LoginPolicyMultiFactorAddedEvent:
|
||||
if wm.MFAType == e.MFAType {
|
||||
wm.WriteModel.AppendEvents(&e.MultiFactorAddedEvent)
|
||||
}
|
||||
case *iam.LoginPolicyMultiFactorRemovedEvent:
|
||||
case *instance.LoginPolicyMultiFactorRemovedEvent:
|
||||
if wm.MFAType == e.MFAType {
|
||||
wm.WriteModel.AppendEvents(&e.MultiFactorRemovedEvent)
|
||||
}
|
||||
@@ -84,18 +84,18 @@ func (wm *IAMMultiFactorWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMMultiFactorWriteModel) Reduce() error {
|
||||
func (wm *InstanceMultiFactorWriteModel) Reduce() error {
|
||||
return wm.MultiFactorWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMMultiFactorWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceMultiFactorWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.WriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.LoginPolicyMultiFactorAddedEventType,
|
||||
iam.LoginPolicyMultiFactorRemovedEventType).
|
||||
instance.LoginPolicyMultiFactorAddedEventType,
|
||||
instance.LoginPolicyMultiFactorRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
+10
-10
@@ -3,15 +3,15 @@ package command
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMIdentityProviderWriteModel struct {
|
||||
type InstanceIdentityProviderWriteModel struct {
|
||||
IdentityProviderWriteModel
|
||||
}
|
||||
|
||||
func NewIAMIdentityProviderWriteModel(idpConfigID string) *IAMIdentityProviderWriteModel {
|
||||
return &IAMIdentityProviderWriteModel{
|
||||
func NewInstanceIdentityProviderWriteModel(idpConfigID string) *InstanceIdentityProviderWriteModel {
|
||||
return &InstanceIdentityProviderWriteModel{
|
||||
IdentityProviderWriteModel: IdentityProviderWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -22,15 +22,15 @@ func NewIAMIdentityProviderWriteModel(idpConfigID string) *IAMIdentityProviderWr
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMIdentityProviderWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceIdentityProviderWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.IdentityProviderAddedEvent:
|
||||
case *instance.IdentityProviderAddedEvent:
|
||||
if e.IDPConfigID != wm.IDPConfigID {
|
||||
continue
|
||||
}
|
||||
wm.IdentityProviderWriteModel.AppendEvents(&e.IdentityProviderAddedEvent)
|
||||
case *iam.IdentityProviderRemovedEvent:
|
||||
case *instance.IdentityProviderRemovedEvent:
|
||||
if e.IDPConfigID != wm.IDPConfigID {
|
||||
continue
|
||||
}
|
||||
@@ -39,15 +39,15 @@ func (wm *IAMIdentityProviderWriteModel) AppendEvents(events ...eventstore.Event
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMIdentityProviderWriteModel) Reduce() error {
|
||||
func (wm *InstanceIdentityProviderWriteModel) Reduce() error {
|
||||
return wm.IdentityProviderWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMIdentityProviderWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceIdentityProviderWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
Builder()
|
||||
}
|
||||
+16
-16
@@ -7,16 +7,16 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type IAMLoginPolicyWriteModel struct {
|
||||
type InstanceLoginPolicyWriteModel struct {
|
||||
LoginPolicyWriteModel
|
||||
}
|
||||
|
||||
func NewIAMLoginPolicyWriteModel() *IAMLoginPolicyWriteModel {
|
||||
return &IAMLoginPolicyWriteModel{
|
||||
func NewInstanceLoginPolicyWriteModel() *InstanceLoginPolicyWriteModel {
|
||||
return &InstanceLoginPolicyWriteModel{
|
||||
LoginPolicyWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -26,38 +26,38 @@ func NewIAMLoginPolicyWriteModel() *IAMLoginPolicyWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMLoginPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceLoginPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.LoginPolicyAddedEvent:
|
||||
case *instance.LoginPolicyAddedEvent:
|
||||
wm.LoginPolicyWriteModel.AppendEvents(&e.LoginPolicyAddedEvent)
|
||||
case *iam.LoginPolicyChangedEvent:
|
||||
case *instance.LoginPolicyChangedEvent:
|
||||
wm.LoginPolicyWriteModel.AppendEvents(&e.LoginPolicyChangedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMLoginPolicyWriteModel) IsValid() bool {
|
||||
func (wm *InstanceLoginPolicyWriteModel) IsValid() bool {
|
||||
return wm.AggregateID != ""
|
||||
}
|
||||
|
||||
func (wm *IAMLoginPolicyWriteModel) Reduce() error {
|
||||
func (wm *InstanceLoginPolicyWriteModel) Reduce() error {
|
||||
return wm.LoginPolicyWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMLoginPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceLoginPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.LoginPolicyWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.LoginPolicyAddedEventType,
|
||||
iam.LoginPolicyChangedEventType).
|
||||
instance.LoginPolicyAddedEventType,
|
||||
instance.LoginPolicyChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMLoginPolicyWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceLoginPolicyWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
allowUsernamePassword,
|
||||
@@ -71,7 +71,7 @@ func (wm *IAMLoginPolicyWriteModel) NewChangedEvent(
|
||||
mfaInitSkipLifetime,
|
||||
secondFactorCheckLifetime,
|
||||
multiFactorCheckLifetime time.Duration,
|
||||
) (*iam.LoginPolicyChangedEvent, bool) {
|
||||
) (*instance.LoginPolicyChangedEvent, bool) {
|
||||
|
||||
changes := make([]policy.LoginPolicyChanges, 0)
|
||||
if wm.AllowUserNamePassword != allowUsernamePassword {
|
||||
@@ -110,7 +110,7 @@ func (wm *IAMLoginPolicyWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewLoginPolicyChangedEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewLoginPolicyChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
+76
-76
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
"github.com/caos/zitadel/internal/repository/user"
|
||||
|
||||
@@ -42,8 +42,8 @@ func TestCommandSide_AddDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
@@ -81,8 +81,8 @@ func TestCommandSide_AddDefaultLoginPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -200,8 +200,8 @@ func TestCommandSide_ChangeDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -245,8 +245,8 @@ func TestCommandSide_ChangeDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -395,8 +395,8 @@ func TestCommandSide_AddIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -431,8 +431,8 @@ func TestCommandSide_AddIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -449,8 +449,8 @@ func TestCommandSide_AddIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
),
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name",
|
||||
domain.IDPConfigTypeOIDC,
|
||||
@@ -461,8 +461,8 @@ func TestCommandSide_AddIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
),
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
),
|
||||
),
|
||||
@@ -486,8 +486,8 @@ func TestCommandSide_AddIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -504,8 +504,8 @@ func TestCommandSide_AddIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
),
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIDPConfigAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIDPConfigAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
"name",
|
||||
domain.IDPConfigTypeOIDC,
|
||||
@@ -518,8 +518,8 @@ func TestCommandSide_AddIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1"),
|
||||
),
|
||||
},
|
||||
@@ -621,8 +621,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -657,8 +657,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -675,14 +675,14 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
),
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
),
|
||||
),
|
||||
@@ -706,8 +706,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -724,8 +724,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
),
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
),
|
||||
),
|
||||
@@ -733,8 +733,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1"),
|
||||
),
|
||||
},
|
||||
@@ -760,8 +760,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -778,8 +778,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
),
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
),
|
||||
),
|
||||
@@ -787,8 +787,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1"),
|
||||
),
|
||||
},
|
||||
@@ -822,8 +822,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
@@ -840,8 +840,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
),
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1",
|
||||
),
|
||||
),
|
||||
@@ -856,8 +856,8 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewIdentityProviderRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewIdentityProviderRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"config1"),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
@@ -950,8 +950,8 @@ func TestCommandSide_AddSecondFactorDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecondFactorTypeOTP,
|
||||
),
|
||||
),
|
||||
@@ -975,8 +975,8 @@ func TestCommandSide_AddSecondFactorDefaultLoginPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecondFactorTypeOTP),
|
||||
),
|
||||
},
|
||||
@@ -1069,14 +1069,14 @@ func TestCommandSide_RemoveSecondFactorDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecondFactorTypeOTP,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecondFactorTypeOTP,
|
||||
),
|
||||
),
|
||||
@@ -1098,8 +1098,8 @@ func TestCommandSide_RemoveSecondFactorDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecondFactorTypeOTP,
|
||||
),
|
||||
),
|
||||
@@ -1107,8 +1107,8 @@ func TestCommandSide_RemoveSecondFactorDefaultLoginPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecondFactorTypeOTP),
|
||||
),
|
||||
},
|
||||
@@ -1185,8 +1185,8 @@ func TestCommandSide_AddMultiFactorDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.MultiFactorTypeU2FWithPIN,
|
||||
),
|
||||
),
|
||||
@@ -1210,8 +1210,8 @@ func TestCommandSide_AddMultiFactorDefaultLoginPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.MultiFactorTypeU2FWithPIN),
|
||||
),
|
||||
},
|
||||
@@ -1304,14 +1304,14 @@ func TestCommandSide_RemoveMultiFactorDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.MultiFactorTypeU2FWithPIN,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.MultiFactorTypeU2FWithPIN,
|
||||
),
|
||||
),
|
||||
@@ -1333,8 +1333,8 @@ func TestCommandSide_RemoveMultiFactorDefaultLoginPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.MultiFactorTypeU2FWithPIN,
|
||||
),
|
||||
),
|
||||
@@ -1342,8 +1342,8 @@ func TestCommandSide_RemoveMultiFactorDefaultLoginPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.MultiFactorTypeU2FWithPIN),
|
||||
),
|
||||
},
|
||||
@@ -1382,9 +1382,9 @@ func TestCommandSide_RemoveMultiFactorDefaultLoginPolicy(t *testing.T) {
|
||||
|
||||
func newDefaultLoginPolicyChangedEvent(ctx context.Context, allowRegister, allowUsernamePassword, allowExternalIDP, forceMFA, hidePasswordReset bool,
|
||||
passwordlessType domain.PasswordlessType,
|
||||
passwordLifetime, externalLoginLifetime, mfaInitSkipLifetime, secondFactorLifetime, multiFactorLifetime time.Duration) *iam.LoginPolicyChangedEvent {
|
||||
event, _ := iam.NewLoginPolicyChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
passwordLifetime, externalLoginLifetime, mfaInitSkipLifetime, secondFactorLifetime, multiFactorLifetime time.Duration) *instance.LoginPolicyChangedEvent {
|
||||
event, _ := instance.NewLoginPolicyChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]policy.LoginPolicyChanges{
|
||||
policy.ChangeAllowRegister(allowRegister),
|
||||
policy.ChangeAllowExternalIDP(allowExternalIDP),
|
||||
+16
-16
@@ -6,14 +6,14 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDefaultMailTemplate(ctx context.Context, policy *domain.MailTemplate) (*domain.MailTemplate, error) {
|
||||
addedPolicy := NewIAMMailTemplateWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedPolicy.MailTemplateWriteModel.WriteModel)
|
||||
event, err := c.addDefaultMailTemplate(ctx, iamAgg, addedPolicy, policy)
|
||||
addedPolicy := NewInstanceMailTemplateWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedPolicy.MailTemplateWriteModel.WriteModel)
|
||||
event, err := c.addDefaultMailTemplate(ctx, instanceAgg, addedPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -29,19 +29,19 @@ func (c *Commands) AddDefaultMailTemplate(ctx context.Context, policy *domain.Ma
|
||||
return writeModelToMailTemplatePolicy(&addedPolicy.MailTemplateWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultMailTemplate(ctx context.Context, iamAgg *eventstore.Aggregate, addedPolicy *IAMMailTemplateWriteModel, policy *domain.MailTemplate) (eventstore.Command, error) {
|
||||
func (c *Commands) addDefaultMailTemplate(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstanceMailTemplateWriteModel, policy *domain.MailTemplate) (eventstore.Command, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-fm9sd", "Errors.IAM.MailTemplate.Invalid")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-fm9sd", "Errors.IAM.MailTemplate.Invalid")
|
||||
}
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedPolicy.State == domain.PolicyStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-5n8fs", "Errors.IAM.MailTemplate.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-5n8fs", "Errors.IAM.MailTemplate.AlreadyExists")
|
||||
}
|
||||
|
||||
return iam_repo.NewMailTemplateAddedEvent(ctx, iamAgg, policy.Template), nil
|
||||
return instance.NewMailTemplateAddedEvent(ctx, instanceAgg, policy.Template), nil
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultMailTemplate(ctx context.Context, policy *domain.MailTemplate) (*domain.MailTemplate, error) {
|
||||
@@ -60,9 +60,9 @@ func (c *Commands) ChangeDefaultMailTemplate(ctx context.Context, policy *domain
|
||||
return writeModelToMailTemplatePolicy(&existingPolicy.MailTemplateWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) changeDefaultMailTemplate(ctx context.Context, policy *domain.MailTemplate) (*IAMMailTemplateWriteModel, eventstore.Command, error) {
|
||||
func (c *Commands) changeDefaultMailTemplate(ctx context.Context, policy *domain.MailTemplate) (*InstanceMailTemplateWriteModel, eventstore.Command, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, nil, caos_errs.ThrowInvalidArgument(nil, "IAM-4m9ds", "Errors.IAM.MailTemplate.Invalid")
|
||||
return nil, nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-4m9ds", "Errors.IAM.MailTemplate.Invalid")
|
||||
}
|
||||
existingPolicy, err := c.defaultMailTemplateWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
@@ -70,23 +70,23 @@ func (c *Commands) changeDefaultMailTemplate(ctx context.Context, policy *domain
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, nil, caos_errs.ThrowNotFound(nil, "IAM-2N8fs", "Errors.IAM.MailTemplate.NotFound")
|
||||
return nil, nil, caos_errs.ThrowNotFound(nil, "INSTANCE-2N8fs", "Errors.IAM.MailTemplate.NotFound")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.MailTemplateWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, iamAgg, policy.Template)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.MailTemplateWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, instanceAgg, policy.Template)
|
||||
if !hasChanged {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-3nfsG", "Errors.IAM.MailTemplate.NotChanged")
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-3nfsG", "Errors.IAM.MailTemplate.NotChanged")
|
||||
}
|
||||
|
||||
return existingPolicy, changedEvent, nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultMailTemplateWriteModelByID(ctx context.Context) (policy *IAMMailTemplateWriteModel, err error) {
|
||||
func (c *Commands) defaultMailTemplateWriteModelByID(ctx context.Context) (policy *InstanceMailTemplateWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMMailTemplateWriteModel()
|
||||
writeModel := NewInstanceMailTemplateWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+15
-15
@@ -7,16 +7,16 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type IAMMailTemplateWriteModel struct {
|
||||
type InstanceMailTemplateWriteModel struct {
|
||||
MailTemplateWriteModel
|
||||
}
|
||||
|
||||
func NewIAMMailTemplateWriteModel() *IAMMailTemplateWriteModel {
|
||||
return &IAMMailTemplateWriteModel{
|
||||
func NewInstanceMailTemplateWriteModel() *InstanceMailTemplateWriteModel {
|
||||
return &InstanceMailTemplateWriteModel{
|
||||
MailTemplateWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -26,38 +26,38 @@ func NewIAMMailTemplateWriteModel() *IAMMailTemplateWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMMailTemplateWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceMailTemplateWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.MailTemplateAddedEvent:
|
||||
case *instance.MailTemplateAddedEvent:
|
||||
wm.MailTemplateWriteModel.AppendEvents(&e.MailTemplateAddedEvent)
|
||||
case *iam.MailTemplateChangedEvent:
|
||||
case *instance.MailTemplateChangedEvent:
|
||||
wm.MailTemplateWriteModel.AppendEvents(&e.MailTemplateChangedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMMailTemplateWriteModel) Reduce() error {
|
||||
func (wm *InstanceMailTemplateWriteModel) Reduce() error {
|
||||
return wm.MailTemplateWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMMailTemplateWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceMailTemplateWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.MailTemplateWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.MailTemplateAddedEventType,
|
||||
iam.MailTemplateChangedEventType).
|
||||
instance.MailTemplateAddedEventType,
|
||||
instance.MailTemplateChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMMailTemplateWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceMailTemplateWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
template []byte,
|
||||
) (*iam.MailTemplateChangedEvent, bool) {
|
||||
) (*instance.MailTemplateChangedEvent, bool) {
|
||||
changes := make([]policy.MailTemplateChanges, 0)
|
||||
if !reflect.DeepEqual(wm.Template, template) {
|
||||
changes = append(changes, policy.ChangeTemplate(template))
|
||||
@@ -65,7 +65,7 @@ func (wm *IAMMailTemplateWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewMailTemplateChangedEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewMailTemplateChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
+12
-12
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -53,8 +53,8 @@ func TestCommandSide_AddDefaultMailTemplatePolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewMailTemplateAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewMailTemplateAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]byte("template"),
|
||||
),
|
||||
),
|
||||
@@ -80,8 +80,8 @@ func TestCommandSide_AddDefaultMailTemplatePolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewMailTemplateAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewMailTemplateAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]byte("template"),
|
||||
),
|
||||
),
|
||||
@@ -183,8 +183,8 @@ func TestCommandSide_ChangeDefaultMailTemplatePolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewMailTemplateAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewMailTemplateAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]byte("template"),
|
||||
),
|
||||
),
|
||||
@@ -208,8 +208,8 @@ func TestCommandSide_ChangeDefaultMailTemplatePolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewMailTemplateAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewMailTemplateAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]byte("template"),
|
||||
),
|
||||
),
|
||||
@@ -259,9 +259,9 @@ func TestCommandSide_ChangeDefaultMailTemplatePolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultMailTemplatePolicyChangedEvent(ctx context.Context, template []byte) *iam.MailTemplateChangedEvent {
|
||||
event, _ := iam.NewMailTemplateChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultMailTemplatePolicyChangedEvent(ctx context.Context, template []byte) *instance.MailTemplateChangedEvent {
|
||||
event, _ := instance.NewMailTemplateChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]policy.MailTemplateChanges{
|
||||
policy.ChangeTemplate(template),
|
||||
},
|
||||
+13
-13
@@ -6,14 +6,14 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDefaultPasswordAgePolicy(ctx context.Context, policy *domain.PasswordAgePolicy) (*domain.PasswordAgePolicy, error) {
|
||||
addedPolicy := NewIAMPasswordAgePolicyWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
event, err := c.addDefaultPasswordAgePolicy(ctx, iamAgg, addedPolicy, policy)
|
||||
addedPolicy := NewInstancePasswordAgePolicyWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
event, err := c.addDefaultPasswordAgePolicy(ctx, instanceAgg, addedPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -29,16 +29,16 @@ func (c *Commands) AddDefaultPasswordAgePolicy(ctx context.Context, policy *doma
|
||||
return writeModelToPasswordAgePolicy(&addedPolicy.PasswordAgePolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultPasswordAgePolicy(ctx context.Context, iamAgg *eventstore.Aggregate, addedPolicy *IAMPasswordAgePolicyWriteModel, policy *domain.PasswordAgePolicy) (eventstore.Command, error) {
|
||||
func (c *Commands) addDefaultPasswordAgePolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstancePasswordAgePolicyWriteModel, policy *domain.PasswordAgePolicy) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedPolicy.State == domain.PolicyStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-Lk0dS", "Errors.IAM.PasswordAgePolicy.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-Lk0dS", "Errors.IAM.PasswordAgePolicy.AlreadyExists")
|
||||
}
|
||||
|
||||
return iam_repo.NewPasswordAgePolicyAddedEvent(ctx, iamAgg, policy.ExpireWarnDays, policy.MaxAgeDays), nil
|
||||
return instance.NewPasswordAgePolicyAddedEvent(ctx, instanceAgg, policy.ExpireWarnDays, policy.MaxAgeDays), nil
|
||||
|
||||
}
|
||||
|
||||
@@ -48,13 +48,13 @@ func (c *Commands) ChangeDefaultPasswordAgePolicy(ctx context.Context, policy *d
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-0oPew", "Errors.IAM.PasswordAgePolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-0oPew", "Errors.IAM.PasswordAgePolicy.NotFound")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.PasswordAgePolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, iamAgg, policy.ExpireWarnDays, policy.MaxAgeDays)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.PasswordAgePolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, instanceAgg, policy.ExpireWarnDays, policy.MaxAgeDays)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
@@ -69,11 +69,11 @@ func (c *Commands) ChangeDefaultPasswordAgePolicy(ctx context.Context, policy *d
|
||||
return writeModelToPasswordAgePolicy(&existingPolicy.PasswordAgePolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultPasswordAgePolicyWriteModelByID(ctx context.Context) (policy *IAMPasswordAgePolicyWriteModel, err error) {
|
||||
func (c *Commands) defaultPasswordAgePolicyWriteModelByID(ctx context.Context) (policy *InstancePasswordAgePolicyWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMPasswordAgePolicyWriteModel()
|
||||
writeModel := NewInstancePasswordAgePolicyWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+12
-12
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -38,8 +38,8 @@ func TestCommandSide_AddDefaultPasswordAgePolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewPasswordAgePolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPasswordAgePolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
365,
|
||||
10,
|
||||
),
|
||||
@@ -67,8 +67,8 @@ func TestCommandSide_AddDefaultPasswordAgePolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewPasswordAgePolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPasswordAgePolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
365,
|
||||
10,
|
||||
),
|
||||
@@ -159,8 +159,8 @@ func TestCommandSide_ChangeDefaultPasswordAgePolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewPasswordAgePolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPasswordAgePolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
365,
|
||||
10,
|
||||
),
|
||||
@@ -186,8 +186,8 @@ func TestCommandSide_ChangeDefaultPasswordAgePolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewPasswordAgePolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPasswordAgePolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
365,
|
||||
10,
|
||||
),
|
||||
@@ -240,9 +240,9 @@ func TestCommandSide_ChangeDefaultPasswordAgePolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultPasswordAgePolicyChangedEvent(ctx context.Context, maxAgeDays, expiryWarnDays uint64) *iam.PasswordAgePolicyChangedEvent {
|
||||
event, _ := iam.NewPasswordAgePolicyChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultPasswordAgePolicyChangedEvent(ctx context.Context, maxAgeDays, expiryWarnDays uint64) *instance.PasswordAgePolicyChangedEvent {
|
||||
event, _ := instance.NewPasswordAgePolicyChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]policy.PasswordAgePolicyChanges{
|
||||
policy.ChangeExpireWarnDays(expiryWarnDays),
|
||||
policy.ChangeMaxAgeDays(maxAgeDays),
|
||||
+15
-15
@@ -6,18 +6,18 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) getDefaultPasswordComplexityPolicy(ctx context.Context) (*domain.PasswordComplexityPolicy, error) {
|
||||
policyWriteModel := NewIAMPasswordComplexityPolicyWriteModel()
|
||||
policyWriteModel := NewInstancePasswordComplexityPolicyWriteModel()
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, policyWriteModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !policyWriteModel.State.Exists() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-M0gsf", "Errors.IAM.OrgIAMPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-M0gsf", "Errors.IAM.PasswordComplexityPolicy.NotFound")
|
||||
}
|
||||
policy := writeModelToPasswordComplexityPolicy(&policyWriteModel.PasswordComplexityPolicyWriteModel)
|
||||
policy.Default = true
|
||||
@@ -25,9 +25,9 @@ func (c *Commands) getDefaultPasswordComplexityPolicy(ctx context.Context) (*dom
|
||||
}
|
||||
|
||||
func (c *Commands) AddDefaultPasswordComplexityPolicy(ctx context.Context, policy *domain.PasswordComplexityPolicy) (*domain.PasswordComplexityPolicy, error) {
|
||||
addedPolicy := NewIAMPasswordComplexityPolicyWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
events, err := c.addDefaultPasswordComplexityPolicy(ctx, iamAgg, addedPolicy, policy)
|
||||
addedPolicy := NewInstancePasswordComplexityPolicyWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
events, err := c.addDefaultPasswordComplexityPolicy(ctx, instanceAgg, addedPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func (c *Commands) AddDefaultPasswordComplexityPolicy(ctx context.Context, polic
|
||||
return writeModelToPasswordComplexityPolicy(&addedPolicy.PasswordComplexityPolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultPasswordComplexityPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, addedPolicy *IAMPasswordComplexityPolicyWriteModel, policy *domain.PasswordComplexityPolicy) (eventstore.Command, error) {
|
||||
func (c *Commands) addDefaultPasswordComplexityPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstancePasswordComplexityPolicyWriteModel, policy *domain.PasswordComplexityPolicy) (eventstore.Command, error) {
|
||||
if err := policy.IsValid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -53,10 +53,10 @@ func (c *Commands) addDefaultPasswordComplexityPolicy(ctx context.Context, iamAg
|
||||
return nil, err
|
||||
}
|
||||
if addedPolicy.State == domain.PolicyStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-Lk0dS", "Errors.IAM.PasswordComplexityPolicy.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-Lk0dS", "Errors.IAM.PasswordComplexityPolicy.AlreadyExists")
|
||||
}
|
||||
|
||||
return iam_repo.NewPasswordComplexityPolicyAddedEvent(ctx, iamAgg, policy.MinLength, policy.HasLowercase, policy.HasUppercase, policy.HasNumber, policy.HasSymbol), nil
|
||||
return instance.NewPasswordComplexityPolicyAddedEvent(ctx, instanceAgg, policy.MinLength, policy.HasLowercase, policy.HasUppercase, policy.HasNumber, policy.HasSymbol), nil
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultPasswordComplexityPolicy(ctx context.Context, policy *domain.PasswordComplexityPolicy) (*domain.PasswordComplexityPolicy, error) {
|
||||
@@ -69,13 +69,13 @@ func (c *Commands) ChangeDefaultPasswordComplexityPolicy(ctx context.Context, po
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-0oPew", "Errors.IAM.PasswordAgePolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-0oPew", "Errors.IAM.PasswordAgePolicy.NotFound")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.PasswordComplexityPolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, iamAgg, policy.MinLength, policy.HasLowercase, policy.HasUppercase, policy.HasNumber, policy.HasSymbol)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.PasswordComplexityPolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, instanceAgg, policy.MinLength, policy.HasLowercase, policy.HasUppercase, policy.HasNumber, policy.HasSymbol)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
}
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
if err != nil {
|
||||
@@ -88,11 +88,11 @@ func (c *Commands) ChangeDefaultPasswordComplexityPolicy(ctx context.Context, po
|
||||
return writeModelToPasswordComplexityPolicy(&existingPolicy.PasswordComplexityPolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultPasswordComplexityPolicyWriteModelByID(ctx context.Context) (policy *IAMPasswordComplexityPolicyWriteModel, err error) {
|
||||
func (c *Commands) defaultPasswordComplexityPolicyWriteModelByID(ctx context.Context) (policy *InstancePasswordComplexityPolicyWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMPasswordComplexityPolicyWriteModel()
|
||||
writeModel := NewInstancePasswordComplexityPolicyWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+15
-15
@@ -6,16 +6,16 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type IAMPasswordComplexityPolicyWriteModel struct {
|
||||
type InstancePasswordComplexityPolicyWriteModel struct {
|
||||
PasswordComplexityPolicyWriteModel
|
||||
}
|
||||
|
||||
func NewIAMPasswordComplexityPolicyWriteModel() *IAMPasswordComplexityPolicyWriteModel {
|
||||
return &IAMPasswordComplexityPolicyWriteModel{
|
||||
func NewInstancePasswordComplexityPolicyWriteModel() *InstancePasswordComplexityPolicyWriteModel {
|
||||
return &InstancePasswordComplexityPolicyWriteModel{
|
||||
PasswordComplexityPolicyWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -25,34 +25,34 @@ func NewIAMPasswordComplexityPolicyWriteModel() *IAMPasswordComplexityPolicyWrit
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMPasswordComplexityPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstancePasswordComplexityPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.PasswordComplexityPolicyAddedEvent:
|
||||
case *instance.PasswordComplexityPolicyAddedEvent:
|
||||
wm.PasswordComplexityPolicyWriteModel.AppendEvents(&e.PasswordComplexityPolicyAddedEvent)
|
||||
case *iam.PasswordComplexityPolicyChangedEvent:
|
||||
case *instance.PasswordComplexityPolicyChangedEvent:
|
||||
wm.PasswordComplexityPolicyWriteModel.AppendEvents(&e.PasswordComplexityPolicyChangedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMPasswordComplexityPolicyWriteModel) Reduce() error {
|
||||
func (wm *InstancePasswordComplexityPolicyWriteModel) Reduce() error {
|
||||
return wm.PasswordComplexityPolicyWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMPasswordComplexityPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstancePasswordComplexityPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.PasswordComplexityPolicyWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.PasswordComplexityPolicyAddedEventType,
|
||||
iam.PasswordComplexityPolicyChangedEventType).
|
||||
instance.PasswordComplexityPolicyAddedEventType,
|
||||
instance.PasswordComplexityPolicyChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMPasswordComplexityPolicyWriteModel) NewChangedEvent(
|
||||
func (wm *InstancePasswordComplexityPolicyWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
minLength uint64,
|
||||
@@ -60,7 +60,7 @@ func (wm *IAMPasswordComplexityPolicyWriteModel) NewChangedEvent(
|
||||
hasUppercase,
|
||||
hasNumber,
|
||||
hasSymbol bool,
|
||||
) (*iam.PasswordComplexityPolicyChangedEvent, bool) {
|
||||
) (*instance.PasswordComplexityPolicyChangedEvent, bool) {
|
||||
|
||||
changes := make([]policy.PasswordComplexityPolicyChanges, 0)
|
||||
if wm.MinLength != minLength {
|
||||
@@ -81,7 +81,7 @@ func (wm *IAMPasswordComplexityPolicyWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewPasswordComplexityPolicyChangedEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewPasswordComplexityPolicyChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
+12
-12
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -59,8 +59,8 @@ func TestCommandSide_AddDefaultPasswordComplexityPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
8,
|
||||
true, true, true, true,
|
||||
),
|
||||
@@ -91,8 +91,8 @@ func TestCommandSide_AddDefaultPasswordComplexityPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
8,
|
||||
true, true, true, true,
|
||||
),
|
||||
@@ -213,8 +213,8 @@ func TestCommandSide_ChangeDefaultPasswordComplexityPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
8,
|
||||
true, true, true, true,
|
||||
),
|
||||
@@ -243,8 +243,8 @@ func TestCommandSide_ChangeDefaultPasswordComplexityPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
8,
|
||||
true, true, true, true,
|
||||
),
|
||||
@@ -303,9 +303,9 @@ func TestCommandSide_ChangeDefaultPasswordComplexityPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultPasswordComplexityPolicyChangedEvent(ctx context.Context, minLength uint64, hasUpper, hasLower, hasNumber, hasSymbol bool) *iam.PasswordComplexityPolicyChangedEvent {
|
||||
event, _ := iam.NewPasswordComplexityPolicyChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultPasswordComplexityPolicyChangedEvent(ctx context.Context, minLength uint64, hasUpper, hasLower, hasNumber, hasSymbol bool) *instance.PasswordComplexityPolicyChangedEvent {
|
||||
event, _ := instance.NewPasswordComplexityPolicyChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]policy.PasswordComplexityPolicyChanges{
|
||||
policy.ChangeMinLength(minLength),
|
||||
policy.ChangeHasUppercase(hasUpper),
|
||||
+13
-13
@@ -6,14 +6,14 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDefaultLockoutPolicy(ctx context.Context, policy *domain.LockoutPolicy) (*domain.LockoutPolicy, error) {
|
||||
addedPolicy := NewIAMLockoutPolicyWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
event, err := c.addDefaultLockoutPolicy(ctx, iamAgg, addedPolicy, policy)
|
||||
addedPolicy := NewInstanceLockoutPolicyWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
event, err := c.addDefaultLockoutPolicy(ctx, instanceAgg, addedPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -29,16 +29,16 @@ func (c *Commands) AddDefaultLockoutPolicy(ctx context.Context, policy *domain.L
|
||||
return writeModelToLockoutPolicy(&addedPolicy.LockoutPolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultLockoutPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, addedPolicy *IAMLockoutPolicyWriteModel, policy *domain.LockoutPolicy) (eventstore.Command, error) {
|
||||
func (c *Commands) addDefaultLockoutPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstanceLockoutPolicyWriteModel, policy *domain.LockoutPolicy) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedPolicy.State == domain.PolicyStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-0olDf", "Errors.IAM.LockoutPolicy.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-0olDf", "Errors.IAM.LockoutPolicy.AlreadyExists")
|
||||
}
|
||||
|
||||
return iam_repo.NewLockoutPolicyAddedEvent(ctx, iamAgg, policy.MaxPasswordAttempts, policy.ShowLockOutFailures), nil
|
||||
return instance.NewLockoutPolicyAddedEvent(ctx, instanceAgg, policy.MaxPasswordAttempts, policy.ShowLockOutFailures), nil
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultLockoutPolicy(ctx context.Context, policy *domain.LockoutPolicy) (*domain.LockoutPolicy, error) {
|
||||
@@ -47,13 +47,13 @@ func (c *Commands) ChangeDefaultLockoutPolicy(ctx context.Context, policy *domai
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-0oPew", "Errors.IAM.LockoutPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-0oPew", "Errors.IAM.LockoutPolicy.NotFound")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.LockoutPolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, iamAgg, policy.MaxPasswordAttempts, policy.ShowLockOutFailures)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.LockoutPolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, instanceAgg, policy.MaxPasswordAttempts, policy.ShowLockOutFailures)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-4M9vs", "Errors.IAM.LockoutPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-4M9vs", "Errors.IAM.LockoutPolicy.NotChanged")
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
@@ -67,11 +67,11 @@ func (c *Commands) ChangeDefaultLockoutPolicy(ctx context.Context, policy *domai
|
||||
return writeModelToLockoutPolicy(&existingPolicy.LockoutPolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultLockoutPolicyWriteModelByID(ctx context.Context) (policy *IAMLockoutPolicyWriteModel, err error) {
|
||||
func (c *Commands) defaultLockoutPolicyWriteModelByID(ctx context.Context) (policy *InstanceLockoutPolicyWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMLockoutPolicyWriteModel()
|
||||
writeModel := NewInstanceLockoutPolicyWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+15
-15
@@ -6,16 +6,16 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type IAMLockoutPolicyWriteModel struct {
|
||||
type InstanceLockoutPolicyWriteModel struct {
|
||||
LockoutPolicyWriteModel
|
||||
}
|
||||
|
||||
func NewIAMLockoutPolicyWriteModel() *IAMLockoutPolicyWriteModel {
|
||||
return &IAMLockoutPolicyWriteModel{
|
||||
func NewInstanceLockoutPolicyWriteModel() *InstanceLockoutPolicyWriteModel {
|
||||
return &InstanceLockoutPolicyWriteModel{
|
||||
LockoutPolicyWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -25,38 +25,38 @@ func NewIAMLockoutPolicyWriteModel() *IAMLockoutPolicyWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMLockoutPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstanceLockoutPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.LockoutPolicyAddedEvent:
|
||||
case *instance.LockoutPolicyAddedEvent:
|
||||
wm.LockoutPolicyWriteModel.AppendEvents(&e.LockoutPolicyAddedEvent)
|
||||
case *iam.LockoutPolicyChangedEvent:
|
||||
case *instance.LockoutPolicyChangedEvent:
|
||||
wm.LockoutPolicyWriteModel.AppendEvents(&e.LockoutPolicyChangedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMLockoutPolicyWriteModel) Reduce() error {
|
||||
func (wm *InstanceLockoutPolicyWriteModel) Reduce() error {
|
||||
return wm.LockoutPolicyWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMLockoutPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceLockoutPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.LockoutPolicyWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.LockoutPolicyAddedEventType,
|
||||
iam.LockoutPolicyChangedEventType).
|
||||
instance.LockoutPolicyAddedEventType,
|
||||
instance.LockoutPolicyChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMLockoutPolicyWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceLockoutPolicyWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
maxAttempts uint64,
|
||||
showLockoutFailure bool) (*iam.LockoutPolicyChangedEvent, bool) {
|
||||
showLockoutFailure bool) (*instance.LockoutPolicyChangedEvent, bool) {
|
||||
changes := make([]policy.LockoutPolicyChanges, 0)
|
||||
if wm.MaxPasswordAttempts != maxAttempts {
|
||||
changes = append(changes, policy.ChangeMaxAttempts(maxAttempts))
|
||||
@@ -67,7 +67,7 @@ func (wm *IAMLockoutPolicyWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewLockoutPolicyChangedEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewLockoutPolicyChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
+14
-13
@@ -2,15 +2,16 @@ package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCommandSide_AddDefaultLockoutPolicy(t *testing.T) {
|
||||
@@ -38,8 +39,8 @@ func TestCommandSide_AddDefaultLockoutPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLockoutPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLockoutPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
10,
|
||||
true,
|
||||
),
|
||||
@@ -67,8 +68,8 @@ func TestCommandSide_AddDefaultLockoutPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewLockoutPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLockoutPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
10,
|
||||
true,
|
||||
),
|
||||
@@ -159,8 +160,8 @@ func TestCommandSide_ChangeDefaultLockoutPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLockoutPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLockoutPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
10,
|
||||
true,
|
||||
),
|
||||
@@ -186,8 +187,8 @@ func TestCommandSide_ChangeDefaultLockoutPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewLockoutPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewLockoutPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
10,
|
||||
true,
|
||||
),
|
||||
@@ -240,9 +241,9 @@ func TestCommandSide_ChangeDefaultLockoutPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultLockoutPolicyChangedEvent(ctx context.Context, maxAttempts uint64, showLockoutFailure bool) *iam.LockoutPolicyChangedEvent {
|
||||
event, _ := iam.NewLockoutPolicyChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultLockoutPolicyChangedEvent(ctx context.Context, maxAttempts uint64, showLockoutFailure bool) *instance.LockoutPolicyChangedEvent {
|
||||
event, _ := instance.NewLockoutPolicyChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]policy.LockoutPolicyChanges{
|
||||
policy.ChangeMaxAttempts(maxAttempts),
|
||||
policy.ChangeShowLockOutFailures(showLockoutFailure),
|
||||
+15
-15
@@ -6,18 +6,18 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) getDefaultPrivacyPolicy(ctx context.Context) (*domain.PrivacyPolicy, error) {
|
||||
policyWriteModel := NewIAMPrivacyPolicyWriteModel()
|
||||
policyWriteModel := NewInstancePrivacyPolicyWriteModel()
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, policyWriteModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !policyWriteModel.State.Exists() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-559os", "Errors.IAM.OrgIAMPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-559os", "Errors.IAM.PasswordAgePolicy.NotFound")
|
||||
}
|
||||
policy := writeModelToPrivacyPolicy(&policyWriteModel.PrivacyPolicyWriteModel)
|
||||
policy.Default = true
|
||||
@@ -25,9 +25,9 @@ func (c *Commands) getDefaultPrivacyPolicy(ctx context.Context) (*domain.Privacy
|
||||
}
|
||||
|
||||
func (c *Commands) AddDefaultPrivacyPolicy(ctx context.Context, policy *domain.PrivacyPolicy) (*domain.PrivacyPolicy, error) {
|
||||
addedPolicy := NewIAMPrivacyPolicyWriteModel()
|
||||
iamAgg := IAMAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
events, err := c.addDefaultPrivacyPolicy(ctx, iamAgg, addedPolicy, policy)
|
||||
addedPolicy := NewInstancePrivacyPolicyWriteModel()
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&addedPolicy.WriteModel)
|
||||
events, err := c.addDefaultPrivacyPolicy(ctx, instanceAgg, addedPolicy, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -43,16 +43,16 @@ func (c *Commands) AddDefaultPrivacyPolicy(ctx context.Context, policy *domain.P
|
||||
return writeModelToPrivacyPolicy(&addedPolicy.PrivacyPolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) addDefaultPrivacyPolicy(ctx context.Context, iamAgg *eventstore.Aggregate, addedPolicy *IAMPrivacyPolicyWriteModel, policy *domain.PrivacyPolicy) (eventstore.Command, error) {
|
||||
func (c *Commands) addDefaultPrivacyPolicy(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstancePrivacyPolicyWriteModel, policy *domain.PrivacyPolicy) (eventstore.Command, error) {
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addedPolicy.State == domain.PolicyStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "IAM-M00rJ", "Errors.IAM.PrivacyPolicy.AlreadyExists")
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-M00rJ", "Errors.IAM.PrivacyPolicy.AlreadyExists")
|
||||
}
|
||||
|
||||
return iam_repo.NewPrivacyPolicyAddedEvent(ctx, iamAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink), nil
|
||||
return instance.NewPrivacyPolicyAddedEvent(ctx, instanceAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink), nil
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultPrivacyPolicy(ctx context.Context, policy *domain.PrivacyPolicy) (*domain.PrivacyPolicy, error) {
|
||||
@@ -61,13 +61,13 @@ func (c *Commands) ChangeDefaultPrivacyPolicy(ctx context.Context, policy *domai
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-0oPew", "Errors.IAM.PasswordAgePolicy.NotFound")
|
||||
return nil, caos_errs.ThrowNotFound(nil, "INSTANCE-0oPew", "Errors.IAM.PasswordAgePolicy.NotFound")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.PrivacyPolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, iamAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.PrivacyPolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, instanceAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-4M9vs", "Errors.IAM.LabelPolicy.NotChanged")
|
||||
}
|
||||
pushedEvents, err := c.eventstore.Push(ctx, changedEvent)
|
||||
if err != nil {
|
||||
@@ -80,11 +80,11 @@ func (c *Commands) ChangeDefaultPrivacyPolicy(ctx context.Context, policy *domai
|
||||
return writeModelToPrivacyPolicy(&existingPolicy.PrivacyPolicyWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultPrivacyPolicyWriteModelByID(ctx context.Context) (policy *IAMPrivacyPolicyWriteModel, err error) {
|
||||
func (c *Commands) defaultPrivacyPolicyWriteModelByID(ctx context.Context) (policy *InstancePrivacyPolicyWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewIAMPrivacyPolicyWriteModel()
|
||||
writeModel := NewInstancePrivacyPolicyWriteModel()
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+16
-17
@@ -3,19 +3,18 @@ package command
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type IAMPrivacyPolicyWriteModel struct {
|
||||
type InstancePrivacyPolicyWriteModel struct {
|
||||
PrivacyPolicyWriteModel
|
||||
}
|
||||
|
||||
func NewIAMPrivacyPolicyWriteModel() *IAMPrivacyPolicyWriteModel {
|
||||
return &IAMPrivacyPolicyWriteModel{
|
||||
func NewInstancePrivacyPolicyWriteModel() *InstancePrivacyPolicyWriteModel {
|
||||
return &InstancePrivacyPolicyWriteModel{
|
||||
PrivacyPolicyWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
@@ -25,40 +24,40 @@ func NewIAMPrivacyPolicyWriteModel() *IAMPrivacyPolicyWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMPrivacyPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
func (wm *InstancePrivacyPolicyWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *iam.PrivacyPolicyAddedEvent:
|
||||
case *instance.PrivacyPolicyAddedEvent:
|
||||
wm.PrivacyPolicyWriteModel.AppendEvents(&e.PrivacyPolicyAddedEvent)
|
||||
case *iam.PrivacyPolicyChangedEvent:
|
||||
case *instance.PrivacyPolicyChangedEvent:
|
||||
wm.PrivacyPolicyWriteModel.AppendEvents(&e.PrivacyPolicyChangedEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMPrivacyPolicyWriteModel) Reduce() error {
|
||||
func (wm *InstancePrivacyPolicyWriteModel) Reduce() error {
|
||||
return wm.PrivacyPolicyWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMPrivacyPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstancePrivacyPolicyWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.PrivacyPolicyWriteModel.AggregateID).
|
||||
EventTypes(
|
||||
iam.PrivacyPolicyAddedEventType,
|
||||
iam.PrivacyPolicyChangedEventType).
|
||||
instance.PrivacyPolicyAddedEventType,
|
||||
instance.PrivacyPolicyChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMPrivacyPolicyWriteModel) NewChangedEvent(
|
||||
func (wm *InstancePrivacyPolicyWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
tosLink,
|
||||
privacyLink,
|
||||
helpLink string,
|
||||
) (*iam.PrivacyPolicyChangedEvent, bool) {
|
||||
) (*instance.PrivacyPolicyChangedEvent, bool) {
|
||||
|
||||
changes := make([]policy.PrivacyPolicyChanges, 0)
|
||||
if wm.TOSLink != tosLink {
|
||||
@@ -73,7 +72,7 @@ func (wm *IAMPrivacyPolicyWriteModel) NewChangedEvent(
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
changedEvent, err := iam.NewPrivacyPolicyChangedEvent(ctx, aggregate, changes)
|
||||
changedEvent, err := instance.NewPrivacyPolicyChangedEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
+14
-14
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
"github.com/caos/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
@@ -40,8 +40,8 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
@@ -71,8 +71,8 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
@@ -111,8 +111,8 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
@@ -207,8 +207,8 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
@@ -236,8 +236,8 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewPrivacyPolicyAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
@@ -297,9 +297,9 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultPrivacyPolicyChangedEvent(ctx context.Context, tosLink, privacyLink, helpLink string) *iam.PrivacyPolicyChangedEvent {
|
||||
event, _ := iam.NewPrivacyPolicyChangedEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
func newDefaultPrivacyPolicyChangedEvent(ctx context.Context, tosLink, privacyLink, helpLink string) *instance.PrivacyPolicyChangedEvent {
|
||||
event, _ := instance.NewPrivacyPolicyChangedEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
[]policy.PrivacyPolicyChanges{
|
||||
policy.ChangeTOSLink(tosLink),
|
||||
policy.ChangePrivacyLink(privacyLink),
|
||||
+23
-23
@@ -6,10 +6,10 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMSecretGeneratorConfigWriteModel struct {
|
||||
type InstanceSecretGeneratorConfigWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
GeneratorType domain.SecretGeneratorType
|
||||
@@ -22,8 +22,8 @@ type IAMSecretGeneratorConfigWriteModel struct {
|
||||
State domain.SecretGeneratorState
|
||||
}
|
||||
|
||||
func NewIAMSecretGeneratorConfigWriteModel(GeneratorType domain.SecretGeneratorType) *IAMSecretGeneratorConfigWriteModel {
|
||||
return &IAMSecretGeneratorConfigWriteModel{
|
||||
func NewInstanceSecretGeneratorConfigWriteModel(GeneratorType domain.SecretGeneratorType) *InstanceSecretGeneratorConfigWriteModel {
|
||||
return &InstanceSecretGeneratorConfigWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
ResourceOwner: domain.IAMID,
|
||||
@@ -32,10 +32,10 @@ func NewIAMSecretGeneratorConfigWriteModel(GeneratorType domain.SecretGeneratorT
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMSecretGeneratorConfigWriteModel) Reduce() error {
|
||||
func (wm *InstanceSecretGeneratorConfigWriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
switch e := event.(type) {
|
||||
case *iam.SecretGeneratorAddedEvent:
|
||||
case *instance.SecretGeneratorAddedEvent:
|
||||
if wm.GeneratorType != e.GeneratorType {
|
||||
continue
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func (wm *IAMSecretGeneratorConfigWriteModel) Reduce() error {
|
||||
wm.IncludeDigits = e.IncludeDigits
|
||||
wm.IncludeSymbols = e.IncludeDigits
|
||||
wm.State = domain.SecretGeneratorStateActive
|
||||
case *iam.SecretGeneratorChangedEvent:
|
||||
case *instance.SecretGeneratorChangedEvent:
|
||||
if wm.GeneratorType != e.GeneratorType {
|
||||
continue
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (wm *IAMSecretGeneratorConfigWriteModel) Reduce() error {
|
||||
if e.IncludeSymbols != nil {
|
||||
wm.IncludeSymbols = *e.IncludeSymbols
|
||||
}
|
||||
case *iam.SecretGeneratorRemovedEvent:
|
||||
case *instance.SecretGeneratorRemovedEvent:
|
||||
if wm.GeneratorType != e.GeneratorType {
|
||||
continue
|
||||
}
|
||||
@@ -84,20 +84,20 @@ func (wm *IAMSecretGeneratorConfigWriteModel) Reduce() error {
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMSecretGeneratorConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceSecretGeneratorConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
EventTypes(
|
||||
iam.SecretGeneratorAddedEventType,
|
||||
iam.SecretGeneratorChangedEventType,
|
||||
iam.SecretGeneratorRemovedEventType).
|
||||
instance.SecretGeneratorAddedEventType,
|
||||
instance.SecretGeneratorChangedEventType,
|
||||
instance.SecretGeneratorRemovedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMSecretGeneratorConfigWriteModel) NewChangedEvent(
|
||||
func (wm *InstanceSecretGeneratorConfigWriteModel) NewChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
generatorType domain.SecretGeneratorType,
|
||||
@@ -107,32 +107,32 @@ func (wm *IAMSecretGeneratorConfigWriteModel) NewChangedEvent(
|
||||
includeUpperLetters,
|
||||
includeDigits,
|
||||
includeSymbols bool,
|
||||
) (*iam.SecretGeneratorChangedEvent, bool, error) {
|
||||
changes := make([]iam.SecretGeneratorChanges, 0)
|
||||
) (*instance.SecretGeneratorChangedEvent, bool, error) {
|
||||
changes := make([]instance.SecretGeneratorChanges, 0)
|
||||
var err error
|
||||
|
||||
if wm.Length != length {
|
||||
changes = append(changes, iam.ChangeSecretGeneratorLength(length))
|
||||
changes = append(changes, instance.ChangeSecretGeneratorLength(length))
|
||||
}
|
||||
if wm.Expiry != expiry {
|
||||
changes = append(changes, iam.ChangeSecretGeneratorExpiry(expiry))
|
||||
changes = append(changes, instance.ChangeSecretGeneratorExpiry(expiry))
|
||||
}
|
||||
if wm.IncludeLowerLetters != includeLowerLetters {
|
||||
changes = append(changes, iam.ChangeSecretGeneratorIncludeLowerLetters(includeLowerLetters))
|
||||
changes = append(changes, instance.ChangeSecretGeneratorIncludeLowerLetters(includeLowerLetters))
|
||||
}
|
||||
if wm.IncludeUpperLetters != includeUpperLetters {
|
||||
changes = append(changes, iam.ChangeSecretGeneratorIncludeUpperLetters(includeUpperLetters))
|
||||
changes = append(changes, instance.ChangeSecretGeneratorIncludeUpperLetters(includeUpperLetters))
|
||||
}
|
||||
if wm.IncludeDigits != includeDigits {
|
||||
changes = append(changes, iam.ChangeSecretGeneratorIncludeDigits(includeDigits))
|
||||
changes = append(changes, instance.ChangeSecretGeneratorIncludeDigits(includeDigits))
|
||||
}
|
||||
if wm.IncludeSymbols != includeSymbols {
|
||||
changes = append(changes, iam.ChangeSecretGeneratorIncludeSymbols(includeSymbols))
|
||||
changes = append(changes, instance.ChangeSecretGeneratorIncludeSymbols(includeSymbols))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
changeEvent, err := iam.NewSecretGeneratorChangeEvent(ctx, aggregate, generatorType, changes)
|
||||
changeEvent, err := instance.NewSecretGeneratorChangeEvent(ctx, aggregate, generatorType, changes)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"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/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func (c *Commands) AddSecretGeneratorConfig(ctx context.Context, generatorType domain.SecretGeneratorType, config *crypto.GeneratorConfig) (*domain.ObjectDetails, error) {
|
||||
@@ -21,10 +21,10 @@ func (c *Commands) AddSecretGeneratorConfig(ctx context.Context, generatorType d
|
||||
if generatorWriteModel.State == domain.SecretGeneratorStateActive {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "COMMAND-3n9ls", "Errors.SecretGenerator.AlreadyExists")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&generatorWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam.NewSecretGeneratorAddedEvent(
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&generatorWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewSecretGeneratorAddedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
generatorType,
|
||||
config.Length,
|
||||
config.Expiry,
|
||||
@@ -54,11 +54,11 @@ func (c *Commands) ChangeSecretGeneratorConfig(ctx context.Context, generatorTyp
|
||||
if generatorWriteModel.State == domain.SecretGeneratorStateUnspecified || generatorWriteModel.State == domain.SecretGeneratorStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "COMMAND-3n9ls", "Errors.SecretGenerator.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&generatorWriteModel.WriteModel)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&generatorWriteModel.WriteModel)
|
||||
|
||||
changedEvent, hasChanged, err := generatorWriteModel.NewChangedEvent(
|
||||
ctx,
|
||||
iamAgg,
|
||||
instanceAgg,
|
||||
generatorType,
|
||||
config.Length,
|
||||
config.Expiry,
|
||||
@@ -95,8 +95,8 @@ func (c *Commands) RemoveSecretGeneratorConfig(ctx context.Context, generatorTyp
|
||||
if generatorWriteModel.State == domain.SecretGeneratorStateUnspecified || generatorWriteModel.State == domain.SecretGeneratorStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "COMMAND-b8les", "Errors.SecretGenerator.NotFound")
|
||||
}
|
||||
iamAgg := IAMAggregateFromWriteModel(&generatorWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, iam.NewSecretGeneratorRemovedEvent(ctx, iamAgg, generatorType))
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&generatorWriteModel.WriteModel)
|
||||
pushedEvents, err := c.eventstore.Push(ctx, instance.NewSecretGeneratorRemovedEvent(ctx, instanceAgg, generatorType))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -107,8 +107,8 @@ func (c *Commands) RemoveSecretGeneratorConfig(ctx context.Context, generatorTyp
|
||||
return writeModelToObjectDetails(&generatorWriteModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) getSecretConfig(ctx context.Context, generatorType domain.SecretGeneratorType) (_ *IAMSecretGeneratorConfigWriteModel, err error) {
|
||||
writeModel := NewIAMSecretGeneratorConfigWriteModel(generatorType)
|
||||
func (c *Commands) getSecretConfig(ctx context.Context, generatorType domain.SecretGeneratorType) (_ *InstanceSecretGeneratorConfigWriteModel, err error) {
|
||||
writeModel := NewInstanceSecretGeneratorConfigWriteModel(generatorType)
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
+33
-33
@@ -12,7 +12,7 @@ import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func TestCommandSide_AddSecretGenerator(t *testing.T) {
|
||||
@@ -57,8 +57,8 @@ func TestCommandSide_AddSecretGenerator(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewSecretGeneratorAddedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewSecretGeneratorAddedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode,
|
||||
4,
|
||||
time.Hour*1,
|
||||
@@ -95,9 +95,9 @@ func TestCommandSide_AddSecretGenerator(t *testing.T) {
|
||||
expectFilter(),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(iam.NewSecretGeneratorAddedEvent(
|
||||
eventFromEventPusher(instance.NewSecretGeneratorAddedEvent(
|
||||
context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode,
|
||||
4,
|
||||
time.Hour*1,
|
||||
@@ -108,7 +108,7 @@ func TestCommandSide_AddSecretGenerator(t *testing.T) {
|
||||
),
|
||||
),
|
||||
},
|
||||
uniqueConstraintsFromEventConstraint(iam.NewAddSecretGeneratorTypeUniqueConstraint(domain.SecretGeneratorTypeInitCode)),
|
||||
uniqueConstraintsFromEventConstraint(instance.NewAddSecretGeneratorTypeUniqueConstraint(domain.SecretGeneratorTypeInitCode)),
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -208,9 +208,9 @@ func TestCommandSide_ChangeSecretGenerator(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewSecretGeneratorAddedEvent(
|
||||
instance.NewSecretGeneratorAddedEvent(
|
||||
context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode,
|
||||
4,
|
||||
time.Hour*1,
|
||||
@@ -221,8 +221,8 @@ func TestCommandSide_ChangeSecretGenerator(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewSecretGeneratorRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewSecretGeneratorRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode),
|
||||
),
|
||||
),
|
||||
@@ -243,9 +243,9 @@ func TestCommandSide_ChangeSecretGenerator(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewSecretGeneratorAddedEvent(
|
||||
instance.NewSecretGeneratorAddedEvent(
|
||||
context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode,
|
||||
4,
|
||||
time.Hour*1,
|
||||
@@ -281,9 +281,9 @@ func TestCommandSide_ChangeSecretGenerator(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewSecretGeneratorAddedEvent(
|
||||
instance.NewSecretGeneratorAddedEvent(
|
||||
context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode,
|
||||
4,
|
||||
time.Hour*1,
|
||||
@@ -404,9 +404,9 @@ func TestCommandSide_RemoveSecretGenerator(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewSecretGeneratorAddedEvent(
|
||||
instance.NewSecretGeneratorAddedEvent(
|
||||
context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode,
|
||||
4,
|
||||
time.Hour*1,
|
||||
@@ -417,8 +417,8 @@ func TestCommandSide_RemoveSecretGenerator(t *testing.T) {
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
iam.NewSecretGeneratorRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewSecretGeneratorRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode),
|
||||
),
|
||||
),
|
||||
@@ -439,9 +439,9 @@ func TestCommandSide_RemoveSecretGenerator(t *testing.T) {
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
iam.NewSecretGeneratorAddedEvent(
|
||||
instance.NewSecretGeneratorAddedEvent(
|
||||
context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode,
|
||||
4,
|
||||
time.Hour*1,
|
||||
@@ -455,12 +455,12 @@ func TestCommandSide_RemoveSecretGenerator(t *testing.T) {
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
iam.NewSecretGeneratorRemovedEvent(context.Background(),
|
||||
&iam.NewAggregate().Aggregate,
|
||||
instance.NewSecretGeneratorRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate().Aggregate,
|
||||
domain.SecretGeneratorTypeInitCode),
|
||||
),
|
||||
},
|
||||
uniqueConstraintsFromEventConstraint(iam.NewRemoveSecretGeneratorTypeUniqueConstraint(domain.SecretGeneratorTypeInitCode)),
|
||||
uniqueConstraintsFromEventConstraint(instance.NewRemoveSecretGeneratorTypeUniqueConstraint(domain.SecretGeneratorTypeInitCode)),
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -494,17 +494,17 @@ func TestCommandSide_RemoveSecretGenerator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newSecretGeneratorChangedEvent(ctx context.Context, generatorType domain.SecretGeneratorType, length uint, expiry time.Duration, lowerCase, upperCase, digits, symbols bool) *iam.SecretGeneratorChangedEvent {
|
||||
changes := []iam.SecretGeneratorChanges{
|
||||
iam.ChangeSecretGeneratorLength(length),
|
||||
iam.ChangeSecretGeneratorExpiry(expiry),
|
||||
iam.ChangeSecretGeneratorIncludeLowerLetters(lowerCase),
|
||||
iam.ChangeSecretGeneratorIncludeUpperLetters(upperCase),
|
||||
iam.ChangeSecretGeneratorIncludeDigits(digits),
|
||||
iam.ChangeSecretGeneratorIncludeSymbols(symbols),
|
||||
func newSecretGeneratorChangedEvent(ctx context.Context, generatorType domain.SecretGeneratorType, length uint, expiry time.Duration, lowerCase, upperCase, digits, symbols bool) *instance.SecretGeneratorChangedEvent {
|
||||
changes := []instance.SecretGeneratorChanges{
|
||||
instance.ChangeSecretGeneratorLength(length),
|
||||
instance.ChangeSecretGeneratorExpiry(expiry),
|
||||
instance.ChangeSecretGeneratorIncludeLowerLetters(lowerCase),
|
||||
instance.ChangeSecretGeneratorIncludeUpperLetters(upperCase),
|
||||
instance.ChangeSecretGeneratorIncludeDigits(digits),
|
||||
instance.ChangeSecretGeneratorIncludeSymbols(symbols),
|
||||
}
|
||||
event, _ := iam.NewSecretGeneratorChangeEvent(ctx,
|
||||
&iam.NewAggregate().Aggregate,
|
||||
event, _ := instance.NewSecretGeneratorChangeEvent(ctx,
|
||||
&instance.NewAggregate().Aggregate,
|
||||
generatorType,
|
||||
changes,
|
||||
)
|
||||
+20
-20
@@ -6,10 +6,10 @@ import (
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type IAMSMTPConfigWriteModel struct {
|
||||
type InstanceSMTPConfigWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
SenderAddress string
|
||||
@@ -21,8 +21,8 @@ type IAMSMTPConfigWriteModel struct {
|
||||
State domain.SMTPConfigState
|
||||
}
|
||||
|
||||
func NewIAMSMTPConfigWriteModel() *IAMSMTPConfigWriteModel {
|
||||
return &IAMSMTPConfigWriteModel{
|
||||
func NewInstanceSMTPConfigWriteModel() *InstanceSMTPConfigWriteModel {
|
||||
return &InstanceSMTPConfigWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: domain.IAMID,
|
||||
ResourceOwner: domain.IAMID,
|
||||
@@ -30,10 +30,10 @@ func NewIAMSMTPConfigWriteModel() *IAMSMTPConfigWriteModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *IAMSMTPConfigWriteModel) Reduce() error {
|
||||
func (wm *InstanceSMTPConfigWriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
switch e := event.(type) {
|
||||
case *iam.SMTPConfigAddedEvent:
|
||||
case *instance.SMTPConfigAddedEvent:
|
||||
wm.TLS = e.TLS
|
||||
wm.SenderAddress = e.SenderAddress
|
||||
wm.SenderName = e.SenderName
|
||||
@@ -41,7 +41,7 @@ func (wm *IAMSMTPConfigWriteModel) Reduce() error {
|
||||
wm.User = e.User
|
||||
wm.Password = e.Password
|
||||
wm.State = domain.SMTPConfigStateActive
|
||||
case *iam.SMTPConfigChangedEvent:
|
||||
case *instance.SMTPConfigChangedEvent:
|
||||
if e.TLS != nil {
|
||||
wm.TLS = *e.TLS
|
||||
}
|
||||
@@ -62,43 +62,43 @@ func (wm *IAMSMTPConfigWriteModel) Reduce() error {
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *IAMSMTPConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
func (wm *InstanceSMTPConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateTypes(iam.AggregateType).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
EventTypes(
|
||||
iam.SMTPConfigAddedEventType,
|
||||
iam.SMTPConfigChangedEventType,
|
||||
iam.SMTPConfigPasswordChangedEventType).
|
||||
instance.SMTPConfigAddedEventType,
|
||||
instance.SMTPConfigChangedEventType,
|
||||
instance.SMTPConfigPasswordChangedEventType).
|
||||
Builder()
|
||||
}
|
||||
|
||||
func (wm *IAMSMTPConfigWriteModel) NewChangedEvent(ctx context.Context, aggregate *eventstore.Aggregate, tls bool, fromAddress, fromName, smtpHost, smtpUser string) (*iam.SMTPConfigChangedEvent, bool, error) {
|
||||
changes := make([]iam.SMTPConfigChanges, 0)
|
||||
func (wm *InstanceSMTPConfigWriteModel) NewChangedEvent(ctx context.Context, aggregate *eventstore.Aggregate, tls bool, fromAddress, fromName, smtpHost, smtpUser string) (*instance.SMTPConfigChangedEvent, bool, error) {
|
||||
changes := make([]instance.SMTPConfigChanges, 0)
|
||||
var err error
|
||||
|
||||
if wm.TLS != tls {
|
||||
changes = append(changes, iam.ChangeSMTPConfigTLS(tls))
|
||||
changes = append(changes, instance.ChangeSMTPConfigTLS(tls))
|
||||
}
|
||||
if wm.SenderAddress != fromAddress {
|
||||
changes = append(changes, iam.ChangeSMTPConfigFromAddress(fromAddress))
|
||||
changes = append(changes, instance.ChangeSMTPConfigFromAddress(fromAddress))
|
||||
}
|
||||
if wm.SenderName != fromName {
|
||||
changes = append(changes, iam.ChangeSMTPConfigFromName(fromName))
|
||||
changes = append(changes, instance.ChangeSMTPConfigFromName(fromName))
|
||||
}
|
||||
if wm.Host != smtpHost {
|
||||
changes = append(changes, iam.ChangeSMTPConfigSMTPHost(smtpHost))
|
||||
changes = append(changes, instance.ChangeSMTPConfigSMTPHost(smtpHost))
|
||||
}
|
||||
if wm.User != smtpUser {
|
||||
changes = append(changes, iam.ChangeSMTPConfigSMTPUser(smtpUser))
|
||||
changes = append(changes, instance.ChangeSMTPConfigSMTPUser(smtpUser))
|
||||
}
|
||||
|
||||
if len(changes) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
changeEvent, err := iam.NewSMTPConfigChangeEvent(ctx, aggregate, changes)
|
||||
changeEvent, err := instance.NewSMTPConfigChangeEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository/mock"
|
||||
action_repo "github.com/caos/zitadel/internal/repository/action"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/iam"
|
||||
iam_repo "github.com/caos/zitadel/internal/repository/instance"
|
||||
key_repo "github.com/caos/zitadel/internal/repository/keypair"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
proj_repo "github.com/caos/zitadel/internal/repository/project"
|
||||
|
||||
@@ -33,9 +33,9 @@ func (c *Commands) checkOrgExists(ctx context.Context, orgID string) error {
|
||||
}
|
||||
|
||||
func (c *Commands) SetUpOrg(ctx context.Context, organisation *domain.Org, admin *domain.Human, initCodeGenerator crypto.Generator, phoneCodeGenerator crypto.Generator, claimedUserIDs []string, selfregistered bool) (*domain.ObjectDetails, error) {
|
||||
orgIAMPolicy, err := c.getDefaultOrgIAMPolicy(ctx)
|
||||
orgIAMPolicy, err := c.getDefaultDomainPolicy(ctx)
|
||||
if err != nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(err, "COMMAND-33M9f", "Errors.IAM.OrgIAMPolicy.NotFound")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(err, "COMMAND-33M9f", "Errors.IAM.DomainPolicy.NotFound")
|
||||
}
|
||||
pwPolicy, err := c.getDefaultPasswordComplexityPolicy(ctx)
|
||||
if err != nil {
|
||||
@@ -167,7 +167,7 @@ func (c *Commands) setUpOrg(
|
||||
ctx context.Context,
|
||||
organisation *domain.Org,
|
||||
admin *domain.Human,
|
||||
loginPolicy *domain.OrgIAMPolicy,
|
||||
loginPolicy *domain.DomainPolicy,
|
||||
pwPolicy *domain.PasswordComplexityPolicy,
|
||||
initCodeGenerator crypto.Generator,
|
||||
phoneCodeGenerator crypto.Generator,
|
||||
|
||||
@@ -13,9 +13,9 @@ func orgWriteModelToOrg(wm *OrgWriteModel) *domain.Org {
|
||||
}
|
||||
}
|
||||
|
||||
func orgWriteModelToOrgIAMPolicy(wm *ORGOrgIAMPolicyWriteModel) *domain.OrgIAMPolicy {
|
||||
return &domain.OrgIAMPolicy{
|
||||
ObjectRoot: writeModelToObjectRoot(wm.PolicyOrgIAMWriteModel.WriteModel),
|
||||
func orgWriteModelToDomainPolicy(wm *OrgDomainPolicyWriteModel) *domain.DomainPolicy {
|
||||
return &domain.DomainPolicy{
|
||||
ObjectRoot: writeModelToObjectRoot(wm.PolicyDomainWriteModel.WriteModel),
|
||||
UserLoginMustBeDomain: wm.UserLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user