2017-03-29 21:09:05 +00:00
|
|
|
# author: Alex Bedley
|
|
|
|
# author: Steffanie Freeman
|
|
|
|
|
|
|
|
module AwsIam
|
|
|
|
class UserProvider
|
|
|
|
def initialize(conn = AWSConnection.new)
|
|
|
|
@iam_resource = conn.iam_resource
|
|
|
|
end
|
|
|
|
|
2017-05-10 19:41:03 +00:00
|
|
|
def user(name)
|
2017-03-29 21:09:05 +00:00
|
|
|
aws_user = @iam_resource.user(name)
|
|
|
|
self.class.convert(aws_user)
|
|
|
|
end
|
|
|
|
|
2017-05-10 19:41:03 +00:00
|
|
|
def list_users
|
|
|
|
aws_users = @iam_resource.users
|
|
|
|
aws_users.map do |aws_user|
|
|
|
|
self.class.convert(aws_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-29 21:09:05 +00:00
|
|
|
class << self
|
2017-08-08 13:50:35 +00:00
|
|
|
def name(aws_user)
|
|
|
|
aws_user.name
|
|
|
|
end
|
|
|
|
|
2017-03-29 21:09:05 +00:00
|
|
|
def has_mfa_enabled?(aws_user)
|
|
|
|
!aws_user.mfa_devices.first.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_console_password?(aws_user)
|
|
|
|
return !aws_user.login_profile.create_date.nil?
|
|
|
|
rescue Aws::IAM::Errors::NoSuchEntity
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2017-06-13 05:36:43 +00:00
|
|
|
def access_keys(aws_user)
|
|
|
|
aws_user.access_keys
|
|
|
|
end
|
|
|
|
|
2017-03-29 21:09:05 +00:00
|
|
|
def convert(aws_user)
|
|
|
|
{
|
2017-08-08 13:50:35 +00:00
|
|
|
name: name(aws_user),
|
2017-03-29 21:09:05 +00:00
|
|
|
has_mfa_enabled?: has_mfa_enabled?(aws_user),
|
|
|
|
has_console_password?: has_console_password?(aws_user),
|
2017-06-13 05:36:43 +00:00
|
|
|
access_keys: access_keys(aws_user),
|
2017-03-29 21:09:05 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|