-
Notifications
You must be signed in to change notification settings - Fork 483
/
key.go
117 lines (98 loc) · 2.97 KB
/
key.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package project
import (
"context"
"encoding/json"
"time"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore/repository"
)
const (
applicationKeyEventPrefix = applicationEventTypePrefix + "oidc.key."
ApplicationKeyAddedEventType = applicationKeyEventPrefix + "added"
ApplicationKeyRemovedEventType = applicationKeyEventPrefix + "removed"
)
type ApplicationKeyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
AppID string `json:"applicationId"`
ClientID string `json:"clientId,omitempty"`
KeyID string `json:"keyId,omitempty"`
KeyType domain.AuthNKeyType `json:"type,omitempty"`
ExpirationDate time.Time `json:"expirationDate,omitempty"`
PublicKey []byte `json:"publicKey,omitempty"`
}
func (e *ApplicationKeyAddedEvent) Data() interface{} {
return e
}
func (e *ApplicationKeyAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewApplicationKeyAddedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
appID,
clientID,
keyID string,
keyType domain.AuthNKeyType,
expirationDate time.Time,
publicKey []byte,
) *ApplicationKeyAddedEvent {
return &ApplicationKeyAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
aggregate,
ApplicationKeyAddedEventType,
),
AppID: appID,
ClientID: clientID,
KeyID: keyID,
KeyType: keyType,
ExpirationDate: expirationDate,
PublicKey: publicKey,
}
}
func ApplicationKeyAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
e := &ApplicationKeyAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "API-BFd15", "unable to unmarshal api config")
}
return e, nil
}
type ApplicationKeyRemovedEvent struct {
eventstore.BaseEvent `json:"-"`
KeyID string `json:"keyId,omitempty"`
}
func (e *ApplicationKeyRemovedEvent) Data() interface{} {
return e
}
func (e *ApplicationKeyRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewApplicationKeyRemovedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
keyID string,
) *ApplicationKeyRemovedEvent {
return &ApplicationKeyRemovedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
aggregate,
ApplicationKeyRemovedEventType,
),
KeyID: keyID,
}
}
func ApplicationKeyRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
applicationKeyRemoved := &ApplicationKeyRemovedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, applicationKeyRemoved)
if err != nil {
return nil, errors.ThrowInternal(err, "USER-5Gm9s", "unable to unmarshal application key removed")
}
return applicationKeyRemoved, nil
}