Skip to content

Commit

Permalink
Merge pull request #8 from fydrah/evacuate_html_templates
Browse files Browse the repository at this point in the history
Evacuate html templates from binary
  • Loading branch information
fydrah authored Oct 28, 2018
2 parents 3ba9c7b + 8351947 commit 607bf14
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 66 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LABEL maintainer="Flavien Hardy <[email protected]>"

COPY --from=build /go/src/${REPO}/bin/loginapp-static /loginapp
COPY --from=build /go/src/${REPO}/assets /assets
COPY --from=build /go/src/${REPO}/templates /templates

ENTRYPOINT ["/loginapp"]
CMD [""]
2 changes: 1 addition & 1 deletion example/config-loginapp-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ log:
web_output:
main_client_id: "loginapp"
main_username_claim: "email"
assets_dir: "../assets/"
assets_dir: "./assets/"
skip_main_page: true
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type KubeUserInfo struct {
Claims interface{}
ClientSecret string
UsernameClaim string
Name string
}

// OAuth2Config generate oauth config
Expand Down Expand Up @@ -216,6 +217,7 @@ func (s *Server) ProcessCallback(w http.ResponseWriter, r *http.Request) (KubeUs
ClientSecret: s.config.OIDC.Client.Secret,
ClientID: s.config.WebOutput.MainClientID,
UsernameClaim: usernameClaim.(string),
Name: s.config.Name,
}, nil
}

Expand Down
67 changes: 2 additions & 65 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,68 +42,5 @@ func renderTemplate(w http.ResponseWriter, tmpl *template.Template, data interfa
}
}

var indexTmpl = template.Must(template.New("index.html").Parse(`<html>
<head>
<link rel="stylesheet" type="text/css" href="assets/css/form-style.min.css">
<script type="text/javascript">function adjust_textarea(t){t.style.height="20px",t.style.height=t.scrollHeight+"px"}</script>
</head>
<body>
<form class="form-style-7" action="/login" method="post">
<h1>Kubernetes Loginapp</h1>
<ul>
<li>
<label for="access">CLI access</label>
<input name="access" type="submit" value="CLI" />
<span>Login and retrieve your kubeconfig for CLI authentication</span>
</li>
</ul>
</form>
</body>
</html>`))

var tokenTmpl = template.Must(template.New("token.html").Parse(`<html>
<head>
<link rel="stylesheet" type="text/css" href="assets/css/code-box-copy.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/prism.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/form-style.min.css">
</head>
<body>
<div class="form-style-7">
<h1>Kubernetes Loginapp</h1>
<form class="form-style-7" action="/" method="get">
<ul>
<li>
<label>Copy this in your ~/.kube/config file</label>
<div class="code-box-copy">
<button class="code-box-copy__btn" title="Copy" type="button" data-clipboard-target="#kubeconfig"></button>
<pre><code class="language-yaml" id="kubeconfig">- name: {{ .UsernameClaim }}
user:
auth-provider:
config:
idp-issuer-url: {{ .Claims.iss }}
client-id: {{ .ClientID }}
id-token: {{ .IDToken }}
{{- if ne .RefreshToken "" }}
client-secret: {{ .ClientSecret }}
refresh-token: {{ .RefreshToken }}
{{- end }}
name: oidc</code></pre>
</div>
</li>
<li>
<label>Return to login page</label>
<input type="submit" value="Home" />
</li>
</ul>
</form>
</div>
<script src="assets/js/clipboard.min.js"></script>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/prism.min.js"></script>
<script src="assets/js/code-box-copy.min.js"></script>
<script>
$('.code-box-copy').codeBoxCopy();
</script>
</body>
</html>
`))
var indexTmpl = template.Must(template.ParseFiles("templates/index.html"))
var tokenTmpl = template.Must(template.ParseFiles("templates/token.html"))
21 changes: 21 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href=
"assets/css/form-style.min.css">
<script type="text/javascript">
function adjust_textarea(t){t.style.height="20px",t.style.height=t.scrollHeight+"px"}
</script>
<title>{{ .Name }}</title>
</head>
<body>
<form class="form-style-7" action="/login" method="post">
<h1>{{ .Name }}</h1>
<ul>
<li><label for="access">CLI access</label> <input name=
"access" type="submit" value="CLI"> <span>Login and retrieve
your kubeconfig for CLI authentication</span></li>
</ul>
</form>
</body>
</html>
55 changes: 55 additions & 0 deletions templates/token.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href=
"assets/css/code-box-copy.min.css">
<link rel="stylesheet" type="text/css" href=
"assets/css/prism.min.css">
<link rel="stylesheet" type="text/css" href=
"assets/css/form-style.min.css">
<title>{{ .Name }}</title>
</head>
<body>
<div class="form-style-7">
<h1>{{ .Name }}</h1>
<form class="form-style-7" action="/" method="get">
<ul>
<li>
<label>Copy this in your ~/.kube/config file</label>
<div class="code-box-copy">
<button class="code-box-copy__btn" title=
"Copy" type="button" data-clipboard-target="#kubeconfig">
</button>
<pre><code class="language-yaml" id=
"kubeconfig">- name: {{ .UsernameClaim }}
user:
auth-provider:
config:
idp-issuer-url: {{ .Claims.iss }}
client-id: {{ .ClientID }}
id-token: {{ .IDToken }}
{{- if ne .RefreshToken "" }}
client-secret: {{ .ClientSecret }}
refresh-token: {{ .RefreshToken }}
{{- end }}
name: oidc</code></pre>
</div>
</li>
<li><label>Return to login page</label> <input type=
"submit" value="Home"></li>
</ul>
</form>
</div>
<script src="assets/js/clipboard.min.js">
</script>
<script src="assets/js/jquery.min.js">
</script>
<script src="assets/js/prism.min.js">
</script>
<script src="assets/js/code-box-copy.min.js">
</script>
<script>
$('.code-box-copy').codeBoxCopy();
</script>
</body>
</html>

0 comments on commit 607bf14

Please sign in to comment.