-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
51 lines (45 loc) · 1.64 KB
/
store.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
package auth
import (
"fmt"
"strings"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rancher/pkg/auth/providers/common"
"github.com/rancher/rancher/pkg/namespace"
corev1 "github.com/rancher/types/apis/core/v1"
client "github.com/rancher/types/client/management/v3"
)
var TypeToField = map[string]string{
client.GithubConfigType: "clientSecret",
client.ActiveDirectoryConfigType: "serviceAccountPassword",
client.AzureADConfigType: "applicationSecret",
client.OpenLdapConfigType: "serviceAccountPassword",
client.FreeIpaConfigType: "serviceAccountPassword",
client.PingConfigType: "spKey",
client.ADFSConfigType: "spKey",
client.KeyCloakConfigType: "spKey",
client.OKTAConfigType: "spKey",
}
func Wrap(store types.Store, secrets corev1.SecretInterface) types.Store {
return &Store{
Store: store,
Secrets: secrets,
}
}
type Store struct {
types.Store
Secrets corev1.SecretInterface
}
func (s *Store) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
for kind, field := range TypeToField {
if val, ok := data[field]; ok {
val := convert.ToString(val)
if err := common.CreateOrUpdateSecrets(s.Secrets, val, strings.ToLower(field), strings.ToLower(kind)); err != nil {
return nil, fmt.Errorf("error creating secret for %s:%s", kind, field)
}
data[field] = fmt.Sprintf("%s:%s-%s", namespace.GlobalNamespace, strings.ToLower(kind), strings.ToLower(field))
break
}
}
return s.Store.Update(apiContext, schema, data, id)
}