-
Notifications
You must be signed in to change notification settings - Fork 88
/
identity_context.go
80 lines (67 loc) · 1.95 KB
/
identity_context.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
package template
import (
"strconv"
"text/template"
identitytypes "github.com/replicatedhq/kots/pkg/identity/types"
"github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
)
type identityCtx struct {
identityConfig *v1beta1.IdentityConfig
appInfo *ApplicationInfo
}
func newIdentityCtx(identityConfig *v1beta1.IdentityConfig, appInfo *ApplicationInfo) identityCtx {
return identityCtx{
identityConfig: identityConfig,
appInfo: appInfo,
}
}
// FuncMap represents the available functions in the identityCtx.
func (ctx identityCtx) FuncMap() template.FuncMap {
return template.FuncMap{
"IdentityServiceEnabled": ctx.identityServiceEnabled,
"IdentityServiceClientID": ctx.identityServiceClientID,
"IdentityServiceClientSecret": ctx.identityServiceClientSecret,
"IdentityServiceRoles": ctx.identityServiceRoles,
"IdentityServiceName": ctx.identityServiceName,
"IdentityServicePort": ctx.identityServicePort,
}
}
func (ctx identityCtx) identityServiceEnabled() bool {
if ctx.identityConfig == nil {
return false
}
return ctx.identityConfig.Spec.Enabled
}
func (ctx identityCtx) identityServiceClientID() string {
if ctx.identityConfig == nil {
return ""
}
return ctx.identityConfig.Spec.ClientID
}
func (ctx identityCtx) identityServiceClientSecret() (string, error) {
if ctx.identityConfig == nil {
return "", nil
}
return ctx.identityConfig.Spec.ClientSecret.GetValue()
}
func (ctx identityCtx) identityServiceRoles() map[string]interface{} {
m := map[string]interface{}{}
if ctx.identityConfig != nil {
for _, g := range ctx.identityConfig.Spec.Groups {
m[g.ID] = g.RoleIDs
}
}
return m
}
func (ctx identityCtx) identityServiceName() string {
if ctx.appInfo == nil {
return ""
}
return identitytypes.ServiceName(ctx.appInfo.Slug)
}
func (ctx identityCtx) identityServicePort() string {
if ctx.appInfo == nil {
return ""
}
return strconv.Itoa(int(identitytypes.ServicePort()))
}