1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/iam/access_keys.rb

37 lines
935 B
Ruby
Raw Normal View History

2012-06-04 15:24:02 +02:00
require 'fog/core/collection'
require 'fog/aws/models/iam/access_key'
module Fog
module AWS
class IAM
class AccessKeys < Fog::Collection
2012-12-22 23:30:34 +00:00
2012-06-04 15:24:02 +02:00
model Fog::AWS::IAM::AccessKey
2012-12-22 23:30:34 +00:00
def initialize(attributes = {})
@username = attributes[:username]
raise ArgumentError.new("Can't get an access_key's user without a username") unless @username
2012-06-04 15:24:02 +02:00
super
end
2012-12-22 23:30:34 +00:00
def all
data = service.list_access_keys('UserName'=> @username).body['AccessKeys']
2012-06-04 15:24:02 +02:00
# AWS response doesn't contain the UserName, this injects it
data.each {|access_key| access_key['UserName'] = @username }
2012-06-04 15:24:02 +02:00
load(data)
end
def get(identity)
self.all.select {|access_key| access_key.id == identity}.first
end
2012-12-22 23:30:34 +00:00
2012-06-04 15:24:02 +02:00
def new(attributes = {})
super({ :username => @username }.merge!(attributes))
2012-06-04 15:24:02 +02:00
end
end
end
end
2012-12-22 23:30:34 +00:00
end