forked from dexidp/dex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
61 lines (52 loc) · 1.43 KB
/
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
61
// DO NOT EDIT: This file was auto-generated by "go generate"
// To regenerate run:
// go install github.com/coreos/dex/cmd/genconfig
// go generate <<fully qualified package name>>
package connector
import (
"encoding/json"
"errors"
"fmt"
)
type NewConnectorConfigFunc func() ConnectorConfig
var (
connectorTypes map[string]NewConnectorConfigFunc
)
func RegisterConnectorConfigType(connectorType string, fn NewConnectorConfigFunc) {
if connectorTypes == nil {
connectorTypes = make(map[string]NewConnectorConfigFunc)
}
if _, ok := connectorTypes[connectorType]; ok {
panic(fmt.Sprintf("connector config type %q already registered", connectorType))
}
connectorTypes[connectorType] = fn
}
func NewConnectorConfigFromType(connectorType string) (ConnectorConfig, error) {
fn, ok := connectorTypes[connectorType]
if !ok {
return nil, fmt.Errorf("unrecognized connector config type %q", connectorType)
}
return fn(), nil
}
func newConnectorConfigFromMap(m map[string]interface{}) (ConnectorConfig, error) {
ityp, ok := m["type"]
if !ok {
return nil, errors.New("connector config type not set")
}
typ, ok := ityp.(string)
if !ok {
return nil, errors.New("connector config type not string")
}
cfg, err := NewConnectorConfigFromType(typ)
if err != nil {
return nil, err
}
b, err := json.Marshal(m)
if err != nil {
return nil, err
}
if err = json.Unmarshal(b, cfg); err != nil {
return nil, err
}
return cfg, nil
}