-
Notifications
You must be signed in to change notification settings - Fork 90
/
brand.go
66 lines (56 loc) · 2.05 KB
/
brand.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
package identity
import (
"context"
"github.com/pkg/errors"
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
)
func getWebConfig(ctx context.Context, clientset kubernetes.Interface, namespace string, singleApp bool) (*kotsv1beta1.IdentityWebConfig, error) {
webConfig := &kotsv1beta1.IdentityWebConfig{
Title: "Admin Console",
Theme: &kotsv1beta1.IdentityWebConfigTheme{
StyleCSSBase64: KotsStyleCSSBase64,
// LogoURL: KotsLogoURL,
LogoBase64: KotsLogoBase64,
FaviconBase64: KotsFaviconBase64,
},
}
if !singleApp {
return webConfig, nil
}
brandingConfigMap, err := clientset.CoreV1().ConfigMaps(namespace).Get(ctx, "kotsadm-application-metadata", metav1.GetOptions{})
if kuberneteserrors.IsNotFound(err) {
return webConfig, nil
} else if err != nil {
return webConfig, errors.Wrap(err, "failed to get branding config map")
}
data, ok := brandingConfigMap.Data["application.yaml"]
if !ok {
return webConfig, errors.New("branding config map has no application.yaml")
}
// parse data as a kotskind
decode := scheme.Codecs.UniversalDeserializer().Decode
obj, gvk, err := decode([]byte(data), nil, nil)
if err != nil {
return webConfig, errors.Wrap(err, "failed to decode application gvk")
}
if gvk.Group != "kots.io" || gvk.Version != "v1beta1" || gvk.Kind != "Application" {
return webConfig, errors.New("unexpected gvk found in metadata")
}
application := obj.(*kotsv1beta1.Application)
if application.Spec.Icon != "" {
// NOTE: this will not work for base64 icons
// something to do with the dex templating
// we will have to override the template
// <img class="theme-navbar__logo" src="{{ url .ReqPath logo }}">
webConfig.Theme.LogoURL = application.Spec.Icon
}
if application.Spec.Title != "" {
webConfig.Title = application.Spec.Title
}
// TODO: we don't really support base64 here for favicon
return webConfig, nil
}