forked from mintel/dex-k8s-authenticator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.go
95 lines (84 loc) · 2.31 KB
/
templates.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// FIXME: Dislike this file a bit - what's the take on referencing
// viper config values (treat it as a global, or pass values around?)
package main
import (
"encoding/json"
"html/template"
"log"
"net/http"
"strings"
)
// compile all templates and cache them
var templates = template.Must(template.ParseGlob("./templates/*.html"))
func renderIndex(w http.ResponseWriter, config *Config) {
t, _ := template.ParseFiles("./templates/index.html")
err := t.Execute(w, config)
if err != nil {
log.Fatal(err)
}
}
type templateData struct {
IDToken string
RefreshToken string
RedirectURL string
Claims string
Username string
Issuer string
ClusterName string
ShortDescription string
ClientSecret string
ClientID string
K8sMasterURI string
K8sCaURI string
K8sCaPem string
IDPCaURI string
IDPCaPem string
LogoURI string
Web_Path_Prefix string
StaticContextName bool
KubectlVersion string
}
func (cluster *Cluster) renderToken(w http.ResponseWriter,
idToken,
refreshToken string,
idpCaURI string,
idpCaPem string,
logoURI string,
webPathPrefix string,
kubectlVersion string,
claims []byte) {
var data map[string]interface{}
err := json.Unmarshal(claims, &data)
if err != nil {
panic(err)
}
unix_username := "user"
if data["email"] != nil {
email := data["email"].(string)
unix_username = strings.Split(email, "@")[0]
}
token_data := templateData{
IDToken: idToken,
RefreshToken: refreshToken,
RedirectURL: cluster.Redirect_URI,
Claims: string(claims),
Username: unix_username,
Issuer: data["iss"].(string),
ClusterName: cluster.Name,
ShortDescription: cluster.Short_Description,
ClientSecret: cluster.Client_Secret,
ClientID: cluster.Client_ID,
K8sMasterURI: cluster.K8s_Master_URI,
K8sCaURI: cluster.K8s_Ca_URI,
K8sCaPem: cluster.K8s_Ca_Pem,
IDPCaURI: idpCaURI,
IDPCaPem: idpCaPem,
LogoURI: logoURI,
Web_Path_Prefix: webPathPrefix,
StaticContextName: cluster.Static_Context_Name,
KubectlVersion: kubectlVersion}
err = templates.ExecuteTemplate(w, "kubeconfig.html", token_data)
if err != nil {
log.Fatal(err)
}
}