feat: Notification providers config (#3212)

* feat: add login check lifetimes to login policy

* feat: org features test

* feat: debug notificatiaon events

* feat: debug notification file/log commands

* feat: add requests to proto

* feat: add api for debug notification providers file/log

* feat: add projection for debug notifiication providers

* feat: requests

* feat: merge v2

* feat: add settings proto to generate

* feat: notifiaction providers

* fix: remove unused code

* Update iam_converter.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
Fabi
2022-03-07 14:22:37 +01:00
committed by GitHub
parent 7d6c933485
commit 7899a0b851
47 changed files with 2489 additions and 200 deletions

View File

@@ -0,0 +1,106 @@
package iam
import (
"context"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/repository/settings"
"github.com/caos/zitadel/internal/eventstore/repository"
)
const (
fileType = ".file"
)
var (
DebugNotificationProviderFileAddedEventType = iamEventTypePrefix + settings.DebugNotificationPrefix + fileType + settings.DebugNotificationProviderAdded
DebugNotificationProviderFileChangedEventType = iamEventTypePrefix + settings.DebugNotificationPrefix + fileType + settings.DebugNotificationProviderChanged
DebugNotificationProviderFileRemovedEventType = iamEventTypePrefix + settings.DebugNotificationPrefix + fileType + settings.DebugNotificationProviderRemoved
)
type DebugNotificationProviderFileAddedEvent struct {
settings.DebugNotificationProviderAddedEvent
}
func NewDebugNotificationProviderFileAddedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
compact bool,
) *DebugNotificationProviderFileAddedEvent {
return &DebugNotificationProviderFileAddedEvent{
DebugNotificationProviderAddedEvent: *settings.NewDebugNotificationProviderAddedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
DebugNotificationProviderFileAddedEventType),
compact),
}
}
func DebugNotificationProviderFileAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := settings.DebugNotificationProviderAddedEventMapper(event)
if err != nil {
return nil, err
}
return &DebugNotificationProviderFileAddedEvent{DebugNotificationProviderAddedEvent: *e.(*settings.DebugNotificationProviderAddedEvent)}, nil
}
type DebugNotificationProviderFileChangedEvent struct {
settings.DebugNotificationProviderChangedEvent
}
func NewDebugNotificationProviderFileChangedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
changes []settings.DebugNotificationProviderChanges,
) (*DebugNotificationProviderFileChangedEvent, error) {
changedEvent, err := settings.NewDebugNotificationProviderChangedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
DebugNotificationProviderFileChangedEventType),
changes,
)
if err != nil {
return nil, err
}
return &DebugNotificationProviderFileChangedEvent{DebugNotificationProviderChangedEvent: *changedEvent}, nil
}
func DebugNotificationProviderFileChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := settings.DebugNotificationProviderChangedEventMapper(event)
if err != nil {
return nil, err
}
return &DebugNotificationProviderFileChangedEvent{DebugNotificationProviderChangedEvent: *e.(*settings.DebugNotificationProviderChangedEvent)}, nil
}
type DebugNotificationProviderFileRemovedEvent struct {
settings.DebugNotificationProviderRemovedEvent
}
func NewDebugNotificationProviderFileRemovedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
) *DebugNotificationProviderFileRemovedEvent {
return &DebugNotificationProviderFileRemovedEvent{
DebugNotificationProviderRemovedEvent: *settings.NewDebugNotificationProviderRemovedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
DebugNotificationProviderFileRemovedEventType),
),
}
}
func DebugNotificationProviderFileRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := settings.DebugNotificationProviderRemovedEventMapper(event)
if err != nil {
return nil, err
}
return &DebugNotificationProviderFileRemovedEvent{DebugNotificationProviderRemovedEvent: *e.(*settings.DebugNotificationProviderRemovedEvent)}, nil
}

View File

@@ -0,0 +1,108 @@
package iam
import (
"context"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/repository/settings"
"github.com/caos/zitadel/internal/eventstore/repository"
)
const (
logType = ".log"
)
var (
DebugNotificationProviderLogAddedEventType = iamEventTypePrefix + settings.DebugNotificationPrefix + logType + settings.DebugNotificationProviderAdded
DebugNotificationProviderLogChangedEventType = iamEventTypePrefix + settings.DebugNotificationPrefix + logType + settings.DebugNotificationProviderChanged
DebugNotificationProviderLogEnabledEventType = iamEventTypePrefix + settings.DebugNotificationPrefix + logType + settings.DebugNotificationProviderEnabled
DebugNotificationProviderLogDisabledEventType = iamEventTypePrefix + settings.DebugNotificationPrefix + logType + settings.DebugNotificationProviderDisabled
DebugNotificationProviderLogRemovedEventType = iamEventTypePrefix + settings.DebugNotificationPrefix + logType + settings.DebugNotificationProviderRemoved
)
type DebugNotificationProviderLogAddedEvent struct {
settings.DebugNotificationProviderAddedEvent
}
func NewDebugNotificationProviderLogAddedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
compact bool,
) *DebugNotificationProviderLogAddedEvent {
return &DebugNotificationProviderLogAddedEvent{
DebugNotificationProviderAddedEvent: *settings.NewDebugNotificationProviderAddedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
DebugNotificationProviderLogAddedEventType),
compact),
}
}
func DebugNotificationProviderLogAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := settings.DebugNotificationProviderAddedEventMapper(event)
if err != nil {
return nil, err
}
return &DebugNotificationProviderLogAddedEvent{DebugNotificationProviderAddedEvent: *e.(*settings.DebugNotificationProviderAddedEvent)}, nil
}
type DebugNotificationProviderLogChangedEvent struct {
settings.DebugNotificationProviderChangedEvent
}
func NewDebugNotificationProviderLogChangedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
changes []settings.DebugNotificationProviderChanges,
) (*DebugNotificationProviderLogChangedEvent, error) {
changedEvent, err := settings.NewDebugNotificationProviderChangedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
DebugNotificationProviderLogChangedEventType),
changes,
)
if err != nil {
return nil, err
}
return &DebugNotificationProviderLogChangedEvent{DebugNotificationProviderChangedEvent: *changedEvent}, nil
}
func DebugNotificationProviderLogChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := settings.DebugNotificationProviderChangedEventMapper(event)
if err != nil {
return nil, err
}
return &DebugNotificationProviderLogChangedEvent{DebugNotificationProviderChangedEvent: *e.(*settings.DebugNotificationProviderChangedEvent)}, nil
}
type DebugNotificationProviderLogRemovedEvent struct {
settings.DebugNotificationProviderRemovedEvent
}
func NewDebugNotificationProviderLogRemovedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
) *DebugNotificationProviderLogRemovedEvent {
return &DebugNotificationProviderLogRemovedEvent{
DebugNotificationProviderRemovedEvent: *settings.NewDebugNotificationProviderRemovedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
DebugNotificationProviderLogRemovedEventType),
),
}
}
func DebugNotificationProviderLogRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
e, err := settings.DebugNotificationProviderRemovedEventMapper(event)
if err != nil {
return nil, err
}
return &DebugNotificationProviderLogRemovedEvent{DebugNotificationProviderRemovedEvent: *e.(*settings.DebugNotificationProviderRemovedEvent)}, nil
}

View File

@@ -23,6 +23,12 @@ func RegisterEventMappers(es *eventstore.Eventstore) {
RegisterFilterEventMapper(SMSConfigActivatedEventType, SMSConfigActivatedEventMapper).
RegisterFilterEventMapper(SMSConfigDeactivatedEventType, SMSConfigDeactivatedEventMapper).
RegisterFilterEventMapper(SMSConfigRemovedEventType, SMSConfigRemovedEventMapper).
RegisterFilterEventMapper(DebugNotificationProviderFileAddedEventType, DebugNotificationProviderFileAddedEventMapper).
RegisterFilterEventMapper(DebugNotificationProviderFileChangedEventType, DebugNotificationProviderFileChangedEventMapper).
RegisterFilterEventMapper(DebugNotificationProviderFileRemovedEventType, DebugNotificationProviderFileRemovedEventMapper).
RegisterFilterEventMapper(DebugNotificationProviderLogAddedEventType, DebugNotificationProviderLogAddedEventMapper).
RegisterFilterEventMapper(DebugNotificationProviderLogChangedEventType, DebugNotificationProviderLogChangedEventMapper).
RegisterFilterEventMapper(DebugNotificationProviderLogRemovedEventType, DebugNotificationProviderLogRemovedEventMapper).
RegisterFilterEventMapper(OIDCSettingsAddedEventType, OIDCSettingsAddedEventMapper).
RegisterFilterEventMapper(OIDCSettingsChangedEventType, OIDCSettingsChangedEventMapper).
RegisterFilterEventMapper(LabelPolicyAddedEventType, LabelPolicyAddedEventMapper).

View File

@@ -0,0 +1,130 @@
package settings
import (
"encoding/json"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/repository"
)
const (
DebugNotificationPrefix = "notification.provider.debug"
DebugNotificationProviderAdded = "added"
DebugNotificationProviderChanged = "changed"
DebugNotificationProviderEnabled = "enabled"
DebugNotificationProviderDisabled = "disabled"
DebugNotificationProviderRemoved = "removed"
)
type DebugNotificationProviderAddedEvent struct {
eventstore.BaseEvent `json:"-"`
Compact bool `json:"compact,omitempty"`
}
func (e *DebugNotificationProviderAddedEvent) Data() interface{} {
return e
}
func (e *DebugNotificationProviderAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewDebugNotificationProviderAddedEvent(
base *eventstore.BaseEvent,
compact bool,
) *DebugNotificationProviderAddedEvent {
return &DebugNotificationProviderAddedEvent{
BaseEvent: *base,
Compact: compact,
}
}
func DebugNotificationProviderAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
e := &DebugNotificationProviderAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "SET-f93ns", "unable to unmarshal debug notification added")
}
return e, nil
}
type DebugNotificationProviderChangedEvent struct {
eventstore.BaseEvent `json:"-"`
Compact *bool `json:"compact,omitempty"`
}
func (e *DebugNotificationProviderChangedEvent) Data() interface{} {
return e
}
func (e *DebugNotificationProviderChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewDebugNotificationProviderChangedEvent(
base *eventstore.BaseEvent,
changes []DebugNotificationProviderChanges,
) (*DebugNotificationProviderChangedEvent, error) {
if len(changes) == 0 {
return nil, errors.ThrowPreconditionFailed(nil, "SET-hj90s", "Errors.NoChangesFound")
}
changeEvent := &DebugNotificationProviderChangedEvent{
BaseEvent: *base,
}
for _, change := range changes {
change(changeEvent)
}
return changeEvent, nil
}
type DebugNotificationProviderChanges func(*DebugNotificationProviderChangedEvent)
func ChangeCompact(compact bool) func(*DebugNotificationProviderChangedEvent) {
return func(e *DebugNotificationProviderChangedEvent) {
e.Compact = &compact
}
}
func DebugNotificationProviderChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
e := &DebugNotificationProviderChangedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "POLIC-ehssl", "unable to unmarshal policy")
}
return e, nil
}
type DebugNotificationProviderRemovedEvent struct {
eventstore.BaseEvent `json:"-"`
}
func (e *DebugNotificationProviderRemovedEvent) Data() interface{} {
return nil
}
func (e *DebugNotificationProviderRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewDebugNotificationProviderRemovedEvent(base *eventstore.BaseEvent) *DebugNotificationProviderRemovedEvent {
return &DebugNotificationProviderRemovedEvent{
BaseEvent: *base,
}
}
func DebugNotificationProviderRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
return &DebugNotificationProviderRemovedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}, nil
}