├── .github └── workflows │ └── deploy.yml ├── .gitignore ├── 2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D.png ├── Makefile ├── README.md ├── icon.png └── info.plist /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy 2 | 3 | on: 4 | push: 5 | tags: 6 | - v* 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v1 16 | - name: Build 17 | run: make all 18 | - name: Release 19 | uses: softprops/action-gh-release@v1 20 | if: startsWith(github.ref, 'refs/tags/') 21 | with: 22 | files: Open_AWS_via_aws-vault.alfredworkflow 23 | env: 24 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.alfredworkflow 2 | -------------------------------------------------------------------------------- /2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kangaechu/aws-vault-alfred-workflow/8c93fbbbd8e4a0d1ffdc24d29b6baf8abcfdfadf/2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D.png -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | 3 | all: 4 | zip -j9 --filesync "Open_AWS_via_aws-vault.alfredworkflow" *.{plist,png,py} 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aws-vault-alfred-workflow 2 | 3 | Open the AWS management console via aws-vault. 4 | 5 | ![mymovie](https://user-images.githubusercontent.com/989985/67284090-dea23e00-f50f-11e9-9ce5-a94d53e39a5f.gif) 6 | 7 | ## Overview 8 | 9 | aws-vault is a tool for securely managing AWS credentials and authenticating multiple AWS accounts via assumeRole. `aws-vault login` is useful, but the browser cannot open multiple AWS accounts at the same time. This workflow creates a browser profile for each AWS account and opens a window for each profile. 10 | It allows you to open multiple AWS accounts at the same time. 11 | 12 | ## How to use 13 | 14 | `aws [profile name]` 15 | 16 | The profile name corresponds to the profile name in `$HOME/.aws/config`. 17 | Internally launch the `aws-vault login` command and launch your browser with a separate profile. 18 | 19 | ## Support browsers 20 | 21 | - Google Chrome 22 | - Firefox 23 | - Firefox Containers 24 | 25 | When you want to use firefox, follow this instructions. 26 | 27 | 1. Open Alfred Preference, then open Workflows. 28 | 2. Select Open AWS via aws-vault. 29 | 3. Select [x] icon. 30 | 4. From Workflow Environment Variables, change preferred_browser variable from `chrome` to `firefox`. 31 | 32 | When you want to use Firefox Containers, follow this instructions. 33 | 34 | 1. Install [Firefox Multi-Account Containers](https://addons.mozilla.org/en-US/firefox/addon/multi-account-containers/) and [Open external links in a container](https://addons.mozilla.org/en-US/firefox/addon/open-url-in-container/). 35 | 2. Open Alfred Preference, then open Workflows. 36 | 3. Select Open AWS via aws-vault. 37 | 4. Select [x] icon. 38 | 5. From Workflow Environment Variables, change preferred_browser variable from `chrome` to `firefox-containers`. 39 | 40 | ## Requirements 41 | 42 | 1. [Alfred 4 or later](https://www.alfredapp.com/#download) 43 | 1. [Alfred Powerpack](https://www.alfredapp.com/shop/) 44 | 1. [aws-vault](https://github.com/99designs/aws-vault) 45 | 46 | ## Installing 47 | 48 | 1. Download workflow from [packal](http://www.packal.org/workflow/open-aws-aws-vault) or [Release](https://github.com/kangaechu/aws-vault-alfred-workflow/releases). 49 | 2. Double-click to import into Alfred. 50 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kangaechu/aws-vault-alfred-workflow/8c93fbbbd8e4a0d1ffdc24d29b6baf8abcfdfadf/icon.png -------------------------------------------------------------------------------- /info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleid 6 | com.kangaechu.aws-vault-alfred-workflow 7 | category 8 | Tools 9 | connections 10 | 11 | 2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D 12 | 13 | 14 | destinationuid 15 | BCF9D88B-14B0-4B42-AE3C-411695BDC870 16 | modifiers 17 | 0 18 | modifiersubtext 19 | 20 | vitoclose 21 | 22 | 23 | 24 | BCF9D88B-14B0-4B42-AE3C-411695BDC870 25 | 26 | 27 | destinationuid 28 | 16039760-F173-4AB8-9C73-DA7401D5DE23 29 | modifiers 30 | 0 31 | modifiersubtext 32 | 33 | vitoclose 34 | 35 | 36 | 37 | 38 | createdby 39 | kangaechu 40 | description 41 | Open AWS via aws-vault 42 | disabled 43 | 44 | name 45 | Open AWS via aws-vault 46 | objects 47 | 48 | 49 | config 50 | 51 | alfredfiltersresults 52 | 53 | alfredfiltersresultsmatchmode 54 | 0 55 | argumenttreatemptyqueryasnil 56 | 57 | argumenttrimmode 58 | 0 59 | argumenttype 60 | 1 61 | escaping 62 | 0 63 | keyword 64 | aws 65 | queuedelaycustom 66 | 3 67 | queuedelayimmediatelyinitially 68 | 69 | queuedelaymode 70 | 0 71 | queuemode 72 | 1 73 | runningsubtext 74 | 75 | script 76 | #!/bin/bash 77 | 78 | set -e 79 | 80 | # load system path 81 | eval "$(/usr/libexec/path_helper -s)" 82 | 83 | function fetch(){ 84 | result=$(aws-vault list) 85 | if [[ $? -ne 0 ]]; then 86 | echo "error on running aws-vault list" 87 | echo "${result}" >&2 88 | exit 1 89 | fi 90 | echo "${result}" 91 | } 92 | 93 | function parse(){ 94 | local aws_vault_result="$1" 95 | echo "${aws_vault_result}" | tail +3 | cut -f 1 -d' ' | grep -Ev '^-$' 96 | } 97 | 98 | function format_alfred(){ 99 | local profiles="$1" 100 | local profiles_max_lines=$(echo -n "${profiles}" | grep -c '^') 101 | local i=0 102 | 103 | echo '{"items": [' 104 | for profile in ${profiles}; do 105 | cat << EOS 106 | { 107 | "uid": "${profile}", 108 | "title": "${profile}", 109 | "arg": "${profile}", 110 | "icon": {"path": "icon.png"}, 111 | "autocomplete": "${profile}" 112 | EOS 113 | i=$(( i+1 )) 114 | if [[ $i -eq $profiles_max_lines ]]; then 115 | echo ' }' 116 | else 117 | echo ' },' 118 | fi 119 | done 120 | echo ']}' 121 | 122 | } 123 | 124 | aws_vault_result=$(fetch) 125 | profiles=$(parse "${aws_vault_result}") 126 | format_alfred "${profiles}" 127 | 128 | scriptargtype 129 | 1 130 | scriptfile 131 | format_aws_vault_profiles.sh 132 | subtext 133 | profiles 134 | title 135 | Open AWS via aws-vault 136 | type 137 | 0 138 | withspace 139 | 140 | 141 | type 142 | alfred.workflow.input.scriptfilter 143 | uid 144 | 2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D 145 | version 146 | 3 147 | 148 | 149 | config 150 | 151 | concurrently 152 | 153 | escaping 154 | 102 155 | script 156 | aws_account=${1:-$default_profile} 157 | aws_account=${aws_account// /} # trim space 158 | 159 | AWS_ASSUME_ROLE_TTL=${AWS_ASSUME_ROLE_TTL:-1h} 160 | AWS_FEDERATION_TOKEN_TTL=${AWS_FEDERATION_TOKEN_TTL:-1h} 161 | export AWS_VAULT_PROMPT="${AWS_VAULT_PROMPT:-osascript}" 162 | 163 | # load system path 164 | eval "$(/usr/libexec/path_helper -s)" 165 | 166 | firefox-bin() { 167 | "${firefox_path:-/Applications/Firefox.app/Contents/MacOS/firefox}" "$@" 168 | } 169 | 170 | login_url="$(aws-vault login "$aws_account" --stdout)" 171 | 172 | if [[ $? -ne 0 ]] then; 173 | osascript -e 'display dialog "AWS Authentication failed"' 174 | echo ${login_url} > /tmp/aws-vault-login-${aws_account}-$(date +"%Y%m%d_%H%M%S").log 175 | exit 1 176 | fi 177 | 178 | if [[ ${preferred_browser} == "firefox" ]]; then 179 | open -na firefox --args --profile $HOME/Library/Application\ Support/Firefox/Profiles/aws-vault/${aws_account} ${login_url} 180 | 181 | elif [[ ${preferred_browser} == "chrome" ]]; then 182 | open -na "Google Chrome" --args --user-data-dir=$HOME/Library/Application\ Support/Google/Chrome/aws-vault/${aws_account} ${login_url} 183 | 184 | elif [[ ${preferred_browser} == "firefox-containers" ]]; then 185 | # to work install add-on: 186 | # https://addons.mozilla.org/en-US/firefox/addon/open-url-in-container/ 187 | 188 | ENCODED_URL="${login_url//&/%26}" 189 | URI_HANDLER="ext+container:name=${aws_account}&url=${ENCODED_URL}" 190 | 191 | firefox-bin "${URI_HANDLER}" 192 | fi 193 | 194 | scriptargtype 195 | 1 196 | scriptfile 197 | 198 | type 199 | 5 200 | 201 | type 202 | alfred.workflow.action.script 203 | uid 204 | 16039760-F173-4AB8-9C73-DA7401D5DE23 205 | version 206 | 2 207 | 208 | 209 | config 210 | 211 | argument 212 | {query} 213 | variables 214 | 215 | aws_vault_path 216 | {var:aws_vault_path} 217 | default_profile 218 | {var:default_profile} 219 | 220 | 221 | type 222 | alfred.workflow.utility.argument 223 | uid 224 | BCF9D88B-14B0-4B42-AE3C-411695BDC870 225 | version 226 | 1 227 | 228 | 229 | readme 230 | Open the AWS management console via aws-vault. 231 | 232 | aws-vault is a tool for securely managing AWS credentials and authenticating multiple AWS accounts via assumeRole. `aws-vault login` is useful, but the browser cannot open multiple AWS accounts at the same time. This workflow creates a browser profile for each AWS account and opens a window for each profile. 233 | It allows you to open multiple AWS accounts at the same time. 234 | uidata 235 | 236 | 16039760-F173-4AB8-9C73-DA7401D5DE23 237 | 238 | xpos 239 | 500 240 | ypos 241 | 60 242 | 243 | 2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D 244 | 245 | xpos 246 | 235 247 | ypos 248 | 60 249 | 250 | BCF9D88B-14B0-4B42-AE3C-411695BDC870 251 | 252 | xpos 253 | 405 254 | ypos 255 | 90 256 | 257 | 258 | variables 259 | 260 | aws_vault_path 261 | /usr/local/bin/aws-vault 262 | default_profile 263 | 264 | firefox_path 265 | /Applications/Firefox.app/Contents/MacOS/firefox 266 | preferred_browser 267 | chrome 268 | 269 | variablesdontexport 270 | 271 | default_profile 272 | 273 | version 274 | 0.0.7 275 | webaddress 276 | https://github.com/kangaechu/aws-vault-alfred-workflow 277 | 278 | 279 | --------------------------------------------------------------------------------