1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
This commit is contained in:
Sean Handley 2012-07-27 13:14:06 +01:00
commit 2dfd9a2728
21 changed files with 174 additions and 29 deletions

View file

@ -42,7 +42,7 @@ Gem::Specification.new do |s|
## List your runtime dependencies here. Runtime dependencies are those
## that are needed for an end user to actually USE your code.
s.add_dependency('builder')
s.add_dependency('excon', '~>0.14.0')
s.add_dependency('excon', '~>0.14')
s.add_dependency('formatador', '~>0.2.0')
s.add_dependency('multi_json', '~>1.0')
s.add_dependency('mime-types')

View file

@ -53,7 +53,7 @@ module Fog
:auto_minor_version_upgrade => auto_upgrade,
:engine => engine,
:engine_version => engine_version,
:notification_topic_arn => (notification_config['TopicArn']).strip,
:notification_topic_arn => notification_config['TopicArn'],
:port => port,
:preferred_availablility_zone => zone,
:preferred_maintenance_window => maintenance_window,

View file

@ -7,11 +7,16 @@ module Fog
class Users < Fog::Collection
attribute :is_truncated, :aliases => 'IsTruncated'
attribute :marker, :aliases => 'Marker'
model Fog::AWS::IAM::User
def all
data = connection.list_users.body['Users']
load(data) # data is an array of attribute hashes
def all(options = {})
merge_attributes(options)
data = connection.list_users(options).body
merge_attributes('IsTruncated' => data['IsTruncated'], 'Marker' => data['Marker'])
load(data['Users']) # data is an array of attribute hashes
end
def get(identity)
@ -21,7 +26,24 @@ module Fog
nil
end
alias :each_user_this_page :each
def each
if !block_given?
self
else
subset = dup.all
subset.each_user_this_page {|f| yield f}
while subset.is_truncated
subset = subset.all('Marker' => subset.marker, 'MaxItems' => 1000)
subset.each_user_this_page {|f| yield f}
end
self
end
end
end
end
end
end
end

View file

@ -90,7 +90,7 @@ module Fog
@use_iam_profile = options[:use_iam_profile]
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end

View file

@ -43,7 +43,7 @@ module Fog
'AutoMinorVersionUpgrade' => options[:auto_minor_version_upgrade],
'CacheParameterGroupName' => options[:parameter_group_name],
'EngineVersion' => options[:engine_version],
'NotificationTopicArn' => (options[:notification_topic_arn]).strip,
'NotificationTopicArn' => options[:notification_topic_arn],
'Port' => options[:port],
'PreferredAvailabilityZone' => options[:preferred_availablility_zone],
'PreferredMaintenanceWindow' => options[:preferred_maintenance_window],

View file

@ -51,7 +51,7 @@ module Fog
'AutoMinorVersionUpgrade' => options[:auto_minor_version_upgrade],
'CacheParameterGroupName' => options[:parameter_group_name],
'EngineVersion' => options[:engine_version],
'NotificationTopicArn' => (options[:notification_topic_arn]).strip,
'NotificationTopicArn' => options[:notification_topic_arn],
'NotificationTopicStatus' => options[:notification_topic_status],
'PreferredMaintenanceWindow' => options[:preferred_maintenance_window],
:parser => Fog::Parsers::AWS::Elasticache::SingleCacheCluster.new

View file

@ -40,7 +40,7 @@ module Fog
setup_credentials(options)
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
end

View file

@ -7,8 +7,8 @@ module Fog
attribute :security_group_id, :type => :string
attribute :protocol, :type => :string
attribute :start_port, :type => :integer
attribute :end_port, :type => :integer
attribute :start_port, :type => :integer, :aliases => 'startport'
attribute :end_port, :type => :integer, :aliases => 'endport'
attribute :cidr, :type => :string
attribute :direction, :type => :string
@ -19,6 +19,10 @@ module Fog
job.successful?
end
def port_range
(self.start_port..self.end_port)
end
def save
requires :security_group_id, :cidr, :direction
@ -36,6 +40,7 @@ module Fog
def reload
requires :id, :security_group_id, :cidr
merge_attributes(security_group.rules.get(self.id))
end

View file

@ -59,7 +59,6 @@ module Fog
}
self.data[:jobs][job_id]= job
self.data[:security_groups][security_group_id] = security_group
{ "authorizesecuritygroupegressresponse" => { "jobid" => job_id } }
end

View file

@ -62,7 +62,6 @@ module Fog
}
self.data[:jobs][job_id]= job
self.data[:security_groups][security_group_id] = security_group
{ "authorizesecuritygroupingressresponse" => { "jobid" => job_id } }
end

View file

@ -16,8 +16,8 @@ module Fog
raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter id')
end
security_group_id, security_group = self.data[:security_groups].find do |id,group|
group['egressrule'] && group['egressrule'].delete_if { |r| r['id'] == security_group_rule_id }
security_group = self.data[:security_groups].values.find do |group|
(rule = (group['egressrule'] || []).find{|r| r['ruleid'] == security_group_rule_id}) && group['egressrule'].delete(rule)
end
job_id = Fog::Cloudstack.uuid
@ -33,7 +33,6 @@ module Fog
}
self.data[:jobs][job_id]= job
self.data[:security_groups][security_group_id] = security_group
{"revokesecuritygroupegress" => { "jobid" => job_id }}
end

View file

@ -19,8 +19,8 @@ module Fog
raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter id')
end
security_group_id, security_group = self.data[:security_groups].find do |id,group|
group['ingressrule'] && group['ingressrule'].delete_if { |r| r['id'] == security_group_rule_id }
security_group = self.data[:security_groups].values.find do |group|
(rule = (group['ingressrule'] || []).find{|r| r['ruleid'] == security_group_rule_id}) && group['ingressrule'].delete(rule)
end
job_id = Fog::Cloudstack.uuid
@ -36,7 +36,6 @@ module Fog
}
self.data[:jobs][job_id]= job
self.data[:security_groups][security_group_id] = security_group
{"revokesecuritygroupingress" => { "jobid" => job_id }}
end

View file

@ -186,7 +186,7 @@ module Fog
end
def dup_attributes!
@attributes = @attributes.dup
@attributes = @attributes.dup if @attributes
end
private

View file

@ -65,7 +65,7 @@ module Fog
@dynect_password = options[:dynect_password]
@connection_options = options[:connection_options] || {}
@host = "api2.dynect.net"
@host = 'api2.dynect.net'
@port = options[:port] || 443
@path = options[:path] || '/REST'
@persistent = options[:persistent] || false
@ -86,16 +86,25 @@ module Fog
params[:headers] ||= {}
params[:headers]['Content-Type'] = 'application/json'
params[:headers]['API-Version'] = @version
params[:headers]['Auth-Token'] = auth_token unless params[:path] == "Session"
params[:headers]['Auth-Token'] = auth_token unless params[:path] == 'Session'
params[:path] = "#{@path}/#{params[:path]}" unless params[:path] =~ %r{^#{Regexp.escape(@path)}/}
response = @connection.request(params.merge!({:host => @host}))
if response.status == 307
response = poll_job(response)
elsif !response.body.empty?
if response.body.empty?
response.body = {}
else
response.body = Fog::JSON.decode(response.body)
end
if response.body['status'] == 'failure'
raise Error, response.body['msgs'].first['INFO']
end
if response.status == 307 && params[:path] !~ %r{^/REST/Job/}
response = poll_job(response)
end
response
rescue Excon::Errors::HTTPStatusError => error
if @auth_token && error.message =~ /login: (Bad or expired credentials|inactivity logout)/

View file

@ -12,6 +12,8 @@ module Fog
# attribute :content_type, :aliases => 'Content-Type'
attribute :last_modified, :aliases => 'Last-Modified'
require 'uri'
def body
attributes[:body] ||= if last_modified
collection.get(identity).body
@ -73,7 +75,16 @@ module Fog
end
def public_url
nil
requires :directory, :key
if connection.endpoint
escaped_directory = URI.escape(directory.key)
escaped_key = URI.escape(key)
::File.join(connection.endpoint, escaped_directory, escaped_key)
else
nil
end
end
def save(options = {})

View file

@ -6,6 +6,7 @@ module Fog
class Local < Fog::Service
requires :local_root
recognizes :endpoint, :scheme, :host, :port, :path
model_path 'fog/local/models/storage'
collection :directories
@ -13,8 +14,12 @@ module Fog
model :file
collection :files
require 'uri'
class Mock
attr_reader :endpoint
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {}
@ -30,6 +35,8 @@ module Fog
require 'mime/types'
@local_root = ::File.expand_path(options[:local_root])
@endpoint = options[:endpoint] || build_endpoint_from_options(options)
end
def data
@ -48,13 +55,23 @@ module Fog
self.class.data.delete(@local_root)
end
private
def build_endpoint_from_options(options)
return unless options[:host]
URI::Generic.build(options).to_s
end
end
class Real
attr_reader :endpoint
def initialize(options={})
require 'mime/types'
@local_root = ::File.expand_path(options[:local_root])
@endpoint = options[:endpoint] || build_endpoint_from_options(options)
end
def local_root
@ -72,6 +89,13 @@ module Fog
::FileUtils.mkdir_p(::File.dirname(target_path))
::FileUtils.copy_file(source_path, target_path)
end
private
def build_endpoint_from_options(options)
return unless options[:host]
URI::Generic.build(options).to_s
end
end
end

View file

@ -8,6 +8,7 @@ module Fog
API_URL = "http://api.ninefold.com/compute/v1.0/"
requires :ninefold_compute_key, :ninefold_compute_secret
recognizes :ninefold_api_url # allow us to specify non-prod environments
model_path 'fog/ninefold/models/compute'
model :server

View file

@ -16,7 +16,7 @@ module Fog
data['enabled'] = options[:enabled]
end
if options.has_key? :secure_traffic_only
data['secureTrafficOnly'] - options[:secure_traffic_only]
data['secureTrafficOnly'] = options[:secure_traffic_only]
end
request(
:body => Fog::JSON.encode(data),

View file

@ -98,7 +98,7 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache']
body = AWS[:elasticache].modify_cache_cluster(c.id,
{
:num_nodes => NUM_NODES - 1,
:nodes_to_remove => node_id,
:nodes_to_remove => [node_id],
:apply_immediately => true,
}).body
c.reload

View file

@ -0,0 +1,40 @@
Shindo.tests('Storage[:local] | file', [:local]) do
before do
@options = { :local_root => '~/.fog' }
end
tests('#public_url') do
tests('when connection has an endpoint').
returns('http://example.com/files/directory/file.txt') do
@options[:endpoint] = 'http://example.com/files'
connection = Fog::Storage::Local.new(@options)
directory = connection.directories.new(:key => 'directory')
file = directory.files.new(:key => 'file.txt')
file.public_url
end
tests('when connection has no endpoint').
returns(nil) do
@options[:endpoint] = nil
connection = Fog::Storage::Local.new(@options)
directory = connection.directories.new(:key => 'directory')
file = directory.files.new(:key => 'file.txt')
file.public_url
end
tests('when file path has escapable characters').
returns('http://example.com/files/my%20directory/my%20file.txt') do
@options[:endpoint] = 'http://example.com/files'
connection = Fog::Storage::Local.new(@options)
directory = connection.directories.new(:key => 'my directory')
file = directory.files.new(:key => 'my file.txt')
file.public_url
end
end
end

View file

@ -0,0 +1,37 @@
Shindo.tests('Local | storage') do
before do
@options = { :local_root => "~/.fog" }
end
tests('#endpoint') do
tests('when no endpoint is provided').
returns(nil) do
Fog::Storage::Local.new(@options).endpoint
end
tests('when no host is provided').
returns(nil) do
@options[:scheme] = 'http'
@options[:path] = '/files'
@options[:port] = 80
Fog::Storage::Local.new(@options).endpoint
end
tests('when endpoint is provided').
returns('http://example.com/files') do
@options[:endpoint] = 'http://example.com/files'
Fog::Storage::Local.new(@options).endpoint
end
tests('when at least host option is provided').
returns('http://example.com/files') do
@options[:scheme] = 'http'
@options[:host] = 'example.com'
@options[:path] = '/files'
Fog::Storage::Local.new(@options).endpoint
end
end
end