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)


42
43
44
45
46
# File 'lib/stratus/aws/iam.rb', line 42

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)


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

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)


49
50
51
# File 'lib/stratus/aws/iam.rb', line 49

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



474
475
476
477
478
479
480
# File 'lib/stratus/aws/iam.rb', line 474

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)


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

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)


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

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_login_profile(options = {}) ⇒ Hash

Calls create_login_profile API

Parameters:

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

Returns:

  • (Hash)


440
441
442
443
444
445
446
# File 'lib/stratus/aws/iam.rb', line 440

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

#create_user(options = {}) ⇒ Hash

Calls CreateUser API

Parameters:

  • :user_name (Hash)

    parameter is required

Returns:

  • (Hash)


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

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)


54
55
56
# File 'lib/stratus/aws/iam.rb', line 54

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)


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

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)


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

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)


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

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_login_profile(options = {}) ⇒ Hash

Calls delete_login_profile API

Parameters:

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

Returns:

  • (Hash)


464
465
466
467
468
469
# File 'lib/stratus/aws/iam.rb', line 464

def (options = {})
  check_user_name(options)
  params = { 'UserName' => options[:user_name] }
  response = call_api('DeleteLoginProfile', 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)


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

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)


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

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)


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

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)


59
60
61
# File 'lib/stratus/aws/iam.rb', line 59

def endpoint
  @endpoint
end

#get_group(options = {}) ⇒ Hash

Calls GetGropup API

Parameters:

  • :group_name (Hash)

    parameter is required

Returns:

  • (Hash)


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

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)


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

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_login_profile(options = {}) ⇒ Hash

Calls get_login_profile API

Parameters:

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

Returns:

  • (Hash)


429
430
431
432
433
434
# File 'lib/stratus/aws/iam.rb', line 429

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

#get_user(options = {}) ⇒ Hash

Calls GetUser API

Parameters:

  • (Hash)

Returns:

  • (Hash)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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_login_profile(options = {}) ⇒ Hash

Calls update_login_profile API

Parameters:

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

Returns:

  • (Hash)


452
453
454
455
456
457
458
# File 'lib/stratus/aws/iam.rb', line 452

def (options = {})
  check_user_name(options)
  check_password(options)
  params = { 'UserName' => options[:user_name], 'Password' => options[:password] }
  response = call_api('UpdateLoginProfile', 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)


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

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)


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

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)


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

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