mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
IAM access_key model implemented
This commit is contained in:
parent
cd1ee8de3f
commit
c14fea60fe
5 changed files with 110 additions and 10 deletions
|
@ -60,7 +60,9 @@ module Fog
|
|||
model :user
|
||||
collection :users
|
||||
model :policy
|
||||
collection :policies
|
||||
collection :policies
|
||||
model :access_key
|
||||
collection :access_keys
|
||||
|
||||
|
||||
class Mock
|
||||
|
|
38
lib/fog/aws/models/iam/access_key.rb
Normal file
38
lib/fog/aws/models/iam/access_key.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
|
||||
class AccessKey < Fog::Model
|
||||
|
||||
identity :id, :aliases => 'AccessKeyId'
|
||||
attribute :username, :aliases => 'UserName'
|
||||
attribute :secret_access_key, :aliases => 'SecretAccessKey'
|
||||
attribute :status, :aliases => 'Status'
|
||||
|
||||
def save
|
||||
requires :username
|
||||
|
||||
data = connection.create_access_key('UserName'=> username).body["AccessKey"]
|
||||
merge_attributes(data)
|
||||
true
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
requires :username
|
||||
|
||||
connection.delete_access_key(id,'UserName'=> username)
|
||||
true
|
||||
end
|
||||
|
||||
def user
|
||||
requires :username
|
||||
connection.users.get(username)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
48
lib/fog/aws/models/iam/access_keys.rb
Normal file
48
lib/fog/aws/models/iam/access_keys.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/aws/models/iam/access_key'
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
|
||||
class AccessKeys < Fog::Collection
|
||||
attribute :user
|
||||
attribute :filters
|
||||
|
||||
|
||||
model Fog::AWS::IAM::AccessKey
|
||||
|
||||
def initialize(attributes)
|
||||
self.filters ||= {}
|
||||
if attributes[:user]
|
||||
filters[:identifier] = attributes[:user].id
|
||||
else
|
||||
raise ArgumentError.new("Can't get a user's access_key without a user.id")
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
|
||||
def all
|
||||
data = connection.list_access_keys('UserName'=> filters[:identifier]).body['AccessKeys']
|
||||
# AWS response doesn't contain the UserName, this injects it
|
||||
data.each {|access_key| access_key['UserName'] = filters[:identifier] }
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(identity)
|
||||
self.all.select {|access_key| access_key.id == identity}.first
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
if user
|
||||
super({ :username => user.id }.merge!(attributes))
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -20,21 +20,29 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
requires :username
|
||||
|
||||
connection.delete_user_policy(username, id)
|
||||
true
|
||||
end
|
||||
|
||||
def user
|
||||
requires :username
|
||||
connection.users.get(username)
|
||||
end
|
||||
|
||||
# Converts attributes to a parameter hash suitable for requests
|
||||
def attributes_to_params
|
||||
options = {
|
||||
'PolicyName' => id,
|
||||
'UserName' => username,
|
||||
'PolicyDocument' => document
|
||||
}
|
||||
|
||||
options.delete_if {|key, value| value.nil?}
|
||||
end
|
||||
# def attributes_to_params
|
||||
# options = {
|
||||
# 'PolicyName' => id,
|
||||
# 'UserName' => username,
|
||||
# 'PolicyDocument' => document
|
||||
# }
|
||||
#
|
||||
# options.delete_if {|key, value| value.nil?}
|
||||
# end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,6 +30,10 @@ module Fog
|
|||
connection.policies(:user => self)
|
||||
end
|
||||
|
||||
def access_keys
|
||||
requires :id
|
||||
connection.access_keys(:user => self)
|
||||
end
|
||||
# # Converts attributes to a parameter hash suitable for requests
|
||||
# def attributes_to_params
|
||||
# options = {
|
||||
|
|
Loading…
Reference in a new issue