start idp config

This commit is contained in:
adlerhurst 2020-11-17 13:44:37 +01:00
parent 4b1e79604a
commit edff816ec1
13 changed files with 239 additions and 2 deletions

View 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)
}
}

View File

@ -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) {

View File

@ -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 {

View File

@ -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
}

View File

@ -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
)

View 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
}

View 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
}

View 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
}

View File

@ -0,0 +1,3 @@
package oidc
type AddedEvent struct{}

View File

@ -0,0 +1,3 @@
package oidc
type ChangedEvent struct{}

View 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
)

View File

@ -0,0 +1,3 @@
package oidc
type DeactivatedEvent struct{}

View File

@ -0,0 +1,3 @@
package oidc
type RemovedEvent struct{}