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

Class: AWS::IAM::AccessKey

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#exists?

Constructor Details

#initialize(access_key_id, options = {}) ⇒ AccessKey

Returns a new instance of AccessKey

Parameters:

  • access_key_id (String)

    The id of this access key.

  • options (Hash) (defaults to: {})
  • [String] (Hash)

    a customizable set of options



29
30
31
32
33
34
# File 'lib/aws/iam/access_key.rb', line 29

def initialize access_key_id, options = {}
  @id = access_key_id
  options[:secret_value] = nil unless options.has_key?(:secret_value)
  @user = options[:user]
  @user ? super(@user, options) : super(options)
end

Instance Attribute Details

#create_dateTime (readonly)

Returns the current value of create_date

Returns:

  • (Time)

    the current value of create_date



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

def create_date
  @create_date
end

#idString (readonly) Also known as: access_key_id

Returns the access key id.

Returns:

  • (String)

    Returns the access key id.



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

def id
  @id
end

#statusSymbol (readonly)

The status of this access key. Status may be :active or :inactive.

Returns:

  • (Symbol)

    the current value of status



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

def status
  @status
end

#userUser? (readonly)

Returns the user this access key belongs to. Returns nil if this access key belongs to the AWS account and not a specific user.

Returns:

  • (User, nil)

    Returns the user this access key belongs to. Returns nil if this access key belongs to the AWS account and not a specific user.



39
40
41
# File 'lib/aws/iam/access_key.rb', line 39

def user
  @user
end

Instance Method Details

#activate!nil

Activates this access key.

Examples:

access_key.activate!
access_key.status
# => :active

Returns:

  • (nil)


114
115
116
117
# File 'lib/aws/iam/access_key.rb', line 114

def activate!
  self.status = 'Active'
  nil
end

#active?Boolean

Returns true if this access key is active.

Returns:

  • (Boolean)

    Returns true if this access key is active.



97
98
99
# File 'lib/aws/iam/access_key.rb', line 97

def active?
  status == :active
end

#credentialsHash

Returns a hash that should be saved somewhere safe.

access_keys = iam.access_keys.create
access_keys.credentials
#=> { :access_key_id => '...', :secret_access_key => '...' }

You can also use these credentials to make requests:

s3 = AWS::S3.new(access_keys.credentials)
s3.buckets.create('newbucket')

Returns:

  • (Hash)

    Returns a hash with the access key id and secret access key.



152
153
154
# File 'lib/aws/iam/access_key.rb', line 152

def credentials
  { :access_key_id => id, :secret_access_key => secret }
end

#deactivate!nil

Deactivates this access key.

Examples:

access_key.deactivate!
access_key.status
# => :inactive

Returns:

  • (nil)
  • (nil)


128
129
130
131
# File 'lib/aws/iam/access_key.rb', line 128

def deactivate!
  self.status = 'Inactive'
  nil
end

#deleteObject

Deletes the access key.



134
135
136
137
# File 'lib/aws/iam/access_key.rb', line 134

def delete
  client.delete_access_key(resource_options)
  nil
end

#inactive?Boolean

Returns true if this access key is inactive.

Returns:

  • (Boolean)

    Returns true if this access key is inactive.



102
103
104
# File 'lib/aws/iam/access_key.rb', line 102

def inactive?
  status == :inactive
end

#secretString Also known as: secret_access_key

Returns the secret access key.

You can only access the secret for newly created access keys. Calling secret on existing access keys raises an error.

Examples:

Getting the secret from a newly created access key


access_key = iam.access_keys.create
access_key.secret
#=> 'SECRET_ACCESS_KEY'

Failing to get the secret from an existing access key.


access_key = iam.access_keys.first
access_key.secret
#=> raises a runtime error

Returns:

  • (String)

    Returns the secret access key.



83
84
85
# File 'lib/aws/iam/access_key.rb', line 83

def secret
  secret_value or raise 'secret is only available for new access keys'
end

#user_nameString?

Returns the name of the user this access key belogns to. If the access key belongs to the account, nil is returned.

Returns:

  • (String, nil)

    Returns the name of the user this access key belogns to. If the access key belongs to the account, nil is returned.



92
93
94
# File 'lib/aws/iam/access_key.rb', line 92

def user_name
  @user ? @user.name : nil
end