mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-19 11:45:12 +00:00
feat: setup (#1166)
* 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 Co-authored-by: Fabi <[email protected]>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package project
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
AggregateType = "project"
|
||||
AggregateVersion = "v1"
|
||||
)
|
||||
|
||||
type Aggregate struct {
|
||||
eventstore.Aggregate
|
||||
}
|
||||
|
||||
func NewAggregate(
|
||||
id,
|
||||
resourceOwner string,
|
||||
previousSequence uint64,
|
||||
) *Aggregate {
|
||||
|
||||
return &Aggregate{
|
||||
Aggregate: *eventstore.NewAggregate(
|
||||
id,
|
||||
AggregateType,
|
||||
resourceOwner,
|
||||
AggregateVersion,
|
||||
previousSequence,
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package project
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
"github.com/caos/zitadel/internal/v2/domain"
|
||||
)
|
||||
|
||||
const (
|
||||
applicationEventTypePrefix = projectEventTypePrefix + "application."
|
||||
ApplicationAdded = applicationEventTypePrefix + "added"
|
||||
ApplicationChanged = applicationEventTypePrefix + "changed"
|
||||
ApplicationDeactivated = applicationEventTypePrefix + "deactivated"
|
||||
ApplicationReactivated = applicationEventTypePrefix + "reactivated"
|
||||
ApplicationRemoved = applicationEventTypePrefix + "removed"
|
||||
)
|
||||
|
||||
type ApplicationAddedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
AppID string `json:"appId,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
AppType domain.AppType `json:"appType,omitempty"`
|
||||
}
|
||||
|
||||
func (e *ApplicationAddedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func NewApplicationAddedEvent(ctx context.Context, appID, name string, appType domain.AppType) *ApplicationAddedEvent {
|
||||
return &ApplicationAddedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
ApplicationAdded,
|
||||
),
|
||||
AppID: appID,
|
||||
Name: name,
|
||||
AppType: appType,
|
||||
}
|
||||
}
|
||||
|
||||
func ApplicationAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e := &ApplicationAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "APPLICATION-Nffg2", "unable to unmarshal application")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package project
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/v2/repository/member"
|
||||
)
|
||||
|
||||
var (
|
||||
MemberAddedEventType = projectEventTypePrefix + member.AddedEventType
|
||||
MemberChangedEventType = projectEventTypePrefix + member.ChangedEventType
|
||||
MemberRemovedEventType = projectEventTypePrefix + member.RemovedEventType
|
||||
)
|
||||
|
||||
type MemberAddedEvent struct {
|
||||
member.MemberAddedEvent
|
||||
}
|
||||
|
||||
func NewMemberAddedEvent(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
roles ...string,
|
||||
) *MemberAddedEvent {
|
||||
return &MemberAddedEvent{
|
||||
MemberAddedEvent: *member.NewMemberAddedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
MemberAddedEventType,
|
||||
),
|
||||
userID,
|
||||
roles...,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
type MemberChangedEvent struct {
|
||||
member.MemberChangedEvent
|
||||
}
|
||||
|
||||
func NewMemberChangedEvent(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
roles ...string,
|
||||
) *MemberChangedEvent {
|
||||
|
||||
return &MemberChangedEvent{
|
||||
MemberChangedEvent: *member.NewMemberChangedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
MemberChangedEventType,
|
||||
),
|
||||
userID,
|
||||
roles...,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
type MemberRemovedEvent struct {
|
||||
member.MemberRemovedEvent
|
||||
}
|
||||
|
||||
func NewMemberRemovedEvent(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
) *MemberRemovedEvent {
|
||||
|
||||
return &MemberRemovedEvent{
|
||||
MemberRemovedEvent: *member.NewRemovedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
MemberRemovedEventType,
|
||||
),
|
||||
userID,
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package project
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
"github.com/caos/zitadel/internal/v2/domain"
|
||||
)
|
||||
|
||||
const (
|
||||
OIDCConfigAdded = applicationEventTypePrefix + "config.oidc.added"
|
||||
OIDCConfigChanged = applicationEventTypePrefix + "config.oidc.changed"
|
||||
OIDCConfigSecretChanged = applicationEventTypePrefix + "config.oidc.secret.changed"
|
||||
OIDCClientSecretCheckSucceeded = applicationEventTypePrefix + "oidc.secret.check.succeeded"
|
||||
OIDCClientSecretCheckFailed = applicationEventTypePrefix + "oidc.secret.check.failed"
|
||||
)
|
||||
|
||||
type OIDCConfigAddedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
Version domain.OIDCVersion `json:"oidcVersion,omitempty"`
|
||||
AppID string `json:"appId"`
|
||||
ClientID string `json:"clientId,omitempty"`
|
||||
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
||||
RedirectUris []string `json:"redirectUris,omitempty"`
|
||||
ResponseTypes []domain.OIDCResponseType `json:"responseTypes,omitempty"`
|
||||
GrantTypes []domain.OIDCGrantType `json:"grantTypes,omitempty"`
|
||||
ApplicationType domain.OIDCApplicationType `json:"applicationType,omitempty"`
|
||||
AuthMethodType domain.OIDCAuthMethodType `json:"authMethodType,omitempty"`
|
||||
PostLogoutRedirectUris []string `json:"postLogoutRedirectUris,omitempty"`
|
||||
DevMode bool `json:"devMode,omitempty"`
|
||||
AccessTokenType domain.OIDCTokenType `json:"accessTokenType,omitempty"`
|
||||
AccessTokenRoleAssertion bool `json:"accessTokenRoleAssertion,omitempty"`
|
||||
IDTokenRoleAssertion bool `json:"idTokenRoleAssertion,omitempty"`
|
||||
IDTokenUserinfoAssertion bool `json:"idTokenUserinfoAssertion,omitempty"`
|
||||
ClockSkew time.Duration `json:"clockSkew,omitempty"`
|
||||
}
|
||||
|
||||
func (e *OIDCConfigAddedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func NewOIDCConfigAddedEvent(
|
||||
ctx context.Context,
|
||||
version domain.OIDCVersion,
|
||||
appID string,
|
||||
clientID string,
|
||||
clientSecret *crypto.CryptoValue,
|
||||
redirectUris []string,
|
||||
responseTypes []domain.OIDCResponseType,
|
||||
grantTypes []domain.OIDCGrantType,
|
||||
applicationType domain.OIDCApplicationType,
|
||||
authMethodType domain.OIDCAuthMethodType,
|
||||
postLogoutRedirectUris []string,
|
||||
devMode bool,
|
||||
accessTokenType domain.OIDCTokenType,
|
||||
accessTokenRoleAssertion bool,
|
||||
idTokenRoleAssertion bool,
|
||||
idTokenUserinfoAssertion bool,
|
||||
clockSkew time.Duration,
|
||||
) *OIDCConfigAddedEvent {
|
||||
return &OIDCConfigAddedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
OIDCConfigAdded,
|
||||
),
|
||||
Version: version,
|
||||
AppID: appID,
|
||||
ClientID: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
RedirectUris: redirectUris,
|
||||
ResponseTypes: responseTypes,
|
||||
GrantTypes: grantTypes,
|
||||
ApplicationType: applicationType,
|
||||
AuthMethodType: authMethodType,
|
||||
PostLogoutRedirectUris: postLogoutRedirectUris,
|
||||
DevMode: devMode,
|
||||
AccessTokenType: accessTokenType,
|
||||
AccessTokenRoleAssertion: accessTokenRoleAssertion,
|
||||
IDTokenRoleAssertion: idTokenRoleAssertion,
|
||||
IDTokenUserinfoAssertion: idTokenUserinfoAssertion,
|
||||
ClockSkew: clockSkew,
|
||||
}
|
||||
}
|
||||
|
||||
func OIDCConfigAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e := &OIDCConfigAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "OIDC-BFd15", "unable to unmarshal oidc config")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package project
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
projectEventTypePrefix = eventstore.EventType("project.")
|
||||
ProjectAdded = projectEventTypePrefix + "added"
|
||||
ProjectChanged = projectEventTypePrefix + "changed"
|
||||
ProjectDeactivated = projectEventTypePrefix + "deactivated"
|
||||
ProjectReactivated = projectEventTypePrefix + "reactivated"
|
||||
ProjectRemoved = projectEventTypePrefix + "removed"
|
||||
)
|
||||
|
||||
type ProjectAddedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
Name string `json:"name,omitempty"`
|
||||
ProjectRoleAssertion bool `json:"projectRoleAssertion,omitempty"`
|
||||
ProjectRoleCheck bool `json:"projectRoleCheck,omitempty"`
|
||||
}
|
||||
|
||||
func (e *ProjectAddedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func NewProjectAddedEvent(ctx context.Context, name string) *ProjectAddedEvent {
|
||||
return &ProjectAddedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
ProjectAdded,
|
||||
),
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e := &ProjectAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "PROJECT-Bfg2f", "unable to unmarshal project")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
Reference in New Issue
Block a user