Class: Stratus::AWS::IAM::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/stratus/aws/iam.rb

Constant Summary collapse

VALID_ACCESS_KEY_STATUSES =
[:active, :inactive].freeze
VALID_HTTP_METHODS =
[:get, :post].freeze

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, secret_access_key) ⇒ Base

Returns a new instance of Base.

Parameters:

  • access_key_id (String)
  • secret_access_key (String)


40
41
42
43
44
# File 'lib/stratus/aws/iam.rb', line 40

def initialize(access_key_id, secret_access_key)
  @access_key_id = access_key_id
  @secret_access_key = secret_access_key
  @endpoint = "https://#{DEFAULT_HOST}/"
end

Instance Method Details

#add_user_to_group(options = {}) ⇒ Hash

Calls AddUserToGroup API

Parameters:

  • :group_name (Hash)

    and :user_name parameters is required

Returns:

  • (Hash)


123
124
125
126
127
128
129
# File 'lib/stratus/aws/iam.rb', line 123

def add_user_to_group(options = {})
  check_group_name(options)
  check_user_name(options)
  params = { 'GroupName' => options[:group_name], 'UserName' => options[:user_name] }
  response = call_api('AddUserToGroup', params)
  Response.parse(:xml => response.to_str)
end

#api_versionString

Returns:

  • (String)


47
48
49
# File 'lib/stratus/aws/iam.rb', line 47

def api_version
  API_VERSION
end

#call_api(action, params) ⇒ Object

Returns RestClient::Response.

Parameters:

  • action (String)

    AWS IAM API action name

  • params (Hash)

Returns:

  • RestClient::Response



426
427
428
429
430
431
432
# File 'lib/stratus/aws/iam.rb', line 426

def call_api(action, params)
  params['Action'] = action.to_s
  if params['Action'] == 'UploadSigningCertificate'
    return request(params, :method => :post)
  end
  request(params)
end

#create_access_key(options = {}) ⇒ Hash

Calls CreateAccessKey API

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hash)


218
219
220
221
222
223
# File 'lib/stratus/aws/iam.rb', line 218

def create_access_key(options = {})
  params = {}
  params['UserName'] = options[:user_name] if options[:user_name]
  response = call_api('CreateAccessKey', params)
  Response.parse(:xml => response.to_str)
end

#create_group(options = {}) ⇒ Hash

Calls CreateGropup API

Parameters:

  • :group_name (Hash)

    parameter is required

Returns:

  • (Hash)


77
78
79
80
81
82
83
# File 'lib/stratus/aws/iam.rb', line 77

def create_group(options = {})
  check_group_name(options)
  params = { 'GroupName' => options[:group_name] }
  params['Path'] = options[:path] if options[:path]
  response = call_api('CreateGroup', params)
  Response.parse(:xml => response.to_str)
end

#create_user(options = {}) ⇒ Hash

Calls CreateUser API

Parameters:

  • :user_name (Hash)

    parameter is required

Returns:

  • (Hash)


158
159
160
161
162
163
164
# File 'lib/stratus/aws/iam.rb', line 158

def create_user(options = {})
  check_user_name(options)
  params = { 'UserName' => options[:user_name] }
  params['Path'] = options[:path] if options[:path]
  response = call_api('CreateUser', params)
  Response.parse(:xml => response.to_str)
end

#default_hostString

Returns:

  • (String)


52
53
54
# File 'lib/stratus/aws/iam.rb', line 52

def default_host
  DEFAULT_HOST
end

#delete_access_key(options = {}) ⇒ Hash

Calls DeleteAccessKey API

Parameters:

  • options (Hash) (defaults to: {})

    :access_key_id option is required.

Returns:

  • (Hash)


229
230
231
232
233
234
235
# File 'lib/stratus/aws/iam.rb', line 229

def delete_access_key(options = {})
  check_access_key_id(options)
  params = { 'AccessKeyId' => options[:access_key_id] }
  params['UserName'] = options[:user_name] if options[:user_name]
  response = call_api('DeleteAccessKey', params)
  Response.parse(:xml => response.to_str)
end

#delete_group(options = {}) ⇒ Hash

Calls DeleteGropup API

Parameters:

  • :group_name (Hash)

    parameter is required

Returns:

  • (Hash)


89
90
91
92
93
94
# File 'lib/stratus/aws/iam.rb', line 89

def delete_group(options = {})
  check_group_name(options)
  params = { 'GroupName' => options[:group_name] }
  response = call_api('DeleteGroup', params)
  Response.parse(:xml => response.to_str)
end

#delete_group_policy(options = {}) ⇒ Hash

Calls DeleteGroupPolicy API

Parameters:

  • options (Hash) (defaults to: {})

    :group_name and :policy_name options is required.

Returns:

  • (Hash)


298
299
300
301
302
303
304
# File 'lib/stratus/aws/iam.rb', line 298

def delete_group_policy(options = {})
  check_group_name(options)
  check_policy_name(options)
  params = { 'GroupName' => options[:group_name], 'PolicyName' => options[:policy_name] }
  response = call_api('DeleteGroupPolicy', params)
  Response.parse(:xml => response.to_str)
end

#delete_signing_certificate(options = {}) ⇒ Hash

Calls DeleteSigningCertificate API

Parameters:

  • options (Hash) (defaults to: {})

    :certificate_id options is required.

Returns:

  • (Hash)


404
405
406
407
408
409
410
# File 'lib/stratus/aws/iam.rb', line 404

def delete_signing_certificate(options = {})
  check_certificate_id(options)
  params = { 'CertificateId' => options[:certificate_id] }
  params['UserName'] = options[:user_name] if options[:user_name]
  response = call_api('DeleteSigningCertificate', params)
  Response.parse(:xml => response.to_str)
end

#delete_user(options = {}) ⇒ Hash

Calls DeleteUser API

Parameters:

  • :user_name (Hash)

    parameter is required

Returns:

  • (Hash)


170
171
172
173
174
175
# File 'lib/stratus/aws/iam.rb', line 170

def delete_user(options = {})
  check_user_name(options)
  params = { 'UserName' => options[:user_name] }
  response = call_api('DeleteUser', params)
  Response.parse(:xml => response.to_str)
end

#delete_user_policy(options = {}) ⇒ Hash

Calls DeleteUserPolicy API

Parameters:

  • options (Hash) (defaults to: {})

    :user_name and :policy_name options is required.

Returns:

  • (Hash)


355
356
357
358
359
360
361
# File 'lib/stratus/aws/iam.rb', line 355

def delete_user_policy(options = {})
  check_user_name(options)
  check_policy_name(options)
  params = { 'UserName' => options[:user_name], 'PolicyName' => options[:policy_name] }
  response = call_api('DeleteUserPolicy', params)
  Response.parse(:xml => response.to_str)
end

#endpointString

Returns:

  • (String)


57
58
59
# File 'lib/stratus/aws/iam.rb', line 57

def endpoint
  @endpoint
end

#get_group(options = {}) ⇒ Hash

Calls GetGropup API

Parameters:

  • :group_name (Hash)

    parameter is required

Returns:

  • (Hash)


65
66
67
68
69
70
71
# File 'lib/stratus/aws/iam.rb', line 65

def get_group(options = {})
  check_group_name(options)
  params = make_pagination_params(options)
  params['GroupName'] = options[:group_name]
  response = call_api('GetGroup', params)
  Response.parse(:xml => response.to_str)
end

#get_group_policy(options = {}) ⇒ Hash

Calls GetGroupPolicy API

Parameters:

  • options (Hash) (defaults to: {})

    :group_name and :policy_name options is required.

Returns:

  • (Hash)


265
266
267
268
269
270
271
272
273
274
275
# File 'lib/stratus/aws/iam.rb', line 265

def get_group_policy(options = {})
  check_group_name(options)
  check_policy_name(options)
  params = { 'GroupName' => options[:group_name], 'PolicyName' => options[:policy_name] }
  response = call_api('GetGroupPolicy', params)
  result = Response.parse(:xml => response.to_str)
  if result && result['GetGroupPolicyResult'] && result['GetGroupPolicyResult']['PolicyDocument']
    result['GetGroupPolicyResult']['PolicyDocument'] = decode_uri(result['GetGroupPolicyResult']['PolicyDocument'])
  end
  result
end

#get_user(options = {}) ⇒ Hash

Calls GetUser API

Parameters:

  • (Hash)

Returns:

  • (Hash)


147
148
149
150
151
152
# File 'lib/stratus/aws/iam.rb', line 147

def get_user(options = {})
  params = {}
  params['UserName'] = options[:user_name] if options[:user_name]
  response = call_api('GetUser', params)
  Response.parse(:xml => response.to_str)
end

#get_user_policy(options = {}) ⇒ Hash

Calls GetUserPolicy API

Parameters:

  • options (Hash) (defaults to: {})

    :user_name and :policy_name options is required.

Returns:

  • (Hash)


322
323
324
325
326
327
328
329
330
331
332
# File 'lib/stratus/aws/iam.rb', line 322

def get_user_policy(options = {})
  check_user_name(options)
  check_policy_name(options)
  params = { 'UserName' => options[:user_name], 'PolicyName' => options[:policy_name] }
  response = call_api('GetUserPolicy', params)
  result = Response.parse(:xml => response.to_str)
  if result && result['GetUserPolicyResult'] && result['GetUserPolicyResult']['PolicyDocument']
    result['GetUserPolicyResult']['PolicyDocument'] = decode_uri(result['GetUserPolicyResult']['PolicyDocument'])
  end
  result
end

#list_access_keys(options = {}) ⇒ Hash

Calls ListAccessKeys API

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hash)


254
255
256
257
258
259
# File 'lib/stratus/aws/iam.rb', line 254

def list_access_keys(options = {})
  params = make_pagination_params(options)
  params['UserName'] = options[:user_name] if options[:user_name]
  response = call_api('ListAccessKeys', params)
  Response.parse(:xml => response.to_str)
end

#list_group_policies(options = {}) ⇒ Hash

Calls ListGroupPolicies API

Parameters:

  • options (Hash) (defaults to: {})

    :group_name options is required.

Returns:

  • (Hash)


310
311
312
313
314
315
316
# File 'lib/stratus/aws/iam.rb', line 310

def list_group_policies(options = {})
  check_group_name(options)
  params = make_pagination_params(options)
  params['GroupName'] = options[:group_name]
  response = call_api('ListGroupPolicies', params)
  Response.parse(:xml => response.to_str)
end

#list_groups(options = {}) ⇒ Hash

Calls ListGroups API

Returns:

  • (Hash)


99
100
101
102
103
104
# File 'lib/stratus/aws/iam.rb', line 99

def list_groups(options = {})
  params = make_pagination_params(options)
  params['PathPrefix'] = options[:path_prefix] if options[:path_prefix]
  response = call_api('ListGroups', params)
  Response.parse(:xml => response.to_str)
end

#list_groups_for_user(options = {}) ⇒ Hash

Calls ListGroupsForUser API

Parameters:

  • :user_name (Hash)

    parameter is required

Returns:

  • (Hash)


192
193
194
195
196
197
198
# File 'lib/stratus/aws/iam.rb', line 192

def list_groups_for_user(options = {})
  check_user_name(options)
  params = make_pagination_params(options)
  params['UserName'] = options[:user_name]
  response = call_api('ListGroupsForUser', params)
  Response.parse(:xml => response.to_str)
end

#list_signing_certificates(options = {}) ⇒ Hash

Calls list_signing_certificates API

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hash)


416
417
418
419
420
421
# File 'lib/stratus/aws/iam.rb', line 416

def list_signing_certificates(options = {})
  params = make_pagination_params(options)
  params['UserName'] = options[:user_name] if options[:user_name]
  response = call_api('ListSigningCertificates', params)
  Response.parse(:xml => response.to_str)
end

#list_user_policies(options = {}) ⇒ Hash

Calls ListUserPolicies API

Parameters:

  • options (Hash) (defaults to: {})

    :user_name options is required.

Returns:

  • (Hash)


367
368
369
370
371
372
373
# File 'lib/stratus/aws/iam.rb', line 367

def list_user_policies(options = {})
  check_user_name(options)
  params = make_pagination_params(options)
  params['UserName'] = options[:user_name]
  response = call_api('ListUserPolicies', params)
  Response.parse(:xml => response.to_str)
end

#list_users(options = {}) ⇒ Hash

Calls ListUsers API

Parameters:

  • (Hash)

Returns:

  • (Hash)


181
182
183
184
185
186
# File 'lib/stratus/aws/iam.rb', line 181

def list_users(options = {})
  params = make_pagination_params(options)
  params['PathPrefix'] = options[:path_prefix] if options[:path_prefix]
  response = call_api('ListUsers', params)
  Response.parse(:xml => response.to_str)
end

#put_group_policy(options = {}) ⇒ Hash

Calls PutGroupPolicy API

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hash)


281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/stratus/aws/iam.rb', line 281

def put_group_policy(options = {})
  check_group_name(options)
  check_policy_name(options)
  check_policy_document(options)
  params = {
    'GroupName' => options[:group_name],
    'PolicyName' => options[:policy_name],
    'PolicyDocument' => options[:policy_document]
  }
  response = call_api('PutGroupPolicy', params)
  Response.parse(:xml => response.to_str)
end

#put_user_policy(options = {}) ⇒ Hash

Calls PutUserPolicy API

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hash)


338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/stratus/aws/iam.rb', line 338

def put_user_policy(options = {})
  check_user_name(options)
  check_policy_name(options)
  check_policy_document(options)
  params = {
    'UserName' => options[:user_name],
    'PolicyName' => options[:policy_name],
    'PolicyDocument' => options[:policy_document]
  }
  response = call_api('PutUserPolicy', params)
  Response.parse(:xml => response.to_str)
end

#remove_user_from_group(options = {}) ⇒ Hash

Calls RemoveUserFromGroup API

Parameters:

  • :group_name (Hash)

    and :user_name parameters is required

Returns:

  • (Hash)


135
136
137
138
139
140
141
# File 'lib/stratus/aws/iam.rb', line 135

def remove_user_from_group(options = {})
  check_group_name(options)
  check_user_name(options)
  params = { 'GroupName' => options[:group_name], 'UserName' => options[:user_name] }
  response = call_api('RemoveUserFromGroup', params)
  Response.parse(:xml => response.to_str)
end

#update_access_key(options = {}) ⇒ Hash

Calls UpdateAccessKey API

Parameters:

  • options (Hash) (defaults to: {})

    :access_key_id and :status options is required.

Returns:

  • (Hash)


241
242
243
244
245
246
247
248
# File 'lib/stratus/aws/iam.rb', line 241

def update_access_key(options = {})
  check_access_key_id(options)
  check_activity_status(options)
  params = { 'AccessKeyId' => options[:access_key_id], 'Status' => options[:status].to_s.capitalize }
  params['UserName'] = options[:user_name] if options[:user_name]
  response = call_api('UpdateAccessKey', params)
  Response.parse(:xml => response.to_str)
end

#update_group(options = {}) ⇒ Hash

Calls UpdateGroup API

Parameters:

  • :group_name (Hash)

    parameter is required

Returns:

  • (Hash)


110
111
112
113
114
115
116
117
# File 'lib/stratus/aws/iam.rb', line 110

def update_group(options = {})
  check_group_name(options)
  params = { 'GroupName' => options[:group_name] }
  params['NewGroupName'] = options[:new_group_name] if options[:new_group_name]
  params['NewPathName'] = options[:new_path_name] if options[:new_path_name]
  response = call_api('UpdateGroup', params)
  Response.parse(:xml => response.to_str)
end

#update_signing_certificate(options = {}) ⇒ Hash

Calls UpdateSigningCertificate API

Parameters:

  • options (Hash) (defaults to: {})

    :certificate_id and :status options is required.

Returns:

  • (Hash)


391
392
393
394
395
396
397
398
# File 'lib/stratus/aws/iam.rb', line 391

def update_signing_certificate(options = {})
  check_certificate_id(options)
  check_activity_status(options)
  params = { 'CertificateId' => options[:certificate_id], 'Status' => options[:status].to_s.capitalize }
  params['UserName'] = options[:user_name] if options[:user_name]
  response = call_api('UpdateSigningCertificate', params)
  Response.parse(:xml => response.to_str)
end

#update_user(options = {}) ⇒ Hash

Calls UpdateUser API

Parameters:

  • :user_name (Hash)

    parameter is required

Returns:

  • (Hash)


204
205
206
207
208
209
210
211
212
# File 'lib/stratus/aws/iam.rb', line 204

def update_user(options = {})
  check_user_name(options)
  params = {}
  params['UserName'] = options[:user_name]
  params['NewPath'] = options[:new_path] if options[:new_path]
  params['NewUserName'] = options[:new_user_name] if options[:new_user_name]
  response = call_api('UpdateUser', params)
  Response.parse(:xml => response.to_str)
end

#upload_signing_certificate(options = {}) ⇒ Hash

Calls UploadSigningCertificate API

Parameters:

  • options (Hash) (defaults to: {})

    :certificate_body options is required.

Returns:

  • (Hash)


379
380
381
382
383
384
385
# File 'lib/stratus/aws/iam.rb', line 379

def upload_signing_certificate(options = {})
  check_certificate_body(options)
  params = { 'CertificateBody' => options[:certificate_body] }
  params['UserName'] = options[:user_name] if options[:user_name]
  response = call_api('UploadSigningCertificate', params)
  Response.parse(:xml => response.to_str)
end