2021-01-06 10:47:55 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-01-12 12:59:51 +01:00
|
|
|
"github.com/caos/logging"
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2021-01-12 12:59:51 +01:00
|
|
|
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2021-01-06 10:47:55 +01:00
|
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Step5 struct {
|
|
|
|
DefaultOrgIAMPolicy iam_model.OrgIAMPolicy
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Step5) Step() domain.Step {
|
|
|
|
return domain.Step5
|
|
|
|
}
|
|
|
|
|
2021-02-24 11:17:39 +01:00
|
|
|
func (s *Step5) execute(ctx context.Context, commandSide *Commands) error {
|
2021-01-06 10:47:55 +01:00
|
|
|
return commandSide.SetupStep5(ctx, s)
|
|
|
|
}
|
|
|
|
|
2021-02-24 11:17:39 +01:00
|
|
|
func (c *Commands) SetupStep5(ctx context.Context, step *Step5) error {
|
2021-02-18 14:48:27 +01:00
|
|
|
fn := func(iam *IAMWriteModel) ([]eventstore.EventPusher, error) {
|
2021-01-06 10:47:55 +01:00
|
|
|
iamAgg := IAMAggregateFromWriteModel(&iam.WriteModel)
|
2021-02-24 11:17:39 +01:00
|
|
|
event, err := c.addDefaultOrgIAMPolicy(ctx, iamAgg, NewIAMOrgIAMPolicyWriteModel(), &domain.OrgIAMPolicy{
|
2021-01-06 10:47:55 +01:00
|
|
|
UserLoginMustBeDomain: step.DefaultOrgIAMPolicy.UserLoginMustBeDomain,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-12 12:59:51 +01:00
|
|
|
logging.Log("SETUP-ADgd2").Info("default org iam policy set up")
|
2021-02-18 14:48:27 +01:00
|
|
|
return []eventstore.EventPusher{event}, nil
|
2021-01-06 10:47:55 +01:00
|
|
|
}
|
2021-02-24 11:17:39 +01:00
|
|
|
return c.setup(ctx, step, fn)
|
2021-01-06 10:47:55 +01:00
|
|
|
}
|