Class: Aws::IAM::User
- Inherits:
-
Object
- Object
- Aws::IAM::User
- Extended by:
- Deprecations
- Defined in:
- lib/aws-sdk-iam/user.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#arn ⇒ String
The Amazon Resource Name (ARN) that identifies the user.
-
#create_date ⇒ Time
The date and time, in [ISO 8601 date-time format], when the user was created.
- #name ⇒ String (also: #user_name)
-
#password_last_used ⇒ Time
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.
-
#path ⇒ String
The path to the user.
-
#permissions_boundary ⇒ Types::AttachedPermissionsBoundary
The ARN of the policy used to set the permissions boundary for the user.
-
#tags ⇒ Array<Types::Tag>
A list of tags that are associated with the specified user.
-
#user_id ⇒ String
The stable and unique string identifying the user.
Actions collapse
- #add_group(options = {}) ⇒ EmptyStructure
- #attach_policy(options = {}) ⇒ EmptyStructure
- #create(options = {}) ⇒ User
- #create_access_key_pair(options = {}) ⇒ AccessKeyPair
- #create_login_profile(options = {}) ⇒ LoginProfile
- #create_policy(options = {}) ⇒ UserPolicy
- #delete(options = {}) ⇒ EmptyStructure
- #detach_policy(options = {}) ⇒ EmptyStructure
- #enable_mfa(options = {}) ⇒ MfaDevice
- #remove_group(options = {}) ⇒ EmptyStructure
- #update(options = {}) ⇒ User
Associations collapse
- #access_key(id) ⇒ AccessKey
- #access_keys(options = {}) ⇒ AccessKey::Collection
- #attached_policies(options = {}) ⇒ Policy::Collection
- #groups(options = {}) ⇒ Group::Collection
- #identifiers ⇒ Object deprecated private Deprecated.
- #login_profile ⇒ LoginProfile
- #mfa_device(serial_number) ⇒ MfaDevice
- #mfa_devices(options = {}) ⇒ MfaDevice::Collection
- #policies(options = {}) ⇒ UserPolicy::Collection
- #policy(name) ⇒ UserPolicy
- #signing_certificate(id) ⇒ SigningCertificate
- #signing_certificates(options = {}) ⇒ SigningCertificate::Collection
Instance Method Summary collapse
- #client ⇒ Client
-
#data ⇒ Types::User
Returns the data for this User.
-
#data_loaded? ⇒ Boolean
Returns ‘true` if this resource is loaded.
-
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the User exists.
-
#initialize(*args) ⇒ User
constructor
A new instance of User.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}, &block) ⇒ Resource
deprecated
Deprecated.
Use [Aws::IAM::Client] #wait_until instead
- #wait_until_exists(options = {}) ⇒ User
Constructor Details
#initialize(name, options = {}) ⇒ User #initialize(options = {}) ⇒ User
Returns a new instance of User.
19 20 21 22 23 24 |
# File 'lib/aws-sdk-iam/user.rb', line 19 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @name = extract_name(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() end |
Instance Method Details
#access_key(id) ⇒ AccessKey
667 668 669 670 671 672 673 |
# File 'lib/aws-sdk-iam/user.rb', line 667 def access_key(id) AccessKey.new( user_name: @name, id: id, client: @client ) end |
#access_keys(options = {}) ⇒ AccessKey::Collection
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/aws-sdk-iam/user.rb', line 680 def access_keys( = {}) batches = Enumerator.new do |y| = .merge(user_name: @name) resp = @client.list_access_keys() resp.each_page do |page| batch = [] page.data..each do |a| batch << AccessKey.new( user_name: @name, id: a.access_key_id, data: a, client: @client ) end y.yield(batch) end end AccessKey::Collection.new(batches) end |
#add_group(options = {}) ⇒ EmptyStructure
314 315 316 317 318 |
# File 'lib/aws-sdk-iam/user.rb', line 314 def add_group( = {}) = .merge(user_name: @name) resp = @client.add_user_to_group() resp.data end |
#arn ⇒ String
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.
[1]: docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html
65 66 67 |
# File 'lib/aws-sdk-iam/user.rb', line 65 def arn data[:arn] end |
#attach_policy(options = {}) ⇒ EmptyStructure
336 337 338 339 340 |
# File 'lib/aws-sdk-iam/user.rb', line 336 def attach_policy( = {}) = .merge(user_name: @name) resp = @client.attach_user_policy() resp.data end |
#attached_policies(options = {}) ⇒ Policy::Collection
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/aws-sdk-iam/user.rb', line 722 def attached_policies( = {}) batches = Enumerator.new do |y| = .merge(user_name: @name) resp = @client.list_attached_user_policies() resp.each_page do |page| batch = [] page.data.attached_policies.each do |a| batch << Policy.new( arn: a.policy_arn, client: @client ) end y.yield(batch) end end Policy::Collection.new(batches) end |
#create(options = {}) ⇒ User
392 393 394 395 396 397 398 399 400 |
# File 'lib/aws-sdk-iam/user.rb', line 392 def create( = {}) = .merge(user_name: @name) resp = @client.create_user() User.new( name: [:user_name], data: resp.data.user, client: @client ) end |
#create_access_key_pair(options = {}) ⇒ AccessKeyPair
407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/aws-sdk-iam/user.rb', line 407 def create_access_key_pair( = {}) = .merge(user_name: @name) resp = @client.create_access_key() AccessKeyPair.new( user_name: @name, id: resp.data.access_key.access_key_id, secret: resp.data.access_key.secret_access_key, data: resp.data.access_key, client: @client ) end |
#create_date ⇒ Time
The date and time, in [ISO 8601 date-time format], when the user was created.
76 77 78 |
# File 'lib/aws-sdk-iam/user.rb', line 76 def create_date data[:create_date] end |
#create_login_profile(options = {}) ⇒ LoginProfile
445 446 447 448 449 450 451 452 453 |
# File 'lib/aws-sdk-iam/user.rb', line 445 def create_login_profile( = {}) = .merge(user_name: @name) resp = @client.create_login_profile() LoginProfile.new( user_name: resp.data.login_profile.user_name, data: resp.data.login_profile, client: @client ) end |
#create_policy(options = {}) ⇒ UserPolicy
492 493 494 495 496 497 498 499 500 |
# File 'lib/aws-sdk-iam/user.rb', line 492 def create_policy( = {}) = .merge(user_name: @name) resp = @client.put_user_policy() UserPolicy.new( user_name: @name, name: [:policy_name], client: @client ) end |
#data ⇒ Types::User
Returns the data for this Aws::IAM::User. Calls Client#get_user if #data_loaded? is ‘false`.
156 157 158 159 |
# File 'lib/aws-sdk-iam/user.rb', line 156 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
164 165 166 |
# File 'lib/aws-sdk-iam/user.rb', line 164 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
507 508 509 510 511 |
# File 'lib/aws-sdk-iam/user.rb', line 507 def delete( = {}) = .merge(user_name: @name) resp = @client.delete_user() resp.data end |
#detach_policy(options = {}) ⇒ EmptyStructure
529 530 531 532 533 |
# File 'lib/aws-sdk-iam/user.rb', line 529 def detach_policy( = {}) = .merge(user_name: @name) resp = @client.detach_user_policy() resp.data end |
#enable_mfa(options = {}) ⇒ MfaDevice
586 587 588 589 590 591 592 593 594 |
# File 'lib/aws-sdk-iam/user.rb', line 586 def enable_mfa( = {}) = .merge(user_name: @name) resp = @client.enable_mfa_device() MfaDevice.new( user_name: @name, serial_number: [:serial_number], client: @client ) end |
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the User exists.
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/aws-sdk-iam/user.rb', line 171 def exists?( = {}) begin wait_until_exists(.merge(max_attempts: 1)) true rescue Aws::Waiters::Errors::UnexpectedError => e raise e.error rescue Aws::Waiters::Errors::WaiterFailed false end end |
#groups(options = {}) ⇒ Group::Collection
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
# File 'lib/aws-sdk-iam/user.rb', line 745 def groups( = {}) batches = Enumerator.new do |y| = .merge(user_name: @name) resp = @client.list_groups_for_user() resp.each_page do |page| batch = [] page.data.groups.each do |g| batch << Group.new( name: g.group_name, data: g, client: @client ) end y.yield(batch) end end Group::Collection.new(batches) end |
#identifiers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
878 879 880 |
# File 'lib/aws-sdk-iam/user.rb', line 878 def identifiers { name: @name } end |
#load ⇒ self Also known as: reload
Loads, or reloads #data for the current Aws::IAM::User. Returns ‘self` making it possible to chain methods.
user.reload.data
146 147 148 149 150 |
# File 'lib/aws-sdk-iam/user.rb', line 146 def load resp = @client.get_user(user_name: @name) @data = resp.user self end |
#login_profile ⇒ LoginProfile
765 766 767 768 769 770 |
# File 'lib/aws-sdk-iam/user.rb', line 765 def login_profile LoginProfile.new( user_name: @name, client: @client ) end |
#mfa_device(serial_number) ⇒ MfaDevice
774 775 776 777 778 779 780 |
# File 'lib/aws-sdk-iam/user.rb', line 774 def mfa_device(serial_number) MfaDevice.new( user_name: @name, serial_number: serial_number, client: @client ) end |
#mfa_devices(options = {}) ⇒ MfaDevice::Collection
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
# File 'lib/aws-sdk-iam/user.rb', line 787 def mfa_devices( = {}) batches = Enumerator.new do |y| = .merge(user_name: @name) resp = @client.list_mfa_devices() resp.each_page do |page| batch = [] page.data.mfa_devices.each do |m| batch << MfaDevice.new( user_name: @name, serial_number: m.serial_number, data: m, client: @client ) end y.yield(batch) end end MfaDevice::Collection.new(batches) end |
#name ⇒ String Also known as: user_name
29 30 31 |
# File 'lib/aws-sdk-iam/user.rb', line 29 def name @name end |
#password_last_used ⇒ Time
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 20, 2014.
A null valuedoes 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 operations.
[1]: www.iso.org/iso/iso8601 [2]: docs.aws.amazon.com/IAM/latest/UserGuide/credential-reports.html
105 106 107 |
# File 'lib/aws-sdk-iam/user.rb', line 105 def password_last_used data[:password_last_used] end |
#path ⇒ String
The path to the user. For more information about paths, see [IAM Identifiers] in the *Using IAM* guide.
[1]: docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html
41 42 43 |
# File 'lib/aws-sdk-iam/user.rb', line 41 def path data[:path] end |
#permissions_boundary ⇒ Types::AttachedPermissionsBoundary
The ARN of the policy used to set the permissions boundary for the user.
For more information about permissions boundaries, see [Permissions Boundaries for IAM Identities ](IAM/latest/UserGuide/access_policies_boundaries.html) in the *IAM User Guide*.
117 118 119 |
# File 'lib/aws-sdk-iam/user.rb', line 117 def data[:permissions_boundary] end |
#policies(options = {}) ⇒ UserPolicy::Collection
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# File 'lib/aws-sdk-iam/user.rb', line 812 def policies( = {}) batches = Enumerator.new do |y| = .merge(user_name: @name) resp = @client.list_user_policies() resp.each_page do |page| batch = [] page.data.policy_names.each do |p| batch << UserPolicy.new( user_name: @name, name: p, client: @client ) end y.yield(batch) end end UserPolicy::Collection.new(batches) end |
#policy(name) ⇒ UserPolicy
833 834 835 836 837 838 839 |
# File 'lib/aws-sdk-iam/user.rb', line 833 def policy(name) UserPolicy.new( user_name: @name, name: name, client: @client ) end |
#remove_group(options = {}) ⇒ EmptyStructure
614 615 616 617 618 |
# File 'lib/aws-sdk-iam/user.rb', line 614 def remove_group( = {}) = .merge(user_name: @name) resp = @client.remove_user_from_group() resp.data end |
#signing_certificate(id) ⇒ SigningCertificate
843 844 845 846 847 848 849 |
# File 'lib/aws-sdk-iam/user.rb', line 843 def signing_certificate(id) SigningCertificate.new( user_name: @name, id: id, client: @client ) end |
#signing_certificates(options = {}) ⇒ SigningCertificate::Collection
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 |
# File 'lib/aws-sdk-iam/user.rb', line 856 def signing_certificates( = {}) batches = Enumerator.new do |y| = .merge(user_name: @name) resp = @client.list_signing_certificates() resp.each_page do |page| batch = [] page.data.certificates.each do |c| batch << SigningCertificate.new( user_name: @name, id: c.certificate_id, data: c, client: @client ) end y.yield(batch) end end SigningCertificate::Collection.new(batches) end |
#tags ⇒ Array<Types::Tag>
A list of tags that are associated with the specified user. For more information about tagging, see [Tagging IAM Identities] in the *IAM User Guide*.
129 130 131 |
# File 'lib/aws-sdk-iam/user.rb', line 129 def data[:tags] end |
#update(options = {}) ⇒ User
654 655 656 657 658 659 660 661 |
# File 'lib/aws-sdk-iam/user.rb', line 654 def update( = {}) = .merge(user_name: @name) resp = @client.update_user() User.new( name: [:new_user_name], client: @client ) end |
#user_id ⇒ String
The stable and unique string identifying the user. For more information about IDs, see [IAM Identifiers] in the *Using IAM* guide.
[1]: docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html
53 54 55 |
# File 'lib/aws-sdk-iam/user.rb', line 53 def user_id data[:user_id] end |
#wait_until(options = {}, &block) ⇒ Resource
Use [Aws::IAM::Client] #wait_until instead
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() {|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
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/aws-sdk-iam/user.rb', line 277 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Waiters::Waiter.new().wait({}) end |
#wait_until_exists(options = {}) ⇒ User
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/aws-sdk-iam/user.rb', line 188 def wait_until_exists( = {}) , params = () waiter = Waiters::UserExists.new() yield_waiter_and_warn(waiter, &Proc.new) if block_given? waiter.wait(params.merge(user_name: @name)) User.new({ name: @name, client: @client }) end |