-
Notifications
You must be signed in to change notification settings - Fork 88
/
license_context.go
54 lines (45 loc) · 1.21 KB
/
license_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
package template
import (
"encoding/base64"
"encoding/json"
"fmt"
"text/template"
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
)
type LicenseCtx struct {
License *kotsv1beta1.License
}
// FuncMap represents the available functions in the LicenseCtx.
func (ctx LicenseCtx) FuncMap() template.FuncMap {
return template.FuncMap{
"LicenseFieldValue": ctx.licenseFieldValue,
"LicenseDockerCfg": ctx.licenseDockercfg,
}
}
func (ctx LicenseCtx) licenseFieldValue(name string) string {
for key, entitlement := range ctx.License.Spec.Entitlements {
if key == name {
return fmt.Sprintf("%v", entitlement.Value.Value())
}
}
return ""
}
func (ctx LicenseCtx) licenseDockercfg() string {
auth := fmt.Sprintf("%s:%s", ctx.License.Spec.LicenseID, ctx.License.Spec.LicenseID)
encodedAuth := base64.StdEncoding.EncodeToString([]byte(auth))
dockercfg := map[string]interface{}{
"auths": map[string]interface{}{
"proxy.replicated.com": map[string]string{
"auth": encodedAuth,
},
"registry.replicated.com": map[string]string{
"auth": encodedAuth,
},
},
}
b, err := json.Marshal(dockercfg)
if err != nil {
return ""
}
return base64.StdEncoding.EncodeToString(b)
}