Last active
January 26, 2022 16:59
-
-
Save josharrington/9be84caa72431cfa900f2762d6c8fa0e to your computer and use it in GitHub Desktop.
AWS SSO Surface Account Name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name AWS SSO Display Account | |
// @namespace http://tampermonkey.net/ | |
// @version 0.6 | |
// @description This will make the account switcher show the account name and role when using AWS SSO | |
// @author josharrington | |
// @include /^https?://([\-\d\w]+\.)?console\.aws\.amazon\.com/.*/ | |
// @icon https://www.google.com/s2/favicons?domain=amazon.com | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var accountMapping = { | |
// You can add accounts here to customize the behavior and change the name or color. | |
// Color can be any CSS color including hex in format #abc123 | |
"1234567890" : {"name": "Custom-Name", "color": "#d6146ec4"}, | |
} | |
const regex = /AWSReservedSSO_(\w+)_\w+\/([\w\.@\+]+)/ | |
var sso_string = document.querySelector("#menu--account > div[class*='globalNav'] > div > div:nth-child(2) > span:nth-child(2)"); | |
var switcher = document.querySelector("#nav-usernameMenu > span > span"); | |
try { | |
const match = sso_string.innerText.match(regex); | |
var accountNumber = document.querySelector("#menu--account > div[class*='globalNav'] div > div:nth-child(1) > span:nth-child(2)").innerText.replaceAll('-', ''); | |
var name = "Unknown"; | |
if (accountMapping[accountNumber]) { | |
name = accountMapping[accountNumber].name; | |
if (accountMapping[accountNumber].color) { | |
switcher.style = "background-color: " + (accountMapping[accountNumber].color ?? "null") + ";"; | |
} | |
} | |
switcher.innerText = `AWS SSO: ${match[1]}/${match[2]} @ ${name} (${accountNumber})`; | |
} catch (e) { | |
console.log("We don't appear to be using AWS SSO. TamperMonkey Script will ignore this.") | |
return; | |
} | |
})(); |
Is it possible to fetch account name via a api call?
The account name was on the page already so I used that for this script.
Account names can be retrieved via the organizations api but I'm unsure if
you could access that from a Greasemonkey script
https://docs.aws.amazon.com/cli/latest/reference/organizations/describe-account.html
…On Sat, Sep 11, 2021, 6:06 PM Zheng SHAO ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Is it possible to fetch account name via a api call?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/9be84caa72431cfa900f2762d6c8fa0e#gistcomment-3890000>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAREHKHW7ZZL7PBSTYOMHLLUBPOITANCNFSM45N6L5ZQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
Updated to work with the new aws console
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Click on Raw to install into TamperMonkey