awscli 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,7 +58,7 @@ module Awscli
58
58
  end
59
59
 
60
60
  def self.invalid_credentials
61
- message = "Invalid Credentials, Please check your AWS access and secret key id."
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
 
@@ -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
@@ -4,63 +4,105 @@ module Awscli
4
4
  module Iam
5
5
 
6
6
  class User
7
- def initialize connection, options = {}
8
- @@conn = connection
7
+ def initialize(connection)
8
+ @conn = connection
9
9
  end
10
10
 
11
- def list path
12
- begin
13
- users = @@conn.list_users('PathPrefix' => path).body['Users']
14
- Formatador.display_table(users)
15
- rescue Fog::AWS::IAM::ValidationError
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 username, path
21
- # TODO: Include other options as well
22
- begin
23
- @@conn.create_user(username, path ||= '/')
24
- puts "Created User: #{username}"
25
- rescue Fog::AWS::IAM::ValidationError
26
- puts "ValidationError: #{$!}"
27
- rescue Fog::AWS::IAM::EntityAlreadyExists
28
- puts "[Error] User Exists: #{$!}"
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 username
33
- begin
34
- data = @@conn.create_access_key('UserName' => username)
35
- accesskeyid = data.body['AccessKey']['AccessKeyId']
36
- secretaccesskey = data.body['AccessKey']['SecretAccessKey']
37
- keystatus = data.body['AccessKey']['Status']
38
- puts 'Store the following access id and secret key:'
39
- puts "AccessKey: #{accesskeyid}"
40
- puts "SecretAccessKey: #{secretaccesskey}"
41
- rescue Fog::AWS::IAM::NotFound
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 username
47
- begin
48
- @@conn.access_keys(:username => username).table
49
- rescue Fog::AWS::IAM::NotFound
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 username, accesskeyid
55
- begin
56
- @@conn.delete_access_key(accesskeyid, 'UserName' => username)
57
- puts "Deleted AccessKey for user: #{username}"
58
- rescue Fog::AWS::IAM::NotFound
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 options
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
- begin
73
- @@conn.update_user(options[:user_name], opts)
74
- puts 'Updated user details'
75
- rescue Fog::AWS::IAM::EntityAlreadyExists
76
- puts '[Error] User already exists, pass in a different username'
77
- rescue Fog::AWS::IAM::ValidationError
78
- puts "ValidationError: #{$!}"
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 add_user_to_group username, groupname
83
- begin
84
- @@conn.add_user_to_group(groupname, username)
85
- puts "Added user: #{username}, to group: #{groupname}"
86
- rescue Fog::AWS::IAM::NotFound
87
- puts "[Error]: #{$!}"
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
- end
90
-
91
- def remove_user_from_group username, groupname
92
- begin
93
- @@conn.remove_user_from_group(groupname, username)
94
- puts "Removed user: #{username}, from group: #{groupname}"
95
- rescue Fog::AWS::IAM::NotFound
96
- puts "[Error]: #{$!}"
97
- end
98
- end
99
-
100
- def list_groups_for_user username
101
- begin
102
- groups = @@conn.list_groups_for_user(username).body['GroupsForUser']
103
- Formatador.display_table(groups)
104
- rescue Fog::AWS::IAM::NotFound => e
105
- puts "[Error]: #{$!}"
106
- end
107
- end
108
-
109
- def add_policy options
110
- end
111
-
112
- def assign_password username, password, autogenpwd = false
113
- password = if autogenpwd
114
- # generate a random password
115
- ((33..126).map { |i| i.chr }).to_a.shuffle[0..14].join
116
- end
117
- begin
118
- @@conn.create_login_profile(username, password)
119
- puts "Assigned user #{username} password: #{password}"
120
- rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::ValidationError
121
- puts "[Error]: #{$!}"
122
- rescue Fog::AWS::IAM::Error
123
- puts "[Error]: #{$!}"
124
- if $!.to_s =~ /PasswordPolicyViolation/
125
- #TODO: show password policy, this is not available in fog
126
- puts "Revisit your password polocies"
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
- end
130
-
131
- def remove_password username
132
- begin
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 connection, options = {}
151
- @@conn = connection
233
+ def initialize(connection)
234
+ @conn = connection
152
235
  end
153
236
 
154
- def list path
155
- begin
156
- groups = @@conn.list_groups('PathPrefix' => path).body['Groups']
157
- Formatador.display_table(groups)
158
- rescue Fog::AWS::IAM::ValidationError
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 groupname, path
164
- begin
165
- @@conn.create_group(groupname, path ||= '/')
166
- puts "Created group: #{groupname}"
167
- rescue Fog::AWS::IAM::ValidationError
168
- puts "ValidationError: #{$!}"
169
- rescue Fog::AWS::IAM::EntityAlreadyExists
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 groupname
175
- begin
176
- @@conn.delete_group(groupname)
177
- puts "Create group: #{groupname}"
178
- rescue Fog::AWS::IAM::NotFound
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 connection, options = {}
186
- @@conn = connection
262
+ def initialize(connection)
263
+ @conn = connection
187
264
  end
188
265
 
189
- def list options
266
+ def list(options)
190
267
  if options[:user_name]
191
- user = @@conn.users.get(options[:user_name])
192
- abort "[Error]: User not found #{user_name}" unless user
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 = @@conn.list_group_policies(options[:group_name]).body['PolicyNames'].map { |p| { 'Policy' => p } }
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 = @@conn.list_role_policies(options[:role_name]).body['PolicyNames'].map { |p| {'Policy' => p} }
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 options
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
- @@conn.put_user_policy(options[:user_name],
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
- @@conn.put_group_policy(option[:group_name],
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
- @@conn.put_role_policy(options[:role_name],
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 options
277
- begin
278
- if options[:user_name]
279
- @@conn.delete_user_policy(options[:user_name], options[:policy_name])
280
- elsif options[:group_name]
281
- @@conn.delete_group_policy(options[:group_name], options[:policy_name])
282
- elsif options[:role_name]
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? json_string
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 connection, options = {}
303
- @@conn = connection
377
+ def initialize(connection)
378
+ @conn = connection
304
379
  end
305
380
 
306
381
  def list
307
- roles = @@conn.list_roles.body['Roles']
308
- Formatador.display_table(roles, ['Arn', 'RoleName', 'Path', 'RoleId'])
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 rolename, document, path
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
- begin
318
- @@conn.create_role(rolename, JSON.parse(json_string), path)
319
- # Example document, AssumeRolePolicyDocument={"Version":"2008-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},"Action":["sts:AssumeRole"]}]}
320
- puts "Created role: #{rolename}"
321
- rescue Fog::AWS::IAM::Error
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 delete_role rolename
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 connection, options = {}
352
- @@conn = connection
422
+ def initialize(connection)
423
+ @conn = connection
353
424
  end
354
425
 
355
426
  def list
356
- profiles = @@conn.list_instance_profiles.body['InstanceProfiles']
357
- Formatador.display_table(profiles, ['Arn', 'InstanceProfileName', 'InstanceProfileId', 'Path', 'Roles'])
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 rolename
361
- begin
362
- profiles = @@conn.list_instance_profiles_for_role(rolename).body['InstanceProfiles']
363
- Formatador.display_table(profiles, ['Arn', 'InstanceProfileName', 'InstanceProfileId', 'Path', 'Roles'])
364
- rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
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 rolename, profilename
370
- begin
371
- @@conn.remove_role_from_instance_profile(rolename, profilename)
372
- rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
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 profilename, path
378
- begin
379
- @@conn.create_instance_profile(profilename, path)
380
- rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
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 profilename
386
- begin
387
- @@conn.delete_instance_profile(profilename)
388
- rescue Fog::AWS::IAM::NotFound, Fog::AWS::IAM::Error
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