diff options
author | Mike Crute <mike@crute.us> | 2021-11-16 14:46:24 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2021-11-17 07:56:10 -0800 |
commit | cc58a3da7d647de8520e33dc4356672d2ed1a366 (patch) | |
tree | 1b232a0d51446eb6370cfb13932190d31ce053df /templates | |
parent | a42d794a286154a3106551e6e483861af2a9ef16 (diff) | |
download | cloud-identity-broker-cc58a3da7d647de8520e33dc4356672d2ed1a366.tar.bz2 cloud-identity-broker-cc58a3da7d647de8520e33dc4356672d2ed1a366.tar.xz cloud-identity-broker-cc58a3da7d647de8520e33dc4356672d2ed1a366.zip |
Import of source code
Diffstat (limited to 'templates')
-rw-r--r-- | templates/404.tpl | 10 | ||||
-rw-r--r-- | templates/40x.tpl | 10 | ||||
-rw-r--r-- | templates/50x.tpl | 10 | ||||
-rw-r--r-- | templates/footer.tpl | 0 | ||||
-rw-r--r-- | templates/header.tpl | 0 | ||||
-rw-r--r-- | templates/index.tpl | 204 |
6 files changed, 234 insertions, 0 deletions
diff --git a/templates/404.tpl b/templates/404.tpl new file mode 100644 index 0000000..e87ed60 --- /dev/null +++ b/templates/404.tpl | |||
@@ -0,0 +1,10 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <html lang="en"> | ||
3 | <head> | ||
4 | <title>Not Found</title> | ||
5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
6 | </head> | ||
7 | <body> | ||
8 | <h1>Requested Resource Not Found</h1> | ||
9 | </body> | ||
10 | </html> | ||
diff --git a/templates/40x.tpl b/templates/40x.tpl new file mode 100644 index 0000000..c3f55c0 --- /dev/null +++ b/templates/40x.tpl | |||
@@ -0,0 +1,10 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <html lang="en"> | ||
3 | <head> | ||
4 | <title>Request Error</title> | ||
5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
6 | </head> | ||
7 | <body> | ||
8 | <h1>Request Error</h1> | ||
9 | </body> | ||
10 | </html> | ||
diff --git a/templates/50x.tpl b/templates/50x.tpl new file mode 100644 index 0000000..b8e1702 --- /dev/null +++ b/templates/50x.tpl | |||
@@ -0,0 +1,10 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <html lang="en"> | ||
3 | <head> | ||
4 | <title>Server Error</title> | ||
5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
6 | </head> | ||
7 | <body> | ||
8 | <h1>Server Error</h1> | ||
9 | </body> | ||
10 | </html> | ||
diff --git a/templates/footer.tpl b/templates/footer.tpl new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/templates/footer.tpl | |||
diff --git a/templates/header.tpl b/templates/header.tpl new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/templates/header.tpl | |||
diff --git a/templates/index.tpl b/templates/index.tpl new file mode 100644 index 0000000..cbc7a72 --- /dev/null +++ b/templates/index.tpl | |||
@@ -0,0 +1,204 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <html lang="en"> | ||
3 | <head> | ||
4 | <title>Select Account</title> | ||
5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
6 | <style type="text/css"> | ||
7 | body { | ||
8 | margin: 0 10%; | ||
9 | } | ||
10 | table { | ||
11 | width: 100%; | ||
12 | border: 1px solid black; | ||
13 | border-collapse: collapse; | ||
14 | } | ||
15 | td, th { | ||
16 | border: 1px solid black; | ||
17 | padding: 0.5em; | ||
18 | } | ||
19 | th { | ||
20 | background-color: #CCCCCC; | ||
21 | } | ||
22 | td.alt-creds { | ||
23 | text-align: center; | ||
24 | } | ||
25 | textarea { | ||
26 | height: 10em; | ||
27 | width: 100%; | ||
28 | } | ||
29 | a, a:visited { | ||
30 | color: blue; | ||
31 | } | ||
32 | h1 { | ||
33 | text-align: center; | ||
34 | } | ||
35 | tt { | ||
36 | background-color: #CCC; | ||
37 | border: 1px solid #999; | ||
38 | padding: 0.25em; | ||
39 | } | ||
40 | #api-key { | ||
41 | margin: auto; | ||
42 | } | ||
43 | #api-key textarea { | ||
44 | height: 100%; | ||
45 | } | ||
46 | #api-error { | ||
47 | border: 0.25em solid red; | ||
48 | color: white; | ||
49 | font-size: 2em; | ||
50 | background-color: #ff8080; | ||
51 | padding: 1em; | ||
52 | text-align: center; | ||
53 | display: none; | ||
54 | } | ||
55 | </style> | ||
56 | <script id="shell_template" type="text/template"> | ||
57 | export AWS_CREDS_EXPIRATION="[[ .expiration ]]" | ||
58 | export AWS_ACCESS_KEY_ID="[[ .access_key ]]" | ||
59 | export AWS_SECRET_ACCESS_KEY="[[ .secret_key ]]" | ||
60 | export AWS_SESSION_TOKEN="[[ .session_token ]]" | ||
61 | </script> | ||
62 | <script id="powershell_template" type="text/template"> | ||
63 | Set-Item -path env:AWS_CREDS_EXPIRATION -value '[[ .expiration ]]' | ||
64 | Set-Item -path env:AWS_ACCESS_KEY_ID -value '[[ .access_key ]]' | ||
65 | Set-Item -path env:AWS_SECRET_ACCESS_KEY -value '[[ .secret_key ]]' | ||
66 | Set-Item -path env:AWS_SESSION_TOKEN -value '[[ .session_token ]]' | ||
67 | </script> | ||
68 | <script id="aws_config_template" type="text/template"> | ||
69 | [profile [[ .ShortName ]]] | ||
70 | aws_access_key_id=[[ .access_key ]] | ||
71 | aws_secret_access_key=[[ .secret_key ]] | ||
72 | aws_session_token=[[ .session_token ]] | ||
73 | expiration=[[ .expiration ]] | ||
74 | </script> | ||
75 | <script id="credential_row_template" type="text/template"> | ||
76 | <body> | ||
77 | <tr id="credentials-for-[[ .Account ]]"> | ||
78 | <td colspan="2"> | ||
79 | <textarea>[[ .Content ]]</textarea> | ||
80 | <button>Close</button> | ||
81 | </td> | ||
82 | </tr> | ||
83 | </body> | ||
84 | </script> | ||
85 | <script id="account_row_template" type="text/template"> | ||
86 | <tr id="account-row-[[ .short_name ]]" data-account-name="[[ .short_name ]]" data-global-credential-endpoint="[[ .global_credential_url ]]"> | ||
87 | <td>[[ .name ]]</td> | ||
88 | <td class="alt-creds"> | ||
89 | <a href="[[ .console_redirect_url ]]">Console</a> | | ||
90 | <a data-template="aws_config_template" href="#/cli/[[ .short_name ]]">AWS CLI</a> | | ||
91 | <a data-template="shell_template" href="#/sh/[[ .short_name ]]">Bash</a> | | ||
92 | <a data-template="powershell_template" href="#/ps/[[ .short_name ]]">Powershell</a> | ||
93 | </td> | ||
94 | </tr> | ||
95 | </script> | ||
96 | <script type="text/javascript"> | ||
97 | function fillTemplate(templateId, values) { | ||
98 | var tpl = document.getElementById(templateId).text; | ||
99 | |||
100 | Object.keys(values).forEach(function(key) { | ||
101 | tpl = tpl.replace(new RegExp("\\[\\[ \\." + key + " \\]\\]", "g"), values[key]); | ||
102 | }); | ||
103 | |||
104 | var out = []; | ||
105 | tpl.split("\n").forEach(function(line) { | ||
106 | line = line.replace(/^\s+/, "").replace(/\s+$/, ""); | ||
107 | if (line !== "") { | ||
108 | out.push(line); | ||
109 | } | ||
110 | }); | ||
111 | |||
112 | return out.join("\n"); | ||
113 | } | ||
114 | |||
115 | function getJSON(response) { | ||
116 | if (!response.ok) { | ||
117 | document.getElementById("api-error").style.display = "block"; | ||
118 | throw new Error("Error loading api"); | ||
119 | } | ||
120 | |||
121 | return response.json(); | ||
122 | } | ||
123 | |||
124 | function accountTableLinkClick(event) { | ||
125 | event.preventDefault(); | ||
126 | |||
127 | var thisRow = event.target.parentElement.parentElement; | ||
128 | var template = event.target.getAttribute("data-template"); | ||
129 | var account = thisRow.getAttribute("data-account-name"); | ||
130 | var credentialEndpoint = thisRow.getAttribute("data-global-credential-endpoint"); | ||
131 | var oldText = event.target.text; | ||
132 | |||
133 | var existingTr = document.getElementById("credentials-for-" + account); | ||
134 | if (existingTr) { | ||
135 | existingTr.remove(); | ||
136 | } | ||
137 | |||
138 | event.target.text = "Loading..."; | ||
139 | |||
140 | fetch(credentialEndpoint).then(getJSON).then(function(vals) { | ||
141 | vals["ShortName"] = account; | ||
142 | |||
143 | var newTr = fillTemplate("credential_row_template", { | ||
144 | "Account": account, | ||
145 | "Content": fillTemplate(template, vals) | ||
146 | }); | ||
147 | |||
148 | event.target.text = oldText; | ||
149 | thisRow.insertAdjacentHTML("afterend", newTr); | ||
150 | thisRow.nextElementSibling.getElementsByTagName("button")[0].addEventListener("click", function(event) { | ||
151 | event.target.parentNode.parentNode.remove(); | ||
152 | }); | ||
153 | }); | ||
154 | |||
155 | return false; | ||
156 | } | ||
157 | |||
158 | function populateAccountTable() { | ||
159 | fetch("/api/account").then(getJSON).then(function(response) { | ||
160 | response.forEach(populateAccountRow); | ||
161 | }); | ||
162 | } | ||
163 | |||
164 | function populateAccountRow(row) { | ||
165 | var out = fillTemplate("account_row_template", row); | ||
166 | document.querySelector("#account-table tr").insertAdjacentHTML("afterend", out); | ||
167 | |||
168 | document.querySelectorAll("#account-row-" + row["short_name"] + " a[data-template]").forEach(function(element) { | ||
169 | element.addEventListener("click", accountTableLinkClick); | ||
170 | }); | ||
171 | } | ||
172 | |||
173 | function getCookie(name) { | ||
174 | return document.cookie.match(new RegExp(name + "=\"?([^;\"]*)\"?;?"))[1]; | ||
175 | } | ||
176 | |||
177 | function populateAPIKey() { | ||
178 | document.querySelector("#api-key textarea").innerText = getCookie("session"); | ||
179 | document.querySelector("#session-expires").innerText = getCookie("session-expires"); | ||
180 | } | ||
181 | |||
182 | window.addEventListener('load', populateAPIKey); | ||
183 | window.addEventListener('load', populateAccountTable); | ||
184 | </script> | ||
185 | </head> | ||
186 | <body> | ||
187 | <p id="api-error">Error communicating with the API.</p> | ||
188 | |||
189 | <h1>AWS Accounts</h1> | ||
190 | <table id="account-table"> | ||
191 | <tr> | ||
192 | <th>Console Login</th> | ||
193 | <th>Get Credentials</th> | ||
194 | </tr> | ||
195 | </table> | ||
196 | |||
197 | <h1>API Key</h1> | ||
198 | <div id="api-key"> | ||
199 | <p>To access <a href="/api/account">the API</a> set the value of <tt>Authorization</tt> header to:</p> | ||
200 | <textarea>Bearer {token}</textarea> | ||
201 | <p><b>Token Expires:</b> <span id="session-expires"></span></p> | ||
202 | </div> | ||
203 | </body> | ||
204 | </html> | ||