diff --git a/Rakefile b/Rakefile index cf0d8238d..f285b4ce8 100644 --- a/Rakefile +++ b/Rakefile @@ -236,9 +236,6 @@ task :changelog do file.write("\n\n") file.write(old_changelog) end - - `echo "#{changelog.join("\n")}" | pbcopy` - p 'changelog copied to clipboard' end task :docs do diff --git a/bin/fog b/bin/fog index 6409e099a..9fd7ae58a 100755 --- a/bin/fog +++ b/bin/fog @@ -19,7 +19,10 @@ end if ARGV.length > 1 - puts(instance_eval(ARGV[1..-1].join(' ')).to_json) + require 'multi_json' + + result = instance_eval(ARGV[1..-1].join(' ')) + puts(MultiJson.encode(result)) else diff --git a/fog.gemspec b/fog.gemspec index 24330d9b7..d8ad03d50 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -37,13 +37,13 @@ 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.6.4') - s.add_dependency('formatador', '~>0.1.5') - s.add_dependency('multi_json', '~> 1.0') + s.add_dependency('excon', '~>0.6.5') + s.add_dependency('formatador', '~>0.2.0') + s.add_dependency('multi_json', '~>1.0.3') s.add_dependency('mime-types') s.add_dependency('net-scp', '~>1.0.4') s.add_dependency('net-ssh', '~>2.1.4') - s.add_dependency('nokogiri', '~>1.4.4') + s.add_dependency('nokogiri', '~>1.5.0') s.add_dependency('ruby-hmac') ## List your development dependencies here. Development dependencies are diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index 70837fbad..10a28abda 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -144,34 +144,33 @@ module Fog :version => '2011-04-05' } ) - begin - response = @connection.request({ - :body => body, - :expects => 200, - :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, - :idempotent => idempotent, - :host => @host, - :method => 'POST', - :parser => parser - }) - rescue Excon::Errors::HTTPStatusError => error - if match = error.message.match(/(.*)<\/Code>/m) - case match[1] - when 'LoadBalancerNotFound' - raise Fog::AWS::ELB::NotFound - when 'DuplicateLoadBalancerName' - raise Fog::AWS::ELB::IdentifierTaken - when 'InvalidInstance' - raise Fog::AWS::ELB::InvalidInstance - else - raise - end + + response = @connection.request({ + :body => body, + :expects => 200, + :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, + :idempotent => idempotent, + :host => @host, + :method => 'POST', + :parser => parser + }) + rescue Excon::Errors::HTTPStatusError => error + if match = error.message.match(/(.*)<\/Code>(?:.*(.*)<\/Message>)?/m) + case match[1] + when 'CertificateNotFound' + raise Fog::AWS::IAM::NotFound.slurp(error, match[2]) + when 'LoadBalancerNotFound' + raise Fog::AWS::ELB::NotFound.slurp(error, match[2]) + when 'DuplicateLoadBalancerName' + raise Fog::AWS::ELB::IdentifierTaken.slurp(error, match[2]) + when 'InvalidInstance' + raise Fog::AWS::ELB::InvalidInstance.slurp(error, match[2]) else raise end + else + raise end - - response end end end diff --git a/lib/fog/aws/iam.rb b/lib/fog/aws/iam.rb index 363d9d091..77f39f7f9 100644 --- a/lib/fog/aws/iam.rb +++ b/lib/fog/aws/iam.rb @@ -31,6 +31,7 @@ module Fog request :get_user_policy request :get_group request :get_group_policy + request :get_server_certificate request :list_access_keys request :list_account_aliases request :list_groups @@ -152,7 +153,7 @@ module Fog rescue Excon::Errors::HTTPStatusError => error if match = error.message.match(/(.*)<\/Code>(?:.*(.*)<\/Message>)?/m) case match[1] - when 'CertificateNotFound' + when 'CertificateNotFound', 'NoSuchEntity' raise Fog::AWS::IAM::NotFound.slurp(error, match[2]) when 'EntityAlreadyExists' raise Fog::AWS::IAM::EntityAlreadyExists.slurp(error, match[2]) diff --git a/lib/fog/aws/models/elb/listener.rb b/lib/fog/aws/models/elb/listener.rb index 4a6c7a303..bd8a5c484 100644 --- a/lib/fog/aws/models/elb/listener.rb +++ b/lib/fog/aws/models/elb/listener.rb @@ -11,8 +11,8 @@ module Fog attribute :ssl_id, :aliases => 'SSLCertificateId' def initialize(attributes={}) - defaults = {:policy_names => [], :instance_port => 80, :lb_port => 80, :protocol => 'HTTP'} - attributes = defaults.merge(attributes) + # set defaults, which may be overridden in super + merge_attributes(:policy_names => [], :instance_port => 80, :lb_port => 80, :protocol => 'HTTP') super end diff --git a/lib/fog/aws/parsers/sns/add_permission.rb b/lib/fog/aws/parsers/sns/add_permission.rb new file mode 100644 index 000000000..8da72261d --- /dev/null +++ b/lib/fog/aws/parsers/sns/add_permission.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module SNS + + class AddPermission < Fog::Parsers::Base + + def reset + @response = {} + end + + def end_element(name) + case name + when 'RequestId' + @response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/confirm_subscription.rb b/lib/fog/aws/parsers/sns/confirm_subscription.rb new file mode 100644 index 000000000..15631cc51 --- /dev/null +++ b/lib/fog/aws/parsers/sns/confirm_subscription.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module SNS + + class ConfirmSubscription < Fog::Parsers::Base + + def reset + @response = {} + end + + def end_element(name) + case name + when 'SubscriptionArn', 'RequestId' + @response[name] = @value.rstrip + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/create_topic.rb b/lib/fog/aws/parsers/sns/create_topic.rb new file mode 100644 index 000000000..ee842d399 --- /dev/null +++ b/lib/fog/aws/parsers/sns/create_topic.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module SNS + + class CreateTopic < Fog::Parsers::Base + + def reset + @response = {} + end + + def end_element(name) + case name + when 'TopicArn', 'RequestId' + @response[name] = @value.rstrip + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/delete_topic.rb b/lib/fog/aws/parsers/sns/delete_topic.rb new file mode 100644 index 000000000..0a0a27ff3 --- /dev/null +++ b/lib/fog/aws/parsers/sns/delete_topic.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module SNS + + class DeleteTopic < Fog::Parsers::Base + + def reset + @response = {} + end + + def end_element(name) + case name + when 'RequestId' + @response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/get_topic_attributes.rb b/lib/fog/aws/parsers/sns/get_topic_attributes.rb new file mode 100644 index 000000000..ea974f5d9 --- /dev/null +++ b/lib/fog/aws/parsers/sns/get_topic_attributes.rb @@ -0,0 +1,32 @@ +module Fog + module Parsers + module AWS + module SNS + + class GetTopicAttributes < Fog::Parsers::Base + + def reset + @response = { 'Attributes' => {} } + end + + def end_element(name) + case name + when 'key' + @key = @value.rstrip + when 'value' + case @key + when 'SubscriptionsConfirmed', 'SubscriptionsDeleted', 'SubscriptionsPending' + @response['Attributes'][@key] = @value.rstrip.to_i + else + @response['Attributes'][@key] = @value.rstrip + end + when 'RequestId' + @response[name] = @value + end + end + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/list_subscriptions.rb b/lib/fog/aws/parsers/sns/list_subscriptions.rb new file mode 100644 index 000000000..07424a680 --- /dev/null +++ b/lib/fog/aws/parsers/sns/list_subscriptions.rb @@ -0,0 +1,29 @@ +module Fog + module Parsers + module AWS + module SNS + + class ListSubscriptions < Fog::Parsers::Base + + def reset + @response = { 'Subscriptions' => [] } + @subscription = {} + end + + def end_element(name) + case name + when "TopicArn", "Protocol", "SubscriptionArn", "Owner", "Endpoint" + @subscription[name] = @value.rstrip + when "member" + @response['Subscriptions'] << @subscription + @subscription = {} + when 'RequestId', 'NextToken' + @response[name] = @value.rstrip + end + end + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/list_topics.rb b/lib/fog/aws/parsers/sns/list_topics.rb new file mode 100644 index 000000000..efef64c6a --- /dev/null +++ b/lib/fog/aws/parsers/sns/list_topics.rb @@ -0,0 +1,26 @@ +module Fog + module Parsers + module AWS + module SNS + + class ListTopics < Fog::Parsers::Base + + def reset + @response = { 'Topics' => [] } + end + + def end_element(name) + case name + when 'TopicArn' + @response['Topics'] << @value + when 'NextToken', 'RequestId' + response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/publish.rb b/lib/fog/aws/parsers/sns/publish.rb new file mode 100644 index 000000000..91b2a62ee --- /dev/null +++ b/lib/fog/aws/parsers/sns/publish.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module SNS + + class Publish < Fog::Parsers::Base + + def reset + @response = {} + end + + def end_element(name) + case name + when 'MessageId', 'RequestId' + @response[name] = @value.rstrip + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/remove_permission.rb b/lib/fog/aws/parsers/sns/remove_permission.rb new file mode 100644 index 000000000..e4e43a175 --- /dev/null +++ b/lib/fog/aws/parsers/sns/remove_permission.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module SNS + + class RemovePermission < Fog::Parsers::Base + + def reset + @response = {} + end + + def end_element(name) + case name + when 'RequestId' + @response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/set_topic_attributes.rb b/lib/fog/aws/parsers/sns/set_topic_attributes.rb new file mode 100644 index 000000000..19639b7fe --- /dev/null +++ b/lib/fog/aws/parsers/sns/set_topic_attributes.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module SNS + + class SetTopicAttributes < Fog::Parsers::Base + + def reset + @response = {} + end + + def end_element(name) + case name + when 'RequestId' + @response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/subscribe.rb b/lib/fog/aws/parsers/sns/subscribe.rb new file mode 100644 index 000000000..8f209daa0 --- /dev/null +++ b/lib/fog/aws/parsers/sns/subscribe.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module SNS + + class Subscribe < Fog::Parsers::Base + + def reset + @response = {} + end + + def end_element(name) + case name + when 'SubscriptionArn', 'RequestId' + @response[name] = @value.rstrip + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sns/unsubscribe.rb b/lib/fog/aws/parsers/sns/unsubscribe.rb new file mode 100644 index 000000000..dcab5e46f --- /dev/null +++ b/lib/fog/aws/parsers/sns/unsubscribe.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module SNS + + class Unsubscribe < Fog::Parsers::Base + + def reset + @response = {} + end + + def end_element(name) + case name + when 'RequestId' + @response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sqs/basic.rb b/lib/fog/aws/parsers/sqs/basic.rb new file mode 100644 index 000000000..f99763114 --- /dev/null +++ b/lib/fog/aws/parsers/sqs/basic.rb @@ -0,0 +1,23 @@ +module Fog + module Parsers + module AWS + module SQS + class Basic < Fog::Parsers::Base + + def reset + @response = { 'ResponseMetadata' => {} } + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sqs/create_queue.rb b/lib/fog/aws/parsers/sqs/create_queue.rb new file mode 100644 index 000000000..516feaed5 --- /dev/null +++ b/lib/fog/aws/parsers/sqs/create_queue.rb @@ -0,0 +1,26 @@ +module Fog + module Parsers + module AWS + module SQS + + class CreateQueue < Fog::Parsers::Base + + def reset + @response = { 'ResponseMetadata' => {} } + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = @value + when 'QueueUrl' + @response['QueueUrl'] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sqs/get_queue_attributes.rb b/lib/fog/aws/parsers/sqs/get_queue_attributes.rb new file mode 100644 index 000000000..dbbd65511 --- /dev/null +++ b/lib/fog/aws/parsers/sqs/get_queue_attributes.rb @@ -0,0 +1,35 @@ +module Fog + module Parsers + module AWS + module SQS + + class GetQueueAttributes < Fog::Parsers::Base + + def reset + @response = { 'ResponseMetadata' => {}, 'Attributes' => {}} + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata']['RequestId'] = @value + when 'Name' + @current_attribute_name = @value + when 'Value' + case @current_attribute_name + when 'ApproximateNumberOfMessages', 'ApproximateNumberOfMessagesNotVisible', 'MaximumMessageSize', 'MessageRetentionPeriod', 'VisibilityTimeout' + @response['Attributes'][@current_attribute_name] = @value.to_i + when 'CreatedTimestamp', 'LastModifiedTimestamp' + @response['Attributes'][@current_attribute_name] = Time.at(@value.to_i) + else + @response['Attributes'][@current_attribute_name] = @value + end + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sqs/list_queues.rb b/lib/fog/aws/parsers/sqs/list_queues.rb new file mode 100644 index 000000000..8f3664b94 --- /dev/null +++ b/lib/fog/aws/parsers/sqs/list_queues.rb @@ -0,0 +1,25 @@ +module Fog + module Parsers + module AWS + module SQS + class ListQueues < Fog::Parsers::Base + + def reset + @response = { 'QueueUrls' => [], 'ResponseMetadata' => {} } + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = @value + when 'QueueUrl' + @response['QueueUrls'] << @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sqs/receive_message.rb b/lib/fog/aws/parsers/sqs/receive_message.rb new file mode 100644 index 000000000..391c00dd8 --- /dev/null +++ b/lib/fog/aws/parsers/sqs/receive_message.rb @@ -0,0 +1,41 @@ +module Fog + module Parsers + module AWS + module SQS + + class ReceiveMessage < Fog::Parsers::Base + + def reset + @message = { 'Attributes' => {} } + @response = { 'ResponseMetadata' => {}, 'Message' => []} + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata']['RequestId'] = @value + when 'Message' + @response['Message'] << @message + @message = { 'Attributes' => {} } + when 'Body', 'MD5OfBody', 'MessageId', 'ReceiptHandle' + @message[name] = @value + when 'Name' + @current_attribute_name = @value + when 'Value' + case @current_attribute_name + when 'ApproximateFirstReceiveTimestamp', 'SentTimestamp' + @message['Attributes'][@current_attribute_name] = Time.at(@value.to_i) + when 'ApproximateReceiveCount' + @message['Attributes'][@current_attribute_name] = @value.to_i + else + @message['Attributes'][@current_attribute_name] = @value + end + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/sqs/send_message.rb b/lib/fog/aws/parsers/sqs/send_message.rb new file mode 100644 index 000000000..00374bf6d --- /dev/null +++ b/lib/fog/aws/parsers/sqs/send_message.rb @@ -0,0 +1,28 @@ +module Fog + module Parsers + module AWS + module SQS + + class SendMessage < Fog::Parsers::Base + + def reset + @response = { 'ResponseMetadata' => {} } + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = @value + when 'MessageId' + @response['MessageId'] = @value + when 'MD5OfMessageBody' + @response['MD5OfMessageBody'] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/requests/elb/create_load_balancer.rb b/lib/fog/aws/requests/elb/create_load_balancer.rb index a46f04c5e..da9a2939f 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer.rb @@ -47,7 +47,6 @@ module Fog :parser => Fog::Parsers::AWS::ELB::CreateLoadBalancer.new }.merge!(params)) end - end class Mock @@ -61,9 +60,7 @@ module Fog listeners = [*listeners].map do |listener| if listener['SSLCertificateId'] and !certificate_ids.include? listener['SSLCertificateId'] - response.status = 400 - response.body = "CertificateNotFoundThe specified SSL ID does not refer to a valid SSL certificate in the AWS Identity and Access Management Service..#{Fog::AWS::Mock.request_id}" - raise Excon::Errors.status_error({:expects => 200}, response) + raise Fog::AWS::IAM::NotFound.new('CertificateNotFound') end {'Listener' => listener, 'PolicyNames' => []} end diff --git a/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb b/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb index 4a976c372..51f3219a0 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb @@ -56,9 +56,7 @@ module Fog listeners.each do |listener| if listener['SSLCertificateId'] and !certificate_ids.include? listener['SSLCertificateId'] - response.status = 400 - response.body = "CertificateNotFoundThe specified SSL ID does not refer to a valid SSL certificate in the AWS Identity and Access Management Service..#{Fog::AWS::Mock.request_id}" - raise Excon::Errors.status_error({:expects => 200}, response) + raise Fog::AWS::IAM::NotFound.new('CertificateNotFound') end load_balancer['ListenerDescriptions'] << {'Listener' => listener, 'PolicyNames' => []} end diff --git a/lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb b/lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb index e11bc3a0f..902862a32 100644 --- a/lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb +++ b/lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb @@ -16,7 +16,7 @@ module Fog # * 'ResponseMetadata'<~Hash>: # * 'RequestId'<~String> - Id of request def delete_load_balancer_listeners(lb_name, load_balancer_ports) - params = Fog::AWS.indexed_param('LoadBalancerPorts.memeber.%d', load_balancer_ports) + params = Fog::AWS.indexed_param('LoadBalancerPorts.member.%d', load_balancer_ports) request({ 'Action' => 'DeleteLoadBalancerListeners', diff --git a/lib/fog/aws/requests/iam/get_server_certificate.rb b/lib/fog/aws/requests/iam/get_server_certificate.rb new file mode 100644 index 000000000..a6b0be204 --- /dev/null +++ b/lib/fog/aws/requests/iam/get_server_certificate.rb @@ -0,0 +1,50 @@ +module Fog + module AWS + class IAM + class Real + + require 'fog/aws/parsers/iam/upload_server_certificate' + + # Gets the specified server certificate. + # + # ==== Parameters + # * server_certificate_name<~String>: The name of the server certificate you want to get. + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'RequestId'<~String> - Id of the request + # + # ==== See Also + # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_GetServerCertificate.html + # + def get_server_certificate(server_certificate_name) + request({ + 'Action' => 'GetServerCertificate', + 'ServerCertificateName' => server_certificate_name, + :parser => Fog::Parsers::AWS::IAM::UploadServerCertificate.new + }) + end + + end + + class Mock + def get_server_certificate(server_certificate_name) + raise Fog::AWS::IAM::NotFound unless self.data[:server_certificates].key?(server_certificate_name) + + response = Excon::Response.new + response.status = 200 + response.body = { + 'Certificate' => self.data[:server_certificates][server_certificate_name], + 'RequestId' => Fog::AWS::Mock.request_id + } + + self.data[:server_certificates] + + response + end + end + end + end +end + diff --git a/lib/fog/aws/requests/iam/put_group_policy.rb b/lib/fog/aws/requests/iam/put_group_policy.rb index 48837f1f9..209e734ca 100644 --- a/lib/fog/aws/requests/iam/put_group_policy.rb +++ b/lib/fog/aws/requests/iam/put_group_policy.rb @@ -25,7 +25,7 @@ module Fog 'Action' => 'PutGroupPolicy', 'GroupName' => group_name, 'PolicyName' => policy_name, - 'PolicyDocument' => policy_document.to_json, + 'PolicyDocument' => MultiJson.encode(policy_document), :parser => Fog::Parsers::AWS::IAM::Basic.new ) end diff --git a/lib/fog/aws/requests/iam/put_user_policy.rb b/lib/fog/aws/requests/iam/put_user_policy.rb index d0b8840c3..c529d8a02 100644 --- a/lib/fog/aws/requests/iam/put_user_policy.rb +++ b/lib/fog/aws/requests/iam/put_user_policy.rb @@ -24,7 +24,7 @@ module Fog request( 'Action' => 'PutUserPolicy', 'PolicyName' => policy_name, - 'PolicyDocument' => policy_document.to_json, + 'PolicyDocument' => MultiJson.encode(policy_document), 'UserName' => user_name, :parser => Fog::Parsers::AWS::IAM::Basic.new ) diff --git a/lib/fog/aws/requests/simpledb/get_attributes.rb b/lib/fog/aws/requests/simpledb/get_attributes.rb index d23b5b0b1..5dbcc33a8 100644 --- a/lib/fog/aws/requests/simpledb/get_attributes.rb +++ b/lib/fog/aws/requests/simpledb/get_attributes.rb @@ -48,7 +48,7 @@ module Fog class Mock def get_attributes(domain_name, item_name, options = {}) - unless options.empty? || options['AttributeName'] + if options.is_a?(Array) Formatador.display_line("[yellow][WARN] get_attributes with array attributes param is deprecated, use 'AttributeName' => attributes) instead[/] [light_black](#{caller.first})[/]") options['AttributeName'] ||= options if options.is_a?(Array) end diff --git a/lib/fog/aws/requests/sns/add_permission.rb b/lib/fog/aws/requests/sns/add_permission.rb new file mode 100644 index 000000000..b6ec32b2c --- /dev/null +++ b/lib/fog/aws/requests/sns/add_permission.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/add_permission' + + def add_permission(options = {}) + request({ + 'Action' => 'AddPermission', + :parser => Fog::Parsers::AWS::SNS::AddPermission.new + }.merge!(options)) + end + + end + + class Mock + + def add_permission(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/sns/confirm_subscription.rb b/lib/fog/aws/requests/sns/confirm_subscription.rb new file mode 100644 index 000000000..862f2d97e --- /dev/null +++ b/lib/fog/aws/requests/sns/confirm_subscription.rb @@ -0,0 +1,33 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/confirm_subscription' + + # Confirm a subscription + # + # ==== Parameters + # * arn<~String> - Arn of topic to confirm subscription to + # * token<~String> - Token sent to endpoint during subscribe action + # * options<~Hash>: + # * AuthenticateOnUnsubscribe<~Boolean> - whether or not unsubscription should be authenticated, defaults to false + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_ConfirmSubscription.html + # + + def confirm_subscription(arn, token, options = {}) + request({ + 'Action' => 'ConfirmSubscription', + 'Token' => token, + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::ConfirmSubscription.new + }.merge!(options)) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/create_topic.rb b/lib/fog/aws/requests/sns/create_topic.rb new file mode 100644 index 000000000..b44b6fa78 --- /dev/null +++ b/lib/fog/aws/requests/sns/create_topic.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/create_topic' + + # Create a topic + # + # ==== Parameters + # * name<~String> - Name of topic to create + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_CreateTopic.html + # + + def create_topic(name) + request({ + 'Action' => 'CreateTopic', + 'Name' => name, + :parser => Fog::Parsers::AWS::SNS::CreateTopic.new + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/delete_topic.rb b/lib/fog/aws/requests/sns/delete_topic.rb new file mode 100644 index 000000000..c5b71a865 --- /dev/null +++ b/lib/fog/aws/requests/sns/delete_topic.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/delete_topic' + + # Delete a topic + # + # ==== Parameters + # * arn<~String> - The Arn of the topic to delete + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_DeleteTopic.html + # + + def delete_topic(arn) + request({ + 'Action' => 'DeleteTopic', + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::DeleteTopic.new + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/get_topic_attributes.rb b/lib/fog/aws/requests/sns/get_topic_attributes.rb new file mode 100644 index 000000000..34a3336f7 --- /dev/null +++ b/lib/fog/aws/requests/sns/get_topic_attributes.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/get_topic_attributes' + + # Get attributes of a topic + # + # ==== Parameters + # * arn<~Hash>: The Arn of the topic to get attributes for + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_GetTopicAttributes.html + # + + def get_topic_attributes(arn) + request({ + 'Action' => 'GetTopicAttributes', + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::GetTopicAttributes.new + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/list_subscriptions.rb b/lib/fog/aws/requests/sns/list_subscriptions.rb new file mode 100644 index 000000000..223d7311e --- /dev/null +++ b/lib/fog/aws/requests/sns/list_subscriptions.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/list_subscriptions' + + # List subscriptions + # + # ==== Parameters + # * options<~Hash>: + # * 'NextToken'<~String> - Token returned from previous request, used for pagination + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_ListSubscriptions.html + # + + def list_subscriptions(options = {}) + request({ + 'Action' => 'ListSubscriptions', + :parser => Fog::Parsers::AWS::SNS::ListSubscriptions.new + }.merge!(options)) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb b/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb new file mode 100644 index 000000000..7b19df2ed --- /dev/null +++ b/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb @@ -0,0 +1,31 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/list_subscriptions' + + # List subscriptions for a topic + # + # ==== Parameters + # * arn<~String> - Arn of topic to list subscriptions for + # * options<~Hash>: + # * 'NextToken'<~String> - Token returned from previous request, used for pagination + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_ListSubscriptionsByTopic.html + # + + def list_subscriptions_by_topic(arn, options = {}) + request({ + 'Action' => 'ListSubscriptionsByTopic', + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::ListSubscriptions.new + }.merge!(options)) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/list_topics.rb b/lib/fog/aws/requests/sns/list_topics.rb new file mode 100644 index 000000000..fdd9fd07e --- /dev/null +++ b/lib/fog/aws/requests/sns/list_topics.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/list_topics' + + # List topics + # + # ==== Parameters + # * options<~Hash>: + # * 'NextToken'<~String> - Token returned from previous request, used for pagination + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_ListTopics.html + # + + def list_topics(options = {}) + request({ + 'Action' => 'ListTopics', + :parser => Fog::Parsers::AWS::SNS::ListTopics.new + }.merge!(options)) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/publish.rb b/lib/fog/aws/requests/sns/publish.rb new file mode 100644 index 000000000..790d5e44d --- /dev/null +++ b/lib/fog/aws/requests/sns/publish.rb @@ -0,0 +1,34 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/publish' + + # Send a message to a topic + # + # ==== Parameters + # * arn<~String> - Arn of topic to send message to + # * message<~String> - Message to send to topic + # * options<~Hash>: + # * MessageStructure<~String> - message structure, in ['json'] + # * Subject<~String> - value to use for subject when delivering by email + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_Publish.html + # + + def publish(arn, message, options = {}) + request({ + 'Action' => 'Publish', + 'Message' => message, + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::Publish.new + }.merge!(options)) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/remove_permission.rb b/lib/fog/aws/requests/sns/remove_permission.rb new file mode 100644 index 000000000..b920314b0 --- /dev/null +++ b/lib/fog/aws/requests/sns/remove_permission.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/remove_permission' + + def remove_permission(options = {}) + request({ + 'Action' => 'RemovePermission', + :parser => Fog::Parsers::AWS::SNS::RemovePermission.new + }.merge!(options)) + end + + end + + class Mock + + def remove_permission(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/sns/set_topic_attributes.rb b/lib/fog/aws/requests/sns/set_topic_attributes.rb new file mode 100644 index 000000000..99f4e2d6f --- /dev/null +++ b/lib/fog/aws/requests/sns/set_topic_attributes.rb @@ -0,0 +1,33 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/set_topic_attributes' + + # Set attributes of a topic + # + # ==== Parameters + # * arn<~Hash> - The Arn of the topic to get attributes for + # * attribute_name<~String> - Name of attribute to set, in ['DisplayName', 'Policy'] + # * attribute_value<~String> - Value to set attribute to + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_SetTopicAttributes.html + # + + def set_topic_attributes(arn, attribute_name, attribute_value) + request({ + 'Action' => 'SetTopicAttributes', + 'AttributeName' => attribute_name, + 'AttributeValue' => attribute_value, + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::SetTopicAttributes.new + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/subscribe.rb b/lib/fog/aws/requests/sns/subscribe.rb new file mode 100644 index 000000000..91beec446 --- /dev/null +++ b/lib/fog/aws/requests/sns/subscribe.rb @@ -0,0 +1,33 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/subscribe' + + # Create a subscription + # + # ==== Parameters + # * arn<~String> - Arn of topic to subscribe to + # * endpoint<~String> - Endpoint to notify + # * protocol<~String> - Protocol to notify endpoint with, in ['email', 'email-json', 'http', 'https', 'sqs'] + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_Subscribe.html + # + + def subscribe(arn, endpoint, protocol) + request({ + 'Action' => 'Subscribe', + 'Endpoint' => endpoint, + 'Protocol' => protocol, + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::Subscribe.new + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sns/unsubscribe.rb b/lib/fog/aws/requests/sns/unsubscribe.rb new file mode 100644 index 000000000..29ca5df73 --- /dev/null +++ b/lib/fog/aws/requests/sns/unsubscribe.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/unsubscribe' + + # Delete a subscription + # + # ==== Parameters + # * arn<~String> - Arn of subscription to delete + # + # ==== See Also + # http://docs.amazonwebservices.com/sns/latest/api/API_Unsubscribe.html + # + + def unsubscribe(arn) + request({ + 'Action' => 'Unsubscribe', + 'SubscriptionArn' => arn, + :parser => Fog::Parsers::AWS::SNS::Unsubscribe.new + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sqs/change_message_visibility.rb b/lib/fog/aws/requests/sqs/change_message_visibility.rb new file mode 100644 index 000000000..2902f7404 --- /dev/null +++ b/lib/fog/aws/requests/sqs/change_message_visibility.rb @@ -0,0 +1,33 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/basic' + + # Change visibility timeout for a message + # + # ==== Parameters + # * queue_url<~String> - Url of queue for message to update + # * receipt_handle<~String> - Token from previous recieve message + # * visibility_timeout<~Integer> - New visibility timeout in 0..43200 + # + # ==== See Also + # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryChangeMessageVisibility.html + # + + def change_message_visibility(queue_url, receipt_handle, visibility_timeout) + request({ + 'Action' => 'ChangeMessageVisibility', + 'ReceiptHandle' => receipt_handle, + 'VisibilityTimeout' => visibility_timeout, + :parser => Fog::Parsers::AWS::SQS::Basic.new, + :path => path_from_queue_url(queue_url) + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sqs/create_queue.rb b/lib/fog/aws/requests/sqs/create_queue.rb new file mode 100644 index 000000000..610dd7946 --- /dev/null +++ b/lib/fog/aws/requests/sqs/create_queue.rb @@ -0,0 +1,31 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/create_queue' + + # Create a queue + # + # ==== Parameters + # * name<~String> - Name of queue to create + # * options<~Hash>: + # * DefaultVisibilityTimeout<~String> - Time, in seconds, to hide a message after it has been received, in 0..43200, defaults to 30 + # + # ==== See Also + # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryCreateQueue.html + # + + def create_queue(name, options = {}) + request({ + 'Action' => 'CreateQueue', + 'QueueName' => name, + :parser => Fog::Parsers::AWS::SQS::CreateQueue.new + }.merge!(options)) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sqs/delete_message.rb b/lib/fog/aws/requests/sqs/delete_message.rb new file mode 100644 index 000000000..c17e65dfe --- /dev/null +++ b/lib/fog/aws/requests/sqs/delete_message.rb @@ -0,0 +1,31 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/basic' + + # Delete a message from a queue + # + # ==== Parameters + # * queue_url<~String> - Url of queue to delete message from + # * receipt_handle<~String> - Token from previous recieve message + # + # ==== See Also + # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryDeleteMessage.html + # + + def delete_message(queue_url, receipt_handle) + request({ + 'Action' => 'DeleteMessage', + 'ReceiptHandle' => receipt_handle, + :parser => Fog::Parsers::AWS::SQS::Basic.new, + :path => path_from_queue_url(queue_url), + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sqs/delete_queue.rb b/lib/fog/aws/requests/sqs/delete_queue.rb new file mode 100644 index 000000000..2b5d93a27 --- /dev/null +++ b/lib/fog/aws/requests/sqs/delete_queue.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/basic' + + # Delete a queue + # + # ==== Parameters + # * queue_url<~String> - Url of queue to delete + # + # ==== See Also + # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryDeleteQueue.html + # + + def delete_queue(queue_url) + request({ + 'Action' => 'DeleteQueue', + :parser => Fog::Parsers::AWS::SQS::Basic.new, + :path => path_from_queue_url(queue_url), + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sqs/get_queue_attributes.rb b/lib/fog/aws/requests/sqs/get_queue_attributes.rb new file mode 100644 index 000000000..ff88b57eb --- /dev/null +++ b/lib/fog/aws/requests/sqs/get_queue_attributes.rb @@ -0,0 +1,31 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/get_queue_attributes' + + # Get attributes of a queue + # + # ==== Parameters + # * queue_url<~String> - Url of queue to get attributes for + # * attribute_name<~Array> - Name of attribute to return, in ['All', 'ApproximateNumberOfMessages', 'ApproximateNumberOfMessagesNotVisible', 'CreatedTimestamp', 'LastModifiedTimestamp', 'MaximumMessageSize', 'MessageRetentionPeriod', 'Policy', 'QueueArn', 'VisibilityTimeout'] + # + # ==== See Also + # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryGetQueueAttributes.html + # + + def get_queue_attributes(queue_url, attribute_name) + request({ + 'Action' => 'GetQueueAttributes', + 'AttributeName' => attribute_name, + :path => path_from_queue_url(queue_url), + :parser => Fog::Parsers::AWS::SQS::GetQueueAttributes.new + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sqs/list_queues.rb b/lib/fog/aws/requests/sqs/list_queues.rb new file mode 100644 index 000000000..05364cc67 --- /dev/null +++ b/lib/fog/aws/requests/sqs/list_queues.rb @@ -0,0 +1,28 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/list_queues' + + # List queues + # + # ==== Parameters + # * options<~Hash>: + # * QueueNamePrefix<~String> - String used to filter results to only those with matching prefixes + # + # ==== See Also + # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryListQueues.html + # + + def list_queues(options = {}) + request({ + 'Action' => 'ListQueues', + :parser => Fog::Parsers::AWS::SQS::ListQueues.new + }.merge!(options)) + end + end + + end + end +end diff --git a/lib/fog/aws/requests/sqs/receive_message.rb b/lib/fog/aws/requests/sqs/receive_message.rb new file mode 100644 index 000000000..b01c42a59 --- /dev/null +++ b/lib/fog/aws/requests/sqs/receive_message.rb @@ -0,0 +1,34 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/receive_message' + + # Get a message from a queue (marks it as unavailable temporarily, but does not remove from queue, see delete_message) + # + # ==== Parameters + # * queue_url<~String> - Url of queue to get message from + # * options<~Hash>: + # * Attributes<~Array> - List of attributes to return, in ['All', 'ApproximateFirstReceiveTimestamp', 'ApproximateReceiveCount', 'SenderId', 'SentTimestamp'], defaults to 'All' + # * MaxNumberOfMessages<~Integer> - Maximum number of messages to return, defaults to 1 + # * VisibilityTimeout<~Integer> - Duration, in seconds, to hide message from other receives. In 0..43200, defaults to visibility timeout for queue + # + # ==== See Also + # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryReceiveMessage.html + # + + def receive_message(queue_url, options = {}) + request({ + 'Action' => 'ReceiveMessage', + 'AttributeName' => 'All', + :path => path_from_queue_url(queue_url), + :parser => Fog::Parsers::AWS::SQS::ReceiveMessage.new + }.merge!(options)) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sqs/send_message.rb b/lib/fog/aws/requests/sqs/send_message.rb new file mode 100644 index 000000000..e066d6202 --- /dev/null +++ b/lib/fog/aws/requests/sqs/send_message.rb @@ -0,0 +1,31 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/send_message' + + # Add a message to a queue + # + # ==== Parameters + # * queue_url<~String> - Url of queue to add message to + # * message<~String> - Message to add to queue + # + # ==== See Also + # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QuerySendMessage.html + # + + def send_message(queue_url, message) + request({ + 'Action' => 'SendMessage', + 'MessageBody' => message, + :path => path_from_queue_url(queue_url), + :parser => Fog::Parsers::AWS::SQS::SendMessage.new + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/requests/sqs/set_queue_attributes.rb b/lib/fog/aws/requests/sqs/set_queue_attributes.rb new file mode 100644 index 000000000..38811bc4c --- /dev/null +++ b/lib/fog/aws/requests/sqs/set_queue_attributes.rb @@ -0,0 +1,33 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/basic' + + # Get attributes of a queue + # + # ==== Parameters + # * queue_url<~String> - Url of queue to get attributes for + # * attribute_name<~String> - Name of attribute to set, keys in ['MaximumMessageSize', 'MessageRetentionPeriod', 'Policy', 'VisibilityTimeout'] + # * attribute_value<~String> - Value to set for attribute + # + # ==== See Also + # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QuerySetQueueAttributes.html + # + + def set_queue_attributes(queue_url, attribute_name, attribute_value) + request({ + 'Action' => 'SetQueueAttributes', + 'Attribute.Name' => attribute_name, + 'Attribute.Value' => attribute_value, + :path => path_from_queue_url(queue_url), + :parser => Fog::Parsers::AWS::SQS::Basic.new + }) + end + + end + + end + end +end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb new file mode 100644 index 000000000..7ac11d6fa --- /dev/null +++ b/lib/fog/aws/sns.rb @@ -0,0 +1,112 @@ +module Fog + module AWS + class SNS < Fog::Service + + requires :aws_access_key_id, :aws_secret_access_key + recognizes :host, :path, :port, :scheme, :persistent + + request_path 'fog/aws/requests/sns' + request :add_permission + request :confirm_subscription + request :create_topic + request :delete_topic + request :get_topic_attributes + request :list_subscriptions + request :list_subscriptions_by_topic + request :list_topics + request :publish + request :remove_permission + request :set_topic_attributes + request :subscribe + request :unsubscribe + + class Mock + + def initialize(options={}) + end + + end + + class Real + + # Initialize connection to SNS + # + # ==== Notes + # options parameter must include values for :aws_access_key_id and + # :aws_secret_access_key in order to create a connection + # + # ==== Examples + # sns = SNS.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 + # * SNS object with connection to AWS. + def initialize(options={}) + require 'multi_json' + @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) + + options[:region] ||= 'us-east-1' + @host = options[:host] || case options[:region] + when 'ap-southeast-1' + 'sns.ap-southeast-1.amazonaws.com' + when 'eu-west-1' + 'sns.eu-west-1.amazonaws.com' + when 'us-east-1' + 'sns.us-east-1.amazonaws.com' + when 'us-west-1' + 'sns.us-west-1.amazonaws.com' + else + raise ArgumentError, "Unknown region: #{options[:region].inspect}" + end + + @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, + :port => @port + } + ) + + 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 diff --git a/lib/fog/aws/sqs.rb b/lib/fog/aws/sqs.rb new file mode 100644 index 000000000..b568a7b6c --- /dev/null +++ b/lib/fog/aws/sqs.rb @@ -0,0 +1,115 @@ +module Fog + module AWS + class SQS < Fog::Service + + requires :aws_access_key_id, :aws_secret_access_key + recognizes :region, :host, :path, :port, :scheme, :persistent + + request_path 'fog/aws/requests/sqs' + request :change_message_visibility + request :create_queue + request :delete_message + request :delete_queue + request :get_queue_attributes + request :list_queues + request :receive_message + request :send_message + request :set_queue_attributes + + class Mock + + def initialize(options={}) + end + + end + + class Real + + # Initialize connection to SQS + # + # ==== Notes + # options parameter must include values for :aws_access_key_id and + # :aws_secret_access_key in order to create a connection + # + # ==== Examples + # sqs = SQS.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 {}. + # * region<~String> - optional region to use, in ['eu-west-1', 'us-east-1', 'us-west-1', 'ap-southeast-1'] + # + # ==== Returns + # * SQS 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) + options[:region] ||= 'us-east-1' + @host = options[:host] || case options[:region] + when 'ap-southeast-1' + 'ap-southeast-1.queue.amazonaws.com' + when 'eu-west-1' + 'eu-west-1.queue.amazonaws.com' + when 'us-east-1' + 'queue.amazonaws.com' + when 'us-west-1' + 'us-west-1.queue.amazonaws.com' + else + raise ArgumentError, "Unknown region: #{options[:region].inspect}" + end + @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 path_from_queue_url(queue_url) + queue_url.split('.com', 2).last + end + + def request(params) + idempotent = params.delete(:idempotent) + parser = params.delete(:parser) + path = params.delete(:path) + + body = AWS.signed_params( + params, + { + :aws_access_key_id => @aws_access_key_id, + :hmac => @hmac, + :host => @host, + :path => path || @path, + :port => @port, + :version => '2009-02-01' + } + ) + + args = { + :body => body, + :expects => 200, + :idempotent => idempotent, + :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, + :host => @host, + :method => 'POST', + :parser => parser + } + args.merge!(:path => path) if path + + response = @connection.request(args) + + response + end + + end + end + end +end diff --git a/lib/fog/bin/aws.rb b/lib/fog/bin/aws.rb index 46091d5cd..58820663f 100644 --- a/lib/fog/bin/aws.rb +++ b/lib/fog/bin/aws.rb @@ -23,10 +23,14 @@ class AWS < Fog::Bin Fog::AWS::SimpleDB when :ses Fog::AWS::SES + when :sqs + Fog::AWS::SQS when :eu_storage, :storage Fog::Storage::AWS when :rds Fog::AWS::RDS + when :sns + Fog::AWS::SNS else # @todo Replace most instances of ArgumentError with NotImplementedError # @todo For a list of widely supported Exceptions, see: @@ -65,9 +69,13 @@ class AWS < Fog::Bin Fog::AWS::SimpleDB.new when :ses Fog::AWS::SES.new + when :sqs + Fog::AWS::SQS.new when :storage Formatador.display_line("[yellow][WARN] AWS[:storage] is deprecated, use Storage[:aws] instead[/]") Fog::Storage.new(:provider => 'AWS') + when :sns + Fog::AWS::SNS.new else raise ArgumentError, "Unrecognized service: #{key.inspect}" end diff --git a/lib/fog/cdn/rackspace.rb b/lib/fog/cdn/rackspace.rb index 04a393d47..a023ba7ba 100644 --- a/lib/fog/cdn/rackspace.rb +++ b/lib/fog/cdn/rackspace.rb @@ -85,7 +85,7 @@ module Fog end end if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json} - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/compute/aws.rb b/lib/fog/compute/aws.rb index 304b6d347..a1dd9559b 100644 --- a/lib/fog/compute/aws.rb +++ b/lib/fog/compute/aws.rb @@ -24,6 +24,8 @@ module Fog collection :tags model :volume collection :volumes + model :spot_request + collection :spot_requests request_path 'fog/compute/requests/aws' request :allocate_address diff --git a/lib/fog/compute/bluebox.rb b/lib/fog/compute/bluebox.rb index c13ffc4f3..c120544d0 100644 --- a/lib/fog/compute/bluebox.rb +++ b/lib/fog/compute/bluebox.rb @@ -83,7 +83,7 @@ module Fog end end unless response.body.empty? - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/compute/brightbox.rb b/lib/fog/compute/brightbox.rb index b36b348ea..0976df39e 100644 --- a/lib/fog/compute/brightbox.rb +++ b/lib/fog/compute/brightbox.rb @@ -106,7 +106,7 @@ module Fog response = authenticated_request(params) end unless response.body.empty? - response = ::MultiJson.decode(response.body) + response = MultiJson.decode(response.body) end end @@ -119,7 +119,7 @@ module Fog auth_url = options[:brightbox_auth_url] || @auth_url connection = Fog::Connection.new(auth_url) - @authentication_body = {'client_id' => @brightbox_client_id, 'grant_type' => 'none'}.to_json + @authentication_body = MultiJson.encode({'client_id' => @brightbox_client_id, 'grant_type' => 'none'}) response = connection.request({ :path => "/token", @@ -131,7 +131,7 @@ module Fog :method => 'POST', :body => @authentication_body }) - @oauth_token = ::MultiJson.decode(response.body)["access_token"] + @oauth_token = MultiJson.decode(response.body)["access_token"] return @oauth_token end diff --git a/lib/fog/compute/go_grid.rb b/lib/fog/compute/go_grid.rb index 3601d0700..5831354c1 100644 --- a/lib/fog/compute/go_grid.rb +++ b/lib/fog/compute/go_grid.rb @@ -100,7 +100,7 @@ module Fog end unless response.body.empty? - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) end response diff --git a/lib/fog/compute/linode.rb b/lib/fog/compute/linode.rb index f834596a2..c3b8a6244 100644 --- a/lib/fog/compute/linode.rb +++ b/lib/fog/compute/linode.rb @@ -96,7 +96,7 @@ module Fog response = @connection.request(params.merge!({:host => @host})) unless response.body.empty? - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) if data = response.body['ERRORARRAY'].first error = case data['ERRORCODE'] when 5 diff --git a/lib/fog/compute/models/aws/server.rb b/lib/fog/compute/models/aws/server.rb index b2ef5c1cc..369658d2e 100644 --- a/lib/fog/compute/models/aws/server.rb +++ b/lib/fog/compute/models/aws/server.rb @@ -177,7 +177,7 @@ module Fog commands = [ %{mkdir .ssh}, %{passwd -l #{username}}, - %{echo "#{attributes.to_json}" >> ~/attributes.json} + %{echo "#{MultiJson.encode(attributes)}" >> ~/attributes.json} ] if public_key commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys} diff --git a/lib/fog/compute/models/aws/spot_request.rb b/lib/fog/compute/models/aws/spot_request.rb new file mode 100644 index 000000000..b622175fb --- /dev/null +++ b/lib/fog/compute/models/aws/spot_request.rb @@ -0,0 +1,93 @@ +require 'fog/core/model' + +module Fog + module Compute + class AWS + + class SpotRequest < Fog::Model + + identity :id, :aliases => 'spotInstanceRequestId' + + attribute :price, :aliases => 'spotPrice' + attribute :request_type, :aliases => 'type' + attribute :created_at, :aliases => 'createTime' + attribute :instance_count, :aliases => 'instanceCount' + attribute :instance_id, :aliases => 'instanceId' + attribute :state + + attribute :valid_from, :aliases => 'validFrom' + attribute :valid_until, :aliases => 'validUntil' + attribute :launch_group, :aliases => 'launchGroup' + attribute :availability_zone_group, :aliases => 'availabilityZoneGroup' + attribute :product_description, :aliases => 'productDescription' + + attribute :groups, :aliases => 'LaunchSpecification.SecurityGroup' + attribute :key_name, :aliases => 'LaunchSpecification.KeyName' + attribute :availability_zone, :aliases => 'LaunchSpecification.Placement.AvailabilityZone' + attribute :flavor_id, :aliases => 'LaunchSpecification.InstanceType' + attribute :image_id, :aliases => 'LaunchSpecification.ImageId' + attribute :monitoring, :aliases => 'LaunchSpecification.Monitoring' + attribute :block_device_mapping, :aliases => 'LaunchSpecification.BlockDeviceMapping' + attribute :tags, :aliases => 'tagSet' + attribute :fault, :squash => 'message' + attribute :user_data + + attr_writer :username + + def initialize(attributes={}) + self.groups ||= ["default"] + self.flavor_id ||= 't1.micro' + self.image_id ||= begin + self.username = 'ubuntu' + case attributes[:connection].instance_variable_get(:@region) # Ubuntu 10.04 LTS 64bit (EBS) + when 'ap-northeast-1' + 'ami-5e0fa45f' + when 'ap-southeast-1' + 'ami-f092eca2' + when 'eu-west-1' + 'ami-3d1f2b49' + when 'us-east-1' + 'ami-3202f25b' + when 'us-west-1' + 'ami-f5bfefb0' + end + end + super + end + + def save + requires :image_id, :flavor_id, :price + + options = { + 'AvailabilityZoneGroup' => availability_zone_group, + 'InstanceCount' => instance_count, + 'LaunchGroup' => launch_group, + 'LaunchSpecification.BlockDeviceMapping' => block_device_mapping, + 'LaunchSpecification.KeyName' => key_name, + 'LaunchSpecification.Monitoring.Enabled' => monitoring, + 'LaunchSpecification.Placement.AvailabilityZone' => availability_zone, + 'LaunchSpecification.SecurityGroup' => groups, + 'LaunchSpecification.UserData' => user_data, + 'Type' => request_type, + 'ValidFrom' => valid_from, + 'ValidUntil' => valid_until } + options.delete_if {|key, value| value.nil?} + + data = connection.request_spot_instances(image_id, flavor_id, price, options).body + spot_instance_request = data['spotInstanceRequestSet'].first + spot_instance_request['launchSpecification'].each do |name,value| + spot_instance_request['LaunchSpecification.' + name[0,1].upcase + name[1..-1]] = value + end + spot_instance_request.merge(:groups => spot_instance_request['LaunchSpecification.GroupSet']) + spot_instance_request.merge(options) + merge_attributes( spot_instance_request ) + end + + def ready? + state == 'active' + end + + end + end + end +end diff --git a/lib/fog/compute/models/aws/spot_requests.rb b/lib/fog/compute/models/aws/spot_requests.rb new file mode 100644 index 000000000..9db6f4727 --- /dev/null +++ b/lib/fog/compute/models/aws/spot_requests.rb @@ -0,0 +1,48 @@ +require 'fog/core/collection' +require 'fog/compute/models/aws/spot_request' + +module Fog + module Compute + class AWS + class SpotRequests < Fog::Collection + + attribute :filters + + model Fog::Compute::AWS::SpotRequest + + def initialize(attributes) + self.filters ||= {} + super + end + + def all(filters = self.filters) + unless filters.is_a?(Hash) + Formatador.display_line("[yellow][WARN] all with #{filters.class} param is deprecated, use all('spot-instance-request-id' => []) instead[/] [light_black](#{caller.first})[/]") + filters = {'spot-instance-request-id' => [*filters]} + end + self.filters = filters + data = connection.describe_spot_instance_requests(filters).body + load( + data['spotInstanceRequestSet'].map do |spot_instance_request| + spot_instance_request['LaunchSpecification.Placement.AvailabilityZone'] = spot_instance_request['launchedAvailabilityZone'] + spot_instance_request['launchSpecification'].each do |name,value| + spot_instance_request['LaunchSpecification.' + name[0,1].upcase + name[1..-1]] = value + end + spot_instance_request.merge(:groups => spot_instance_request['LaunchSpecification.GroupSet']) + spot_instance_request + end.flatten + ) + end + + def get(spot_request_id) + if spot_request_id + self.class.new(:connection => connection).all('spot-instance-request-id' => spot_request_id).first + end + rescue Fog::Errors::NotFound + nil + end + + end + end + end +end diff --git a/lib/fog/compute/models/bluebox/server.rb b/lib/fog/compute/models/bluebox/server.rb index 648d48b98..afda7b0b7 100644 --- a/lib/fog/compute/models/bluebox/server.rb +++ b/lib/fog/compute/models/bluebox/server.rb @@ -113,7 +113,7 @@ module Fog %{mkdir .ssh}, %{echo "#{public_key}" >> ~/.ssh/authorized_keys}, %{passwd -l #{username}}, - %{echo "#{attributes.to_json}" >> ~/attributes.json} + %{echo "#{MultiJson.encode(attributes)}" >> ~/attributes.json} ]) rescue Errno::ECONNREFUSED sleep(1) diff --git a/lib/fog/compute/models/go_grid/server.rb b/lib/fog/compute/models/go_grid/server.rb index 27d89aa35..b81c884b1 100644 --- a/lib/fog/compute/models/go_grid/server.rb +++ b/lib/fog/compute/models/go_grid/server.rb @@ -92,8 +92,8 @@ module Fog %{mkdir .ssh}, %{echo "#{public_key}" >> ~/.ssh/authorized_keys}, %{passwd -l root}, - %{echo "#{attributes.to_json}" >> ~/attributes.json}, - %{echo "#{metadata.to_json}" >> ~/metadata.json} + %{echo "#{MultiJson.encode(attributes)}" >> ~/attributes.json}, + %{echo "#{MultiJson.encode(metadata)}" >> ~/metadata.json} ]) rescue Errno::ECONNREFUSED sleep(1) diff --git a/lib/fog/compute/models/rackspace/server.rb b/lib/fog/compute/models/rackspace/server.rb index e6de41878..20eb881e0 100644 --- a/lib/fog/compute/models/rackspace/server.rb +++ b/lib/fog/compute/models/rackspace/server.rb @@ -104,8 +104,8 @@ module Fog %{mkdir .ssh}, %{echo "#{public_key}" >> ~/.ssh/authorized_keys}, %{passwd -l #{username}}, - %{echo "#{attributes.to_json}" >> ~/attributes.json}, - %{echo "#{metadata.to_json}" >> ~/metadata.json} + %{echo "#{MultiJson.encode(attributes)}" >> ~/attributes.json}, + %{echo "#{MultiJson.encode(metadata)}" >> ~/metadata.json} ]) rescue Errno::ECONNREFUSED sleep(1) diff --git a/lib/fog/compute/models/slicehost/server.rb b/lib/fog/compute/models/slicehost/server.rb index f2e8041b1..f1d83146f 100644 --- a/lib/fog/compute/models/slicehost/server.rb +++ b/lib/fog/compute/models/slicehost/server.rb @@ -95,7 +95,7 @@ module Fog %{mkdir .ssh}, %{echo "#{public_key}" >> ~/.ssh/authorized_keys}, %{passwd -l #{username}}, - %{echo "#{attributes.to_json}" >> ~/attributes.json} + %{echo "#{MultiJson.encode(attributes)}" >> ~/attributes.json} ]) rescue Errno::ECONNREFUSED sleep(1) diff --git a/lib/fog/compute/models/virtual_box/server.rb b/lib/fog/compute/models/virtual_box/server.rb index 96640646e..3ba7420da 100644 --- a/lib/fog/compute/models/virtual_box/server.rb +++ b/lib/fog/compute/models/virtual_box/server.rb @@ -167,8 +167,8 @@ module Fog # %{mkdir .ssh}, # %{echo "#{public_key}" >> ~/.ssh/authorized_keys}, # %{passwd -l #{username}}, - # %{echo "#{attributes.to_json}" >> ~/attributes.json}, - # %{echo "#{metadata.to_json}" >> ~/metadata.json} + # %{echo "#{MultiJson.encode(attributes)}" >> ~/attributes.json}, + # %{echo "#{MultiJson.encode(metadata)}" >> ~/metadata.json} # ]) # rescue Errno::ECONNREFUSED # sleep(1) diff --git a/lib/fog/compute/ninefold.rb b/lib/fog/compute/ninefold.rb index d7b89de64..d1a34b233 100644 --- a/lib/fog/compute/ninefold.rb +++ b/lib/fog/compute/ninefold.rb @@ -104,7 +104,7 @@ module Fog # Because the response is some weird xml-json thing, we need to try and mung # the values out with a prefix, and if there is an empty data entry return an # empty version of the expected type (if provided) - response = ::MultiJson.decode(response.body) + response = MultiJson.decode(response.body) if options.has_key? :response_prefix keys = options[:response_prefix].split('/') keys.each do |k| diff --git a/lib/fog/compute/rackspace.rb b/lib/fog/compute/rackspace.rb index 11295a3a8..730df2dc2 100644 --- a/lib/fog/compute/rackspace.rb +++ b/lib/fog/compute/rackspace.rb @@ -120,7 +120,7 @@ module Fog end end unless response.body.empty? - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/compute/requests/brightbox/activate_console_server.rb b/lib/fog/compute/requests/brightbox/activate_console_server.rb index 19f8559e3..22e47bed4 100644 --- a/lib/fog/compute/requests/brightbox/activate_console_server.rb +++ b/lib/fog/compute/requests/brightbox/activate_console_server.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/servers/#{identifier}/activate_console", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb b/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb index 02e198c38..559796abe 100644 --- a/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb +++ b/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/load_balancers/#{identifier}/add_listeners", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/add_nodes_load_balancer.rb b/lib/fog/compute/requests/brightbox/add_nodes_load_balancer.rb index be5cb66e9..b66624482 100644 --- a/lib/fog/compute/requests/brightbox/add_nodes_load_balancer.rb +++ b/lib/fog/compute/requests/brightbox/add_nodes_load_balancer.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/load_balancers/#{identifier}/add_nodes", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/create_api_client.rb b/lib/fog/compute/requests/brightbox/create_api_client.rb index d828a9a41..c12c52fc4 100644 --- a/lib/fog/compute/requests/brightbox/create_api_client.rb +++ b/lib/fog/compute/requests/brightbox/create_api_client.rb @@ -9,7 +9,7 @@ module Fog :method => 'POST', :path => "/1.0/api_clients", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/create_cloud_ip.rb b/lib/fog/compute/requests/brightbox/create_cloud_ip.rb index 1112c65e0..567d838e1 100644 --- a/lib/fog/compute/requests/brightbox/create_cloud_ip.rb +++ b/lib/fog/compute/requests/brightbox/create_cloud_ip.rb @@ -9,7 +9,7 @@ module Fog :method => 'POST', :path => "/1.0/cloud_ips", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/create_image.rb b/lib/fog/compute/requests/brightbox/create_image.rb index a0598e572..837514527 100644 --- a/lib/fog/compute/requests/brightbox/create_image.rb +++ b/lib/fog/compute/requests/brightbox/create_image.rb @@ -9,7 +9,7 @@ module Fog :method => 'POST', :path => "/1.0/images", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/create_load_balancer.rb b/lib/fog/compute/requests/brightbox/create_load_balancer.rb index f99f47adc..2acc9c5bf 100644 --- a/lib/fog/compute/requests/brightbox/create_load_balancer.rb +++ b/lib/fog/compute/requests/brightbox/create_load_balancer.rb @@ -9,7 +9,7 @@ module Fog :method => 'POST', :path => "/1.0/load_balancers", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/create_server.rb b/lib/fog/compute/requests/brightbox/create_server.rb index 66ac84623..33b6e512d 100644 --- a/lib/fog/compute/requests/brightbox/create_server.rb +++ b/lib/fog/compute/requests/brightbox/create_server.rb @@ -9,7 +9,7 @@ module Fog :method => 'POST', :path => "/1.0/servers", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/destroy_api_client.rb b/lib/fog/compute/requests/brightbox/destroy_api_client.rb index d66ae39f7..5d5244736 100644 --- a/lib/fog/compute/requests/brightbox/destroy_api_client.rb +++ b/lib/fog/compute/requests/brightbox/destroy_api_client.rb @@ -10,7 +10,7 @@ module Fog :method => 'DELETE', :path => "/1.0/api_clients/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb b/lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb index d73a54cdd..b92a6859f 100644 --- a/lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb +++ b/lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb @@ -10,7 +10,7 @@ module Fog :method => 'DELETE', :path => "/1.0/cloud_ips/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/destroy_image.rb b/lib/fog/compute/requests/brightbox/destroy_image.rb index ffff80c77..b51e4eea8 100644 --- a/lib/fog/compute/requests/brightbox/destroy_image.rb +++ b/lib/fog/compute/requests/brightbox/destroy_image.rb @@ -10,7 +10,7 @@ module Fog :method => 'DELETE', :path => "/1.0/images/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/destroy_load_balancer.rb b/lib/fog/compute/requests/brightbox/destroy_load_balancer.rb index 5d0fa7906..0543db09a 100644 --- a/lib/fog/compute/requests/brightbox/destroy_load_balancer.rb +++ b/lib/fog/compute/requests/brightbox/destroy_load_balancer.rb @@ -10,7 +10,7 @@ module Fog :method => 'DELETE', :path => "/1.0/load_balancers/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/destroy_server.rb b/lib/fog/compute/requests/brightbox/destroy_server.rb index f0f999153..2c6372240 100644 --- a/lib/fog/compute/requests/brightbox/destroy_server.rb +++ b/lib/fog/compute/requests/brightbox/destroy_server.rb @@ -10,7 +10,7 @@ module Fog :method => 'DELETE', :path => "/1.0/servers/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_account.rb b/lib/fog/compute/requests/brightbox/get_account.rb index ce0dae9c7..c96b8d369 100644 --- a/lib/fog/compute/requests/brightbox/get_account.rb +++ b/lib/fog/compute/requests/brightbox/get_account.rb @@ -9,7 +9,7 @@ module Fog :method => 'GET', :path => "/1.0/account", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_api_client.rb b/lib/fog/compute/requests/brightbox/get_api_client.rb index a4f14ba50..d239b389f 100644 --- a/lib/fog/compute/requests/brightbox/get_api_client.rb +++ b/lib/fog/compute/requests/brightbox/get_api_client.rb @@ -10,7 +10,7 @@ module Fog :method => 'GET', :path => "/1.0/api_clients/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_cloud_ip.rb b/lib/fog/compute/requests/brightbox/get_cloud_ip.rb index 9bbb14015..2e921bf9e 100644 --- a/lib/fog/compute/requests/brightbox/get_cloud_ip.rb +++ b/lib/fog/compute/requests/brightbox/get_cloud_ip.rb @@ -10,7 +10,7 @@ module Fog :method => 'GET', :path => "/1.0/cloud_ips/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_image.rb b/lib/fog/compute/requests/brightbox/get_image.rb index cb4a46b47..80703ddac 100644 --- a/lib/fog/compute/requests/brightbox/get_image.rb +++ b/lib/fog/compute/requests/brightbox/get_image.rb @@ -10,7 +10,7 @@ module Fog :method => 'GET', :path => "/1.0/images/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_interface.rb b/lib/fog/compute/requests/brightbox/get_interface.rb index 808a280ff..491ac094b 100644 --- a/lib/fog/compute/requests/brightbox/get_interface.rb +++ b/lib/fog/compute/requests/brightbox/get_interface.rb @@ -10,7 +10,7 @@ module Fog :method => 'GET', :path => "/1.0/interfaces/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_load_balancer.rb b/lib/fog/compute/requests/brightbox/get_load_balancer.rb index af7524715..f88ba72bb 100644 --- a/lib/fog/compute/requests/brightbox/get_load_balancer.rb +++ b/lib/fog/compute/requests/brightbox/get_load_balancer.rb @@ -10,7 +10,7 @@ module Fog :method => 'GET', :path => "/1.0/load_balancers/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_server.rb b/lib/fog/compute/requests/brightbox/get_server.rb index cf7e521d1..01e6d0b83 100644 --- a/lib/fog/compute/requests/brightbox/get_server.rb +++ b/lib/fog/compute/requests/brightbox/get_server.rb @@ -10,7 +10,7 @@ module Fog :method => 'GET', :path => "/1.0/servers/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_server_type.rb b/lib/fog/compute/requests/brightbox/get_server_type.rb index 64542c0bb..7811a4c9d 100644 --- a/lib/fog/compute/requests/brightbox/get_server_type.rb +++ b/lib/fog/compute/requests/brightbox/get_server_type.rb @@ -10,7 +10,7 @@ module Fog :method => 'GET', :path => "/1.0/server_types/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_user.rb b/lib/fog/compute/requests/brightbox/get_user.rb index b1106e067..6ce6fff57 100644 --- a/lib/fog/compute/requests/brightbox/get_user.rb +++ b/lib/fog/compute/requests/brightbox/get_user.rb @@ -10,7 +10,7 @@ module Fog :method => 'GET', :path => "/1.0/users/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/get_zone.rb b/lib/fog/compute/requests/brightbox/get_zone.rb index 4de89890e..0800cd1f9 100644 --- a/lib/fog/compute/requests/brightbox/get_zone.rb +++ b/lib/fog/compute/requests/brightbox/get_zone.rb @@ -10,7 +10,7 @@ module Fog :method => 'GET', :path => "/1.0/zones/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/list_api_clients.rb b/lib/fog/compute/requests/brightbox/list_api_clients.rb index 1f3f6fa78..2f21bebb0 100644 --- a/lib/fog/compute/requests/brightbox/list_api_clients.rb +++ b/lib/fog/compute/requests/brightbox/list_api_clients.rb @@ -9,7 +9,7 @@ module Fog :method => 'GET', :path => "/1.0/api_clients", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/list_cloud_ips.rb b/lib/fog/compute/requests/brightbox/list_cloud_ips.rb index ca78200d3..6d78dae3a 100644 --- a/lib/fog/compute/requests/brightbox/list_cloud_ips.rb +++ b/lib/fog/compute/requests/brightbox/list_cloud_ips.rb @@ -9,7 +9,7 @@ module Fog :method => 'GET', :path => "/1.0/cloud_ips", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/list_images.rb b/lib/fog/compute/requests/brightbox/list_images.rb index d1eb78a2c..fc3f59c09 100644 --- a/lib/fog/compute/requests/brightbox/list_images.rb +++ b/lib/fog/compute/requests/brightbox/list_images.rb @@ -9,7 +9,7 @@ module Fog :method => 'GET', :path => "/1.0/images", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/list_load_balancers.rb b/lib/fog/compute/requests/brightbox/list_load_balancers.rb index b6ffeb918..2fadf61f1 100644 --- a/lib/fog/compute/requests/brightbox/list_load_balancers.rb +++ b/lib/fog/compute/requests/brightbox/list_load_balancers.rb @@ -9,7 +9,7 @@ module Fog :method => 'GET', :path => "/1.0/load_balancers", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/list_server_types.rb b/lib/fog/compute/requests/brightbox/list_server_types.rb index 13c0f3f00..fcd1b3a3d 100644 --- a/lib/fog/compute/requests/brightbox/list_server_types.rb +++ b/lib/fog/compute/requests/brightbox/list_server_types.rb @@ -9,7 +9,7 @@ module Fog :method => 'GET', :path => "/1.0/server_types", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/list_servers.rb b/lib/fog/compute/requests/brightbox/list_servers.rb index 1759df90f..1772fcf31 100644 --- a/lib/fog/compute/requests/brightbox/list_servers.rb +++ b/lib/fog/compute/requests/brightbox/list_servers.rb @@ -9,7 +9,7 @@ module Fog :method => 'GET', :path => "/1.0/servers", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/list_users.rb b/lib/fog/compute/requests/brightbox/list_users.rb index acdd05537..4df982355 100644 --- a/lib/fog/compute/requests/brightbox/list_users.rb +++ b/lib/fog/compute/requests/brightbox/list_users.rb @@ -9,7 +9,7 @@ module Fog :method => 'GET', :path => "/1.0/users", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/list_zones.rb b/lib/fog/compute/requests/brightbox/list_zones.rb index 509985370..12305b67a 100644 --- a/lib/fog/compute/requests/brightbox/list_zones.rb +++ b/lib/fog/compute/requests/brightbox/list_zones.rb @@ -9,7 +9,7 @@ module Fog :method => 'GET', :path => "/1.0/zones", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/map_cloud_ip.rb b/lib/fog/compute/requests/brightbox/map_cloud_ip.rb index ef9860bbc..2578c7e84 100644 --- a/lib/fog/compute/requests/brightbox/map_cloud_ip.rb +++ b/lib/fog/compute/requests/brightbox/map_cloud_ip.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/cloud_ips/#{identifier}/map", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb b/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb index 9e722a8ee..5fc2f3625 100644 --- a/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb +++ b/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/load_balancers/#{identifier}/remove_listeners", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/remove_nodes_load_balancer.rb b/lib/fog/compute/requests/brightbox/remove_nodes_load_balancer.rb index 10855100e..2b27b1384 100644 --- a/lib/fog/compute/requests/brightbox/remove_nodes_load_balancer.rb +++ b/lib/fog/compute/requests/brightbox/remove_nodes_load_balancer.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/load_balancers/#{identifier}/remove_nodes", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/reset_ftp_password_account.rb b/lib/fog/compute/requests/brightbox/reset_ftp_password_account.rb index 789366301..cb0fd89d4 100644 --- a/lib/fog/compute/requests/brightbox/reset_ftp_password_account.rb +++ b/lib/fog/compute/requests/brightbox/reset_ftp_password_account.rb @@ -9,7 +9,7 @@ module Fog :method => 'POST', :path => "/1.0/account/reset_ftp_password", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/resize_server.rb b/lib/fog/compute/requests/brightbox/resize_server.rb index 95c2fa333..a0cff1cd0 100644 --- a/lib/fog/compute/requests/brightbox/resize_server.rb +++ b/lib/fog/compute/requests/brightbox/resize_server.rb @@ -9,7 +9,7 @@ module Fog :method => 'POST', :path => "/1.0/servers/#{identifier}/resize", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/shutdown_server.rb b/lib/fog/compute/requests/brightbox/shutdown_server.rb index 088a7a96f..ca8c24ba7 100644 --- a/lib/fog/compute/requests/brightbox/shutdown_server.rb +++ b/lib/fog/compute/requests/brightbox/shutdown_server.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/servers/#{identifier}/shutdown", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/snapshot_server.rb b/lib/fog/compute/requests/brightbox/snapshot_server.rb index aa590d5bb..4547d2a47 100644 --- a/lib/fog/compute/requests/brightbox/snapshot_server.rb +++ b/lib/fog/compute/requests/brightbox/snapshot_server.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/servers/#{identifier}/snapshot", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/start_server.rb b/lib/fog/compute/requests/brightbox/start_server.rb index 0af664aa6..4e0086c23 100644 --- a/lib/fog/compute/requests/brightbox/start_server.rb +++ b/lib/fog/compute/requests/brightbox/start_server.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/servers/#{identifier}/start", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/stop_server.rb b/lib/fog/compute/requests/brightbox/stop_server.rb index 74ce1507c..4e7c4a98c 100644 --- a/lib/fog/compute/requests/brightbox/stop_server.rb +++ b/lib/fog/compute/requests/brightbox/stop_server.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/servers/#{identifier}/stop", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb b/lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb index 5c8d22276..22f5faa03 100644 --- a/lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb +++ b/lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb @@ -10,7 +10,7 @@ module Fog :method => 'POST', :path => "/1.0/cloud_ips/#{identifier}/unmap", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/update_account.rb b/lib/fog/compute/requests/brightbox/update_account.rb index 07aac6c21..3e23e8e22 100644 --- a/lib/fog/compute/requests/brightbox/update_account.rb +++ b/lib/fog/compute/requests/brightbox/update_account.rb @@ -10,7 +10,7 @@ module Fog :method => 'PUT', :path => "/1.0/account", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/update_api_client.rb b/lib/fog/compute/requests/brightbox/update_api_client.rb index ed6295348..a24285a46 100644 --- a/lib/fog/compute/requests/brightbox/update_api_client.rb +++ b/lib/fog/compute/requests/brightbox/update_api_client.rb @@ -11,7 +11,7 @@ module Fog :method => 'PUT', :path => "/1.0/api_clients/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/update_image.rb b/lib/fog/compute/requests/brightbox/update_image.rb index 69e735e0e..682ea3a04 100644 --- a/lib/fog/compute/requests/brightbox/update_image.rb +++ b/lib/fog/compute/requests/brightbox/update_image.rb @@ -11,7 +11,7 @@ module Fog :method => 'PUT', :path => "/1.0/images/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/update_load_balancer.rb b/lib/fog/compute/requests/brightbox/update_load_balancer.rb index 4c4af3eb5..6f745a14b 100644 --- a/lib/fog/compute/requests/brightbox/update_load_balancer.rb +++ b/lib/fog/compute/requests/brightbox/update_load_balancer.rb @@ -11,7 +11,7 @@ module Fog :method => 'PUT', :path => "/1.0/load_balancers/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/update_server.rb b/lib/fog/compute/requests/brightbox/update_server.rb index 530991f8c..cc1ffb080 100644 --- a/lib/fog/compute/requests/brightbox/update_server.rb +++ b/lib/fog/compute/requests/brightbox/update_server.rb @@ -11,7 +11,7 @@ module Fog :method => 'PUT', :path => "/1.0/servers/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/brightbox/update_user.rb b/lib/fog/compute/requests/brightbox/update_user.rb index 04f1fa636..5ad6f5ae7 100644 --- a/lib/fog/compute/requests/brightbox/update_user.rb +++ b/lib/fog/compute/requests/brightbox/update_user.rb @@ -11,7 +11,7 @@ module Fog :method => 'PUT', :path => "/1.0/users/#{identifier}", :headers => {"Content-Type" => "application/json"}, - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/linode/linode_disk_createfromstackscript.rb b/lib/fog/compute/requests/linode/linode_disk_createfromstackscript.rb index bb2f74539..6b61fdf6b 100644 --- a/lib/fog/compute/requests/linode/linode_disk_createfromstackscript.rb +++ b/lib/fog/compute/requests/linode/linode_disk_createfromstackscript.rb @@ -15,7 +15,7 @@ module Fog :label => name, :size => size, :rootPass => password, - :stackScriptUDFResponses => options.to_json + :stackScriptUDFResponses => MultiJson.encode(options) } ) end diff --git a/lib/fog/compute/requests/rackspace/create_image.rb b/lib/fog/compute/requests/rackspace/create_image.rb index 85577f3b5..d0fcaaa51 100644 --- a/lib/fog/compute/requests/rackspace/create_image.rb +++ b/lib/fog/compute/requests/rackspace/create_image.rb @@ -25,7 +25,7 @@ module Fog data['image']['name'] = options['name'] end request( - :body => data.to_json, + :body => MultiJson.encode(data), :expects => 202, :method => 'POST', :path => "images" diff --git a/lib/fog/compute/requests/rackspace/create_server.rb b/lib/fog/compute/requests/rackspace/create_server.rb index a28dd6c00..c5e81ed82 100644 --- a/lib/fog/compute/requests/rackspace/create_server.rb +++ b/lib/fog/compute/requests/rackspace/create_server.rb @@ -56,7 +56,7 @@ module Fog end end request( - :body => data.to_json, + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => 'servers.json' diff --git a/lib/fog/compute/requests/rackspace/server_action.rb b/lib/fog/compute/requests/rackspace/server_action.rb index eac401e4b..f05ed0bb9 100644 --- a/lib/fog/compute/requests/rackspace/server_action.rb +++ b/lib/fog/compute/requests/rackspace/server_action.rb @@ -7,12 +7,12 @@ module Fog # # ==== Parameters # * server_id<~Integer> - Id of server to reboot - # * body<~.to_json object> - Body of the request, describes the action (see reboot_server as an example) + # * body<~String> - Body of the request, describes the action (see reboot_server as an example) # * expect<~Integer> - expected return, 202 except for confirm resize (204) # def server_action(server_id, body, expects=202) request( - :body => body.to_json, + :body => MultiJson.encode(body), :expects => expects, :method => 'POST', :path => "servers/#{server_id}/action.json" diff --git a/lib/fog/compute/requests/rackspace/update_server.rb b/lib/fog/compute/requests/rackspace/update_server.rb index a06a47d6e..e4f2cc700 100644 --- a/lib/fog/compute/requests/rackspace/update_server.rb +++ b/lib/fog/compute/requests/rackspace/update_server.rb @@ -12,7 +12,7 @@ module Fog # * name<~String> - New name for server def update_server(server_id, options = {}) request( - :body => { 'server' => options }.to_json, + :body => MultiJson.encode({ 'server' => options }), :expects => 204, :method => 'PUT', :path => "servers/#{server_id}.json" diff --git a/lib/fog/compute/requests/storm_on_demand/add_balancer_node.rb b/lib/fog/compute/requests/storm_on_demand/add_balancer_node.rb index c76c0b004..530ae030a 100644 --- a/lib/fog/compute/requests/storm_on_demand/add_balancer_node.rb +++ b/lib/fog/compute/requests/storm_on_demand/add_balancer_node.rb @@ -6,7 +6,7 @@ module Fog def add_balancer_node(options = {}) request( :path => "/network/loadbalancer/addnode", - :body => {:params => options}.to_json + :body => MultiJson.encode({:params => options}) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/clone_server.rb b/lib/fog/compute/requests/storm_on_demand/clone_server.rb index a49f43a8b..be6da5989 100644 --- a/lib/fog/compute/requests/storm_on_demand/clone_server.rb +++ b/lib/fog/compute/requests/storm_on_demand/clone_server.rb @@ -6,7 +6,7 @@ module Fog def clone_server(options = {}) request( :path => "/storm/server/clone", - :body => {:params => options}.to_json + :body => MultiJson.encode({:params => options}) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/create_server.rb b/lib/fog/compute/requests/storm_on_demand/create_server.rb index c117f1e9f..da71b0ecb 100644 --- a/lib/fog/compute/requests/storm_on_demand/create_server.rb +++ b/lib/fog/compute/requests/storm_on_demand/create_server.rb @@ -6,7 +6,7 @@ module Fog def create_server(options = {}) request( :path => "/storm/server/create", - :body => {:params => options}.to_json + :body => MultiJson.encode({:params => options}) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/delete_server.rb b/lib/fog/compute/requests/storm_on_demand/delete_server.rb index d0731f636..0ad6b2999 100644 --- a/lib/fog/compute/requests/storm_on_demand/delete_server.rb +++ b/lib/fog/compute/requests/storm_on_demand/delete_server.rb @@ -6,7 +6,7 @@ module Fog def delete_server(options = {}) request( :path => "/storm/server/destroy", - :body => {:params => options}.to_json + :body => MultiJson.encode({:params => options}) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/get_server.rb b/lib/fog/compute/requests/storm_on_demand/get_server.rb index fae6ee14a..e76b38138 100644 --- a/lib/fog/compute/requests/storm_on_demand/get_server.rb +++ b/lib/fog/compute/requests/storm_on_demand/get_server.rb @@ -6,7 +6,7 @@ module Fog def get_server(options = {}) request( :path => "/storm/server/details", - :body => {:params => options}.to_json + :body => MultiJson.encode({:params => options}) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/get_stats.rb b/lib/fog/compute/requests/storm_on_demand/get_stats.rb index 03e993c81..4c038d3a0 100644 --- a/lib/fog/compute/requests/storm_on_demand/get_stats.rb +++ b/lib/fog/compute/requests/storm_on_demand/get_stats.rb @@ -6,7 +6,7 @@ module Fog def get_stats(options = {}) request( :path => "/monitoring/load/stats", - :body => {:params => options}.to_json + :body => MultiJson.encode({:params => options}) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/list_balancers.rb b/lib/fog/compute/requests/storm_on_demand/list_balancers.rb index 1f6fbc144..ae6441c5a 100644 --- a/lib/fog/compute/requests/storm_on_demand/list_balancers.rb +++ b/lib/fog/compute/requests/storm_on_demand/list_balancers.rb @@ -6,7 +6,7 @@ module Fog def list_balancers(options = {}) request( :path => "/network/loadbalancer/list", - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/list_configs.rb b/lib/fog/compute/requests/storm_on_demand/list_configs.rb index 97805bddc..87cd946db 100644 --- a/lib/fog/compute/requests/storm_on_demand/list_configs.rb +++ b/lib/fog/compute/requests/storm_on_demand/list_configs.rb @@ -6,7 +6,7 @@ module Fog def list_configs(options = {}) request( :path => "/storm/config/list", - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/list_images.rb b/lib/fog/compute/requests/storm_on_demand/list_images.rb index 9fc2c264e..f2ea9ab45 100644 --- a/lib/fog/compute/requests/storm_on_demand/list_images.rb +++ b/lib/fog/compute/requests/storm_on_demand/list_images.rb @@ -6,7 +6,7 @@ module Fog def list_images(options = {}) request( :path => "/server/image/list", - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/list_private_ips.rb b/lib/fog/compute/requests/storm_on_demand/list_private_ips.rb index 3b040368b..c553994aa 100644 --- a/lib/fog/compute/requests/storm_on_demand/list_private_ips.rb +++ b/lib/fog/compute/requests/storm_on_demand/list_private_ips.rb @@ -6,7 +6,7 @@ module Fog def list_private_ips(options = {}) request( :path => "/network/private/get", - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/list_servers.rb b/lib/fog/compute/requests/storm_on_demand/list_servers.rb index 1429efe1f..4b008e6c0 100644 --- a/lib/fog/compute/requests/storm_on_demand/list_servers.rb +++ b/lib/fog/compute/requests/storm_on_demand/list_servers.rb @@ -6,7 +6,7 @@ module Fog def list_servers(options = {}) request( :path => "/storm/server/list", - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/list_templates.rb b/lib/fog/compute/requests/storm_on_demand/list_templates.rb index 6e2adbc27..6f6f55ef8 100644 --- a/lib/fog/compute/requests/storm_on_demand/list_templates.rb +++ b/lib/fog/compute/requests/storm_on_demand/list_templates.rb @@ -6,7 +6,7 @@ module Fog def list_templates(options = {}) request( :path => "/server/template/list", - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/reboot_server.rb b/lib/fog/compute/requests/storm_on_demand/reboot_server.rb index 089480336..42d1df45e 100644 --- a/lib/fog/compute/requests/storm_on_demand/reboot_server.rb +++ b/lib/fog/compute/requests/storm_on_demand/reboot_server.rb @@ -6,7 +6,7 @@ module Fog def reboot_server(options = {}) request( :path => "/storm/server/reboot", - :body => {:params => options}.to_json + :body => MultiJson.encode({:params => options}) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/remove_balancer_node.rb b/lib/fog/compute/requests/storm_on_demand/remove_balancer_node.rb index a6d4b5201..e5822ca06 100644 --- a/lib/fog/compute/requests/storm_on_demand/remove_balancer_node.rb +++ b/lib/fog/compute/requests/storm_on_demand/remove_balancer_node.rb @@ -6,7 +6,7 @@ module Fog def remove_balancer_node(options = {}) request( :path => "/network/loadbalancer/removenode", - :body => {:params => options}.to_json + :body => MultiJson.encode({:params => options}) ) end diff --git a/lib/fog/compute/requests/storm_on_demand/resize_server.rb b/lib/fog/compute/requests/storm_on_demand/resize_server.rb index a63e22a5d..c9cb5ca32 100644 --- a/lib/fog/compute/requests/storm_on_demand/resize_server.rb +++ b/lib/fog/compute/requests/storm_on_demand/resize_server.rb @@ -6,7 +6,7 @@ module Fog def resize_server(options = {}) request( :path => "/storm/server/resize", - :body => {:params => options}.to_json + :body => MultiJson.encode({:params => options}) ) end diff --git a/lib/fog/compute/storm_on_demand.rb b/lib/fog/compute/storm_on_demand.rb index cb88317cd..6dcb7d5eb 100644 --- a/lib/fog/compute/storm_on_demand.rb +++ b/lib/fog/compute/storm_on_demand.rb @@ -118,7 +118,7 @@ module Fog end end unless response.body.empty? - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) end if response.body.keys.include?('full_error') raise(Fog::Compute::StormOnDemand::Error, response.body.inspect) diff --git a/lib/fog/compute/vcloud.rb b/lib/fog/compute/vcloud.rb index a6cb242b7..020998296 100644 --- a/lib/fog/compute/vcloud.rb +++ b/lib/fog/compute/vcloud.rb @@ -117,9 +117,11 @@ module Fog request :undeploy class Mock - def request(options) - raise "Not implemented" + + def initialize(options={}) + Fog::Mock.not_implemented end + end class Real diff --git a/lib/fog/core.rb b/lib/fog/core.rb index 6e1fa00e6..de26240cc 100644 --- a/lib/fog/core.rb +++ b/lib/fog/core.rb @@ -25,7 +25,7 @@ require 'fog/core/errors' require 'fog/core/hmac' require 'fog/core/model' require 'fog/core/mock' -# require 'fog/core/parser' +require 'fog/core/parser' # FIXME: would be better to only load when nokogiri is required require 'fog/core/provider' require 'fog/core/service' require 'fog/core/ssh' diff --git a/lib/fog/core/attributes.rb b/lib/fog/core/attributes.rb index a7dcd0360..cab8d6f52 100644 --- a/lib/fog/core/attributes.rb +++ b/lib/fog/core/attributes.rb @@ -71,8 +71,10 @@ module Fog class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_data) if new_data.is_a?(Hash) - if new_data[:#{squash}] || new_data["#{squash}"] - attributes[:#{name}] = new_data[:#{squash}] || new_data["#{squash}"] + if new_data.has_key?(:#{squash}) + attributes[:#{name}] = new_data[:#{squash}] + elsif new_data.has_key?("#{squash}") + attributes[:#{name}] = new_data["#{squash}"] else attributes[:#{name}] = [ new_data ] end diff --git a/lib/fog/core/collection.rb b/lib/fog/core/collection.rb index 15d6f26e0..802db6052 100644 --- a/lib/fog/core/collection.rb +++ b/lib/fog/core/collection.rb @@ -6,19 +6,19 @@ module Fog Array.public_instance_methods(false).each do |method| unless [:reject, :select, :slice].include?(method.to_sym) - class_eval <<-RUBY + class_eval <<-EOS, __FILE__, __LINE__ def #{method}(*args) unless @loaded lazy_load end super end - RUBY + EOS end end %w[reject select slice].each do |method| - class_eval <<-RUBY + class_eval <<-EOS, __FILE__, __LINE__ def #{method}(*args) unless @loaded lazy_load @@ -26,7 +26,7 @@ module Fog data = super result = self.clone.clear.concat(data) end - RUBY + EOS end def self.model(new_model=nil) @@ -117,7 +117,7 @@ module Fog def to_json(options = {}) require 'multi_json' - self.map {|member| member.attributes}.to_json(options) + MultiJson.encode(self.map {|member| member.attributes}) end private diff --git a/lib/fog/core/model.rb b/lib/fog/core/model.rb index fd5531265..3e6722697 100644 --- a/lib/fog/core/model.rb +++ b/lib/fog/core/model.rb @@ -39,7 +39,7 @@ module Fog def to_json(options = {}) require 'multi_json' - attributes.to_json(options) + MultiJson.encode(attributes) end def wait_for(timeout=Fog.timeout, interval=1, &block) diff --git a/lib/fog/dns/dnsimple.rb b/lib/fog/dns/dnsimple.rb index c6fdd878c..71d0f6146 100644 --- a/lib/fog/dns/dnsimple.rb +++ b/lib/fog/dns/dnsimple.rb @@ -82,7 +82,7 @@ module Fog response = @connection.request(params.merge!({:host => @host})) unless response.body.empty? - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/dns/dnsmadeeasy.rb b/lib/fog/dns/dnsmadeeasy.rb index 08ceb9c86..323cc34cf 100644 --- a/lib/fog/dns/dnsmadeeasy.rb +++ b/lib/fog/dns/dnsmadeeasy.rb @@ -117,7 +117,7 @@ module Fog end unless response.body.empty? - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) end response diff --git a/lib/fog/dns/linode.rb b/lib/fog/dns/linode.rb index 25e1cce82..35c190eba 100644 --- a/lib/fog/dns/linode.rb +++ b/lib/fog/dns/linode.rb @@ -69,7 +69,7 @@ module Fog response = @connection.request(params.merge!({:host => @host})) unless response.body.empty? - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) if data = response.body['ERRORARRAY'].first error = case data['ERRORCODE'] when 5 diff --git a/lib/fog/dns/requests/dnsimple/create_domain.rb b/lib/fog/dns/requests/dnsimple/create_domain.rb index a0caba17c..d5ea8e8c5 100644 --- a/lib/fog/dns/requests/dnsimple/create_domain.rb +++ b/lib/fog/dns/requests/dnsimple/create_domain.rb @@ -14,7 +14,7 @@ module Fog def create_domain(name) body = { "domain" => { "name" => name } } request( - :body => body.to_json, + :body => MultiJson.encode(body), :expects => 201, :method => 'POST', :path => '/domains' diff --git a/lib/fog/dns/requests/dnsimple/create_record.rb b/lib/fog/dns/requests/dnsimple/create_record.rb index a6bc78d25..eee1db1a0 100644 --- a/lib/fog/dns/requests/dnsimple/create_record.rb +++ b/lib/fog/dns/requests/dnsimple/create_record.rb @@ -36,7 +36,7 @@ module Fog body["record"].merge!(options) - request( :body => body.to_json, + request( :body => MultiJson.encode(body), :expects => 201, :method => 'POST', :path => "/domains/#{domain}/records" ) diff --git a/lib/fog/dns/requests/dnsimple/update_record.rb b/lib/fog/dns/requests/dnsimple/update_record.rb index f2c9af52e..744fd03f7 100644 --- a/lib/fog/dns/requests/dnsimple/update_record.rb +++ b/lib/fog/dns/requests/dnsimple/update_record.rb @@ -30,7 +30,7 @@ module Fog body = { "record" => options } - request( :body => body.to_json, + request( :body => MultiJson.encode(body), :expects => 200, :method => "PUT", :path => "/domains/#{domain}/records/#{record_id}" ) diff --git a/lib/fog/dns/requests/dnsmadeeasy/create_record.rb b/lib/fog/dns/requests/dnsmadeeasy/create_record.rb index 7fd26f72d..561c30d96 100644 --- a/lib/fog/dns/requests/dnsmadeeasy/create_record.rb +++ b/lib/fog/dns/requests/dnsmadeeasy/create_record.rb @@ -52,7 +52,7 @@ module Fog :expects => 201, :method => "POST", :path => "/V1.2/domains/#{domain}/records", - :body => body.to_json + :body => MultiJson.encode(body) ) end diff --git a/lib/fog/dns/requests/dnsmadeeasy/create_secondary.rb b/lib/fog/dns/requests/dnsmadeeasy/create_secondary.rb index 42e6628b2..e50e8054b 100644 --- a/lib/fog/dns/requests/dnsmadeeasy/create_secondary.rb +++ b/lib/fog/dns/requests/dnsmadeeasy/create_secondary.rb @@ -26,7 +26,7 @@ module Fog :expects => 201, :method => 'PUT', :path => "/V1.2/secondary/#{secondary_name}", - :body => body.to_json + :body => MultiJson.encode(body) ) end diff --git a/lib/fog/dns/requests/dnsmadeeasy/update_record.rb b/lib/fog/dns/requests/dnsmadeeasy/update_record.rb index b7f61f23d..cefd06ff7 100644 --- a/lib/fog/dns/requests/dnsmadeeasy/update_record.rb +++ b/lib/fog/dns/requests/dnsmadeeasy/update_record.rb @@ -46,7 +46,7 @@ module Fog :expects => 200, :method => "PUT", :path => "/V1.2/domains/#{domain}/records/#{record_id}", - :body => options.to_json + :body => MultiJson.encode(options) ) end diff --git a/lib/fog/dns/requests/dnsmadeeasy/update_secondary.rb b/lib/fog/dns/requests/dnsmadeeasy/update_secondary.rb index 50ca05ca0..51fcc2110 100644 --- a/lib/fog/dns/requests/dnsmadeeasy/update_secondary.rb +++ b/lib/fog/dns/requests/dnsmadeeasy/update_secondary.rb @@ -26,7 +26,7 @@ module Fog :expects => 201, :method => 'PUT', :path => "/V1.2/secondary/#{secondary_name}", - :body => body.to_json + :body => MultiJson.encode(body) ) end diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index fa804e483..e818ee302 100644 --- a/lib/fog/providers/aws.rb +++ b/lib/fog/providers/aws.rb @@ -1,5 +1,4 @@ require 'fog/core' -require 'fog/core/parser' require 'openssl' # For RSA key pairs require 'base64' # For console output @@ -12,13 +11,15 @@ module Fog service(:cdn, 'cdn/aws') service(:compute, 'compute/aws') service(:cloud_formation, 'aws/cloud_formation') - service(:cloud_watch, 'aws/cloud_watch') + service(:cloud_watch, 'aws/cloud_watch') service(:dns, 'dns/aws') service(:elb, 'aws/elb') service(:iam, 'aws/iam') service(:rds, 'aws/rds') service(:ses, 'aws/ses') service(:simpledb, 'aws/simpledb') + service(:sns, 'aws/sns') + service(:sqs, 'aws/sqs') service(:storage, 'storage/aws') def self.indexed_param(key, values) diff --git a/lib/fog/storage/rackspace.rb b/lib/fog/storage/rackspace.rb index b77c90986..fa83d20a6 100644 --- a/lib/fog/storage/rackspace.rb +++ b/lib/fog/storage/rackspace.rb @@ -115,7 +115,7 @@ module Fog end end if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json} - response.body = ::MultiJson.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/storage/requests/aws/get_bucket_policy.rb b/lib/fog/storage/requests/aws/get_bucket_policy.rb index f0d2e32ad..458bd0154 100644 --- a/lib/fog/storage/requests/aws/get_bucket_policy.rb +++ b/lib/fog/storage/requests/aws/get_bucket_policy.rb @@ -27,7 +27,7 @@ module Fog :method => 'GET', :query => {'policy' => nil} }) - response.body = ::MultiJson.decode(response.body) unless response.body.nil? + response.body = MultiJson.decode(response.body) unless response.body.nil? end end diff --git a/lib/fog/storage/requests/aws/post_object_hidden_fields.rb b/lib/fog/storage/requests/aws/post_object_hidden_fields.rb index 9970ec9c4..4cd3ce1a4 100644 --- a/lib/fog/storage/requests/aws/post_object_hidden_fields.rb +++ b/lib/fog/storage/requests/aws/post_object_hidden_fields.rb @@ -27,7 +27,7 @@ module Fog def post_object_hidden_fields(options = {}) if options['policy'] - options['policy'] = options['policy'].to_json + options['policy'] = MultiJson.encode(options['policy']) options['AWSAccessKeyId'] = @aws_access_key_id string_to_sign = Base64.encode64(options['policy']).chomp! signed_string = @hmac.sign(string_to_sign) diff --git a/lib/fog/storage/requests/aws/put_bucket_policy.rb b/lib/fog/storage/requests/aws/put_bucket_policy.rb index 7fd7af49b..13bc13fa3 100644 --- a/lib/fog/storage/requests/aws/put_bucket_policy.rb +++ b/lib/fog/storage/requests/aws/put_bucket_policy.rb @@ -14,7 +14,7 @@ module Fog def put_bucket_policy(bucket_name, policy) request({ - :body => policy.to_json, + :body => MultiJson.encode(policy), :expects => 204, :headers => {}, :host => "#{bucket_name}.#{@host}", diff --git a/tests/aws/models/elb/model_tests.rb b/tests/aws/models/elb/model_tests.rb index 41d7fa349..6512c7b73 100644 --- a/tests/aws/models/elb/model_tests.rb +++ b/tests/aws/models/elb/model_tests.rb @@ -1,5 +1,6 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do @availability_zones = Fog::Compute[:aws].describe_availability_zones('state' => 'available').body['availabilityZoneInfo'].collect{ |az| az['zoneName'] } + @key_name = 'fog-test-model' tests('success') do tests('load_balancers') do @@ -33,7 +34,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do tests('create') do tests('without availability zones') do elb = AWS[:elb].load_balancers.create(:id => elb_id) - tests("availability zones are correct").returns(@availability_zones) { elb.availability_zones } + tests("availability zones are correct").returns(@availability_zones.sort) { elb.availability_zones.sort } tests("dns names is set").returns(true) { elb.dns_name.is_a?(String) } tests("created_at is set").returns(true) { Time === elb.created_at } tests("policies is empty").returns([]) { elb.policies } @@ -46,16 +47,24 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do tests('with availability zones') do azs = @availability_zones[1..-1] elb2 = AWS[:elb].load_balancers.create(:id => "#{elb_id}-2", :availability_zones => azs) - tests("availability zones are correct").returns(azs) { elb2.availability_zones } + tests("availability zones are correct").returns(azs.sort) { elb2.availability_zones.sort } elb2.destroy end + # Need to sleep here for IAM changes to propgate tests('with ListenerDescriptions') do + @certificate = AWS[:iam].upload_server_certificate(AWS::IAM::SERVER_CERT_PUBLIC_KEY, AWS::IAM::SERVER_CERT_PRIVATE_KEY, @key_name).body['Certificate'] + sleep(8) unless Fog.mocking? listeners = [{ - 'Listener' => {'LoadBalancerPort' => 2030, 'InstancePort' => 2030, 'Protocol' => 'HTTP'}, + 'Listener' => { + 'LoadBalancerPort' => 2030, 'InstancePort' => 2030, 'Protocol' => 'HTTP' + }, 'PolicyNames' => [] }, { - 'Listener' => {'LoadBalancerPort' => 443, 'InstancePort' => 443, 'Protocol' => 'HTTPS'}, + 'Listener' => { + 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'Protocol' => 'HTTPS', + 'SSLCertificateId' => @certificate['Arn'] + }, 'PolicyNames' => [] }] elb3 = AWS[:elb].load_balancers.create(:id => "#{elb_id}-3", 'ListenerDescriptions' => listeners) @@ -66,6 +75,14 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do tests('protocol is HTTPS').returns('HTTPS') { elb3.listeners.last.protocol } elb3.destroy end + + tests('with invalid Server Cert ARN').raises(Fog::AWS::IAM::NotFound) do + listeners = [{ + 'Listener' => { + 'LoadBalancerPort' => 443, 'InstancePort' => 80, 'Protocol' => 'HTTPS', "SSLCertificateId" => "fakecert"} + }] + AWS[:elb].load_balancers.create(:id => "#{elb_id}-4", "ListenerDescriptions" => listeners) + end end tests('all') do @@ -228,5 +245,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do tests('destroy') do elb.destroy end + + AWS[:iam].delete_server_certificate(@key_name) end end diff --git a/tests/aws/requests/cloud_watch/get_metric_statistics_tests.rb b/tests/aws/requests/cloud_watch/get_metric_statistics_tests.rb index 92febf76b..16859b8e0 100644 --- a/tests/aws/requests/cloud_watch/get_metric_statistics_tests.rb +++ b/tests/aws/requests/cloud_watch/get_metric_statistics_tests.rb @@ -1,6 +1,6 @@ Shindo.tests('AWS::CloudWatch | metric requests', ['aws', 'cloudwatch']) do tests('success') do - + @metrics_statistic_format = { 'GetMetricStatisticsResult' => { 'Label' => String, @@ -18,9 +18,9 @@ Shindo.tests('AWS::CloudWatch | metric requests', ['aws', 'cloudwatch']) do 'RequestId' => String } } - - + tests("#get_metric_statistics").formats(@metrics_statistic_format) do + pending if Fog.mocking? instanceId = 'i-420c352f' AWS[:cloud_watch].get_metric_statistics({'Statistics' => ['Minimum','Maximum','Sum','SampleCount','Average'], 'StartTime' => (Time.now-600).iso8601, 'EndTime' => Time.now.iso8601, 'Period' => 60, 'MetricName' => 'DiskReadBytes', 'Namespace' => 'AWS/EC2', 'Dimensions' => [{'Name' => 'InstanceId', 'Value' => instanceId}]}).body end diff --git a/tests/aws/requests/cloud_watch/list_metrics_test.rb b/tests/aws/requests/cloud_watch/list_metrics_test.rb index 596a08d55..da8174a7d 100644 --- a/tests/aws/requests/cloud_watch/list_metrics_test.rb +++ b/tests/aws/requests/cloud_watch/list_metrics_test.rb @@ -1,5 +1,5 @@ Shindo.tests('AWS::CloudWatch | metric requests', ['aws', 'cloudwatch']) do - + tests('success') do @metrics_list_format = { 'ListMetricsResult' => { @@ -34,23 +34,27 @@ Shindo.tests('AWS::CloudWatch | metric requests', ['aws', 'cloudwatch']) do }, 'ResponseMetadata' => {"RequestId"=> String}, } - + tests("#list_metrics").formats(@metrics_list_format) do + pending if Fog.mocking? AWS[:cloud_watch].list_metrics.body end - + tests("#dimension_filtered_list_metrics").formats(@dimension_filtered_metrics_list_format) do + pending if Fog.mocking? AWS[:cloud_watch].list_metrics('Dimensions' => [{'Name' => 'InstanceId', 'Value' => @instanceId}]).body end - + tests("#metric_name_filtered_list_metrics").returns(true) do + pending if Fog.mocking? metricName = "CPUUtilization" AWS[:cloud_watch].list_metrics('MetricName' => metricName).body['ListMetricsResult']['Metrics'].all? do |metric| metric['MetricName'] == metricName end end - + tests("#namespace_filtered_list_metrics").returns(true) do + pending if Fog.mocking? namespace = "AWS/EC2" AWS[:cloud_watch].list_metrics('Namespace' => namespace).body['ListMetricsResult']['Metrics'].all? do |metric| metric['Namespace'] == namespace diff --git a/tests/aws/requests/cloud_watch/put_metric_data_tests.rb b/tests/aws/requests/cloud_watch/put_metric_data_tests.rb index e1a60b133..209c6af1e 100644 --- a/tests/aws/requests/cloud_watch/put_metric_data_tests.rb +++ b/tests/aws/requests/cloud_watch/put_metric_data_tests.rb @@ -1,24 +1,27 @@ Shindo.tests('AWS::CloudWatch | metric requests', ['aws', 'cloudwatch']) do tests('success') do + namespace = 'Custom/Test' - @puts_format = {'ResponseMetadata' => {'RequestId' => String}} - + tests('#puts_value').formats(@puts_format) do + pending if Fog.mocking? AWS[:cloud_watch].put_metric_data(namespace, [{'MetricName' => 'RequestTest', 'Unit' => 'None', 'Value' => 1}]).body end - + tests('#puts_statistics_set').succeeds do + pending if Fog.mocking? AWS[:cloud_watch].put_metric_data(namespace, [{'MetricName' => 'RequestTest', 'Unit' => 'None', 'StatisticValues' => {'Minimum' => 0, 'Maximum' => 9, 'Sum' => 45, 'SampleCount' => 10, 'Average' => 4.5}}]).body end - + tests('#puts with dimensions').succeeds do + pending if Fog.mocking? dimensions = [{}] - AWS[:cloud_watch].put_metric_data(namespace, [{'MetricName' => 'RequestTest', 'Unit' => 'None', 'Value' => 1, 'Dimensions' => dimensions}]).body end - + tests('#puts more than one').succeeds do + pending if Fog.mocking? datapoints = (0...3).collect do |i| dp = {'MetricName' => "#{i}RequestTest", 'Unit' => 'None', 'Value' => i} if i%2==0 @@ -28,6 +31,6 @@ Shindo.tests('AWS::CloudWatch | metric requests', ['aws', 'cloudwatch']) do end AWS[:cloud_watch].put_metric_data(namespace, datapoints).body end - + end end diff --git a/tests/aws/requests/elb/listener_tests.rb b/tests/aws/requests/elb/listener_tests.rb index a0615dd93..0208149c6 100644 --- a/tests/aws/requests/elb/listener_tests.rb +++ b/tests/aws/requests/elb/listener_tests.rb @@ -8,10 +8,11 @@ Shindo.tests('AWS::ELB | listener_tests', ['aws', 'elb']) do tests("#create_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do listeners = [ - {'Protocol' => 'TCP', 'LoadBalancerPort' => 443, 'InstancePort' => 443}, + {'Protocol' => 'TCP', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => @certificate['Arn']}, {'Protocol' => 'HTTP', 'LoadBalancerPort' => 80, 'InstancePort' => 80} ] - AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body + response = AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body + response end tests("#delete_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do @@ -19,22 +20,30 @@ Shindo.tests('AWS::ELB | listener_tests', ['aws', 'elb']) do AWS[:elb].delete_load_balancer_listeners(@load_balancer_id, ports).body end + tests("#create_load_balancer_listeners with non-existant SSL certificate") do + listeners = [ + {'Protocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => 'non-existant'}, + ] + raises(Fog::AWS::IAM::NotFound) { AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners) } + end + + tests("#create_load_balancer_listeners with invalid SSL certificate").raises(Fog::AWS::IAM::NotFound) do + sleep 8 unless Fog.mocking? + listeners = [ + {'Protocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => "#{@certificate['Arn']}fake"}, + ] + AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body + end + # This is sort of fucked up, but it may or may not fail, thanks AWS tests("#create_load_balancer_listeners with SSL certificate").formats(AWS::ELB::Formats::BASIC) do - sleep 5 unless Fog.mocking? + sleep 8 unless Fog.mocking? listeners = [ {'Protocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => @certificate['Arn']}, ] AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body end - tests("#create_load_balancer_listeners with non-existant SSL certificate") do - listeners = [ - {'Protocol' => 'HTTPS', 'LoadBalancerPort' => 443, 'InstancePort' => 443, 'SSLCertificateId' => 'non-existant'}, - ] - raises(Excon::Errors::BadRequest) { AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners) } - end - AWS[:iam].delete_server_certificate(@key_name) AWS[:elb].delete_load_balancer(@load_balancer_id) end diff --git a/tests/aws/requests/iam/server_certificate_tests.rb b/tests/aws/requests/iam/server_certificate_tests.rb index 580d5218c..894bed287 100644 --- a/tests/aws/requests/iam/server_certificate_tests.rb +++ b/tests/aws/requests/iam/server_certificate_tests.rb @@ -19,6 +19,13 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do AWS[:iam].upload_server_certificate(public_key, private_key, @key_name).body end + tests('#get_server_certificate').formats(@upload_format) do + tests('raises NotFound').raises(Fog::AWS::IAM::NotFound) do + AWS[:iam].get_server_certificate("#{@key_name}fake") + end + AWS[:iam].get_server_certificate(@key_name).body + end + @list_format = { 'Certificates' => [@certificate_format] } tests('#list_server_certificates').formats(@list_format) do result = AWS[:iam].list_server_certificates.body diff --git a/tests/aws/requests/simpledb/attributes_tests.rb b/tests/aws/requests/simpledb/attributes_tests.rb index 9f34c4b1a..48aa6e01d 100644 --- a/tests/aws/requests/simpledb/attributes_tests.rb +++ b/tests/aws/requests/simpledb/attributes_tests.rb @@ -14,8 +14,8 @@ Shindo.tests('AWS::SimpleDB | attributes requests', ['aws']) do AWS[:sdb].get_attributes(@domain_name, 'a', {'ConsistentRead' => true}).body['Attributes'] end - tests("#get_attributes('#{@domain_name}', 'notanattribute')").succeeds do - AWS[:sdb].get_attributes(@domain_name, 'notanattribute') + tests("#get_attributes('#{@domain_name}', 'AttributeName' => 'notanattribute')").succeeds do + AWS[:sdb].get_attributes(@domain_name, 'AttributeName' => 'notanattribute') end tests("#select('select * from #{@domain_name}', {'ConsistentRead' => true}).body['Items']").returns({'a' => { 'b' => ['c'], 'd' => ['e']}, 'x' => { 'y' => ['z'] } }) do diff --git a/tests/aws/requests/sns/helper.rb b/tests/aws/requests/sns/helper.rb new file mode 100644 index 000000000..7cc87d183 --- /dev/null +++ b/tests/aws/requests/sns/helper.rb @@ -0,0 +1,9 @@ +class AWS + module SNS + module Formats + BASIC = { + 'RequestId' => String + } + end + end +end diff --git a/tests/aws/requests/sns/subscription_tests.rb b/tests/aws/requests/sns/subscription_tests.rb new file mode 100644 index 000000000..028eccece --- /dev/null +++ b/tests/aws/requests/sns/subscription_tests.rb @@ -0,0 +1,86 @@ +Shindo.tests('AWS::SES | topic lifecycle tests', ['aws', 'sns']) do + + unless Fog.mocking? + @topic_arn = AWS[:sns].create_topic('fog_subscription_tests').body['TopicArn'] + @queue_url = AWS[:sqs].create_queue('fog_subscription_tests').body['QueueUrl'] + @queue_arn = AWS[:sqs].get_queue_attributes(@queue_url, 'QueueArn').body['Attributes']['QueueArn'] + AWS[:sqs].set_queue_attributes( + @queue_url, + 'Policy', + MultiJson.encode({ + 'Id' => @topic_arn, + 'Statement' => { + 'Action' => 'sqs:SendMessage', + 'Condition' => { + 'StringEquals' => { 'aws:SourceArn' => @topic_arn } + }, + 'Effect' => 'Allow', + 'Principal' => { 'AWS' => '*' }, + 'Resource' => @queue_arn, + 'Sid' => "#{@topic_arn}+sqs:SendMessage" + }, + 'Version' => '2008-10-17' + }) + ) + end + + tests('success') do + + tests("#subscribe('#{@topic_arn}', '#{@queue_arn}', 'sqs')").formats(AWS::SNS::Formats::BASIC.merge('SubscriptionArn' => String)) do + pending if Fog.mocking? + body = AWS[:sns].subscribe(@topic_arn, @queue_arn, 'sqs').body + @subscription_arn = body['SubscriptionArn'] + body + end + + list_subscriptions_format = AWS::SNS::Formats::BASIC.merge({ + 'Subscriptions' => [{ + 'Endpoint' => String, + 'Owner' => String, + 'Protocol' => String, + 'SubscriptionArn' => String, + 'TopicArn' => String + }] + }) + + tests("#list_subscriptions").formats(list_subscriptions_format) do + pending if Fog.mocking? + AWS[:sns].list_subscriptions.body + end + + tests("#list_subscriptions_by_topic('#{@topic_arn}')").formats(list_subscriptions_format) do + pending if Fog.mocking? + body = AWS[:sns].list_subscriptions_by_topic(@topic_arn).body + end + + tests("#publish('#{@topic_arn}', 'message')").formats(AWS::SNS::Formats::BASIC.merge('MessageId' => String)) do + pending if Fog.mocking? + body = AWS[:sns].publish(@topic_arn, 'message').body + end + + tests("#receive_message('#{@queue_url}')...").returns('message') do + pending if Fog.mocking? + message = nil + Fog.wait_for do + message = AWS[:sqs].receive_message(@queue_url).body['Message'].first + end + MultiJson.decode(message['Body'])['Message'] + end + + tests("#unsubscribe('#{@subscription_arn}')").formats(AWS::SNS::Formats::BASIC) do + pending if Fog.mocking? + AWS[:sns].unsubscribe(@subscription_arn).body + end + + end + + tests('failure') do + + end + + unless Fog.mocking? + AWS[:sns].delete_topic(@topic_arn) + AWS[:sqs].delete_queue(@queue_url) + end + +end diff --git a/tests/aws/requests/sns/topic_tests.rb b/tests/aws/requests/sns/topic_tests.rb new file mode 100644 index 000000000..6727fcf7b --- /dev/null +++ b/tests/aws/requests/sns/topic_tests.rb @@ -0,0 +1,50 @@ +Shindo.tests('AWS::SES | topic lifecycle tests', ['aws', 'sns']) do + + tests('success') do + + tests("#create_topic('fog_topic_tests')").formats(AWS::SNS::Formats::BASIC.merge('TopicArn' => String)) do + pending if Fog.mocking? + body = AWS[:sns].create_topic('fog_topic_tests').body + @topic_arn = body["TopicArn"] + body + end + + tests("#list_topics").formats(AWS::SNS::Formats::BASIC.merge('Topics' => [String])) do + pending if Fog.mocking? + AWS[:sns].list_topics.body + end + + tests("#set_topic_attributes('#{@topic_arn}', 'DisplayName', 'other-fog_topic_tests')").formats(AWS::SNS::Formats::BASIC) do + pending if Fog.mocking? + AWS[:sns].set_topic_attributes(@topic_arn, 'DisplayName', 'other-fog_topic_tests').body + end + + get_topic_attributes_format = AWS::SNS::Formats::BASIC.merge({ + 'Attributes' => { + 'DisplayName' => String, + 'Owner' => String, + 'Policy' => String, + 'SubscriptionsConfirmed' => Integer, + 'SubscriptionsDeleted' => Integer, + 'SubscriptionsPending' => Integer, + 'TopicArn' => String + } + }) + + tests("#get_topic_attributes('#{@topic_arn})").formats(get_topic_attributes_format) do + pending if Fog.mocking? + AWS[:sns].get_topic_attributes(@topic_arn).body + end + + tests("#delete_topic('#{@topic_arn}')").formats(AWS::SNS::Formats::BASIC) do + pending if Fog.mocking? + AWS[:sns].delete_topic(@topic_arn).body + end + + end + + tests('failure') do + + end + +end diff --git a/tests/aws/requests/sqs/helper.rb b/tests/aws/requests/sqs/helper.rb new file mode 100644 index 000000000..1e0d5d1b0 --- /dev/null +++ b/tests/aws/requests/sqs/helper.rb @@ -0,0 +1,15 @@ +class AWS + + module SQS + + module Formats + + BASIC = { + 'ResponseMetadata' => {'RequestId' => String} + } + + end + + end + +end diff --git a/tests/aws/requests/sqs/message_tests.rb b/tests/aws/requests/sqs/message_tests.rb new file mode 100644 index 000000000..63092f81b --- /dev/null +++ b/tests/aws/requests/sqs/message_tests.rb @@ -0,0 +1,57 @@ +Shindo.tests('AWS::SQS | message requests', ['aws']) do + + tests('success') do + + unless Fog.mocking? + @queue_url = AWS[:sqs].create_queue('fog_message_tests').body['QueueUrl'] + end + + send_message_format = AWS::SQS::Formats::BASIC.merge({ + 'MessageId' => String, + 'MD5OfMessageBody' => String + }) + + tests("#send_message('#{@queue_url}', 'message')").formats(send_message_format) do + pending if Fog.mocking? + AWS[:sqs].send_message(@queue_url, 'message').body + end + + receive_message_format = AWS::SQS::Formats::BASIC.merge({ + 'Message' => [{ + 'Attributes' => { + 'ApproximateFirstReceiveTimestamp' => Time, + 'ApproximateReceiveCount' => Integer, + 'SenderId' => String, + 'SentTimestamp' => Time + }, + 'Body' => String, + 'MD5OfBody' => String, + 'MessageId' => String, + 'ReceiptHandle' => String + }] + }) + + tests("#receive_message").formats(receive_message_format) do + pending if Fog.mocking? + data = AWS[:sqs].receive_message(@queue_url).body + @receipt_handle = data['Message'].first['ReceiptHandle'] + data + end + + tests("#change_message_visibility('#{@queue_url}, '#{@receipt_handle}', 60)").formats(AWS::SQS::Formats::BASIC) do + pending if Fog.mocking? + AWS[:sqs].change_message_visibility(@queue_url, @receipt_handle, 60).body + end + + tests("#delete_message('#{@queue_url}', '#{@receipt_handle}')").formats(AWS::SQS::Formats::BASIC) do + pending if Fog.mocking? + AWS[:sqs].delete_message(@queue_url, @receipt_handle).body + end + + unless Fog.mocking? + AWS[:sqs].delete_queue(@queue_url) + end + + end + +end \ No newline at end of file diff --git a/tests/aws/requests/sqs/queue_tests.rb b/tests/aws/requests/sqs/queue_tests.rb new file mode 100644 index 000000000..6ba418e0d --- /dev/null +++ b/tests/aws/requests/sqs/queue_tests.rb @@ -0,0 +1,55 @@ +Shindo.tests('AWS::SQS | queue requests', ['aws']) do + + tests('success') do + + create_queue_format = AWS::SQS::Formats::BASIC.merge({ + 'QueueUrl' => String + }) + + tests("#create_queue('fog_queue_tests')").formats(create_queue_format) do + pending if Fog.mocking? + data = AWS[:sqs].create_queue('fog_queue_tests').body + @queue_url = data['QueueUrl'] + data + end + + list_queues_format = AWS::SQS::Formats::BASIC.merge({ + 'QueueUrls' => [String] + }) + + tests("#list_queues").formats(list_queues_format) do + pending if Fog.mocking? + AWS[:sqs].list_queues.body + end + + tests("#set_queue_attributes('#{@queue_url}', 'VisibilityTimeout', 60)").formats(AWS::SQS::Formats::BASIC) do + pending if Fog.mocking? + AWS[:sqs].set_queue_attributes(@queue_url, 'VisibilityTimeout', 60).body + end + + get_queue_attributes_format = AWS::SQS::Formats::BASIC.merge({ + 'Attributes' => { + 'ApproximateNumberOfMessages' => Integer, + 'ApproximateNumberOfMessagesNotVisible' => Integer, + 'CreatedTimestamp' => Time, + 'MaximumMessageSize' => Integer, + 'LastModifiedTimestamp' => Time, + 'MessageRetentionPeriod' => Integer, + 'QueueArn' => String, + 'VisibilityTimeout' => Integer + } + }) + + tests("#get_queue_attributes('#{@queue_url}', 'All')").formats(get_queue_attributes_format) do + pending if Fog.mocking? + AWS[:sqs].get_queue_attributes(@queue_url, 'All').body + end + + tests("#delete_queue('#{@queue_url}')").formats(AWS::SQS::Formats::BASIC) do + pending if Fog.mocking? + AWS[:sqs].delete_queue(@queue_url).body + end + + end + +end \ No newline at end of file diff --git a/tests/compute/models/vcloud/helper.rb b/tests/compute/models/vcloud/helper.rb index bcd6d122f..eb1aebde2 100644 --- a/tests/compute/models/vcloud/helper.rb +++ b/tests/compute/models/vcloud/helper.rb @@ -1,15 +1,25 @@ class Vcloud module Compute module TestSupport - def self.template - template_name = ENV['VCLOUD_TEMPLATE'] - raise "Specify VApp template name in VCLOUD_TEMPLATE env var" unless template_name - template_res = Vcloud.catalogs.item_by_name template_name - raise "URI Not found for specified template - check template name" unless template_res - template_res.href + + if Fog.mocking? + def self.template + 'mock_template' + end + else + def self.template + template_name = ENV['VCLOUD_TEMPLATE'] + raise "Specify VApp template name in VCLOUD_TEMPLATE env var" unless template_name + template_res = Vcloud.catalogs.item_by_name template_name + raise "URI Not found for specified template - check template name" unless template_res + template_res.href + end end + end + module Formats end + end end diff --git a/tests/compute/requests/aws/address_tests.rb b/tests/compute/requests/aws/address_tests.rb index 6ffc017e6..f180cd01f 100644 --- a/tests/compute/requests/aws/address_tests.rb +++ b/tests/compute/requests/aws/address_tests.rb @@ -10,7 +10,7 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do @server = Fog::Compute[:aws].servers.create @server.wait_for { ready? } - @ip_address = @server.ip_address + @ip_address = @server.public_ip_address tests('success') do diff --git a/tests/compute/requests/vcloud/disk_configure_tests.rb b/tests/compute/requests/vcloud/disk_configure_tests.rb index 6c17251e5..2a1fea2b7 100644 --- a/tests/compute/requests/vcloud/disk_configure_tests.rb +++ b/tests/compute/requests/vcloud/disk_configure_tests.rb @@ -59,18 +59,23 @@ EOF end end - Vcloud[:compute].stub!(:request).and_return(MockDiskResponse.new) + unless Fog.mocking? + Vcloud[:compute].stub!(:request).and_return(MockDiskResponse.new) + end tests("Call to generate config returns string").returns(true) do + pending if Fog.mocking? Vcloud[:compute].generate_configure_vm_disks_request('http://blah', disk_hash).kind_of? String end tests("Call to generate config with no changes returns input data").returns(true) do + pending if Fog.mocking? Nokogiri::XML(Vcloud[:compute].generate_configure_vm_disks_request('http://blah', disk_hash)).to_s == Nokogiri::XML(MockDiskResponse.new.body).to_s end tests("Call to generate config with no disks removes disk").returns(true) do + pending if Fog.mocking? xml = Vcloud[:compute].generate_configure_vm_disks_request('http://blah', []) ng = Nokogiri::XML(xml) # Should have 2 controllers, but no disks. @@ -79,6 +84,7 @@ EOF end tests("Call to generate config adding a disk").returns(['4096', true, true]) do + pending if Fog.mocking? disks = disk_hash disks << { :"rasd:AddressOnParent"=>"1", @@ -101,7 +107,8 @@ EOF ng.xpath("//xmlns:ResourceType[ .='17']", @xmlns).size == 2 ] end - - - Vcloud[:compute].unstub!(:request) + + unless Fog.mocking? + Vcloud[:compute].unstub!(:request) + end end diff --git a/tests/core/attribute_tests.rb b/tests/core/attribute_tests.rb index c3122ec0a..2b26c72a9 100644 --- a/tests/core/attribute_tests.rb +++ b/tests/core/attribute_tests.rb @@ -19,6 +19,15 @@ Shindo.tests('Fog::Attributes', 'core') do @model.key end + tests('"keys" => {"id" => false}').returns(false) do + @model.merge_attributes("keys" => {'id' => false }) + @model.key + end + + tests('"keys" => {:id => false}').returns(false) do + @model.merge_attributes("keys" => {:id => false }) + @model.key + end end tests(':type => :time') do @@ -42,4 +51,4 @@ Shindo.tests('Fog::Attributes', 'core') do end -end \ No newline at end of file +end diff --git a/tests/helpers/collection_helper.rb b/tests/helpers/collection_helper.rb index d5fa720c6..9e3dfe47a 100644 --- a/tests/helpers/collection_helper.rb +++ b/tests/helpers/collection_helper.rb @@ -38,7 +38,12 @@ def collection_tests(collection, params = {}, mocks_implemented = true) tests('failure') do if !Fog.mocking? || mocks_implemented - @identity = @identity.to_s.gsub(/\w/, Fog::Mock.random_letters(1)) + @identity = case @identity + when Integer + @identity.to_s.gsub(/\w/, Fog::Mock.random_numbers(1)).to_i + else + @identity.to_s.gsub(/\w/, Fog::Mock.random_letters(1)) + end end tests("#get('#{@identity}')").returns(nil) do diff --git a/tests/helpers/formats_helper.rb b/tests/helpers/formats_helper.rb index 6fed3f6d8..294413edc 100644 --- a/tests/helpers/formats_helper.rb +++ b/tests/helpers/formats_helper.rb @@ -57,7 +57,7 @@ module Shindo valid &&= datum.is_a?(Hash) || p("not Hash: #{datum.inspect}") valid &&= formats_kernel(datum, value, false) else - p "#{key} not #{value}: #{datum.inspect}" unless datum.is_a?(value) + p "#{key.inspect} not #{value.inspect}: #{datum.inspect}" unless datum.is_a?(value) valid &&= datum.is_a?(value) end end diff --git a/tests/helpers/mock_helper.rb b/tests/helpers/mock_helper.rb index 60352e1f0..82c34b0cf 100644 --- a/tests/helpers/mock_helper.rb +++ b/tests/helpers/mock_helper.rb @@ -32,6 +32,8 @@ if Fog.mock? :new_servers_username => 'new_servers_username', :ninefold_compute_key => 'ninefold_compute_key', :ninefold_compute_secret => 'ninefold_compute_secret', + :ninefold_storage_secret => 'ninefold_storage_secret', + :ninefold_storage_token => 'ninefold_storage_token', # :public_key_path => '~/.ssh/id_rsa.pub', # :private_key_path => '~/.ssh/id_rsa', :rackspace_api_key => 'rackspace_api_key', @@ -39,6 +41,9 @@ if Fog.mock? :slicehost_password => 'slicehost_password', :storm_on_demand_username => 'storm_on_demand_username', :storm_on_demand_password => 'storm_on_demand_password', + :vcloud_host => 'vcloud_host', + :vcloud_password => 'vcloud_password', + :vcloud_username => 'vcloud_username', :voxel_api_key => 'voxel_api_key', :voxel_api_secret => 'voxel_api_secret', :zerigo_email => 'zerigo_email', diff --git a/tests/storage/models/ninefold/file_update_tests.rb b/tests/storage/models/ninefold/file_update_tests.rb index 49e4779d1..b4654b0ec 100644 --- a/tests/storage/models/ninefold/file_update_tests.rb +++ b/tests/storage/models/ninefold/file_update_tests.rb @@ -4,6 +4,7 @@ if storage_providers.keys.include? :ninefold Shindo.tests("Storage[:ninefold] | nested directories", [provider]) do ninefold = Fog::Storage[:ninefold] tests("update a file").succeeds do + pending if Fog.mocking? dir = ninefold.directories.create(:key => 'updatefiletests') f = dir.files.create(:key => 'lorem.txt', :body => lorem_file) f.body = "xxxxxx" diff --git a/tests/storage/models/ninefold/nested_directories_tests.rb b/tests/storage/models/ninefold/nested_directories_tests.rb index 47967261b..112f94ee0 100644 --- a/tests/storage/models/ninefold/nested_directories_tests.rb +++ b/tests/storage/models/ninefold/nested_directories_tests.rb @@ -4,18 +4,22 @@ if storage_providers.keys.include? :ninefold Shindo.tests("Storage[:ninefold] | nested directories", [provider]) do ninefold = Fog::Storage[:ninefold] tests("create a directory with a / character").succeeds do + pending if Fog.mocking? ninefold.directories.create(:key => 'sub/path') end tests("List of top directory returns sub dir").returns(1) do + pending if Fog.mocking? ninefold.directories.get('sub').directories.count end tests("create a directory in a sub dir").returns('sub/path/newdir/') do + pending if Fog.mocking? ninefold.directories.get('sub/path').directories.create(:key => 'newdir').identity end tests("Recursively destroy parent dir").succeeds do + pending if Fog.mocking? ninefold.directories.get('sub').destroy(:recursive => true) end diff --git a/tests/storage/requests/rackspace/large_object_tests.rb b/tests/storage/requests/rackspace/large_object_tests.rb index de6a85520..37e10cdfc 100644 --- a/tests/storage/requests/rackspace/large_object_tests.rb +++ b/tests/storage/requests/rackspace/large_object_tests.rb @@ -1,30 +1,32 @@ Shindo.tests('Fog::Storage[:rackspace] | large object requests', [:rackspace]) do - @directory = Fog::Storage[:rackspace].directories.create(:key => 'foglargeobjecttests') + unless Fog.mocking? + @directory = Fog::Storage[:rackspace].directories.create(:key => 'foglargeobjecttests') + end tests('success') do - tests("#put_object('#{@directory.identity}', 'fog_large_object/1', ('x' * 6 * 1024 * 1024))").succeeds do + tests("#put_object('foglargeobjecttests', 'fog_large_object/1', ('x' * 6 * 1024 * 1024))").succeeds do pending if Fog.mocking? Fog::Storage[:rackspace].put_object(@directory.identity, 'fog_large_object/1', ('x' * 6 * 1024 * 1024)) end - tests("#put_object('#{@directory.identity}', 'fog_large_object/2', ('x' * 4 * 1024 * 1024))").succeeds do + tests("#put_object('foglargeobjecttests', 'fog_large_object/2', ('x' * 4 * 1024 * 1024))").succeeds do pending if Fog.mocking? Fog::Storage[:rackspace].put_object(@directory.identity, 'fog_large_object/2', ('x' * 4 * 1024 * 1024)) end - tests("#put_object_manifest('#{@directory.identity}', 'fog_large_object')").succeeds do + tests("#put_object_manifest('foglargeobjecttests', 'fog_large_object')").succeeds do pending if Fog.mocking? Fog::Storage[:rackspace].put_object_manifest(@directory.identity, 'fog_large_object') end - tests("#get_object('#{@directory.identity}', 'fog_large_object').body").succeeds do + tests("#get_object('foglargeobjecttests', 'fog_large_object').body").succeeds do pending if Fog.mocking? Fog::Storage[:rackspace].get_object(@directory.identity, 'fog_large_object').body == ('x' * 10 * 1024 * 1024) end - if !Fog.mocking? + unless Fog.mocking? ['fog_large_object', 'fog_large_object/1', 'fog_large_object/2'].each do |key| @directory.files.new(:key => key).destroy end @@ -38,6 +40,8 @@ Shindo.tests('Fog::Storage[:rackspace] | large object requests', [:rackspace]) d end - @directory.destroy + unless Fog.mocking? + @directory.destroy + end end