mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
start idp config
This commit is contained in:
parent
4b1e79604a
commit
edff816ec1
17
internal/api/grpc/server/middleware/service_interceptor.go
Normal file
17
internal/api/grpc/server/middleware/service_interceptor.go
Normal file
@ -0,0 +1,17 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/service"
|
||||
_ "github.com/caos/zitadel/internal/statik"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func ServiceHandler() grpc.UnaryServerInterceptor {
|
||||
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
||||
namer := info.Server.(interface{ AppName() string })
|
||||
ctx = service.WithService(ctx, namer.AppName())
|
||||
return handler(ctx, req)
|
||||
}
|
||||
}
|
@ -34,10 +34,10 @@ func CreateServer(verifier *authz.TokenVerifier, authConfig authz.Config, lang l
|
||||
middleware.AuthorizationInterceptor(verifier, authConfig),
|
||||
middleware.TranslationHandler(lang),
|
||||
middleware.ValidationHandler(),
|
||||
middleware.ServiceHandler(),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func Serve(ctx context.Context, server *grpc.Server, port string) {
|
||||
|
@ -25,7 +25,8 @@ func (r *Repository) AddIAMMember(ctx context.Context, member *iam_model.IAMMemb
|
||||
}
|
||||
|
||||
iamAgg := iam_repo.AggregateFromReadModel(iam).
|
||||
PushEvents(iam_repo.NewMemberAddedEvent(ctx, member.UserID, member.Roles...))
|
||||
PushMemberAdded(ctx, member.UserID, member.Roles...)
|
||||
// PushEvents(iam_repo.NewMemberAddedEvent(ctx, member.UserID, member.Roles...))
|
||||
|
||||
events, err := r.eventstore.PushAggregates(ctx, iamAgg)
|
||||
if err != nil {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package iam
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
)
|
||||
|
||||
@ -38,3 +40,18 @@ func AggregateFromReadModel(rm *ReadModel) *Aggregate {
|
||||
SetUpStarted: rm.SetUpStarted,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Aggregate) PushMemberAdded(ctx context.Context, userID string, roles ...string) *Aggregate {
|
||||
a.Aggregate = *a.PushEvents(NewMemberAddedEvent(ctx, userID, roles...))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Aggregate) PushMemberChanged(ctx context.Context, userID string, roles ...string) *Aggregate {
|
||||
a.Aggregate = *a.PushEvents(NewMemberChangedEvent(ctx, userID, roles...))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Aggregate) PushMemberRemoved(ctx context.Context, userID string) *Aggregate {
|
||||
a.Aggregate = *a.PushEvents(NewMemberRemovedEvent(ctx, userID))
|
||||
return a
|
||||
}
|
||||
|
@ -1 +1,60 @@
|
||||
package idp
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/v2/repository/idp/oidc"
|
||||
)
|
||||
|
||||
type ConfigAggregate struct {
|
||||
eventstore.Aggregate
|
||||
|
||||
ConfigID string
|
||||
Type ConfigType
|
||||
Name string
|
||||
StylingType StylingType
|
||||
State ConfigState
|
||||
OIDCConfig *oidc.ConfigReadModel
|
||||
}
|
||||
|
||||
type ConfigReadModel struct {
|
||||
eventstore.ReadModel
|
||||
|
||||
ConfigID string
|
||||
Type ConfigType
|
||||
Name string
|
||||
StylingType StylingType
|
||||
State ConfigState
|
||||
OIDCConfig *oidc.ConfigReadModel
|
||||
}
|
||||
|
||||
func (rm *ConfigReadModel) AppendEvents(events ...eventstore.EventReader) error {
|
||||
rm.ReadModel.AppendEvents(events...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rm *ConfigReadModel) Reduce() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type ConfigType int32
|
||||
|
||||
const (
|
||||
ConfigTypeOIDC ConfigType = iota
|
||||
ConfigTypeSAML
|
||||
)
|
||||
|
||||
type ConfigState int32
|
||||
|
||||
const (
|
||||
ConfigStateActive ConfigState = iota
|
||||
ConfigStateInactive
|
||||
ConfigStateRemoved
|
||||
)
|
||||
|
||||
type StylingType int32
|
||||
|
||||
const (
|
||||
StylingTypeUnspecified StylingType = iota
|
||||
StylingTypeGoogle
|
||||
)
|
||||
|
31
internal/v2/repository/idp/event_added.go
Normal file
31
internal/v2/repository/idp/event_added.go
Normal file
@ -0,0 +1,31 @@
|
||||
package idp
|
||||
|
||||
import "github.com/caos/zitadel/internal/eventstore/v2"
|
||||
|
||||
type AddedEvent struct {
|
||||
eventstore.BaseEvent
|
||||
|
||||
ID string `idpConfigId`
|
||||
Name string `name`
|
||||
}
|
||||
|
||||
func NewAddedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
configID string,
|
||||
name string,
|
||||
) *AddedEvent {
|
||||
|
||||
return &AddedEvent{
|
||||
BaseEvent: *base,
|
||||
ID: configID,
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *AddedEvent) CheckPrevious() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *AddedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
37
internal/v2/repository/idp/event_changed.go
Normal file
37
internal/v2/repository/idp/event_changed.go
Normal file
@ -0,0 +1,37 @@
|
||||
package idp
|
||||
|
||||
import "github.com/caos/zitadel/internal/eventstore/v2"
|
||||
|
||||
type ChangedEdvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
current *ConfigAggregate
|
||||
changed *ConfigAggregate
|
||||
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func ChangedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
current *ConfigAggregate,
|
||||
changed *ConfigAggregate,
|
||||
) (*ChangedEdvent, error) {
|
||||
//TODO: who to handle chanes?
|
||||
|
||||
return &ChangedEdvent{
|
||||
BaseEvent: *base,
|
||||
current: current,
|
||||
changed: changed,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *ChangedEdvent) CheckPrevious() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *ChangedEdvent) Data() interface{} {
|
||||
if e.current.Name != e.changed.Name {
|
||||
e.Name = e.changed.Name
|
||||
}
|
||||
return e
|
||||
}
|
28
internal/v2/repository/idp/event_deactivated.go
Normal file
28
internal/v2/repository/idp/event_deactivated.go
Normal file
@ -0,0 +1,28 @@
|
||||
package idp
|
||||
|
||||
import "github.com/caos/zitadel/internal/eventstore/v2"
|
||||
|
||||
type DeactivatedEvent struct {
|
||||
eventstore.BaseEvent
|
||||
|
||||
ID string `idpConfigId`
|
||||
}
|
||||
|
||||
func NewDeactivatedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
configID string,
|
||||
) *DeactivatedEvent {
|
||||
|
||||
return &DeactivatedEvent{
|
||||
BaseEvent: *base,
|
||||
ID: configID,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *DeactivatedEvent) CheckPrevious() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *DeactivatedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
3
internal/v2/repository/idp/oidc/added_event.go
Normal file
3
internal/v2/repository/idp/oidc/added_event.go
Normal file
@ -0,0 +1,3 @@
|
||||
package oidc
|
||||
|
||||
type AddedEvent struct{}
|
3
internal/v2/repository/idp/oidc/changed_event.go
Normal file
3
internal/v2/repository/idp/oidc/changed_event.go
Normal file
@ -0,0 +1,3 @@
|
||||
package oidc
|
||||
|
||||
type ChangedEvent struct{}
|
35
internal/v2/repository/idp/oidc/config.go
Normal file
35
internal/v2/repository/idp/oidc/config.go
Normal file
@ -0,0 +1,35 @@
|
||||
package oidc
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
)
|
||||
|
||||
type ConfigReadModel struct {
|
||||
eventstore.ReadModel
|
||||
|
||||
IDPConfigID string
|
||||
ClientID string
|
||||
ClientSecret *crypto.CryptoValue
|
||||
ClientSecretString string
|
||||
Issuer string
|
||||
Scopes []string
|
||||
IDPDisplayNameMapping MappingField
|
||||
UsernameMapping MappingField
|
||||
}
|
||||
|
||||
func (rm *ConfigReadModel) AppendEvents(events ...eventstore.EventReader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rm *ConfigReadModel) Reduce() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type MappingField int32
|
||||
|
||||
const (
|
||||
OIDCMappingFieldUnspecified MappingField = iota
|
||||
OIDCMappingFieldPreferredLoginName
|
||||
OIDCMappingFieldEmail
|
||||
)
|
3
internal/v2/repository/idp/oidc/deactivated_event.go
Normal file
3
internal/v2/repository/idp/oidc/deactivated_event.go
Normal file
@ -0,0 +1,3 @@
|
||||
package oidc
|
||||
|
||||
type DeactivatedEvent struct{}
|
3
internal/v2/repository/idp/oidc/removed_event.go
Normal file
3
internal/v2/repository/idp/oidc/removed_event.go
Normal file
@ -0,0 +1,3 @@
|
||||
package oidc
|
||||
|
||||
type RemovedEvent struct{}
|
Loading…
Reference in New Issue
Block a user