mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|iam] Updates reference to service
This commit is contained in:
parent
13733d01dc
commit
a550c54407
6 changed files with 45 additions and 45 deletions
|
@ -10,29 +10,29 @@ module Fog
|
||||||
attribute :username, :aliases => 'UserName'
|
attribute :username, :aliases => 'UserName'
|
||||||
attribute :secret_access_key, :aliases => 'SecretAccessKey'
|
attribute :secret_access_key, :aliases => 'SecretAccessKey'
|
||||||
attribute :status, :aliases => 'Status'
|
attribute :status, :aliases => 'Status'
|
||||||
|
|
||||||
def save
|
def save
|
||||||
requires :username
|
requires :username
|
||||||
|
|
||||||
data = connection.create_access_key('UserName'=> username).body["AccessKey"]
|
data = service.create_access_key('UserName'=> username).body["AccessKey"]
|
||||||
merge_attributes(data)
|
merge_attributes(data)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
requires :id
|
requires :id
|
||||||
requires :username
|
requires :username
|
||||||
|
|
||||||
connection.delete_access_key(id,'UserName'=> username)
|
service.delete_access_key(id,'UserName'=> username)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def user
|
def user
|
||||||
requires :username
|
requires :username
|
||||||
connection.users.get(username)
|
service.users.get(username)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,17 +6,17 @@ module Fog
|
||||||
class IAM
|
class IAM
|
||||||
|
|
||||||
class AccessKeys < Fog::Collection
|
class AccessKeys < Fog::Collection
|
||||||
|
|
||||||
model Fog::AWS::IAM::AccessKey
|
model Fog::AWS::IAM::AccessKey
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
@username = attributes[:username]
|
@username = attributes[:username]
|
||||||
raise ArgumentError.new("Can't get an access_key's user without a username") unless @username
|
raise ArgumentError.new("Can't get an access_key's user without a username") unless @username
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def all
|
def all
|
||||||
data = connection.list_access_keys('UserName'=> @username).body['AccessKeys']
|
data = service.list_access_keys('UserName'=> @username).body['AccessKeys']
|
||||||
# AWS response doesn't contain the UserName, this injects it
|
# AWS response doesn't contain the UserName, this injects it
|
||||||
data.each {|access_key| access_key['UserName'] = @username }
|
data.each {|access_key| access_key['UserName'] = @username }
|
||||||
load(data)
|
load(data)
|
||||||
|
@ -25,7 +25,7 @@ module Fog
|
||||||
def get(identity)
|
def get(identity)
|
||||||
self.all.select {|access_key| access_key.id == identity}.first
|
self.all.select {|access_key| access_key.id == identity}.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def new(attributes = {})
|
def new(attributes = {})
|
||||||
super({ :username => @username }.merge!(attributes))
|
super({ :username => @username }.merge!(attributes))
|
||||||
end
|
end
|
||||||
|
@ -33,4 +33,4 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,39 +6,39 @@ module Fog
|
||||||
class IAM
|
class IAM
|
||||||
|
|
||||||
class Policies < Fog::Collection
|
class Policies < Fog::Collection
|
||||||
|
|
||||||
model Fog::AWS::IAM::Policy
|
model Fog::AWS::IAM::Policy
|
||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
@username = attributes[:username]
|
@username = attributes[:username]
|
||||||
raise ArgumentError.new("Can't get a policy's user without a username") unless @username
|
raise ArgumentError.new("Can't get a policy's user without a username") unless @username
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def all
|
def all
|
||||||
# AWS method get_user_policy only returns an array of policy names, this is kind of useless,
|
# AWS method get_user_policy only returns an array of policy names, this is kind of useless,
|
||||||
# that's why it has to loop through the list to get the details of each element. I don't like it because it makes this method slow
|
# that's why it has to loop through the list to get the details of each element. I don't like it because it makes this method slow
|
||||||
policy_names = connection.list_user_policies(@username).body['PolicyNames'] # it returns an array
|
policy_names = service.list_user_policies(@username).body['PolicyNames'] # it returns an array
|
||||||
policies = []
|
policies = []
|
||||||
policy_names.each do |policy_name|
|
policy_names.each do |policy_name|
|
||||||
policies << connection.get_user_policy(policy_name,@username).body['Policy']
|
policies << service.get_user_policy(policy_name,@username).body['Policy']
|
||||||
end
|
end
|
||||||
load(policies) # data is an array of attribute hashes
|
load(policies) # data is an array of attribute hashes
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(identity)
|
def get(identity)
|
||||||
data = connection.get_user_policy(identity,@username).body['Policy']
|
data = service.get_user_policy(identity,@username).body['Policy']
|
||||||
new(data) # data is an attribute hash
|
new(data) # data is an attribute hash
|
||||||
rescue Fog::AWS::IAM::NotFound
|
rescue Fog::AWS::IAM::NotFound
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def new(attributes = {})
|
def new(attributes = {})
|
||||||
super({ :username => @username }.merge!(attributes))
|
super({ :username => @username }.merge!(attributes))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,31 +9,31 @@ module Fog
|
||||||
identity :id, :aliases => 'PolicyName'
|
identity :id, :aliases => 'PolicyName'
|
||||||
attribute :username, :aliases => 'UserName'
|
attribute :username, :aliases => 'UserName'
|
||||||
attribute :document, :aliases => 'PolicyDocument'
|
attribute :document, :aliases => 'PolicyDocument'
|
||||||
|
|
||||||
def save
|
def save
|
||||||
requires :id
|
requires :id
|
||||||
requires :username
|
requires :username
|
||||||
requires :document
|
requires :document
|
||||||
|
|
||||||
data = connection.put_user_policy(username, id, document).body
|
data = service.put_user_policy(username, id, document).body
|
||||||
merge_attributes(data)
|
merge_attributes(data)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
requires :id
|
requires :id
|
||||||
requires :username
|
requires :username
|
||||||
|
|
||||||
connection.delete_user_policy(username, id)
|
service.delete_user_policy(username, id)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def user
|
def user
|
||||||
requires :username
|
requires :username
|
||||||
connection.users.get(username)
|
service.users.get(username)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,31 +10,31 @@ module Fog
|
||||||
attribute :path, :aliases => 'Path'
|
attribute :path, :aliases => 'Path'
|
||||||
attribute :arn, :aliases => 'Arn'
|
attribute :arn, :aliases => 'Arn'
|
||||||
attribute :user_id, :aliases => 'UserId'
|
attribute :user_id, :aliases => 'UserId'
|
||||||
|
|
||||||
def save
|
def save
|
||||||
requires :id
|
requires :id
|
||||||
data = connection.create_user(id, path || '/').body['User']
|
data = service.create_user(id, path || '/').body['User']
|
||||||
merge_attributes(data)
|
merge_attributes(data)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
requires :id
|
requires :id
|
||||||
connection.delete_user(id)
|
service.delete_user(id)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def policies
|
def policies
|
||||||
requires :id
|
requires :id
|
||||||
connection.policies(:username => id)
|
service.policies(:username => id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def access_keys
|
def access_keys
|
||||||
requires :id
|
requires :id
|
||||||
connection.access_keys(:username => id)
|
service.access_keys(:username => id)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,13 +14,13 @@ module Fog
|
||||||
|
|
||||||
def all(options = {})
|
def all(options = {})
|
||||||
merge_attributes(options)
|
merge_attributes(options)
|
||||||
data = connection.list_users(options).body
|
data = service.list_users(options).body
|
||||||
merge_attributes('IsTruncated' => data['IsTruncated'], 'Marker' => data['Marker'])
|
merge_attributes('IsTruncated' => data['IsTruncated'], 'Marker' => data['Marker'])
|
||||||
load(data['Users']) # data is an array of attribute hashes
|
load(data['Users']) # data is an array of attribute hashes
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(identity)
|
def get(identity)
|
||||||
data = connection.get_user(identity).body['User']
|
data = service.get_user(identity).body['User']
|
||||||
new(data) # data is an attribute hash
|
new(data) # data is an attribute hash
|
||||||
rescue Fog::AWS::IAM::NotFound
|
rescue Fog::AWS::IAM::NotFound
|
||||||
nil
|
nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue