-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawsume.mx
132 lines (118 loc) · 3.84 KB
/
awsume.mx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
function awsume {
# Grabs your access tokens for AWS
trypipe {
awsumepy: @{ $ARGS->@[1..]n } -> set generic envs
switch $envs[:0] {
case "Kill" {
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN
unset AWS_REGION
unset AWS_DEFAULT_REGION
unset AWS_PROFILE
unset AWS_DEFAULT_PROFILE
unset AWSUME_EXPIRATION
unset AWSUME_PROFILE
unset AWSUME_COMMAND
}
case "Stop" {
if { = AWS_PROFILE==`auto-refresh-$envs[:1]` } then {
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN
unset AWS_REGION
unset AWS_DEFAULT_REGION
unset AWS_PROFILE
unset AWS_DEFAULT_PROFILE
unset AWSUME_EXPIRATION
unset AWSUME_PROFILE
unset AWSUME_COMMAND
}
}
case "Awsume" {
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN
unset AWS_REGION
unset AWS_DEFAULT_REGION
unset AWS_PROFILE
unset AWS_DEFAULT_PROFILE
unset AWSUME_EXPIRATION
unset AWSUME_PROFILE
unset AWSUME_COMMAND
export AWS_ACCESS_KEY_ID=$envs[:1]
export AWS_SECRET_ACCESS_KEY=$envs[:2]
export AWS_SESSION_TOKEN=$envs[:3]
export AWS_REGION=$envs[:4]
export AWS_DEFAULT_REGION=$envs[:4]
export AWSUME_PROFILE=$envs[:5]
export AWS_PROFILE=$envs[:6]
export AWS_DEFAULT_PROFILE=$envs[:6]
export AWSUME_EXPIRATION=$envs[:7]
if { = `$AWS_PROFILE`==`None` } then {
export AWS_PROFILE=$AWSUME_PROFILE
}
if { = `$AWS_DEFAULT_PROFILE`==`None` } then {
export AWS_DEFAULT_PROFILE=$AWSUME_PROFILE
}
}
catch {
out: $envs
}
}
}
}
alias awscon=awsume
private autocomplete.asumepy {
# Autocompletion flags for `asumepy`
cast: json
config: set proc strict-arrays false
awsumepy: -h -> @[optional arguments:..]s -> tabulate: --map --column-wraps --split-comma --key-inc-hint
}
#test unit private autocomplete.asumepy {
# "StdoutType": "json",
# "StdoutBlock": ({
# -> len -> set len;
# if { = len>0 } then {
# out "Len greater than 0"
# } else {
# err "No elements returned"
# }
# }),
# "StdoutIsMap": true
#}
private autocomplete.awscon {
# Inspect ~/.aws/config for profiles to add to `awsume`'s autocompletion
#trypipe {
# open terraform.tfvars -> [ aws_account_id ] -> set accid
# grep $accid ~/.aws/config -n -> regexp 'f/(^[0-9]+)' -> set int line
# let line=line-3
# cat ~/.aws/config -> @[$line..$line]n -> regexp 'f/^\[profile (.*?)\]/'
#}; catch {
cat ~/.aws/config -> regexp 'f/^\[profile (.*?)\]/' -> sort -> cast str
#}
}
test unit private autocomplete.awscon {
"StdoutType": "str",
"StdoutBlock": ({
if { g: ~/.aws/config } then {
<stdin> -> len -> set len;
if { = len>0 } then {
out "Len greater than 0"
} else {
err "No elements returned"
}
}
}),
"StdoutIsArray": true
}
autocomplete set awsume { [
{
"DynamicDesc": ({ autocomplete.asumepy }),
"Optional": true
},
{
"Dynamic": ({ autocomplete.awscon })
}
] }
autocomplete get awsume -> autocomplete set awscon