From 567c28488e05f2280fa4f3160ab3a37a870225cf Mon Sep 17 00:00:00 2001 From: lightnet328 Date: Fri, 15 Feb 2019 02:01:05 +0900 Subject: [PATCH 1/3] Fix Windows environment variable --- templates/windows-tab.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/windows-tab.html b/templates/windows-tab.html index 1010242..5f53502 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 }} @@ -56,7 +56,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 }} @@ -85,7 +85,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 +94,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 }}
From 34d6adbda51d61b4c5f7eea5def9d77d58c733b7 Mon Sep 17 00:00:00 2001 From: lightnet328 Date: Fri, 15 Feb 2019 02:02:15 +0900 Subject: [PATCH 2/3] Create certificate files with PowerShell --- templates.go | 10 +++++++++- templates/windows-tab.html | 8 ++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/templates.go b/templates.go index a2ec741..44242d6 100644 --- a/templates.go +++ b/templates.go @@ -10,8 +10,16 @@ import ( "strings" ) +var funcMap = template.FuncMap{ + "escape": 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 5f53502..c35a994 100644 --- a/templates/windows-tab.html +++ b/templates/windows-tab.html @@ -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 | escape }} | Out-Null"
{{ 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 | escape }} | Out-Null"
{{ end }} From f438c18c2e0e21a74e015306ef2525d3f2675aa9 Mon Sep 17 00:00:00 2001 From: lightnet328 Date: Fri, 15 Feb 2019 23:25:28 +0900 Subject: [PATCH 3/3] Change func name --- templates.go | 2 +- templates/windows-tab.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates.go b/templates.go index 44242d6..507f56c 100644 --- a/templates.go +++ b/templates.go @@ -11,7 +11,7 @@ import ( ) var funcMap = template.FuncMap{ - "escape": func(text string) template.HTML { + "escapeWin": func(text string) template.HTML { text = strings.Replace(text, " ", "` ", -1) text = strings.Replace(text, "\n", "`r`n", -1) return template.HTML(text) diff --git a/templates/windows-tab.html b/templates/windows-tab.html index c35a994..f6bd4ef 100644 --- a/templates/windows-tab.html +++ b/templates/windows-tab.html @@ -40,7 +40,7 @@

Copy IDP CA From Pem

-
powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "New-Item %USERPROFILE%/.kube/certs/{{ .ClusterName }}/idp-ca.crt -Force -Value {{ .IDPCaPem | escape }} | Out-Null"
+
powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "New-Item %USERPROFILE%/.kube/certs/{{ .ClusterName }}/idp-ca.crt -Force -Value {{ .IDPCaPem | escapeWin }} | Out-Null"
{{ end }} @@ -68,7 +68,7 @@

Copy Kubernetes CA Certificate From PEM

-
powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "New-Item %USERPROFILE%/.kube/certs/{{ .ClusterName }}/k8s-ca.crt -Force -Value {{ .K8sCaPem | escape }} | Out-Null"
+
powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "New-Item %USERPROFILE%/.kube/certs/{{ .ClusterName }}/k8s-ca.crt -Force -Value {{ .K8sCaPem | escapeWin }} | Out-Null"
{{ end }}