1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge branch 'master' of github.com:fog/fog

This commit is contained in:
Nat Welch 2013-10-19 23:59:02 -07:00
commit 2f6b7f1041
10 changed files with 94 additions and 42 deletions

View file

@ -88,6 +88,10 @@ module Fog
hash[key] = {
:owner_id => Fog::AWS::Mock.owner_id,
:server_certificates => {},
:access_keys => [{
"Status" => "Active",
"AccessKeyId" => key
}],
:users => Hash.new do |uhash, ukey|
uhash[ukey] = {
:user_id => Fog::AWS::Mock.key_id,

View file

@ -14,7 +14,11 @@ module Fog
def save
requires :username
data = service.create_access_key('UserName'=> username).body["AccessKey"]
if !persisted?
data = service.create_access_key('UserName'=> username).body["AccessKey"]
else
data = service.update_access_key(id, status, "UserName" => username).body["AccessKey"]
end
merge_attributes(data)
true
end

View file

@ -11,7 +11,6 @@ module Fog
def initialize(attributes = {})
@username = attributes[:username]
raise ArgumentError.new("Can't get an access_key's user without a username") unless @username
super
end

View file

@ -36,23 +36,30 @@ module Fog
def create_access_key(options)
#FIXME: Not 100% correct as AWS will use the signing credentials when there is no 'UserName' in the options hash
# Also doesn't raise an error when there are too many keys
user_name = options['UserName']
if data[:users].has_key? user_name
key = { 'SecretAccessKey' => Fog::Mock.random_base64(40),
'Status' => 'Active',
'AccessKeyId' => Fog::AWS::Mock.key_id(20),
'UserName' => user_name
}
data[:users][user_name][:access_keys] << key
Excon::Response.new.tap do |response|
response.status = 200
response.body = { 'AccessKey' => key,
'RequestId' => Fog::AWS::Mock.request_id }
if user = options['UserName']
if data[:users].has_key? user
access_keys_data = data[:users][user][:access_keys]
else
raise Fog::AWS::IAM::NotFound.new('The user with name #{user_name} cannot be found.')
end
else
raise Fog::AWS::IAM::NotFound.new('The user with name booboboboob cannot be found.')
access_keys_data = data[:access_keys]
end
key = { 'SecretAccessKey' => Fog::Mock.random_base64(40),
'Status' => 'Active',
'AccessKeyId' => Fog::AWS::Mock.key_id(20),
}
if user
key["UserName"] = user
end
access_keys_data << key
Excon::Response.new.tap do |response|
response.status = 200
response.body = { 'AccessKey' => key,
'RequestId' => Fog::AWS::Mock.request_id }
end
end
end

View file

@ -40,19 +40,23 @@ module Fog
def list_access_keys(options = {})
#FIXME: Doesn't do anything with options, aside from UserName
user = options['UserName']
if data[:users].has_key? user
Excon::Response.new.tap do |response|
response.body = { 'AccessKeys' => data[:users][user][:access_keys].map do |akey|
{'Status' => akey['Status'], 'AccessKeyId' => akey['AccessKeyId']}
end,
'IsTruncated' => false,
'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
if user = options['UserName']
if data[:users].has_key? user
access_keys_data = data[:users][user][:access_keys]
else
raise Fog::AWS::IAM::NotFound.new("The user with name #{user} cannot be found.")
end
else
raise Fog::AWS::IAM::NotFound.new("The user with name #{user} cannot be found.")
access_keys_data = data[:access_keys]
end
Excon::Response.new.tap do |response|
response.body = { 'AccessKeys' => access_keys_data.map do |akey|
{'Status' => akey['Status'], 'AccessKeyId' => akey['AccessKeyId']}
end,
'IsTruncated' => false,
'RequestId' => Fog::AWS::Mock.request_id }
response.status = 200
end
end
end

View file

@ -31,6 +31,28 @@ module Fog
end
end
class Mock
def update_access_key(access_key_id, status, options = {})
if user = options['UserName']
if data[:users].has_key? user
access_keys_data = data[:users][user][:access_keys]
else
raise Fog::AWS::IAM::NotFound.new('The user with name #{user_name} cannot be found.')
end
else
access_keys_data = data[:access_keys]
end
key = access_keys_data.detect{|k| k["AccessKeyId"] == access_key_id}
key["Status"] = status
Excon::Response.new.tap do |response|
response.status = 200
response.body = { 'AccessKey' => key,
'RequestId' => Fog::AWS::Mock.request_id }
end
end
end
end
end
end

View file

@ -184,9 +184,9 @@ module Fog
if params[:scheme]
scheme = params[:scheme]
port = params[:port]
port = params[:port] || DEFAULT_SCHEME_PORT[scheme]
else
scheme = @scheme || DEFAULT_SCHEME
scheme = @scheme
port = @port
end
if DEFAULT_SCHEME_PORT[scheme] == port
@ -225,7 +225,7 @@ module Fog
:host => host,
:port => port,
:path => path,
:headers => headers,
:headers => headers
})
#
@ -418,12 +418,10 @@ module Fog
@port = options[:port] || DEFAULT_SCHEME_PORT[@scheme]
@path_style = options[:path_style] || false
end
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
end
def reload
@connection.reset
@connection.reset if @connection
end
def signature(params, expires)
@ -493,6 +491,20 @@ DATA
@hmac = Fog::HMAC.new('sha1', @aws_secret_access_key)
end
def connection(scheme, host, port)
uri = "#{scheme}://#{host}:#{port}"
if @persistent
unless uri == @connection_uri
@connection_uri = uri
reload
@connection = nil
end
else
@connection = nil
end
@connection ||= Fog::Connection.new(uri, @persistent, @connection_options)
end
def request(params, &block)
refresh_credentials_if_expired
@ -502,7 +514,9 @@ DATA
signature = signature(params, expires)
params = request_params(params)
params.delete(:port) unless params[:port]
scheme = params.delete(:scheme)
host = params.delete(:host)
port = params.delete(:port) || DEFAULT_SCHEME_PORT[scheme]
params[:headers]['Date'] = expires
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
@ -510,12 +524,12 @@ DATA
original_params = params.dup
begin
response = @connection.request(params, &block)
response = connection(scheme, host, port).request(params, &block)
rescue Excon::Errors::TemporaryRedirect => error
headers = (error.response.is_a?(Hash) ? error.response[:headers] : error.response.headers)
uri = URI.parse(headers['Location'])
Fog::Logger.warning("fog: followed redirect to #{uri.host}, connecting to the matching region will be more performant")
response = Fog::Connection.new("#{@scheme}://#{uri.host}:#{@port}", false, @connection_options).request(original_params, &block)
response = Fog::Connection.new("#{uri.scheme}://#{uri.host}:#{uri.port}", false, @connection_options).request(original_params, &block)
end
response

View file

@ -26,8 +26,6 @@ module Fog
model :volume_type
collection :volume_types
model :snapshot
collection :snapshots
model :snapshot
collection :snapshots

View file

@ -2,7 +2,7 @@ module Fog
module Generators
module Compute
module VcloudDirector
class EdgeGateway
class EdgeGatewayServiceConfiguration
def initialize(configuration={})
@configuration = configuration
end

View file

@ -3,7 +3,7 @@ module Fog
class VcloudDirector
class Real
require 'fog/vcloud_director/generators/compute/edge_gateway'
require 'fog/vcloud_director/generators/compute/edge_gateway_service_configuration'
# Configure edge gateway services like firewall, nat and load balancer.
#
@ -21,7 +21,7 @@ module Fog
# vCloud API Documentaion
# @since vCloud API version 5.1
def post_configure_edge_gateway_services(id, configuration)
body = Fog::Generators::Compute::VcloudDirector::EdgeGateway.new(configuration).generate_xml
body = Fog::Generators::Compute::VcloudDirector::EdgeGatewayServiceConfiguration.new(configuration).generate_xml
request(
:body => body,