Class: AWS::IAM::VirtualMfaDevice

Inherits:
Resource show all
Defined in:
lib/aws/iam/virtual_mfa_device.rb

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods inherited from Resource

#exists?, prefix_update_attributes, update_prefix

Methods inherited from Core::Resource

attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, #inspect, new_from

Methods included from Core::Cacheable

included, #retrieve_attribute

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(serial_number, options = {}) ⇒ VirtualMfaDevice

Returns a new instance of VirtualMfaDevice.



36
37
38
39
# File 'lib/aws/iam/virtual_mfa_device.rb', line 36

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

Instance Attribute Details

#base_32_string_seedString (readonly)

The Base32 seed defined as specified in RFC3548. Only accessible on newly created devices. This value is Base64-encoded.

Returns:

  • (String)

    the current value of base_32_string_seed



33
34
35
# File 'lib/aws/iam/virtual_mfa_device.rb', line 33

def base_32_string_seed
  @base_32_string_seed
end

#enable_dateDateTime (readonly)

When this device was enabled. Returns nil if this device has not been enabled.

Returns:

  • (DateTime)

    the current value of enable_date



33
34
35
# File 'lib/aws/iam/virtual_mfa_device.rb', line 33

def enable_date
  @enable_date
end

#qr_code_pngBlob (readonly)

A QR code PNG image that encodes otpauth://totp/$virtualMFADeviceName@$AccountName? secret=$Base32String where $virtualMFADeviceName is one of the create call arguments, AccountName is the user name if set (accountId otherwise), and Base32String is the seed in Base32 format. Only accessible on newly created devices. This value is Base64-encoded.

Returns:

  • (Blob)

    the current value of qr_code_png



33
34
35
# File 'lib/aws/iam/virtual_mfa_device.rb', line 33

def qr_code_png
  @qr_code_png
end

#serial_numberString (readonly) Also known as: arn

Returns the virtual MFA device serial number (ARN).

Returns:

  • (String)

    Returns the virtual MFA device serial number (ARN).



42
43
44
# File 'lib/aws/iam/virtual_mfa_device.rb', line 42

def serial_number
  @serial_number
end

Instance Method Details

#deactivatenil Also known as: disable

Deactivates the MFA device and removes it from association with the user for which it was originally enabled.

Returns:

  • (nil)


95
96
97
98
99
100
101
# File 'lib/aws/iam/virtual_mfa_device.rb', line 95

def deactivate
  client_opts = {}
  client_opts[:user_name] = user.name
  client_opts[:serial_number] = serial_number
  client.deactivate_mfa_device(client_opts)
  nil
end

#deletenil

Deletes this virtual MFA device.

Returns:

  • (nil)


106
107
108
109
# File 'lib/aws/iam/virtual_mfa_device.rb', line 106

def delete
  client.delete_virtual_mfa_device(resource_options)
  nil
end

#enable(user, code1, code2) ⇒ Object

Enables the MFA device and associates it with the specified user. When enabled, the MFA device is required for every subsequent login by the user name associated with the device.

Parameters:

  • user (User, String)

    The user (or user name string) you want to enable this device for.

  • code1 (String)

    An authentication code emitted by the device.

  • code2 (String)

    A subsequent authentication code emitted by the device.



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/aws/iam/virtual_mfa_device.rb', line 72

def enable user, code1, code2

  user_name = user.is_a?(User) ? user.name : user

  client.enable_mfa_device(
    :user_name => user_name,
    :serial_number => serial_number,
    :authentication_code_1 => format_auth_code(code1),
    :authentication_code_2 => format_auth_code(code2))

  nil

end

#enabled?Boolean

Returns true if this device has been enabled for a user.

Returns:

  • (Boolean)

    Returns true if this device has been enabled for a user.



88
89
90
# File 'lib/aws/iam/virtual_mfa_device.rb', line 88

def enabled?
  !!enable_date
end

#userUser?

Returns the user this device was enabled for, or nil if this device has not been enabled.

Returns:

  • (User, nil)

    Returns the user this device was enabled for, or nil if this device has not been enabled.



58
59
60
61
62
# File 'lib/aws/iam/virtual_mfa_device.rb', line 58

def user
  if details = user_details
    User.new(details.user_name, :config => config)
  end
end