diff --git a/templates.go b/templates.go index a2ec741..507f56c 100644 --- a/templates.go +++ b/templates.go @@ -10,8 +10,16 @@ import ( "strings" ) +var funcMap = template.FuncMap{ + "escapeWin": func(text string) template.HTML { + text = strings.Replace(text, " ", "` ", -1) + text = strings.Replace(text, "\n", "`r`n", -1) + return template.HTML(text) + }, +} + // compile all templates and cache them -var templates = template.Must(template.ParseGlob("./templates/*.html")) +var templates = template.Must(template.New("").Funcs(funcMap).ParseGlob("./templates/*.html")) func renderIndex(w http.ResponseWriter, config *Config) { t, _ := template.ParseFiles("./templates/index.html") diff --git a/templates/windows-tab.html b/templates/windows-tab.html index 1010242..f6bd4ef 100644 --- a/templates/windows-tab.html +++ b/templates/windows-tab.html @@ -26,7 +26,7 @@

Copy IDP CA Certificate From URL

-
curl --create-dirs -s {{ .IDPCaURI }} -o ${HOME}/.kube/certs/{{ .ClusterName }}/idp-ca.crt
+
curl --create-dirs -s {{ .IDPCaURI }} -o %USERPROFILE%/.kube/certs/{{ .ClusterName }}/idp-ca.crt
{{ end }} @@ -40,9 +40,7 @@

Copy IDP CA From Pem

-
mkdir -p ${HOME}/.kube/certs/{{ .ClusterName }}/ && cat << EOF > ${HOME}/.kube/certs/{{ .ClusterName }}/idp-ca.crt
-{{ .IDPCaPem}}
-EOF
+
powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "New-Item %USERPROFILE%/.kube/certs/{{ .ClusterName }}/idp-ca.crt -Force -Value {{ .IDPCaPem | escapeWin }} | Out-Null"
{{ end }} @@ -56,7 +54,7 @@

Copy Kubernetes CA Certificate From URL

-
curl --create-dirs -s {{ .K8sCaURI }} -o ${HOME}/.kube/certs/{{ .ClusterName }}/k8s-ca.crt
+
curl --create-dirs -s {{ .K8sCaURI }} -o %USERPROFILE%/.kube/certs/{{ .ClusterName }}/k8s-ca.crt
{{ end }} @@ -70,9 +68,7 @@

Copy Kubernetes CA Certificate From PEM

-
mkdir -p ${HOME}/.kube/certs/{{ .ClusterName }}/ && cat << EOF > ${HOME}/.kube/certs/{{ .ClusterName }}/k8s-ca.crt
-{{ .K8sCaPem }}
-EOF
+
powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "New-Item %USERPROFILE%/.kube/certs/{{ .ClusterName }}/k8s-ca.crt -Force -Value {{ .K8sCaPem | escapeWin }} | Out-Null"
{{ end }} @@ -85,7 +81,7 @@

Run configuration commands

-
kubectl config set-cluster {{ .ClusterName }} --certificate-authority=${HOME}/.kube/certs/{{ .ClusterName}}/k8s-ca.crt --server={{ .K8sMasterURI }}
+
kubectl config set-cluster {{ .ClusterName }} --certificate-authority=%USERPROFILE%/.kube/certs/{{ .ClusterName}}/k8s-ca.crt --server={{ .K8sMasterURI }}
@@ -94,7 +90,7 @@

Run configuration commands

kubectl config set-credentials {{ .Username }}-{{ .ClusterName }} --auth-provider=oidc --auth-provider-arg=idp-issuer-url={{ .Issuer }} --auth-provider-arg=client-id={{ .ClientID }} --auth-provider-arg=client-secret={{ .ClientSecret }} --auth-provider-arg=refresh-token={{ .RefreshToken }} --auth-provider-arg=id-token={{ .IDToken }}
-  {{- if or (.IDPCaURI) (.IDPCaPem) }} --auth-provider-arg=idp-certificate-authority=${HOME}/.kube/certs/{{ .ClusterName }}/idp-ca.crt
+  {{- if or (.IDPCaURI) (.IDPCaPem) }} --auth-provider-arg=idp-certificate-authority=%USERPROFILE%/.kube/certs/{{ .ClusterName }}/idp-ca.crt
   {{- end }}