Skip to content

Commit 81a4446

Browse files
committed
implement autocompletion
1 parent 8e05804 commit 81a4446

File tree

5 files changed

+182
-22
lines changed

5 files changed

+182
-22
lines changed

.github/workflows/deploy.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.alfredworkflow

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SHELL=/bin/bash
2+
3+
all:
4+
zip -j9 --filesync "Open_AWS_via_aws-vault.alfredworkflow" *.{plist,png,py}

format_aws_vault_profiles.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
3+
import subprocess
4+
import sys
5+
import json
6+
import os
7+
8+
9+
def fetch():
10+
if 'aws_vault_path' in os.environ:
11+
aws_vault_path = os.environ['aws_vault_path']
12+
else:
13+
aws_vault_path = "/usr/local/bin/aws-vault"
14+
15+
try:
16+
result = subprocess.run([aws_vault_path, "list"], stdout=subprocess.PIPE)
17+
except:
18+
print("error on running aws-vault list")
19+
sys.stderr.buffer.write(result.stdout)
20+
exit(1)
21+
22+
return result.stdout.decode()
23+
24+
25+
def parse(aws_vault_result):
26+
# skip first 2 lines (header)
27+
profiles = []
28+
for profile in aws_vault_result.splitlines()[2:]:
29+
if profile.split()[0] == '-':
30+
continue
31+
profiles.append(profile.split()[0])
32+
return profiles
33+
34+
def format_alfred(profiles):
35+
formatted_profiles = []
36+
for profile in profiles:
37+
formatted_profiles.append({
38+
"uid": profile,
39+
"title": profile,
40+
"arg": profile,
41+
"icon": {"path": "icon.png"},
42+
"autocomplete": profile
43+
})
44+
45+
return json.dumps({"items" : formatted_profiles}, indent=2)
46+
47+
def run():
48+
aws_vault_result = fetch()
49+
profiles = parse(aws_vault_result)
50+
alfred_json = format_alfred(profiles)
51+
return alfred_json
52+
53+
54+
if __name__ == '__main__':
55+
print(run())

info.plist

Lines changed: 98 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44
<dict>
55
<key>bundleid</key>
66
<string>com.kangaechu.aws-vault-alfred-workflow</string>
7-
<key>category</key>
8-
<string>Internet</string>
97
<key>connections</key>
108
<dict>
119
<key>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</key>
10+
<array>
11+
<dict>
12+
<key>destinationuid</key>
13+
<string>BCF9D88B-14B0-4B42-AE3C-411695BDC870</string>
14+
<key>modifiers</key>
15+
<integer>0</integer>
16+
<key>modifiersubtext</key>
17+
<string></string>
18+
<key>vitoclose</key>
19+
<false/>
20+
</dict>
21+
</array>
22+
<key>BCF9D88B-14B0-4B42-AE3C-411695BDC870</key>
1223
<array>
1324
<dict>
1425
<key>destinationuid</key>
@@ -25,13 +36,62 @@
2536
<key>createdby</key>
2637
<string>kangaechu</string>
2738
<key>description</key>
28-
<string>Open AWS in Google Chrome via aws-vault</string>
39+
<string>Open AWS via aws-vault</string>
2940
<key>disabled</key>
3041
<false/>
3142
<key>name</key>
32-
<string>Open AWS in Google Chrome via aws-vault</string>
43+
<string>Open AWS via aws-vault</string>
3344
<key>objects</key>
3445
<array>
46+
<dict>
47+
<key>config</key>
48+
<dict>
49+
<key>alfredfiltersresults</key>
50+
<true/>
51+
<key>alfredfiltersresultsmatchmode</key>
52+
<integer>0</integer>
53+
<key>argumenttreatemptyqueryasnil</key>
54+
<true/>
55+
<key>argumenttrimmode</key>
56+
<integer>0</integer>
57+
<key>argumenttype</key>
58+
<integer>1</integer>
59+
<key>escaping</key>
60+
<integer>0</integer>
61+
<key>keyword</key>
62+
<string>aws</string>
63+
<key>queuedelaycustom</key>
64+
<integer>3</integer>
65+
<key>queuedelayimmediatelyinitially</key>
66+
<true/>
67+
<key>queuedelaymode</key>
68+
<integer>0</integer>
69+
<key>queuemode</key>
70+
<integer>1</integer>
71+
<key>runningsubtext</key>
72+
<string></string>
73+
<key>script</key>
74+
<string></string>
75+
<key>scriptargtype</key>
76+
<integer>1</integer>
77+
<key>scriptfile</key>
78+
<string>format_aws_vault_profiles.py</string>
79+
<key>subtext</key>
80+
<string>profiles</string>
81+
<key>title</key>
82+
<string>Open AWS via aws-vault</string>
83+
<key>type</key>
84+
<integer>8</integer>
85+
<key>withspace</key>
86+
<true/>
87+
</dict>
88+
<key>type</key>
89+
<string>alfred.workflow.input.scriptfilter</string>
90+
<key>uid</key>
91+
<string>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</string>
92+
<key>version</key>
93+
<integer>3</integer>
94+
</dict>
3595
<dict>
3696
<key>config</key>
3797
<dict>
@@ -40,7 +100,7 @@
40100
<key>escaping</key>
41101
<integer>102</integer>
42102
<key>script</key>
43-
<string>aws_account=${1:-main}
103+
<string>aws_account=${1:-$default_profile}
44104
aws_account=${aws_account// /} # trim space
45105
46106
AWS_ASSUME_ROLE_TTL=${AWS_ASSUME_ROLE_TTL:-1h}
@@ -54,7 +114,7 @@ if [[ $? -ne 0 ]] then;
54114
exit 1
55115
fi
56116
57-
open -na "Google Chrome" --args --incognito --user-data-dir=$HOME/Library/Application\ Support/Google/Chrome/aws-vault/${aws_account} ${login_url}</string>
117+
open -na "Google Chrome" --args --user-data-dir=$HOME/Library/Application\ Support/Google/Chrome/aws-vault/${aws_account} ${login_url}</string>
58118
<key>scriptargtype</key>
59119
<integer>1</integer>
60120
<key>scriptfile</key>
@@ -72,27 +132,29 @@ open -na "Google Chrome" --args --incognito --user-data-dir=$HOME/Library/Applic
72132
<dict>
73133
<key>config</key>
74134
<dict>
75-
<key>argumenttype</key>
76-
<integer>1</integer>
77-
<key>keyword</key>
78-
<string>aws</string>
79-
<key>subtext</key>
80-
<string>Open AWS</string>
81-
<key>text</key>
82-
<string>aws</string>
83-
<key>withspace</key>
84-
<true/>
135+
<key>argument</key>
136+
<string>{query}</string>
137+
<key>variables</key>
138+
<dict>
139+
<key>aws_vault_path</key>
140+
<string>{aws_vault_path}</string>
141+
<key>default_profile</key>
142+
<string>{default_profile}</string>
143+
</dict>
85144
</dict>
86145
<key>type</key>
87-
<string>alfred.workflow.input.keyword</string>
146+
<string>alfred.workflow.utility.argument</string>
88147
<key>uid</key>
89-
<string>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</string>
148+
<string>BCF9D88B-14B0-4B42-AE3C-411695BDC870</string>
90149
<key>version</key>
91150
<integer>1</integer>
92151
</dict>
93152
</array>
94153
<key>readme</key>
95-
<string></string>
154+
<string>Open the AWS management console via aws-vault.
155+
156+
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.
157+
It allows you to open multiple AWS accounts at the same time.</string>
96158
<key>uidata</key>
97159
<dict>
98160
<key>16039760-F173-4AB8-9C73-DA7401D5DE23</key>
@@ -105,15 +167,29 @@ open -na "Google Chrome" --args --incognito --user-data-dir=$HOME/Library/Applic
105167
<key>2C99F6F1-EF16-4CF1-9762-5D05A1FFAA4D</key>
106168
<dict>
107169
<key>xpos</key>
108-
<integer>300</integer>
170+
<integer>235</integer>
109171
<key>ypos</key>
110-
<real>60</real>
172+
<integer>60</integer>
111173
</dict>
174+
<key>BCF9D88B-14B0-4B42-AE3C-411695BDC870</key>
175+
<dict>
176+
<key>xpos</key>
177+
<integer>405</integer>
178+
<key>ypos</key>
179+
<integer>90</integer>
180+
</dict>
181+
</dict>
182+
<key>variables</key>
183+
<dict>
184+
<key>aws_vault_path</key>
185+
<string>/usr/local/bin/aws-vault</string>
186+
<key>default_profile</key>
187+
<string>default</string>
112188
</dict>
113189
<key>variablesdontexport</key>
114190
<array/>
115191
<key>version</key>
116-
<string>1.0.3</string>
192+
<string>0.0.1</string>
117193
<key>webaddress</key>
118194
<string>https://github.com/kangaechu/aws-vault-alfred-workflow</string>
119195
</dict>

0 commit comments

Comments
 (0)