-
Notifications
You must be signed in to change notification settings - Fork 461
/
api_config.go
60 lines (52 loc) · 1.74 KB
/
api_config.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
package model
import (
"encoding/json"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/crypto"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/project/model"
)
type APIConfig struct {
es_models.ObjectRoot
AppID string `json:"appId"`
ClientID string `json:"clientId,omitempty"`
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
AuthMethodType int32 `json:"authMethodType,omitempty"`
ClientKeys []*ClientKey `json:"-"`
}
func (c *APIConfig) Changes(changed *APIConfig) map[string]interface{} {
changes := make(map[string]interface{}, 1)
changes["appId"] = c.AppID
if c.AuthMethodType != changed.AuthMethodType {
changes["authMethodType"] = changed.AuthMethodType
}
return changes
}
func APIConfigFromModel(config *model.APIConfig) *APIConfig {
return &APIConfig{
ObjectRoot: config.ObjectRoot,
AppID: config.AppID,
ClientID: config.ClientID,
ClientSecret: config.ClientSecret,
AuthMethodType: int32(config.AuthMethodType),
}
}
func APIConfigToModel(config *APIConfig) *model.APIConfig {
oidcConfig := &model.APIConfig{
ObjectRoot: config.ObjectRoot,
AppID: config.AppID,
ClientID: config.ClientID,
ClientSecret: config.ClientSecret,
AuthMethodType: model.APIAuthMethodType(config.AuthMethodType),
ClientKeys: ClientKeysToModel(config.ClientKeys),
}
return oidcConfig
}
func (o *APIConfig) setData(event *es_models.Event) error {
o.ObjectRoot.AppendEvent(event)
if err := json.Unmarshal(event.Data, o); err != nil {
logging.Log("EVEN-d8e3s").WithError(err).Error("could not unmarshal event data")
return err
}
return nil
}