mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|iam] first pass at basics
This commit is contained in:
parent
defbbecddc
commit
9e601313aa
9 changed files with 291 additions and 1 deletions
|
@ -7,6 +7,7 @@ module Fog
|
|||
service 'compute'
|
||||
service 'ec2'
|
||||
service 'elb'
|
||||
service 'iam'
|
||||
service 's3'
|
||||
service 'simpledb'
|
||||
service 'storage'
|
||||
|
|
|
@ -16,6 +16,8 @@ class AWS < Fog::Bin
|
|||
Fog::AWS::ELB.new
|
||||
when :eu_storage
|
||||
Fog::AWS::Storage.new(:region => 'eu-west-1')
|
||||
when :iam
|
||||
Fog::AWS::IAM.new
|
||||
when :sdb
|
||||
Fog::AWS::SimpleDB.new
|
||||
when :s3
|
||||
|
@ -32,7 +34,7 @@ class AWS < Fog::Bin
|
|||
end
|
||||
|
||||
def services
|
||||
[:compute, :elb, :sdb, :storage]
|
||||
[:compute, :elb, :iam, :sdb, :storage]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
86
lib/fog/aws/iam.rb
Normal file
86
lib/fog/aws/iam.rb
Normal file
|
@ -0,0 +1,86 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM < Fog::Service
|
||||
|
||||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
|
||||
request_path 'fog/aws/requests/iam'
|
||||
request :create_group
|
||||
request :delete_group
|
||||
request :list_groups
|
||||
|
||||
class Mock
|
||||
|
||||
def initialize(options={})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
|
||||
# Initialize connection to IAM
|
||||
#
|
||||
# ==== Notes
|
||||
# options parameter must include values for :aws_access_key_id and
|
||||
# :aws_secret_access_key in order to create a connection
|
||||
#
|
||||
# ==== Examples
|
||||
# iam = IAM.new(
|
||||
# :aws_access_key_id => your_aws_access_key_id,
|
||||
# :aws_secret_access_key => your_aws_secret_access_key
|
||||
# )
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
||||
#
|
||||
# ==== Returns
|
||||
# * IAM object with connection to AWS.
|
||||
def initialize(options={})
|
||||
@aws_access_key_id = options[:aws_access_key_id]
|
||||
@aws_secret_access_key = options[:aws_secret_access_key]
|
||||
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
||||
@host = options[:host] || 'iam.amazonaws.com'
|
||||
@path = options[:path] || '/'
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent])
|
||||
end
|
||||
|
||||
def reload
|
||||
@connection.reset
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request(params)
|
||||
idempotent = params.delete(:idempotent)
|
||||
parser = params.delete(:parser)
|
||||
|
||||
body = AWS.signed_params(
|
||||
params,
|
||||
{
|
||||
:aws_access_key_id => @aws_access_key_id,
|
||||
:hmac => @hmac,
|
||||
:host => @host,
|
||||
:path => @path,
|
||||
:version => '2010-05-08'
|
||||
}
|
||||
)
|
||||
|
||||
response = @connection.request({
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:idempotent => idempotent,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:host => @host,
|
||||
:method => 'POST',
|
||||
:parser => parser
|
||||
})
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
lib/fog/aws/parsers/iam/basic.rb
Normal file
19
lib/fog/aws/parsers/iam/basic.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module IAM
|
||||
|
||||
class Basic < Fog::Parsers::Base
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'requestId'
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/aws/parsers/iam/create_group.rb
Normal file
26
lib/fog/aws/parsers/iam/create_group.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module IAM
|
||||
|
||||
class CreateGroups < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'Group' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Arn', 'GroupId', 'GroupName', 'Path'
|
||||
@response['Group'][name] = @value
|
||||
when 'RequestId'
|
||||
response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/aws/parsers/iam/list_groups.rb
Normal file
32
lib/fog/aws/parsers/iam/list_groups.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module IAM
|
||||
|
||||
class ListGroups < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@group = {}
|
||||
@response = { 'Groups' => [] }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Arn', 'GroupId', 'GroupName', 'Path'
|
||||
@group[name] = @value
|
||||
when 'member'
|
||||
@response['Groups'] << @group
|
||||
@group = {}
|
||||
when 'IsTruncated'
|
||||
response[name] = (@value == 'true')
|
||||
when 'RequestId'
|
||||
response[name] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
43
lib/fog/aws/requests/iam/create_group.rb
Normal file
43
lib/fog/aws/requests/iam/create_group.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/iam/create_group'
|
||||
|
||||
# Create a new group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'GroupName'<~String>: name of the group to create (do not include path)
|
||||
# * 'Path'<~String>: optional path to group, defaults to '/'
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Group'<~Hash>:
|
||||
# * Arn<~String> -
|
||||
# * GroupId<~String> -
|
||||
# * GroupName<~String> -
|
||||
# * Path<~String> -
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
def create_group(group_name, path = '/')
|
||||
request(
|
||||
'Action' => 'CreateGroup',
|
||||
'GroupName' => group_name,
|
||||
'Path' => path,
|
||||
:parser => Fog::Parsers::AWS::IAM::CreateGroups.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def create_group(group_name, path = '/')
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
36
lib/fog/aws/requests/iam/delete_group.rb
Normal file
36
lib/fog/aws/requests/iam/delete_group.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/iam/basic'
|
||||
|
||||
# Delete a group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'GroupName'<~String>: name of the group to delete
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
def delete_group(group_name)
|
||||
request(
|
||||
'Action' => 'DeleteGroup',
|
||||
'GroupName' => group_name,
|
||||
:parser => Fog::Parsers::AWS::IAM::Basic.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def delete_group(group_name)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
45
lib/fog/aws/requests/iam/list_groups.rb
Normal file
45
lib/fog/aws/requests/iam/list_groups.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class IAM
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/iam/list_groups'
|
||||
|
||||
# List groups
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>:
|
||||
# * 'Marker'<~String>: used to paginate subsequent requests
|
||||
# * 'MaxItems'<~Integer>: limit results to this number per page
|
||||
# * 'PathPrefix'<~String>: prefix for filtering results
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Groups'<~Array> - Matching groups
|
||||
# * group<~Hash>:
|
||||
# * Arn<~String> -
|
||||
# * GroupId<~String> -
|
||||
# * GroupName<~String> -
|
||||
# * Path<~String> -
|
||||
# * 'IsTruncated<~Boolean> - Whether or not results were truncated
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
def list_groups
|
||||
request(
|
||||
'Action' => 'ListGroups',
|
||||
:parser => Fog::Parsers::AWS::IAM::ListGroups.new
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_groups
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue