4343 <string >Open AWS via aws-vault </string >
4444 <key >objects </key >
4545 <array >
46- <dict >
47- <key >config </key >
48- <dict >
49- <key >concurrently </key >
50- <false />
51- <key >escaping </key >
52- <integer >102 </integer >
53- <key >script </key >
54- <string >aws_account=${1:-$default_profile}
55- aws_account=${aws_account// /} # trim space
56-
57- AWS_ASSUME_ROLE_TTL=${AWS_ASSUME_ROLE_TTL:-1h}
58- AWS_FEDERATION_TOKEN_TTL=${AWS_FEDERATION_TOKEN_TTL:-1h}
59-
60- login_url=$(aws-vault login ${aws_account} --prompt=osascript --stdout)
61-
62- if [[ $? -ne 0 ]] then;
63- osascript -e 'display dialog "AWS Authentication failed"'
64- echo ${login_url} > /tmp/aws-vault-login-${aws_account}-$(date +"%Y%m%d_%H%M%S").log
65- exit 1
66- fi
67-
68- open -na "Google Chrome" --args --user-data-dir=$HOME/Library/Application\ Support/Google/Chrome/aws-vault/${aws_account} ${login_url} </string >
69- <key >scriptargtype </key >
70- <integer >1 </integer >
71- <key >scriptfile </key >
72- <string ></string >
73- <key >type </key >
74- <integer >5 </integer >
75- </dict >
76- <key >type </key >
77- <string >alfred.workflow.action.script </string >
78- <key >uid </key >
79- <string >16039760-F173-4AB8-9C73-DA7401D5DE23 </string >
80- <key >version </key >
81- <integer >2 </integer >
82- </dict >
8346 <dict >
8447 <key >config </key >
8548 <dict >
@@ -108,7 +71,55 @@ open -na "Google Chrome" --args --user-data-dir=$HOME/Library/Application\ Suppo
10871 <key >runningsubtext </key >
10972 <string ></string >
11073 <key >script </key >
111- <string ></string >
74+ <string >#!/bin/bash
75+
76+ set -e
77+
78+ function fetch(){
79+ local aws_vault_path=${aws_vault_path:-/usr/local/bin/aws-vault}
80+ result=$(${aws_vault_path} list)
81+ if [[ $? -ne 0 ]]; then
82+ echo "error on running aws-vault list"
83+ echo "${result}" >& 2
84+ exit 1
85+ fi
86+ echo "${result}"
87+ }
88+
89+ function parse(){
90+ local aws_vault_result="$1"
91+ echo "${aws_vault_result}" | tail +3 | cut -f 1 -d' ' | grep -Ev '^-$'
92+ }
93+
94+ function format_alfred(){
95+ local profiles="$1"
96+ local profiles_max_lines=$(echo -n "${profiles}" | grep -c '^')
97+ local i=0
98+
99+ echo '{"items": ['
100+ for profile in ${profiles}; do
101+ cat << EOS
102+ {
103+ "uid": "${profile}",
104+ "title": "${profile}",
105+ "arg": "${profile}",
106+ "icon": {"path": "icon.png"},
107+ "autocomplete": "${profile}"
108+ EOS
109+ i=$(( i+1 ))
110+ if [[ $i -eq $profiles_max_lines ]]; then
111+ echo ' }'
112+ else
113+ echo ' },'
114+ fi
115+ done
116+ echo ']}'
117+
118+ }
119+
120+ aws_vault_result=$(fetch)
121+ profiles=$(parse "${aws_vault_result}")
122+ format_alfred "${profiles}" </string >
112123 <key >scriptargtype </key >
113124 <integer >1 </integer >
114125 <key >scriptfile </key >
@@ -118,7 +129,7 @@ open -na "Google Chrome" --args --user-data-dir=$HOME/Library/Application\ Suppo
118129 <key >title </key >
119130 <string >Open AWS via aws-vault </string >
120131 <key >type </key >
121- <integer >8 </integer >
132+ <integer >0 </integer >
122133 <key >withspace </key >
123134 <true />
124135 </dict >
@@ -129,6 +140,43 @@ open -na "Google Chrome" --args --user-data-dir=$HOME/Library/Application\ Suppo
129140 <key >version </key >
130141 <integer >3 </integer >
131142 </dict >
143+ <dict >
144+ <key >config </key >
145+ <dict >
146+ <key >concurrently </key >
147+ <false />
148+ <key >escaping </key >
149+ <integer >102 </integer >
150+ <key >script </key >
151+ <string >aws_account=${1:-$default_profile}
152+ aws_account=${aws_account// /} # trim space
153+
154+ AWS_ASSUME_ROLE_TTL=${AWS_ASSUME_ROLE_TTL:-1h}
155+ AWS_FEDERATION_TOKEN_TTL=${AWS_FEDERATION_TOKEN_TTL:-1h}
156+
157+ login_url=$(aws-vault login ${aws_account} --prompt=osascript --stdout)
158+
159+ if [[ $? -ne 0 ]] then;
160+ osascript -e 'display dialog "AWS Authentication failed"'
161+ echo ${login_url} > /tmp/aws-vault-login-${aws_account}-$(date +"%Y%m%d_%H%M%S").log
162+ exit 1
163+ fi
164+
165+ open -na "Google Chrome" --args --user-data-dir=$HOME/Library/Application\ Support/Google/Chrome/aws-vault/${aws_account} ${login_url} </string >
166+ <key >scriptargtype </key >
167+ <integer >1 </integer >
168+ <key >scriptfile </key >
169+ <string ></string >
170+ <key >type </key >
171+ <integer >5 </integer >
172+ </dict >
173+ <key >type </key >
174+ <string >alfred.workflow.action.script </string >
175+ <key >uid </key >
176+ <string >16039760-F173-4AB8-9C73-DA7401D5DE23 </string >
177+ <key >version </key >
178+ <integer >2 </integer >
179+ </dict >
132180 <dict >
133181 <key >config </key >
134182 <dict >
@@ -184,12 +232,14 @@ It allows you to open multiple AWS accounts at the same time.</string>
184232 <key >aws_vault_path </key >
185233 <string >/usr/local/bin/aws-vault </string >
186234 <key >default_profile </key >
187- <string >default </string >
235+ <string ></string >
188236 </dict >
189237 <key >variablesdontexport </key >
190- <array />
238+ <array >
239+ <string >default_profile </string >
240+ </array >
191241 <key >version </key >
192- <string >0.0.2 </string >
242+ <string >0.0.3 </string >
193243 <key >webaddress </key >
194244 <string >https://github.com/kangaechu/aws-vault-alfred-workflow </string >
195245</dict >
0 commit comments