mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +00:00
feat: Instance commands (#3385)
* fix: add events for domain * fix: add/remove domain command side * fix: add/remove domain command side * fix: add/remove domain query side * fix: create instance * fix: merge v2 * fix: instance domain * fix: instance domain * fix: instance domain * fix: instance domain * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from writemodels * fix: remove domain.IAMID from api * fix: remove domain.IAMID * fix: remove domain.IAMID * fix: add instance domain queries * fix: fix after merge * Update auth_request.go * fix keypair * remove unused code * feat: read instance id from context * feat: remove unused code * feat: use instance id from context * some fixes Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package instance
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
@@ -18,13 +17,13 @@ type Aggregate struct {
|
||||
eventstore.Aggregate
|
||||
}
|
||||
|
||||
func NewAggregate() *Aggregate {
|
||||
func NewAggregate(instanceID string) *Aggregate {
|
||||
return &Aggregate{
|
||||
Aggregate: eventstore.Aggregate{
|
||||
Type: AggregateType,
|
||||
Version: AggregateVersion,
|
||||
ID: domain.IAMID,
|
||||
ResourceOwner: domain.IAMID,
|
||||
ID: instanceID,
|
||||
ResourceOwner: instanceID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
107
internal/repository/instance/domain.go
Normal file
107
internal/repository/instance/domain.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package instance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
UniqueInstanceDomain = "instance_domain"
|
||||
domainEventPrefix = instanceEventTypePrefix + "domain."
|
||||
InstanceDomainAddedEventType = domainEventPrefix + "added"
|
||||
InstanceDomainRemovedEventType = domainEventPrefix + "removed"
|
||||
)
|
||||
|
||||
func NewAddInstanceDomainUniqueConstraint(orgDomain string) *eventstore.EventUniqueConstraint {
|
||||
return eventstore.NewAddEventUniqueConstraint(
|
||||
UniqueInstanceDomain,
|
||||
orgDomain,
|
||||
"Errors.Instance.Domain.AlreadyExists")
|
||||
}
|
||||
|
||||
func NewRemoveInstanceDomainUniqueConstraint(orgDomain string) *eventstore.EventUniqueConstraint {
|
||||
return eventstore.NewRemoveEventUniqueConstraint(
|
||||
UniqueInstanceDomain,
|
||||
orgDomain)
|
||||
}
|
||||
|
||||
type DomainAddedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Generated bool `json:"generated,omitempty"`
|
||||
}
|
||||
|
||||
func (e *DomainAddedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *DomainAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return []*eventstore.EventUniqueConstraint{NewAddInstanceDomainUniqueConstraint(e.Domain)}
|
||||
}
|
||||
|
||||
func NewDomainAddedEvent(ctx context.Context, aggregate *eventstore.Aggregate, domain string, generated bool) *DomainAddedEvent {
|
||||
return &DomainAddedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
InstanceDomainAddedEventType,
|
||||
),
|
||||
Domain: domain,
|
||||
Generated: generated,
|
||||
}
|
||||
}
|
||||
|
||||
func DomainAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
orgDomainAdded := &DomainAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, orgDomainAdded)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "INSTANCE-3noij", "unable to unmarshal instance domain added")
|
||||
}
|
||||
|
||||
return orgDomainAdded, nil
|
||||
}
|
||||
|
||||
type DomainRemovedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
Domain string `json:"domain,omitempty"`
|
||||
}
|
||||
|
||||
func (e *DomainRemovedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *DomainRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return []*eventstore.EventUniqueConstraint{NewRemoveInstanceDomainUniqueConstraint(e.Domain)}
|
||||
}
|
||||
|
||||
func NewDomainRemovedEvent(ctx context.Context, aggregate *eventstore.Aggregate, domain string) *DomainRemovedEvent {
|
||||
return &DomainRemovedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
InstanceDomainRemovedEventType,
|
||||
),
|
||||
Domain: domain,
|
||||
}
|
||||
}
|
||||
|
||||
func DomainRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
orgDomainRemoved := &DomainRemovedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, orgDomainRemoved)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "INSTANCE-BngB2", "unable to unmarshal instance domain removed")
|
||||
}
|
||||
|
||||
return orgDomainRemoved, nil
|
||||
}
|
@@ -85,5 +85,10 @@ func RegisterEventMappers(es *eventstore.Eventstore) {
|
||||
RegisterFilterEventMapper(CustomTextSetEventType, CustomTextSetEventMapper).
|
||||
RegisterFilterEventMapper(CustomTextRemovedEventType, CustomTextRemovedEventMapper).
|
||||
RegisterFilterEventMapper(CustomTextTemplateRemovedEventType, CustomTextTemplateRemovedEventMapper).
|
||||
RegisterFilterEventMapper(FeaturesSetEventType, FeaturesSetEventMapper)
|
||||
RegisterFilterEventMapper(FeaturesSetEventType, FeaturesSetEventMapper).
|
||||
RegisterFilterEventMapper(InstanceDomainAddedEventType, DomainAddedEventMapper).
|
||||
RegisterFilterEventMapper(InstanceDomainRemovedEventType, DomainRemovedEventMapper).
|
||||
RegisterFilterEventMapper(InstanceAddedEventType, InstanceAddedEventMapper).
|
||||
RegisterFilterEventMapper(InstanceChangedEventType, InstanceChangedEventMapper).
|
||||
RegisterFilterEventMapper(InstanceRemovedEventType, InstanceRemovedEventMapper)
|
||||
}
|
||||
|
126
internal/repository/instance/instance.go
Normal file
126
internal/repository/instance/instance.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package instance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
InstanceAddedEventType = instanceEventTypePrefix + "added"
|
||||
InstanceChangedEventType = instanceEventTypePrefix + "changed"
|
||||
InstanceRemovedEventType = instanceEventTypePrefix + "removed"
|
||||
)
|
||||
|
||||
type InstanceAddedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
func (e *InstanceAddedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *InstanceAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstanceAddedEvent(ctx context.Context, aggregate *eventstore.Aggregate, name string) *InstanceAddedEvent {
|
||||
return &InstanceAddedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
InstanceAddedEventType,
|
||||
),
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func InstanceAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
instanceAdded := &InstanceAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, instanceAdded)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "INSTANCE-s9l3F", "unable to unmarshal instance added")
|
||||
}
|
||||
|
||||
return instanceAdded, nil
|
||||
}
|
||||
|
||||
type InstanceChangedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
func (e *InstanceChangedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *InstanceChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstanceChangedEvent(ctx context.Context, aggregate *eventstore.Aggregate, oldName, newName string) *InstanceChangedEvent {
|
||||
return &InstanceChangedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
InstanceChangedEventType,
|
||||
),
|
||||
Name: newName,
|
||||
}
|
||||
}
|
||||
|
||||
func InstanceChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
instanceChanged := &InstanceChangedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, instanceChanged)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "INSTANCE-3hfo8", "unable to unmarshal instance changed")
|
||||
}
|
||||
|
||||
return instanceChanged, nil
|
||||
}
|
||||
|
||||
type InstanceRemovedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
name string
|
||||
}
|
||||
|
||||
func (e *InstanceRemovedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *InstanceRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstanceRemovedEvent(ctx context.Context, aggregate *eventstore.Aggregate, name string) *InstanceRemovedEvent {
|
||||
return &InstanceRemovedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
InstanceRemovedEventType,
|
||||
),
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func InstanceRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
instanceRemoved := &InstanceRemovedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, instanceRemoved)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "INSTANCE-39jlW", "unable to unmarshal instance removed")
|
||||
}
|
||||
|
||||
return instanceRemoved, nil
|
||||
}
|
Reference in New Issue
Block a user