diff options
author | Mike Crute <mike@crute.us> | 2021-11-24 10:27:36 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2021-11-24 10:28:20 -0800 |
commit | ff05652956161dd94aa109e2c5d40bd82d4cfd5d (patch) | |
tree | 67a9e756e64a1e42538e25e46da92c3dd29ba23c /templates | |
parent | 7ba9e94bae1cbeba7fc7e390d09e2821ba46b996 (diff) | |
download | cloud-identity-broker-ff05652956161dd94aa109e2c5d40bd82d4cfd5d.tar.bz2 cloud-identity-broker-ff05652956161dd94aa109e2c5d40bd82d4cfd5d.tar.xz cloud-identity-broker-ff05652956161dd94aa109e2c5d40bd82d4cfd5d.zip |
Move credential rendering to server
Diffstat (limited to 'templates')
-rw-r--r-- | templates/assets/site.js | 18 | ||||
-rw-r--r-- | templates/index.tpl | 27 |
2 files changed, 13 insertions, 32 deletions
diff --git a/templates/assets/site.js b/templates/assets/site.js index 485a4cd..ebf9f5f 100644 --- a/templates/assets/site.js +++ b/templates/assets/site.js | |||
@@ -29,9 +29,7 @@ function accountTableLinkClick(event) { | |||
29 | event.preventDefault(); | 29 | event.preventDefault(); |
30 | 30 | ||
31 | var thisRow = event.target.parentElement.parentElement; | 31 | var thisRow = event.target.parentElement.parentElement; |
32 | var template = event.target.getAttribute("data-template"); | 32 | var account = thisRow.dataset["accountName"]; |
33 | var account = thisRow.getAttribute("data-account-name"); | ||
34 | var credentialEndpoint = thisRow.getAttribute("data-global-credential-endpoint"); | ||
35 | var oldText = event.target.text; | 33 | var oldText = event.target.text; |
36 | 34 | ||
37 | var existingTr = document.getElementById("credentials-for-" + account); | 35 | var existingTr = document.getElementById("credentials-for-" + account); |
@@ -41,12 +39,14 @@ function accountTableLinkClick(event) { | |||
41 | 39 | ||
42 | event.target.text = "Loading..."; | 40 | event.target.text = "Loading..."; |
43 | 41 | ||
44 | fetch(credentialEndpoint).then(getJSON).then(function(vals) { | 42 | fetch(thisRow.dataset["globalCredentialEndpoint"], { |
45 | vals["ShortName"] = account; | 43 | "headers": { |
46 | 44 | "Accept": event.target.dataset["contentType"] | |
45 | } | ||
46 | }).then(r => r.text()).then(function(text) { | ||
47 | var newTr = fillTemplate("credential_row_template", { | 47 | var newTr = fillTemplate("credential_row_template", { |
48 | "Account": account, | 48 | "Account": account, |
49 | "Content": fillTemplate(template, vals) | 49 | "Content": text, |
50 | }); | 50 | }); |
51 | 51 | ||
52 | event.target.text = oldText; | 52 | event.target.text = oldText; |
@@ -69,8 +69,8 @@ function populateAccountRow(row) { | |||
69 | var out = fillTemplate("account_row_template", row); | 69 | var out = fillTemplate("account_row_template", row); |
70 | document.querySelector("#account-table tr").insertAdjacentHTML("afterend", out); | 70 | document.querySelector("#account-table tr").insertAdjacentHTML("afterend", out); |
71 | 71 | ||
72 | document.querySelectorAll("#account-row-" + row["short_name"] + " a[data-template]").forEach(function(element) { | 72 | document.querySelectorAll(".account-row a[data-content-type]").forEach(function(e) { |
73 | element.addEventListener("click", accountTableLinkClick); | 73 | e.addEventListener("click", accountTableLinkClick); |
74 | }); | 74 | }); |
75 | } | 75 | } |
76 | 76 | ||
diff --git a/templates/index.tpl b/templates/index.tpl index da0b59e..c8c95d4 100644 --- a/templates/index.tpl +++ b/templates/index.tpl | |||
@@ -4,25 +4,6 @@ | |||
4 | <title>Select Account</title> | 4 | <title>Select Account</title> |
5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
6 | <link rel="stylesheet" type="text/css" href="/assets/site.css" /> | 6 | <link rel="stylesheet" type="text/css" href="/assets/site.css" /> |
7 | <script id="shell_template" type="text/template"> | ||
8 | export AWS_CREDS_EXPIRATION="[[ .expiration ]]" | ||
9 | export AWS_ACCESS_KEY_ID="[[ .access_key ]]" | ||
10 | export AWS_SECRET_ACCESS_KEY="[[ .secret_key ]]" | ||
11 | export AWS_SESSION_TOKEN="[[ .session_token ]]" | ||
12 | </script> | ||
13 | <script id="powershell_template" type="text/template"> | ||
14 | Set-Item -path env:AWS_CREDS_EXPIRATION -value '[[ .expiration ]]' | ||
15 | Set-Item -path env:AWS_ACCESS_KEY_ID -value '[[ .access_key ]]' | ||
16 | Set-Item -path env:AWS_SECRET_ACCESS_KEY -value '[[ .secret_key ]]' | ||
17 | Set-Item -path env:AWS_SESSION_TOKEN -value '[[ .session_token ]]' | ||
18 | </script> | ||
19 | <script id="aws_config_template" type="text/template"> | ||
20 | [profile [[ .ShortName ]]] | ||
21 | aws_access_key_id=[[ .access_key ]] | ||
22 | aws_secret_access_key=[[ .secret_key ]] | ||
23 | aws_session_token=[[ .session_token ]] | ||
24 | expiration=[[ .expiration ]] | ||
25 | </script> | ||
26 | <script id="credential_row_template" type="text/template"> | 7 | <script id="credential_row_template" type="text/template"> |
27 | <tr id="credentials-for-[[ .Account ]]"> | 8 | <tr id="credentials-for-[[ .Account ]]"> |
28 | <td colspan="3"> | 9 | <td colspan="3"> |
@@ -32,14 +13,14 @@ | |||
32 | </tr> | 13 | </tr> |
33 | </script> | 14 | </script> |
34 | <script id="account_row_template" type="text/template"> | 15 | <script id="account_row_template" type="text/template"> |
35 | <tr id="account-row-[[ .short_name ]]" data-account-name="[[ .short_name ]]" data-global-credential-endpoint="[[ .global_credential_url ]]"> | 16 | <tr id="account-row-[[ .short_name ]]" class="account-row" data-account-name="[[ .short_name ]]" data-global-credential-endpoint="[[ .global_credential_url ]]"> |
36 | <td>[[ .name ]]</td> | 17 | <td>[[ .name ]]</td> |
37 | <td>[[ .vendor ]]</td> | 18 | <td>[[ .vendor ]]</td> |
38 | <td> | 19 | <td> |
39 | <a href="[[ .console_redirect_url ]]">Console</a> | | 20 | <a href="[[ .console_redirect_url ]]">Console</a> | |
40 | <a data-template="aws_config_template" href="#/cli/[[ .short_name ]]">AWS CLI</a> | | 21 | <a data-content-type="application/vnd.broker.v2.credential.aws.ini" href="#/cli/[[ .short_name ]]">AWS CLI</a> | |
41 | <a data-template="shell_template" href="#/sh/[[ .short_name ]]">Bash</a> | | 22 | <a data-content-type="application/vnd.broker.v2.credential.aws.sh" href="#/sh/[[ .short_name ]]">Bash</a> | |
42 | <a data-template="powershell_template" href="#/ps/[[ .short_name ]]">Powershell</a> | 23 | <a data-content-type="application/vnd.broker.v2.credential.aws.psl" href="#/ps/[[ .short_name ]]">Powershell</a> |
43 | <span class="admin">| <a>Edit</a></span> | 24 | <span class="admin">| <a>Edit</a></span> |
44 | </td> | 25 | </td> |
45 | </tr> | 26 | </tr> |