Class: AWS::IAM::MFADeviceCollection

Inherits:
Object
  • Object
show all
Includes:
Collection
Defined in:
lib/aws/iam/mfa_device_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::Collection

#each_batch, #enum, #first, #in_groups_of, #page

Constructor Details

#initialize(user, options = {}) ⇒ MFADeviceCollection

Returns a new instance of MFADeviceCollection.

Parameters:

  • user (User)

    The user that owns this device collection.



22
23
24
25
# File 'lib/aws/iam/mfa_device_collection.rb', line 22

def initialize user, options = {}
  @user = user
  super
end

Instance Attribute Details

#userUser (readonly)

Returns the user that this mfa device collection belongs to.

Returns:

  • (User)

    Returns the user that this mfa device collection belongs to.



17
18
19
# File 'lib/aws/iam/mfa_device_collection.rb', line 17

def user
  @user
end

Instance Method Details

#[](serial_number) ⇒ MFADevice

Returns a reference to an MFA device with the given serial number.

Parameters:

  • serial_number (String)

    The serial number of an MFA device.

Returns:

  • (MFADevice)

    Returns a reference to an MFA device with the given serial number.



62
63
64
# File 'lib/aws/iam/mfa_device_collection.rb', line 62

def [] serial_number
  MFADevice.new(user, serial_number)
end

#clearnil

Deactivates all of the MFA devices in this collection. Virtual MFA devices in this collection will not be deleted. Instead they will be available in the AWS::IAM#virtual_mfa_devices collection so that they can either be deleted or enabled for different users.

Returns:

  • (nil)


73
74
75
76
77
78
# File 'lib/aws/iam/mfa_device_collection.rb', line 73

def clear
  each do |device|
    device.deactivate
  end
  nil
end

#disable(serial_number) ⇒ nil

Parameters:

  • serial_number (String)

    The serial number of the MFA device you want to disable.

Returns:

  • (nil)


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

def disable serial_number
  self[serial_number].disable
  nil
end

#each(options = {}) {|user| ... } ⇒ nil

Yields once for each MFA device.

You can limit the number of devices yielded using :limit.

Parameters:

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

Options Hash (options):

  • :limit (Integer)

    The maximum number of devices to yield.

  • :batch_size (Integer)

    The maximum number of devices receive each service reqeust.

Yield Parameters:

Returns:

  • (nil)


90
91
92
# File 'lib/aws/iam/mfa_device_collection.rb', line 90

def each options = {}, &block
  super(options.merge(:user_name => user.name), &block)
end

#enable(serial_number, authentication_code_1, authentication_code_2) ⇒ MFADevice Also known as: create

Enables an MFA device for this user.

Parameters:

  • serial_number (String)

    The serial number that uniquely identifies the MFA device

  • authentication_code_1 (String)

    An authentication code emitted by the device.

  • authentication_code_2 (String)

    A subsequent authentication code emitted by the device.

Returns:

  • (MFADevice)

    Returns the newly enabled MFA device.



39
40
41
42
43
44
45
46
47
# File 'lib/aws/iam/mfa_device_collection.rb', line 39

def enable serial_number, authentication_code_1, authentication_code_2
  client.enable_mfa_device({
    :user_name => user.name,
    :serial_number => serial_number,
    :authentication_code_1 => authentication_code_1.to_s,
    :authentication_code_2 => authentication_code_2.to_s,
  })
  self[serial_number]
end

#enumerator(options = {}) ⇒ Enumerator

Returns an enumerable object for this collection. This can be useful if you want to call an enumerable method that does not accept options (e.g. collect, first, etc).

mfa_devices.enumerator(:limit => 10).collect(&:serial_number)

Parameters:

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

Options Hash (options):

  • :limit (Integer)

    The maximum number of devices to yield.

  • :batch_size (Integer)

    The maximum number of devices receive each service reqeust.

Returns:

  • (Enumerator)


103
104
105
# File 'lib/aws/iam/mfa_device_collection.rb', line 103

def enumerator options = {}
  super(options)
end