awscli 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/awscli +7 -7
- data/lib/awscli.rb +3 -1
- data/lib/awscli/as.rb +56 -56
- data/lib/awscli/cli.rb +1 -1
- data/lib/awscli/cli/UsageExamples/emr +49 -0
- data/lib/awscli/cli/emr.rb +157 -0
- data/lib/awscli/cli/iam/user.rb +18 -7
- data/lib/awscli/cli/s3/files.rb +43 -37
- data/lib/awscli/connection.rb +34 -31
- data/lib/awscli/ec2.rb +234 -234
- data/lib/awscli/emr.rb +472 -0
- data/lib/awscli/errors.rb +1 -1
- data/lib/awscli/helper.rb +17 -0
- data/lib/awscli/iam.rb +281 -218
- data/lib/awscli/s3.rb +51 -39
- data/lib/awscli/version.rb +1 -1
- metadata +5 -2
data/lib/awscli/errors.rb
CHANGED
@@ -58,7 +58,7 @@ module Awscli
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.invalid_credentials
|
61
|
-
message =
|
61
|
+
message = 'Invalid Credentials, Please check your AWS access and secret key id.'
|
62
62
|
raise(Awscli::Errors::LoadError.new(message))
|
63
63
|
end
|
64
64
|
|
data/lib/awscli/helper.rb
CHANGED
@@ -5,4 +5,21 @@ module Awscli
|
|
5
5
|
INSTANCE_TYPES = %w(on-demand spot)
|
6
6
|
REGIONS = %w(eu-west-1 sa-east-1 us-east-1 ap-northeast-1 us-west-2 us-west-1 ap-southeast-1 ap-southeast-2)
|
7
7
|
end
|
8
|
+
module EMR
|
9
|
+
VALID_JOB_FLOW_STATUS = %w(RUNNING WAITING SHUTTING_DOWN STARTING)
|
10
|
+
HADOOP_HIVE_COMPATIBILITY = {
|
11
|
+
'1.0.3' => '0.8.1.6',
|
12
|
+
'0.20.205' => '0.8.1.2',
|
13
|
+
'0.20' => '0.7.1',
|
14
|
+
'0.18' => '0.7.1'
|
15
|
+
}
|
16
|
+
HADOOP_AMI_MAPPING = {
|
17
|
+
'1.0.3' => '2.3',
|
18
|
+
'0.20.205' => '2.0',
|
19
|
+
'0.20' => '1.0',
|
20
|
+
'0.18' => '1.0'
|
21
|
+
}
|
22
|
+
HBASE_SUPPORTED_HADOOP_VERSIONS = %w(0.20.205 1.0.3)
|
23
|
+
HBASE_INVALID_INSTANCES = %w(m1.small c1.medium)
|
24
|
+
end
|
8
25
|
end
|
data/lib/awscli/iam.rb
CHANGED
@@ -4,63 +4,105 @@ module Awscli
|
|
4
4
|
module Iam
|
5
5
|
|
6
6
|
class User
|
7
|
-
def initialize
|
8
|
-
|
7
|
+
def initialize(connection)
|
8
|
+
@conn = connection
|
9
9
|
end
|
10
10
|
|
11
|
-
def list
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
puts "ValidationError: #{$!}"
|
17
|
-
end
|
11
|
+
def list(path)
|
12
|
+
users = @conn.list_users('PathPrefix' => path).body['Users']
|
13
|
+
Formatador.display_table(users)
|
14
|
+
rescue Fog::AWS::IAM::ValidationError
|
15
|
+
puts "ValidationError: #{$!}"
|
18
16
|
end
|
19
17
|
|
20
|
-
def create
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
def create(options)
|
19
|
+
username = options[:user_name]
|
20
|
+
@conn.create_user(username, options[:path] ||= '/')
|
21
|
+
puts "Created User: #{username}"
|
22
|
+
if options[:password]
|
23
|
+
#Assign a password for the user
|
24
|
+
generate_password username
|
25
|
+
end
|
26
|
+
if options[:group]
|
27
|
+
#add user to the group
|
28
|
+
add_user_to_group username, options[:group]
|
29
|
+
end
|
30
|
+
if options[:access_key]
|
31
|
+
#create a access_key for the user
|
32
|
+
create_user_access_key username
|
33
|
+
end
|
34
|
+
if options[:policy]
|
35
|
+
#upload the policy document
|
36
|
+
document = options[:policy_doc]
|
37
|
+
policy_name = "User-#{username}-Custom"
|
38
|
+
#validate json document
|
39
|
+
doc_path = File.expand_path(document)
|
40
|
+
abort "Invalid file path: #{document}" unless File.exist?(doc_path)
|
41
|
+
json_string = File.read(doc_path)
|
42
|
+
abort "Invalid JSON format found in the document: #{document}" unless valid_json?(json_string)
|
43
|
+
@conn.put_user_policy(username,
|
44
|
+
policy_name,
|
45
|
+
JSON.parse(json_string) #json parsed to hash
|
46
|
+
)
|
47
|
+
puts "Added policy: #{policy_name} to user: #{username}"
|
48
|
+
puts "Added Policy #{policy_name} from #{document}"
|
49
|
+
else
|
50
|
+
#create set of basic policy to the user created
|
51
|
+
user_arn = @conn.users.get(username).arn
|
52
|
+
@conn.put_user_policy(
|
53
|
+
username,
|
54
|
+
"User#{username}Policy",
|
55
|
+
{
|
56
|
+
'Statement' => [
|
57
|
+
{
|
58
|
+
'Effect' => 'Allow',
|
59
|
+
'Action' => 'iam:*AccessKey*',
|
60
|
+
'Resource' => user_arn
|
61
|
+
},
|
62
|
+
{
|
63
|
+
'Effect' => 'Allow',
|
64
|
+
'Action' => ['ec2:Describe*', 's3:Get*', 's3:List*'],
|
65
|
+
'Resource' => '*'
|
66
|
+
}
|
67
|
+
]
|
68
|
+
}
|
69
|
+
)
|
70
|
+
puts 'User policy for accessing/managing keys of their own and read-access is in place'
|
29
71
|
end
|
72
|
+
rescue Fog::AWS::IAM::ValidationError
|
73
|
+
puts "ValidationError: #{$!}"
|
74
|
+
rescue Fog::AWS::IAM::EntityAlreadyExists
|
75
|
+
puts "[Error] User Exists: #{$!}"
|
76
|
+
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
|
77
|
+
puts "[Error]: #{$!}"
|
30
78
|
end
|
31
79
|
|
32
|
-
def create_user_access_key
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
puts "[Error]: #{$!}"
|
43
|
-
end
|
80
|
+
def create_user_access_key(username)
|
81
|
+
data = @conn.create_access_key('UserName' => username)
|
82
|
+
access_key_id = data.body['AccessKey']['AccessKeyId']
|
83
|
+
secret_access_key = data.body['AccessKey']['SecretAccessKey']
|
84
|
+
#keystatus = data.body['AccessKey']['Status']
|
85
|
+
puts 'Store the following access id and secret key:'
|
86
|
+
puts "AccessKey: #{access_key_id}"
|
87
|
+
puts "SecretAccessKey: #{secret_access_key}"
|
88
|
+
rescue Fog::AWS::IAM::NotFound
|
89
|
+
puts "[Error]: #{$!}"
|
44
90
|
end
|
45
91
|
|
46
|
-
def list_user_access_keys
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
puts "[Error]: #{$!}"
|
51
|
-
end
|
92
|
+
def list_user_access_keys(username)
|
93
|
+
@conn.access_keys(:username => username).table
|
94
|
+
rescue Fog::AWS::IAM::NotFound
|
95
|
+
puts "[Error]: #{$!}"
|
52
96
|
end
|
53
97
|
|
54
|
-
def delete_user_access_key
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
puts "[Error]: #{$!}"
|
60
|
-
end
|
98
|
+
def delete_user_access_key(username, access_key_id)
|
99
|
+
@conn.delete_access_key(access_key_id, 'UserName' => username)
|
100
|
+
puts "Deleted AccessKey for user: #{username}"
|
101
|
+
rescue Fog::AWS::IAM::NotFound
|
102
|
+
puts "[Error]: #{$!}"
|
61
103
|
end
|
62
104
|
|
63
|
-
def update_user
|
105
|
+
def update_user(options)
|
64
106
|
opts = Marshal.load(Marshal.dump(options))
|
65
107
|
opts.reject! { |k| k == 'user_name' }
|
66
108
|
if new_user_name = opts.delete(:new_user_name)
|
@@ -69,138 +111,173 @@ module Awscli
|
|
69
111
|
if new_path = opts.delete(:new_path)
|
70
112
|
opts.merge!('NewPath' => new_path)
|
71
113
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
114
|
+
@conn.update_user(options[:user_name], opts)
|
115
|
+
puts 'Updated user details'
|
116
|
+
rescue Fog::AWS::IAM::EntityAlreadyExists
|
117
|
+
puts '[Error] User already exists, pass in a different username'
|
118
|
+
rescue Fog::AWS::IAM::ValidationError
|
119
|
+
puts "ValidationError: #{$!}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def add_user_to_group(username, groupname)
|
123
|
+
@conn.add_user_to_group(groupname, username)
|
124
|
+
puts "Added user: #{username}, to group: #{groupname}"
|
125
|
+
rescue Fog::AWS::IAM::NotFound
|
126
|
+
puts "[Error]: #{$!}"
|
127
|
+
end
|
128
|
+
|
129
|
+
def remove_user_from_group(username, groupname)
|
130
|
+
@conn.remove_user_from_group(groupname, username)
|
131
|
+
puts "Removed user: #{username}, from group: #{groupname}"
|
132
|
+
rescue Fog::AWS::IAM::NotFound
|
133
|
+
puts "[Error]: #{$!}"
|
134
|
+
end
|
135
|
+
|
136
|
+
def list_groups_for_user(username)
|
137
|
+
groups = @conn.list_groups_for_user(username).body['GroupsForUser']
|
138
|
+
Formatador.display_table(groups)
|
139
|
+
rescue Fog::AWS::IAM::NotFound
|
140
|
+
puts "[Error]: #{$!}"
|
141
|
+
end
|
142
|
+
|
143
|
+
def assign_password(username, password)
|
144
|
+
@conn.create_login_profile(username, password)
|
145
|
+
puts "Assigned user #{username} password: #{password}"
|
146
|
+
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::ValidationError
|
147
|
+
puts "[Error]: #{$!}"
|
148
|
+
rescue Fog::AWS::IAM::Error
|
149
|
+
puts "[Error]: #{$!}"
|
150
|
+
if $!.to_s =~ /PasswordPolicyViolation/
|
151
|
+
#TODO: show password policy, this is not available in fog
|
152
|
+
puts 'Password policy is violated, please revisit your password policies'
|
79
153
|
end
|
80
154
|
end
|
81
155
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
156
|
+
def generate_password(username)
|
157
|
+
tries ||= 3
|
158
|
+
password = ((33..126).map { |i| i.chr }).to_a.shuffle[0..14].join
|
159
|
+
@conn.create_login_profile(username, password)
|
160
|
+
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::ValidationError
|
161
|
+
puts "[Error]: #{$!}"
|
162
|
+
rescue Fog::AWS::IAM::Error
|
163
|
+
puts "[Error]: #{$!}"
|
164
|
+
if $!.to_s =~ /PasswordPolicyViolation/
|
165
|
+
#TODO: show password policy, this is not available in fog
|
166
|
+
#if password policy is violated, then our generated password might be weak, retry 3 times before failing
|
167
|
+
retry if (tries -= 1) > 0
|
88
168
|
end
|
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
|
-
|
169
|
+
else
|
170
|
+
puts "Assigned password: '#{password}' for user #{username}"
|
171
|
+
puts 'Store this password, this cannot be retrieved again'
|
172
|
+
end
|
173
|
+
|
174
|
+
def remove_password(username)
|
175
|
+
@conn.delete_login_profile(username)
|
176
|
+
puts "Deleted login profile for user: #{username}"
|
177
|
+
rescue Fog::AWS::IAM::Error, Fog::AWS::IAM::NotFound
|
178
|
+
puts "[Error]: #{$!}"
|
179
|
+
end
|
180
|
+
|
181
|
+
def delete(options)
|
182
|
+
username = options[:user_name]
|
183
|
+
user = @conn.users.get(username)
|
184
|
+
if user
|
185
|
+
if options[:force]
|
186
|
+
#ask user to confirm deletion
|
187
|
+
if agree('Are you sure you want to delete user and users associated login_profile, access_keys, policies ? ')
|
188
|
+
#check if user has login profile
|
189
|
+
begin
|
190
|
+
@conn.get_login_profile(username)
|
191
|
+
user_profile = true
|
192
|
+
rescue Fog::AWS::IAM::NotFound
|
193
|
+
user_profile = false
|
194
|
+
end
|
195
|
+
remove_password username if user_profile
|
196
|
+
#check if user has access_keys
|
197
|
+
access_keys = user.access_keys.map { |access_key| access_key.id }
|
198
|
+
unless access_keys.empty?
|
199
|
+
#delete access_keys
|
200
|
+
access_keys.each do |access_key|
|
201
|
+
delete_user_access_key username, access_key
|
202
|
+
end
|
203
|
+
end
|
204
|
+
#check if user belongs to a group
|
205
|
+
groups = @conn.list_groups_for_user(username).body['GroupsForUser'].map { |k| k['GroupName'] }
|
206
|
+
unless groups.empty?
|
207
|
+
#delete user_groups
|
208
|
+
groups.each do |group|
|
209
|
+
remove_user_from_group username, group
|
210
|
+
end
|
211
|
+
end
|
212
|
+
#check if user has policies
|
213
|
+
policies = user.policies.map { |policy| policy.id }
|
214
|
+
unless policies.empty?
|
215
|
+
policies.each do |policy|
|
216
|
+
@conn.delete_user_policy username, policy
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
127
220
|
end
|
221
|
+
@conn.delete_user(username)
|
222
|
+
else
|
223
|
+
abort "No such user: #{username}"
|
128
224
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
@@conn.delete_login_profile(username)
|
134
|
-
rescue Fog::AWS::IAM::Error, Fog::AWS::IAM::NotFound
|
135
|
-
puts "[Error]: #{$!}"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def delete username
|
140
|
-
begin
|
141
|
-
@@conn.delete_user(username)
|
142
|
-
puts "Deleted User: #{username}"
|
143
|
-
rescue Fog::AWS::IAM::NotFound
|
144
|
-
puts "[Error]: #{$!}"
|
145
|
-
end
|
225
|
+
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
|
226
|
+
puts "[Error]: #{$!}"
|
227
|
+
else
|
228
|
+
puts "Deleted User: #{username}"
|
146
229
|
end
|
147
230
|
end
|
148
231
|
|
149
232
|
class Group
|
150
|
-
def initialize
|
151
|
-
|
233
|
+
def initialize(connection)
|
234
|
+
@conn = connection
|
152
235
|
end
|
153
236
|
|
154
|
-
def list
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
puts "ValidationError: #{$!}"
|
160
|
-
end
|
237
|
+
def list(path)
|
238
|
+
groups = @conn.list_groups('PathPrefix' => path).body['Groups']
|
239
|
+
Formatador.display_table(groups)
|
240
|
+
rescue Fog::AWS::IAM::ValidationError
|
241
|
+
puts "ValidationError: #{$!}"
|
161
242
|
end
|
162
243
|
|
163
|
-
def create
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
puts "[Error] Group Exists: #{$!}"
|
171
|
-
end
|
244
|
+
def create(groupname, path)
|
245
|
+
@conn.create_group(groupname, path ||= '/')
|
246
|
+
puts "Created group: #{groupname}"
|
247
|
+
rescue Fog::AWS::IAM::ValidationError
|
248
|
+
puts "ValidationError: #{$!}"
|
249
|
+
rescue Fog::AWS::IAM::EntityAlreadyExists
|
250
|
+
puts "[Error] Group Exists: #{$!}"
|
172
251
|
end
|
173
252
|
|
174
|
-
def delete
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
puts "[Error]: #{$!}"
|
180
|
-
end
|
253
|
+
def delete(groupname)
|
254
|
+
@conn.delete_group(groupname)
|
255
|
+
puts "Create group: #{groupname}"
|
256
|
+
rescue Fog::AWS::IAM::NotFound
|
257
|
+
puts "[Error]: #{$!}"
|
181
258
|
end
|
182
259
|
end
|
183
260
|
|
184
261
|
class Policies
|
185
|
-
def initialize
|
186
|
-
|
262
|
+
def initialize(connection)
|
263
|
+
@conn = connection
|
187
264
|
end
|
188
265
|
|
189
|
-
def list
|
266
|
+
def list(options)
|
190
267
|
if options[:user_name]
|
191
|
-
user =
|
192
|
-
abort "[Error]: User not found #{
|
268
|
+
user = @conn.users.get(options[:user_name])
|
269
|
+
abort "[Error]: User not found #{user}" unless user
|
193
270
|
user.policies.table
|
194
271
|
elsif options[:group_name]
|
195
272
|
begin
|
196
|
-
grp_policies =
|
273
|
+
grp_policies = @conn.list_group_policies(options[:group_name]).body['PolicyNames'].map { |p| { 'Policy' => p } }
|
197
274
|
Formatador.display_table(grp_policies)
|
198
275
|
rescue Fog::AWS::IAM::NotFound
|
199
276
|
puts "[Error]: #{$!}"
|
200
277
|
end
|
201
278
|
elsif options[:role_name]
|
202
279
|
begin
|
203
|
-
role_policies =
|
280
|
+
role_policies = @conn.list_role_policies(options[:role_name]).body['PolicyNames'].map { |p| {'Policy' => p} }
|
204
281
|
Formatador.display_table(role_policies)
|
205
282
|
rescue Fog::AWS::IAM::NotFound
|
206
283
|
puts "[Error]: #{$!}"
|
@@ -208,7 +285,7 @@ module Awscli
|
|
208
285
|
end
|
209
286
|
end
|
210
287
|
|
211
|
-
def add_policy_document
|
288
|
+
def add_policy_document(options)
|
212
289
|
document = options[:policy_document]
|
213
290
|
policyname = options[:policy_name]
|
214
291
|
#validate json document
|
@@ -218,19 +295,19 @@ module Awscli
|
|
218
295
|
abort "Invalid JSON format found in the document: #{document}" unless valid_json?(json_string)
|
219
296
|
begin
|
220
297
|
if options[:user_name]
|
221
|
-
|
298
|
+
@conn.put_user_policy(options[:user_name],
|
222
299
|
policyname,
|
223
300
|
JSON.parse(json_string) #json parsed to hash
|
224
301
|
)
|
225
302
|
puts "Added policy: #{policyname} to user: #{options[:user_name]}"
|
226
303
|
elsif options[:group_name]
|
227
|
-
|
304
|
+
@conn.put_group_policy(option[:group_name],
|
228
305
|
policyname,
|
229
306
|
JSON.parse(json_string)
|
230
307
|
)
|
231
308
|
puts "Added policy: #{policyname} to group: #{options[:group_name]}"
|
232
309
|
elsif options[:role_name]
|
233
|
-
|
310
|
+
@conn.put_role_policy(options[:role_name],
|
234
311
|
policyname,
|
235
312
|
JSON.parse(json_string)
|
236
313
|
)
|
@@ -273,24 +350,22 @@ module Awscli
|
|
273
350
|
# })
|
274
351
|
end
|
275
352
|
|
276
|
-
def delete_policy
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
@@conn.delete_role_policy(options[:role_name], options[:policy_name])
|
284
|
-
end
|
285
|
-
puts "Deleted Policy #{options[:policy_name]}"
|
286
|
-
rescue Fog::AWS::IAM::NotFound
|
287
|
-
puts "[Error]: #{$!}"
|
288
|
-
rescue Fog::AWS::IAM::Error
|
289
|
-
puts "[Error]: #{$!}"
|
353
|
+
def delete_policy(options)
|
354
|
+
if options[:user_name]
|
355
|
+
@conn.delete_user_policy(options[:user_name], options[:policy_name])
|
356
|
+
elsif options[:group_name]
|
357
|
+
@conn.delete_group_policy(options[:group_name], options[:policy_name])
|
358
|
+
elsif options[:role_name]
|
359
|
+
@conn.delete_role_policy(options[:role_name], options[:policy_name])
|
290
360
|
end
|
361
|
+
puts "Deleted Policy #{options[:policy_name]}"
|
362
|
+
rescue Fog::AWS::IAM::NotFound
|
363
|
+
puts "[Error]: #{$!}"
|
364
|
+
rescue Fog::AWS::IAM::Error
|
365
|
+
puts "[Error]: #{$!}"
|
291
366
|
end
|
292
367
|
|
293
|
-
def valid_json?
|
368
|
+
def valid_json?(json_string)
|
294
369
|
JSON.parse(json_string)
|
295
370
|
return true
|
296
371
|
rescue JSON::ParserError
|
@@ -299,46 +374,42 @@ module Awscli
|
|
299
374
|
end
|
300
375
|
|
301
376
|
class Roles
|
302
|
-
def initialize
|
303
|
-
|
377
|
+
def initialize(connection)
|
378
|
+
@conn = connection
|
304
379
|
end
|
305
380
|
|
306
381
|
def list
|
307
|
-
roles =
|
308
|
-
Formatador.display_table(roles,
|
382
|
+
roles = @conn.list_roles.body['Roles']
|
383
|
+
Formatador.display_table(roles, %w(Arn RoleName Path RoleId))
|
309
384
|
end
|
310
385
|
|
311
|
-
def create_role
|
386
|
+
def create_role(rolename, document, path)
|
312
387
|
#TODO: Build document in line from options use iam-rolecreate as reference
|
313
388
|
doc_path = File.expand_path(document)
|
314
389
|
abort "Invalid file path: #{file_path}" unless File.exist?(doc_path)
|
315
390
|
json_string = File.read(doc_path)
|
316
391
|
abort "Invalid JSON format found in the document: #{document}" unless valid_json?(json_string)
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
392
|
+
@conn.create_role(rolename, JSON.parse(json_string), path)
|
393
|
+
# Example document, AssumeRolePolicyDocument={"Version":"2008-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},"Action":["sts:AssumeRole"]}]}
|
394
|
+
puts "Created role: #{rolename}"
|
395
|
+
rescue Fog::AWS::IAM::Error
|
396
|
+
puts "[Error]: #{$!}"
|
397
|
+
end
|
398
|
+
|
399
|
+
def delete_role(rolename)
|
400
|
+
@conn.delete_role(rolename)
|
401
|
+
puts "Deleted Role #{rolename}"
|
402
|
+
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
|
403
|
+
if $!.to_s =~ /must remove roles from instance profile first/
|
404
|
+
puts "[Error]: #{$!}"
|
405
|
+
profile = @conn.list_instance_profiles_for_role('test').body['InstanceProfiles'].map { |k| k['InstanceProfileName'] }
|
406
|
+
puts "Associated instance profile name: #{profile.to_s}, delete the instance profile using `awscli iam profiles delete-role --profile-name=NAME --role-name=NAME`"
|
407
|
+
else
|
322
408
|
puts "[Error]: #{$!}"
|
323
409
|
end
|
324
410
|
end
|
325
411
|
|
326
|
-
def
|
327
|
-
begin
|
328
|
-
@@conn.delete_role(rolename)
|
329
|
-
puts "Deleted Role #{rolename}"
|
330
|
-
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
|
331
|
-
if $!.to_s =~ /must remove roles from instance profile first/
|
332
|
-
puts "[Error]: #{$!}"
|
333
|
-
profile = @@conn.list_instance_profiles_for_role('test').body['InstanceProfiles'].map { |k| k['InstanceProfileName'] }
|
334
|
-
puts "Associated instance profile name: #{profile.to_s}, delete the instance profile using `awscli iam profiles delete-role --profile-name=NAME --role-name=NAME`"
|
335
|
-
else
|
336
|
-
puts "[Error]: #{$!}"
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
def valid_json? json_string
|
412
|
+
def valid_json?(json_string)
|
342
413
|
# => validates json document
|
343
414
|
JSON.parse(json_string)
|
344
415
|
return true
|
@@ -348,46 +419,38 @@ module Awscli
|
|
348
419
|
end
|
349
420
|
|
350
421
|
class Profiles
|
351
|
-
def initialize
|
352
|
-
|
422
|
+
def initialize(connection)
|
423
|
+
@conn = connection
|
353
424
|
end
|
354
425
|
|
355
426
|
def list
|
356
|
-
profiles =
|
357
|
-
Formatador.display_table(profiles,
|
427
|
+
profiles = @conn.list_instance_profiles.body['InstanceProfiles']
|
428
|
+
Formatador.display_table(profiles, %w(Arn InstanceProfileName InstanceProfileId Path Roles))
|
358
429
|
end
|
359
430
|
|
360
|
-
def list_for_role
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
puts "[Error]: #{$!}"
|
366
|
-
end
|
431
|
+
def list_for_role(rolename)
|
432
|
+
profiles = @conn.list_instance_profiles_for_role(rolename).body['InstanceProfiles']
|
433
|
+
Formatador.display_table(profiles, %w(Arn InstanceProfileName InstanceProfileId Path Roles))
|
434
|
+
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
|
435
|
+
puts "[Error]: #{$!}"
|
367
436
|
end
|
368
437
|
|
369
|
-
def remove_role_from_instance_profile
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
puts "[Error]: #{$!}"
|
374
|
-
end
|
438
|
+
def remove_role_from_instance_profile(rolename, profilename)
|
439
|
+
@conn.remove_role_from_instance_profile(rolename, profilename)
|
440
|
+
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
|
441
|
+
puts "[Error]: #{$!}"
|
375
442
|
end
|
376
443
|
|
377
|
-
def create
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
puts "[Error]: #{$!}"
|
382
|
-
end
|
444
|
+
def create(profilename, path)
|
445
|
+
@conn.create_instance_profile(profilename, path)
|
446
|
+
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
|
447
|
+
puts "[Error]: #{$!}"
|
383
448
|
end
|
384
449
|
|
385
|
-
def delete
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
puts "[Error]: #{$!}"
|
390
|
-
end
|
450
|
+
def delete(profilename)
|
451
|
+
@conn.delete_instance_profile(profilename)
|
452
|
+
rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
|
453
|
+
puts "[Error]: #{$!}"
|
391
454
|
end
|
392
455
|
end
|
393
456
|
|