mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-06 19:08:49 +00:00
feat: org and policies commands (#1167)
* add setup steps * refactoring * omitempty * cleanup * begin org * create org * setup org * setup org * merge * fixes * fixes * fixes * add project * add oidc application * fix app creation * add resourceOwner to writemodels * resource owner * cleanup * global org, iam project and iam member in setup * logs * logs * logs * cleanup * Update internal/v2/command/project.go Co-authored-by: Fabi <[email protected]> * check project state * add org domain commands * add org status changes and member commands * fixes * policies * login policy * fix iam project event * mapper * label policy * change to command * fix * fix * handle change event differently and lot of fixes * fixes * changedEvent handling Co-authored-by: Fabi <[email protected]>
This commit is contained in:
@@ -63,10 +63,32 @@ func (e *LabelPolicyChangedEvent) Data() interface{} {
|
||||
|
||||
func NewLabelPolicyChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *LabelPolicyChangedEvent {
|
||||
return &LabelPolicyChangedEvent{
|
||||
changes []LabelPolicyChanges,
|
||||
) (*LabelPolicyChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "POLICY-Asfd3", "Errors.NoChangesFound")
|
||||
}
|
||||
changeEvent := &LabelPolicyChangedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changeEvent)
|
||||
}
|
||||
return changeEvent, nil
|
||||
}
|
||||
|
||||
type LabelPolicyChanges func(*LabelPolicyChangedEvent)
|
||||
|
||||
func ChangePrimaryColor(primaryColor string) func(*LabelPolicyChangedEvent) {
|
||||
return func(e *LabelPolicyChangedEvent) {
|
||||
e.PrimaryColor = &primaryColor
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeSecondaryColor(secondaryColor string) func(*LabelPolicyChangedEvent) {
|
||||
return func(e *LabelPolicyChangedEvent) {
|
||||
e.SecondaryColor = &secondaryColor
|
||||
}
|
||||
}
|
||||
|
||||
func LabelPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
@@ -90,13 +112,13 @@ func (e *LabelPolicyRemovedEvent) Data() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewRemovedEvent(base *eventstore.BaseEvent) *LabelPolicyRemovedEvent {
|
||||
func NewLabelPolicyRemovedEvent(base *eventstore.BaseEvent) *LabelPolicyRemovedEvent {
|
||||
return &LabelPolicyRemovedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
}
|
||||
|
||||
func RemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
func LabelPolicyRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
return &LabelPolicyRemovedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}, nil
|
||||
|
||||
@@ -79,10 +79,50 @@ func (e *LoginPolicyChangedEvent) Data() interface{} {
|
||||
|
||||
func NewLoginPolicyChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *LoginPolicyChangedEvent {
|
||||
return &LoginPolicyChangedEvent{
|
||||
changes []LoginPolicyChanges,
|
||||
) (*LoginPolicyChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "POLICY-ADg34", "Errors.NoChangesFound")
|
||||
}
|
||||
changeEvent := &LoginPolicyChangedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changeEvent)
|
||||
}
|
||||
return changeEvent, nil
|
||||
}
|
||||
|
||||
type LoginPolicyChanges func(*LoginPolicyChangedEvent)
|
||||
|
||||
func ChangeAllowUserNamePassword(allowUserNamePassword bool) func(*LoginPolicyChangedEvent) {
|
||||
return func(e *LoginPolicyChangedEvent) {
|
||||
e.AllowUserNamePassword = &allowUserNamePassword
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeAllowRegister(allowRegister bool) func(*LoginPolicyChangedEvent) {
|
||||
return func(e *LoginPolicyChangedEvent) {
|
||||
e.AllowRegister = &allowRegister
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeAllowExternalIDP(allowExternalIDP bool) func(*LoginPolicyChangedEvent) {
|
||||
return func(e *LoginPolicyChangedEvent) {
|
||||
e.AllowExternalIDP = &allowExternalIDP
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeForceMFA(forceMFA bool) func(*LoginPolicyChangedEvent) {
|
||||
return func(e *LoginPolicyChangedEvent) {
|
||||
e.ForceMFA = &forceMFA
|
||||
}
|
||||
}
|
||||
|
||||
func ChangePasswordlessType(passwordlessType domain.PasswordlessType) func(*LoginPolicyChangedEvent) {
|
||||
return func(e *LoginPolicyChangedEvent) {
|
||||
e.PasswordlessType = &passwordlessType
|
||||
}
|
||||
}
|
||||
|
||||
func LoginPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package policy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
@@ -59,10 +60,26 @@ func (e *OrgIAMPolicyChangedEvent) Data() interface{} {
|
||||
|
||||
func NewOrgIAMPolicyChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *OrgIAMPolicyChangedEvent {
|
||||
return &OrgIAMPolicyChangedEvent{
|
||||
changes []OrgIAMPolicyChanges,
|
||||
) (*OrgIAMPolicyChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "POLICY-DAf3h", "Errors.NoChangesFound")
|
||||
}
|
||||
changeEvent := &OrgIAMPolicyChangedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changeEvent)
|
||||
}
|
||||
return changeEvent, nil
|
||||
}
|
||||
|
||||
type OrgIAMPolicyChanges func(*OrgIAMPolicyChangedEvent)
|
||||
|
||||
func ChangeUserLoginMustBeDomain(userLoginMustBeDomain bool) func(*OrgIAMPolicyChangedEvent) {
|
||||
return func(e *OrgIAMPolicyChangedEvent) {
|
||||
e.UserLoginMustBeDomain = &userLoginMustBeDomain
|
||||
}
|
||||
}
|
||||
|
||||
func OrgIAMPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
@@ -77,3 +94,23 @@ func OrgIAMPolicyChangedEventMapper(event *repository.Event) (eventstore.EventRe
|
||||
|
||||
return e, nil
|
||||
}
|
||||
|
||||
type OrgIAMPolicyRemovedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
}
|
||||
|
||||
func (e *OrgIAMPolicyRemovedEvent) Data() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewOrgIAMPolicyRemovedEvent(base *eventstore.BaseEvent) *OrgIAMPolicyRemovedEvent {
|
||||
return &OrgIAMPolicyRemovedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
}
|
||||
|
||||
func OrgIAMPolicyRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
return &OrgIAMPolicyRemovedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -63,10 +63,32 @@ func (e *PasswordAgePolicyChangedEvent) Data() interface{} {
|
||||
|
||||
func NewPasswordAgePolicyChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *PasswordAgePolicyChangedEvent {
|
||||
return &PasswordAgePolicyChangedEvent{
|
||||
changes []PasswordAgePolicyChanges,
|
||||
) (*PasswordAgePolicyChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "POLICY-DAgt5", "Errors.NoChangesFound")
|
||||
}
|
||||
changeEvent := &PasswordAgePolicyChangedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changeEvent)
|
||||
}
|
||||
return changeEvent, nil
|
||||
}
|
||||
|
||||
type PasswordAgePolicyChanges func(*PasswordAgePolicyChangedEvent)
|
||||
|
||||
func ChangeExpireWarnDays(expireWarnDay uint64) func(*PasswordAgePolicyChangedEvent) {
|
||||
return func(e *PasswordAgePolicyChangedEvent) {
|
||||
e.ExpireWarnDays = &expireWarnDay
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeMaxAgeDays(maxAgeDays uint64) func(*PasswordAgePolicyChangedEvent) {
|
||||
return func(e *PasswordAgePolicyChangedEvent) {
|
||||
e.MaxAgeDays = &maxAgeDays
|
||||
}
|
||||
}
|
||||
|
||||
func PasswordAgePolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
@@ -90,23 +112,14 @@ func (e *PasswordAgePolicyRemovedEvent) Data() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewPasswordAgePolicyRemovedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *PasswordAgePolicyRemovedEvent {
|
||||
func NewPasswordAgePolicyRemovedEvent(base *eventstore.BaseEvent) *PasswordAgePolicyRemovedEvent {
|
||||
return &PasswordAgePolicyRemovedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
}
|
||||
|
||||
func PasswordAgePolicyRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e := &PasswordAgePolicyRemovedEvent{
|
||||
return &PasswordAgePolicyRemovedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "POLIC-02878", "unable to unmarshal policy")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package policy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
@@ -18,7 +19,7 @@ type PasswordComplexityPolicyAddedEvent struct {
|
||||
|
||||
MinLength uint64 `json:"minLength,omitempty"`
|
||||
HasLowercase bool `json:"hasLowercase,omitempty"`
|
||||
HasUpperCase bool `json:"hasUppercase,omitempty"`
|
||||
HasUppercase bool `json:"hasUppercase,omitempty"`
|
||||
HasNumber bool `json:"hasNumber,omitempty"`
|
||||
HasSymbol bool `json:"hasSymbol,omitempty"`
|
||||
}
|
||||
@@ -39,9 +40,9 @@ func NewPasswordComplexityPolicyAddedEvent(
|
||||
BaseEvent: *base,
|
||||
MinLength: minLength,
|
||||
HasLowercase: hasLowerCase,
|
||||
HasUppercase: hasUpperCase,
|
||||
HasNumber: hasNumber,
|
||||
HasSymbol: hasSymbol,
|
||||
HasUpperCase: hasUpperCase,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +64,7 @@ type PasswordComplexityPolicyChangedEvent struct {
|
||||
|
||||
MinLength *uint64 `json:"minLength,omitempty"`
|
||||
HasLowercase *bool `json:"hasLowercase,omitempty"`
|
||||
HasUpperCase *bool `json:"hasUppercase,omitempty"`
|
||||
HasUppercase *bool `json:"hasUppercase,omitempty"`
|
||||
HasNumber *bool `json:"hasNumber,omitempty"`
|
||||
HasSymbol *bool `json:"hasSymbol,omitempty"`
|
||||
}
|
||||
@@ -74,10 +75,50 @@ func (e *PasswordComplexityPolicyChangedEvent) Data() interface{} {
|
||||
|
||||
func NewPasswordComplexityPolicyChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *PasswordComplexityPolicyChangedEvent {
|
||||
return &PasswordComplexityPolicyChangedEvent{
|
||||
changes []PasswordComplexityPolicyChanges,
|
||||
) (*PasswordComplexityPolicyChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "POLICY-Rdhu3", "Errors.NoChangesFound")
|
||||
}
|
||||
changeEvent := &PasswordComplexityPolicyChangedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changeEvent)
|
||||
}
|
||||
return changeEvent, nil
|
||||
}
|
||||
|
||||
type PasswordComplexityPolicyChanges func(*PasswordComplexityPolicyChangedEvent)
|
||||
|
||||
func ChangeMinLength(minLength uint64) func(*PasswordComplexityPolicyChangedEvent) {
|
||||
return func(e *PasswordComplexityPolicyChangedEvent) {
|
||||
e.MinLength = &minLength
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeHasLowercase(hasLowercase bool) func(*PasswordComplexityPolicyChangedEvent) {
|
||||
return func(e *PasswordComplexityPolicyChangedEvent) {
|
||||
e.HasLowercase = &hasLowercase
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeHasUppercase(hasUppercase bool) func(*PasswordComplexityPolicyChangedEvent) {
|
||||
return func(e *PasswordComplexityPolicyChangedEvent) {
|
||||
e.HasUppercase = &hasUppercase
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeHasNumber(hasNumber bool) func(*PasswordComplexityPolicyChangedEvent) {
|
||||
return func(e *PasswordComplexityPolicyChangedEvent) {
|
||||
e.HasNumber = &hasNumber
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeHasSymbol(hasSymbol bool) func(*PasswordComplexityPolicyChangedEvent) {
|
||||
return func(e *PasswordComplexityPolicyChangedEvent) {
|
||||
e.HasSymbol = &hasSymbol
|
||||
}
|
||||
}
|
||||
|
||||
func PasswordComplexityPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package policy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
@@ -63,10 +64,32 @@ func (e *PasswordLockoutPolicyChangedEvent) Data() interface{} {
|
||||
|
||||
func NewPasswordLockoutPolicyChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *PasswordLockoutPolicyChangedEvent {
|
||||
return &PasswordLockoutPolicyChangedEvent{
|
||||
changes []PasswordLockoutPolicyChanges,
|
||||
) (*PasswordLockoutPolicyChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "POLICY-sdgh6", "Errors.NoChangesFound")
|
||||
}
|
||||
changeEvent := &PasswordLockoutPolicyChangedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changeEvent)
|
||||
}
|
||||
return changeEvent, nil
|
||||
}
|
||||
|
||||
type PasswordLockoutPolicyChanges func(*PasswordLockoutPolicyChangedEvent)
|
||||
|
||||
func ChangeMaxAttempts(maxAttempts uint64) func(*PasswordLockoutPolicyChangedEvent) {
|
||||
return func(e *PasswordLockoutPolicyChangedEvent) {
|
||||
e.MaxAttempts = &maxAttempts
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeShowLockOutFailures(showLockOutFailures bool) func(*PasswordLockoutPolicyChangedEvent) {
|
||||
return func(e *PasswordLockoutPolicyChangedEvent) {
|
||||
e.ShowLockOutFailures = &showLockOutFailures
|
||||
}
|
||||
}
|
||||
|
||||
func PasswordLockoutPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
@@ -90,10 +113,7 @@ func (e *PasswordLockoutPolicyRemovedEvent) Data() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewPasswordLockoutPolicyRemovedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
) *PasswordLockoutPolicyRemovedEvent {
|
||||
|
||||
func NewPasswordLockoutPolicyRemovedEvent(base *eventstore.BaseEvent) *PasswordLockoutPolicyRemovedEvent {
|
||||
return &PasswordLockoutPolicyRemovedEvent{
|
||||
BaseEvent: *base,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user