mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 07:58:08 +00:00
.codecov
.devcontainer
.github
build
cmd
console
deploy
docs
e2e
internal
actions
activity
admin
api
auth
auth_request
authz
command
config
crypto
database
domain
eventstore
execution
feature
form
i18n
iam
id
idp
integration
logstore
migration
net
notification
org
project
protoc
qrcode
query
renderer
repository
action
asset
authrequest
deviceauth
execution
feature
flow
idp
idpconfig
idpintent
instance
keypair
limits
member
metadata
milestone
oidcsession
org
policy
project
aggregate.go
api_config.go
application.go
eventstore.go
grant.go
grant_member.go
key.go
member.go
oidc_config.go
project.go
role.go
saml_config.go
pseudo
quota
restrictions
session
settings
target
user
usergrant
webkey
static
statik
telemetry
test
user
v2
view
webauthn
zerrors
load-test
openapi
pkg
proto
statik
.dockerignore
.gitattributes
.gitignore
.golangci.yaml
.releaserc.js
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
MEETING_SCHEDULE.md
Makefile
README.md
SECURITY.md
buf.gen.yaml
buf.work.yaml
changelog.config.js
go.mod
go.sum
main.go
release-channels.yaml

* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
162 lines
4.0 KiB
Go
162 lines
4.0 KiB
Go
package project
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
const (
|
|
UniqueEntityIDType = "entity_ids"
|
|
SAMLConfigAddedType = applicationEventTypePrefix + "config.saml.added"
|
|
SAMLConfigChangedType = applicationEventTypePrefix + "config.saml.changed"
|
|
)
|
|
|
|
type SAMLConfigAddedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
AppID string `json:"appId"`
|
|
EntityID string `json:"entityId"`
|
|
Metadata []byte `json:"metadata,omitempty"`
|
|
MetadataURL string `json:"metadata_url,omitempty"`
|
|
}
|
|
|
|
func (e *SAMLConfigAddedEvent) Payload() interface{} {
|
|
return e
|
|
}
|
|
|
|
func NewAddSAMLConfigEntityIDUniqueConstraint(entityID string) *eventstore.UniqueConstraint {
|
|
return eventstore.NewAddEventUniqueConstraint(
|
|
UniqueEntityIDType,
|
|
entityID,
|
|
"Errors.Project.App.SAMLEntityIDAlreadyExists")
|
|
}
|
|
|
|
func NewRemoveSAMLConfigEntityIDUniqueConstraint(entityID string) *eventstore.UniqueConstraint {
|
|
return eventstore.NewRemoveUniqueConstraint(
|
|
UniqueEntityIDType,
|
|
entityID)
|
|
}
|
|
|
|
func (e *SAMLConfigAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
return []*eventstore.UniqueConstraint{NewAddSAMLConfigEntityIDUniqueConstraint(e.EntityID)}
|
|
}
|
|
|
|
func NewSAMLConfigAddedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
appID string,
|
|
entityID string,
|
|
metadata []byte,
|
|
metadataURL string,
|
|
) *SAMLConfigAddedEvent {
|
|
return &SAMLConfigAddedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
SAMLConfigAddedType,
|
|
),
|
|
AppID: appID,
|
|
EntityID: entityID,
|
|
Metadata: metadata,
|
|
MetadataURL: metadataURL,
|
|
}
|
|
}
|
|
|
|
func SAMLConfigAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
|
e := &SAMLConfigAddedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := event.Unmarshal(e)
|
|
if err != nil {
|
|
return nil, zerrors.ThrowInternal(err, "SAML-BDd15", "unable to unmarshal saml config")
|
|
}
|
|
|
|
return e, nil
|
|
}
|
|
|
|
type SAMLConfigChangedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
AppID string `json:"appId"`
|
|
EntityID string `json:"entityId"`
|
|
Metadata []byte `json:"metadata,omitempty"`
|
|
MetadataURL *string `json:"metadata_url,omitempty"`
|
|
oldEntityID string
|
|
}
|
|
|
|
func (e *SAMLConfigChangedEvent) Payload() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *SAMLConfigChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
if e.EntityID != "" {
|
|
return []*eventstore.UniqueConstraint{
|
|
NewRemoveSAMLConfigEntityIDUniqueConstraint(e.oldEntityID),
|
|
NewAddSAMLConfigEntityIDUniqueConstraint(e.EntityID),
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func NewSAMLConfigChangedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
appID string,
|
|
oldEntityID string,
|
|
changes []SAMLConfigChanges,
|
|
) (*SAMLConfigChangedEvent, error) {
|
|
if len(changes) == 0 {
|
|
return nil, zerrors.ThrowPreconditionFailed(nil, "SAML-i8idç", "Errors.NoChangesFound")
|
|
}
|
|
|
|
changeEvent := &SAMLConfigChangedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
SAMLConfigChangedType,
|
|
),
|
|
AppID: appID,
|
|
oldEntityID: oldEntityID,
|
|
}
|
|
for _, change := range changes {
|
|
change(changeEvent)
|
|
}
|
|
return changeEvent, nil
|
|
}
|
|
|
|
type SAMLConfigChanges func(event *SAMLConfigChangedEvent)
|
|
|
|
func ChangeMetadata(metadata []byte) func(event *SAMLConfigChangedEvent) {
|
|
return func(e *SAMLConfigChangedEvent) {
|
|
e.Metadata = metadata
|
|
}
|
|
}
|
|
|
|
func ChangeMetadataURL(metadataURL string) func(event *SAMLConfigChangedEvent) {
|
|
return func(e *SAMLConfigChangedEvent) {
|
|
e.MetadataURL = &metadataURL
|
|
}
|
|
}
|
|
|
|
func ChangeEntityID(entityID string) func(event *SAMLConfigChangedEvent) {
|
|
return func(e *SAMLConfigChangedEvent) {
|
|
e.EntityID = entityID
|
|
}
|
|
}
|
|
|
|
func SAMLConfigChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
|
e := &SAMLConfigChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := event.Unmarshal(e)
|
|
if err != nil {
|
|
return nil, zerrors.ThrowInternal(err, "SAML-BFd15", "unable to unmarshal saml config")
|
|
}
|
|
|
|
return e, nil
|
|
}
|