You are viewing documentation for version 3 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: Aws::IAM::CurrentUser

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb

Defined Under Namespace

Classes: Collection

Associations collapse

Read-Only Attributes collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CurrentUser

Returns a new instance of CurrentUser

Options Hash (options):



15
16
17
18
19
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 15

def initialize(*args)
  options = Hash === args.last ? args.pop.dup : {}
  @data = options.delete(:data)
  @client = options.delete(:client) || Client.new(options)
end

Instance Method Details

#access_keys(options = {}) ⇒ AccessKey::Collection

Examples:

Request syntax with placeholder values


access_keys = current_user.access_keys({
  user_name: "existingUserNameType",
})

Parameters:

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

    ({})

Options Hash (options):

  • :user_name (String)

    The name of the user.

    This parameter allows (per its regex pattern) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: =,.@-

Returns:



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 254

def access_keys(options = {})
  batches = Enumerator.new do |y|
    resp = @client.list_access_keys(options)
    resp.each_page do |page|
      batch = []
      page.data..each do |a|
        batch << AccessKey.new(
          user_name: a.user_name,
          id: a.access_key_id,
          data: a,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  AccessKey::Collection.new(batches)
end

#arnString

The Amazon Resource Name (ARN) that identifies the user. For more information about ARNs and how to use ARNs in policies, see IAM Identifiers in the Using IAM guide.

Returns:

  • (String)


60
61
62
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 60

def arn
  data[:arn]
end

#clientClient

Returns:



107
108
109
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 107

def client
  @client
end

#create_dateTime

The date and time, in ISO 8601 date-time format, when the user was created.

Returns:

  • (Time)


71
72
73
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 71

def create_date
  data[:create_date]
end

#dataTypes::User

Returns the data for this Aws::IAM::CurrentUser. Calls Aws::IAM::Client#get_user if #data_loaded? is false.

Returns:



127
128
129
130
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 127

def data
  load unless @data
  @data
end

#data_loaded?Boolean

Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.

Returns:

  • (Boolean)

    Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.



135
136
137
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 135

def data_loaded?
  !!@data
end

#loadself Also known as: reload

Loads, or reloads #data for the current Aws::IAM::CurrentUser. Returns self making it possible to chain methods.

current_user.reload.data

Returns:

  • (self)


117
118
119
120
121
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 117

def load
  resp = @client.get_user
  @data = resp.user
  self
end

#mfa_devices(options = {}) ⇒ MfaDevice::Collection

Examples:

Request syntax with placeholder values


mfa_devices = current_user.mfa_devices({
  user_name: "existingUserNameType",
})

Parameters:

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

    ({})

Options Hash (options):

  • :user_name (String)

    The name of the user whose MFA devices you want to list.

    This parameter allows (per its regex pattern) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: =,.@-

Returns:



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 291

def mfa_devices(options = {})
  batches = Enumerator.new do |y|
    resp = @client.list_mfa_devices(options)
    resp.each_page do |page|
      batch = []
      page.data.mfa_devices.each do |m|
        batch << MfaDevice.new(
          user_name: m.user_name,
          serial_number: m.serial_number,
          data: m,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  MfaDevice::Collection.new(batches)
end

#password_last_usedTime

The date and time, in ISO 8601 date-time format, when the user's password was last used to sign in to an AWS website. For a list of AWS websites that capture a user's last sign-in time, see the Credential Reports topic in the Using IAM guide. If a password is used more than once in a five-minute span, only the first use is returned in this field. If the field is null (no value) then it indicates that they never signed in with a password. This can be because:

  • The user never had a password.

  • A password exists but has not been used since IAM started tracking this information on October 20th, 2014.

A null does not mean that the user never had a password. Also, if the user does not currently have a password, but had one in the past, then this field contains the date and time the most recent password was used.

This value is returned only in the GetUser and ListUsers actions.

Returns:

  • (Time)


100
101
102
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 100

def password_last_used
  data[:password_last_used]
end

#pathString

The path to the user. For more information about paths, see IAM Identifiers in the Using IAM guide.

Returns:

  • (String)


30
31
32
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 30

def path
  data[:path]
end

#signing_certificates(options = {}) ⇒ SigningCertificate::Collection

Examples:

Request syntax with placeholder values


signing_certificates = current_user.signing_certificates({
  user_name: "existingUserNameType",
})

Parameters:

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

    ({})

Options Hash (options):

  • :user_name (String)

    The name of the IAM user whose signing certificates you want to examine.

    This parameter allows (per its regex pattern) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: =,.@-

Returns:



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 329

def signing_certificates(options = {})
  batches = Enumerator.new do |y|
    resp = @client.list_signing_certificates(options)
    resp.each_page do |page|
      batch = []
      page.data.certificates.each do |c|
        batch << SigningCertificate.new(
          user_name: c.user_name,
          id: c.certificate_id,
          data: c,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  SigningCertificate::Collection.new(batches)
end

#userUser?

Returns:



349
350
351
352
353
354
355
356
357
358
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 349

def user
  if data[:user_name]
    User.new(
      name: data[:user_name],
      client: @client
    )
  else
    nil
  end
end

#user_idString

The stable and unique string identifying the user. For more information about IDs, see IAM Identifiers in the Using IAM guide.

Returns:

  • (String)


48
49
50
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 48

def user_id
  data[:user_id]
end

#user_nameString

The friendly name identifying the user.

Returns:

  • (String)


36
37
38
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 36

def user_name
  data[:user_name]
end

#wait_until(options = {}, &block) ⇒ Resource

Deprecated.

Use [Aws::IAM::Client] #wait_until instead

Note:

The waiting operation is performed on a copy. The original resource remains unchanged

Waiter polls an API operation until a resource enters a desired state.

Basic Usage

Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.

# polls in a loop until condition is true
resource.wait_until(options) {|resource| condition}

Example

instance.wait_until(max_attempts:10, delay:5) {|instance| instance.state.name == 'running' }

Configuration

You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:

# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}

Callbacks

You can be notified before each polling attempt and before each delay. If you throw :success or :failure from these callbacks, it will terminate the waiter.

started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
  throw :failure if Time.now - started_at > 3600
end

  # disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}

Handling Errors

When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.

begin
  resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
  # resource did not enter the desired state in time
end

attempts attempt in seconds invoked before each attempt invoked before each wait

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :max_attempts (Integer) — default: 10

    Maximum number of

  • :delay (Integer) — default: 10

    Delay between each

  • :before_attempt (Proc) — default: nil

    Callback

  • :before_wait (Proc) — default: nil

    Callback

Returns:

  • (Resource)

    if the waiter was successful

Raises:

  • (Aws::Waiters::Errors::FailureStateError)

    Raised when the waiter terminates because the waiter has entered a state that it will not transition out of, preventing success.

    yet successful.

  • (Aws::Waiters::Errors::UnexpectedError)

    Raised when an error is encountered while polling for a resource that is not expected.

  • (NotImplementedError)

    Raised when the resource does not



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/current_user.rb', line 217

def wait_until(options = {}, &block)
  self_copy = self.dup
  attempts = 0
  options[:max_attempts] = 10 unless options.key?(:max_attempts)
  options[:delay] ||= 10
  options[:poller] = Proc.new do
    attempts += 1
    if block.call(self_copy)
      [:success, self_copy]
    else
      self_copy.reload unless attempts == options[:max_attempts]
      :retry
    end
  end
  Aws::Waiters::Waiter.new(options).wait({})
end