From f40538fc69c667ae5912e10fdb869f42b4865045 Mon Sep 17 00:00:00 2001 From: Edward Middleton Date: Sat, 2 Jul 2011 13:30:32 +0900 Subject: [PATCH 01/37] add spot instance request models --- lib/fog/compute/aws.rb | 2 + lib/fog/compute/models/aws/spot_request.rb | 83 ++++++++++++ lib/fog/compute/models/aws/spot_requests.rb | 47 +++++++ .../requests/aws/request_spot_instance.rb | 122 ++++++++++++++++++ 4 files changed, 254 insertions(+) create mode 100644 lib/fog/compute/models/aws/spot_request.rb create mode 100644 lib/fog/compute/models/aws/spot_requests.rb create mode 100644 lib/fog/compute/requests/aws/request_spot_instance.rb diff --git a/lib/fog/compute/aws.rb b/lib/fog/compute/aws.rb index 67b66dd51..24b70bfe9 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/models/aws/spot_request.rb b/lib/fog/compute/models/aws/spot_request.rb new file mode 100644 index 000000000..67293c3ec --- /dev/null +++ b/lib/fog/compute/models/aws/spot_request.rb @@ -0,0 +1,83 @@ +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 :state + + # TODO: not sure how to handle + #attribute :fault + 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 => 'launchedAvailabilityZone' + attribute :flavor_id, :aliases => 'LaunchSpecification.InstanceType' + attribute :image_id, :aliases => 'LaunchSpecification.ImageId' + attribute :monitoring, :aliases => 'LaunchSpecification.Monitoring' + + 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 + self.instance_count ||= 1 + super + end + +# def destroy +# requires :name + +# connection.delete_spot_request(name) +# true +# end + + def save + requires :image_id, :flavor_id, :price + + options = { + 'InstanceCount' => instance_count, + 'LaunchSpecification.KeyName' => key_name, + 'LaunchSpecification.Placement.AvailabilityZone' => availability_zone, + 'LaunchSpecification.SecurityGroup' => groups, + 'Type' => request_type } + + connection.request_spot_instances(image_id, flavor_id, price, options) + 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..6db8b0574 --- /dev/null +++ b/lib/fog/compute/models/aws/spot_requests.rb @@ -0,0 +1,47 @@ +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'].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/requests/aws/request_spot_instance.rb b/lib/fog/compute/requests/aws/request_spot_instance.rb new file mode 100644 index 000000000..0a868ca35 --- /dev/null +++ b/lib/fog/compute/requests/aws/request_spot_instance.rb @@ -0,0 +1,122 @@ +module Fog + module AWS + class Compute + class Real + + require 'fog/compute/parsers/aws/request_spot_instance' + + # Creates a Spot Instance request + # + # ==== Parameters + # * image_id<~String> - Id of machine image to load on instances + # * max_price<~String> - The maximum hourly price + # * max_count<~Integer> -The maximium number of instances to launch + # * options<~Hash>: + # * Type<~String> - request type ['one-time'|'persistent'] + # * ValidFrom<> + # * ValidUntil<> + # * LaunchGroup<> + # * AvailabilityZoneGroup<> + # * LaunchSpecification<~Hash> + # * 'Placement.AvailabilityZone'<~String> - Placement constraint for instances + # * 'BlockDeviceMapping'<~Array>: array of hashes + # * 'DeviceName'<~String> - where the volume will be exposed to instance + # * 'VirtualName'<~String> - volume virtual device name + # * 'Ebs.SnapshotId'<~String> - id of snapshot to boot volume from + # * 'Ebs.VolumeSize'<~String> - size of volume in GiBs required unless snapshot is specified + # * 'Ebs.NoDevice'<~String> - specifies that no device should be mappped + # * 'Ebs.DeleteOnTermination'<~String> - specifies whether or not to delete the volume on instance termination + # * 'ClientToken'<~String> - unique case-sensitive token for ensuring idempotency + # * 'SecurityGroup'<~Array> or <~String> - Name of security group(s) for instances (you must omit this parameter if using Virtual Private Clouds) + # * 'InstanceInitiatedShutdownBehaviour'<~String> - specifies whether volumes are stopped or terminated when instance is shutdown, in [stop, terminate] + # * 'InstanceType'<~String> - Type of instance to boot. Valid options + # in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge', 'm2.xlarge', 'm2.2xlarge', 'm2.4xlarge', 't1.micro'] + # default is 'm1.small' + # * 'KernelId'<~String> - Id of kernel with which to launch + # * 'KeyName'<~String> - Name of a keypair to add to booting instances + # * 'Monitoring.Enabled'<~Boolean> - Enables monitoring, defaults to + # disabled + # * 'RamdiskId'<~String> - Id of ramdisk with which to launch + # * 'UserData'<~String> - Additional data to provide to booting instances + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'requestId'<~String> - Id of request + # * 'spotInstanceRequestSet'<~Array>: array of hashes + # * 'item'<~Hash>: + # * 'spotInstanceRequestId'<~String> - + # * 'spotPrice + # * 'amiLaunchIndex'<~Integer> - reference to instance in launch group + # * 'architecture'<~String> - architecture of image in [i386, x86_64] + # * 'blockDeviceMapping'<~Array> + # * 'attachTime'<~Time> - time of volume attachment + # * 'deleteOnTermination'<~Boolean> - whether or not to delete volume on termination + # * 'deviceName'<~String> - specifies how volume is exposed to instance + # * 'status'<~String> - status of attached volume + # * 'volumeId'<~String> - Id of attached volume + # * 'dnsName'<~String> - public dns name, blank until instance is running + # * 'imageId'<~String> - image id of ami used to launch instance + # * 'instanceId'<~String> - id of the instance + # * 'instanceState'<~Hash>: + # * 'code'<~Integer> - current status code + # * 'name'<~String> - current status name + # * 'instanceType'<~String> - type of instance + # * 'ipAddress'<~String> - public ip address assigned to instance + # * 'kernelId'<~String> - Id of kernel used to launch instance + # * 'keyName'<~String> - name of key used launch instances or blank + # * 'launchTime'<~Time> - time instance was launched + # * 'monitoring'<~Hash>: + # * 'state'<~Boolean - state of monitoring + # * 'placement'<~Hash>: + # * 'availabilityZone'<~String> - Availability zone of the instance + # * 'privateDnsName'<~String> - private dns name, blank until instance is running + # * 'privateIpAddress'<~String> - private ip address assigned to instance + # * 'productCodes'<~Array> - Product codes for the instance + # * 'ramdiskId'<~String> - Id of ramdisk used to launch instance + # * 'reason'<~String> - reason for most recent state transition, or blank + # * 'rootDeviceName'<~String> - specifies how the root device is exposed to the instance + # * 'rootDeviceType'<~String> - root device type used by AMI in [ebs, instance-store] + + def request_spot_instance(image_id, max_price, max_count, options = {}) + launch_specification = options.delete('LaunchSpecification') + if block_device_mapping = launch_specification.delete('BlockDeviceMapping') + block_device_mapping.each_with_index do |mapping, index| + for key, value in mapping + launch_specification.merge!({ format("BlockDeviceMapping.%d.#{key}", index) => value }) + end + end + end + if security_groups = launch_specification.delete('SecurityGroup') + launch_specification.merge!(AWS.indexed_param('SecurityGroup', [*security_groups])) + end + if launch_specification['UserData'] + launch_specification['UserData'] = Base64.encode64(launch_specification['UserData']) + end + idempotent = !(launch_specification['ClientToken'].nil? || launch_specification['ClientToken'].empty?) + request({ + 'Action' => 'RequestSpotInstances', + 'SpotPrice' => max_price, + 'InstanceCount' => max_count, + 'MinCount' => min_count, + 'LaunchSpecification.ImageId' => image_id, + :idempotent => idempotent, + :parser => Fog::Parsers::AWS::Compute::RunInstances.new + }.merge!('LaunchSpecification' => launch_specification)) + + end + + end + + class Mock + + def request_spot_instance(image_id, max_price, max_count, options = {}) + response = Excon::Response.new + response.status = 200 + + group_set = [ (options[' + end + end + end + end +end From 866409c2dac43f7c1c9fe444023f391622f41865 Mon Sep 17 00:00:00 2001 From: Edward Middleton Date: Sat, 2 Jul 2011 15:22:08 +0900 Subject: [PATCH 02/37] fixed spot_requests --- .../requests/aws/request_spot_instance.rb | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 lib/fog/compute/requests/aws/request_spot_instance.rb diff --git a/lib/fog/compute/requests/aws/request_spot_instance.rb b/lib/fog/compute/requests/aws/request_spot_instance.rb deleted file mode 100644 index 0a868ca35..000000000 --- a/lib/fog/compute/requests/aws/request_spot_instance.rb +++ /dev/null @@ -1,122 +0,0 @@ -module Fog - module AWS - class Compute - class Real - - require 'fog/compute/parsers/aws/request_spot_instance' - - # Creates a Spot Instance request - # - # ==== Parameters - # * image_id<~String> - Id of machine image to load on instances - # * max_price<~String> - The maximum hourly price - # * max_count<~Integer> -The maximium number of instances to launch - # * options<~Hash>: - # * Type<~String> - request type ['one-time'|'persistent'] - # * ValidFrom<> - # * ValidUntil<> - # * LaunchGroup<> - # * AvailabilityZoneGroup<> - # * LaunchSpecification<~Hash> - # * 'Placement.AvailabilityZone'<~String> - Placement constraint for instances - # * 'BlockDeviceMapping'<~Array>: array of hashes - # * 'DeviceName'<~String> - where the volume will be exposed to instance - # * 'VirtualName'<~String> - volume virtual device name - # * 'Ebs.SnapshotId'<~String> - id of snapshot to boot volume from - # * 'Ebs.VolumeSize'<~String> - size of volume in GiBs required unless snapshot is specified - # * 'Ebs.NoDevice'<~String> - specifies that no device should be mappped - # * 'Ebs.DeleteOnTermination'<~String> - specifies whether or not to delete the volume on instance termination - # * 'ClientToken'<~String> - unique case-sensitive token for ensuring idempotency - # * 'SecurityGroup'<~Array> or <~String> - Name of security group(s) for instances (you must omit this parameter if using Virtual Private Clouds) - # * 'InstanceInitiatedShutdownBehaviour'<~String> - specifies whether volumes are stopped or terminated when instance is shutdown, in [stop, terminate] - # * 'InstanceType'<~String> - Type of instance to boot. Valid options - # in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge', 'm2.xlarge', 'm2.2xlarge', 'm2.4xlarge', 't1.micro'] - # default is 'm1.small' - # * 'KernelId'<~String> - Id of kernel with which to launch - # * 'KeyName'<~String> - Name of a keypair to add to booting instances - # * 'Monitoring.Enabled'<~Boolean> - Enables monitoring, defaults to - # disabled - # * 'RamdiskId'<~String> - Id of ramdisk with which to launch - # * 'UserData'<~String> - Additional data to provide to booting instances - # - # ==== Returns - # * response<~Excon::Response>: - # * body<~Hash>: - # * 'requestId'<~String> - Id of request - # * 'spotInstanceRequestSet'<~Array>: array of hashes - # * 'item'<~Hash>: - # * 'spotInstanceRequestId'<~String> - - # * 'spotPrice - # * 'amiLaunchIndex'<~Integer> - reference to instance in launch group - # * 'architecture'<~String> - architecture of image in [i386, x86_64] - # * 'blockDeviceMapping'<~Array> - # * 'attachTime'<~Time> - time of volume attachment - # * 'deleteOnTermination'<~Boolean> - whether or not to delete volume on termination - # * 'deviceName'<~String> - specifies how volume is exposed to instance - # * 'status'<~String> - status of attached volume - # * 'volumeId'<~String> - Id of attached volume - # * 'dnsName'<~String> - public dns name, blank until instance is running - # * 'imageId'<~String> - image id of ami used to launch instance - # * 'instanceId'<~String> - id of the instance - # * 'instanceState'<~Hash>: - # * 'code'<~Integer> - current status code - # * 'name'<~String> - current status name - # * 'instanceType'<~String> - type of instance - # * 'ipAddress'<~String> - public ip address assigned to instance - # * 'kernelId'<~String> - Id of kernel used to launch instance - # * 'keyName'<~String> - name of key used launch instances or blank - # * 'launchTime'<~Time> - time instance was launched - # * 'monitoring'<~Hash>: - # * 'state'<~Boolean - state of monitoring - # * 'placement'<~Hash>: - # * 'availabilityZone'<~String> - Availability zone of the instance - # * 'privateDnsName'<~String> - private dns name, blank until instance is running - # * 'privateIpAddress'<~String> - private ip address assigned to instance - # * 'productCodes'<~Array> - Product codes for the instance - # * 'ramdiskId'<~String> - Id of ramdisk used to launch instance - # * 'reason'<~String> - reason for most recent state transition, or blank - # * 'rootDeviceName'<~String> - specifies how the root device is exposed to the instance - # * 'rootDeviceType'<~String> - root device type used by AMI in [ebs, instance-store] - - def request_spot_instance(image_id, max_price, max_count, options = {}) - launch_specification = options.delete('LaunchSpecification') - if block_device_mapping = launch_specification.delete('BlockDeviceMapping') - block_device_mapping.each_with_index do |mapping, index| - for key, value in mapping - launch_specification.merge!({ format("BlockDeviceMapping.%d.#{key}", index) => value }) - end - end - end - if security_groups = launch_specification.delete('SecurityGroup') - launch_specification.merge!(AWS.indexed_param('SecurityGroup', [*security_groups])) - end - if launch_specification['UserData'] - launch_specification['UserData'] = Base64.encode64(launch_specification['UserData']) - end - idempotent = !(launch_specification['ClientToken'].nil? || launch_specification['ClientToken'].empty?) - request({ - 'Action' => 'RequestSpotInstances', - 'SpotPrice' => max_price, - 'InstanceCount' => max_count, - 'MinCount' => min_count, - 'LaunchSpecification.ImageId' => image_id, - :idempotent => idempotent, - :parser => Fog::Parsers::AWS::Compute::RunInstances.new - }.merge!('LaunchSpecification' => launch_specification)) - - end - - end - - class Mock - - def request_spot_instance(image_id, max_price, max_count, options = {}) - response = Excon::Response.new - response.status = 200 - - group_set = [ (options[' - end - end - end - end -end From 97fc035c01a71267a6515eccba70648c6006f418 Mon Sep 17 00:00:00 2001 From: Edward Middleton Date: Sat, 2 Jul 2011 16:54:37 +0900 Subject: [PATCH 03/37] spot instance fixes --- lib/fog/compute/models/aws/spot_request.rb | 36 +++++++++++++-------- lib/fog/compute/models/aws/spot_requests.rb | 1 + 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/fog/compute/models/aws/spot_request.rb b/lib/fog/compute/models/aws/spot_request.rb index 67293c3ec..b622175fb 100644 --- a/lib/fog/compute/models/aws/spot_request.rb +++ b/lib/fog/compute/models/aws/spot_request.rb @@ -12,10 +12,9 @@ module Fog attribute :request_type, :aliases => 'type' attribute :created_at, :aliases => 'createTime' attribute :instance_count, :aliases => 'instanceCount' + attribute :instance_id, :aliases => 'instanceId' attribute :state - # TODO: not sure how to handle - #attribute :fault attribute :valid_from, :aliases => 'validFrom' attribute :valid_until, :aliases => 'validUntil' attribute :launch_group, :aliases => 'launchGroup' @@ -24,10 +23,14 @@ module Fog attribute :groups, :aliases => 'LaunchSpecification.SecurityGroup' attribute :key_name, :aliases => 'LaunchSpecification.KeyName' - attribute :availability_zone, :aliases => 'launchedAvailabilityZone' + 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 @@ -49,28 +52,35 @@ module Fog 'ami-f5bfefb0' end end - self.instance_count ||= 1 super end -# def destroy -# requires :name - -# connection.delete_spot_request(name) -# true -# 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, - 'Type' => request_type } + 'LaunchSpecification.UserData' => user_data, + 'Type' => request_type, + 'ValidFrom' => valid_from, + 'ValidUntil' => valid_until } + options.delete_if {|key, value| value.nil?} - connection.request_spot_instances(image_id, flavor_id, price, options) + 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? diff --git a/lib/fog/compute/models/aws/spot_requests.rb b/lib/fog/compute/models/aws/spot_requests.rb index 6db8b0574..9db6f4727 100644 --- a/lib/fog/compute/models/aws/spot_requests.rb +++ b/lib/fog/compute/models/aws/spot_requests.rb @@ -24,6 +24,7 @@ module Fog 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 From 773ba300d0446e42f4e46375f6964735d8269007 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Mon, 18 Jul 2011 17:04:40 -0700 Subject: [PATCH 04/37] [aws|iam] add get_server_certificate request --- lib/fog/aws/iam.rb | 3 +- .../requests/iam/get_server_certificate.rb | 50 +++++++++++++++++++ .../requests/iam/server_certificate_tests.rb | 7 +++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 lib/fog/aws/requests/iam/get_server_certificate.rb 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/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/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 From 348230ce3205b0f469eb7b2a4c594e5d184ea6d7 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Mon, 18 Jul 2011 17:53:32 -0700 Subject: [PATCH 05/37] [aws|elb] Raise proper IAM error for CertificateNotFound when creating an ELB or creating Listeners. --- .../aws/requests/elb/create_load_balancer.rb | 14 ++++++--- .../elb/create_load_balancer_listeners.rb | 13 ++++++-- tests/aws/models/elb/model_tests.rb | 27 ++++++++++++++--- tests/aws/requests/elb/listener_tests.rb | 30 ++++++++++++------- 4 files changed, 63 insertions(+), 21 deletions(-) diff --git a/lib/fog/aws/requests/elb/create_load_balancer.rb b/lib/fog/aws/requests/elb/create_load_balancer.rb index a46f04c5e..07f70a1a5 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer.rb @@ -46,8 +46,16 @@ module Fog 'LoadBalancerName' => lb_name, :parser => Fog::Parsers::AWS::ELB::CreateLoadBalancer.new }.merge!(params)) + 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]) + else + raise + end + end end - end class Mock @@ -61,9 +69,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..83bfad0ac 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb @@ -43,6 +43,15 @@ module Fog 'LoadBalancerName' => lb_name, :parser => Fog::Parsers::AWS::ELB::Empty.new }.merge!(params)) + 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]) + else + raise + end + end end end @@ -56,9 +65,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/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/elb/listener_tests.rb b/tests/aws/requests/elb/listener_tests.rb index a0615dd93..9c4d0c9fb 100644 --- a/tests/aws/requests/elb/listener_tests.rb +++ b/tests/aws/requests/elb/listener_tests.rb @@ -8,10 +8,12 @@ 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 + puts response.inspect + response end tests("#delete_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do @@ -19,22 +21,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 From dc094bd7819f74105a8e83e416af524c809e0b2a Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Tue, 19 Jul 2011 10:12:49 -0700 Subject: [PATCH 06/37] [aws|elb] move ELB error handling related to certs to the ELB service instead of duplicating at the request level. --- lib/fog/aws/elb.rb | 47 +++++++++---------- .../aws/requests/elb/create_load_balancer.rb | 9 ---- .../elb/create_load_balancer_listeners.rb | 9 ---- 3 files changed, 23 insertions(+), 42 deletions(-) diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index 70837fbad..c5d02d01d 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 + when 'DuplicateLoadBalancerName' + raise Fog::AWS::ELB::IdentifierTaken + when 'InvalidInstance' + raise Fog::AWS::ELB::InvalidInstance else raise end + else + raise end - - response 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 07f70a1a5..da9a2939f 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer.rb @@ -46,15 +46,6 @@ module Fog 'LoadBalancerName' => lb_name, :parser => Fog::Parsers::AWS::ELB::CreateLoadBalancer.new }.merge!(params)) - 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]) - else - raise - end - end end 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 83bfad0ac..51f3219a0 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb @@ -43,15 +43,6 @@ module Fog 'LoadBalancerName' => lb_name, :parser => Fog::Parsers::AWS::ELB::Empty.new }.merge!(params)) - 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]) - else - raise - end - end end end From 0435c0ba70169036affa78f438baf2d87538bfd1 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Tue, 19 Jul 2011 10:14:04 -0700 Subject: [PATCH 07/37] [aws|elb] use slurp when raising errors to properly capture exception details --- lib/fog/aws/elb.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index c5d02d01d..10a28abda 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -160,11 +160,11 @@ module Fog when 'CertificateNotFound' raise Fog::AWS::IAM::NotFound.slurp(error, match[2]) when 'LoadBalancerNotFound' - raise Fog::AWS::ELB::NotFound + raise Fog::AWS::ELB::NotFound.slurp(error, match[2]) when 'DuplicateLoadBalancerName' - raise Fog::AWS::ELB::IdentifierTaken + raise Fog::AWS::ELB::IdentifierTaken.slurp(error, match[2]) when 'InvalidInstance' - raise Fog::AWS::ELB::InvalidInstance + raise Fog::AWS::ELB::InvalidInstance.slurp(error, match[2]) else raise end From 750e0e805046a4f84d9a61b8abd77813d22ff4fd Mon Sep 17 00:00:00 2001 From: Jon Crosby Date: Sat, 5 Feb 2011 14:06:44 -0800 Subject: [PATCH 08/37] Begin SQS support * Add SQS object * Add create_queue * Add list_queues * Add delete_queue --- lib/fog/aws/parsers/sqs/create_queue.rb | 26 ++++++ lib/fog/aws/parsers/sqs/delete_queue.rb | 23 +++++ lib/fog/aws/parsers/sqs/list_queues.rb | 25 ++++++ lib/fog/aws/requests/sqs/create_queue.rb | 28 ++++++ lib/fog/aws/requests/sqs/delete_queue.rb | 40 +++++++++ lib/fog/aws/requests/sqs/list_queues.rb | 26 ++++++ lib/fog/aws/sqs.rb | 105 +++++++++++++++++++++++ lib/fog/providers/aws.rb | 1 + 8 files changed, 274 insertions(+) create mode 100644 lib/fog/aws/parsers/sqs/create_queue.rb create mode 100644 lib/fog/aws/parsers/sqs/delete_queue.rb create mode 100644 lib/fog/aws/parsers/sqs/list_queues.rb create mode 100644 lib/fog/aws/requests/sqs/create_queue.rb create mode 100644 lib/fog/aws/requests/sqs/delete_queue.rb create mode 100644 lib/fog/aws/requests/sqs/list_queues.rb create mode 100644 lib/fog/aws/sqs.rb 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/delete_queue.rb b/lib/fog/aws/parsers/sqs/delete_queue.rb new file mode 100644 index 000000000..0eb113c8f --- /dev/null +++ b/lib/fog/aws/parsers/sqs/delete_queue.rb @@ -0,0 +1,23 @@ +module Fog + module Parsers + module AWS + module SQS + class DeleteQueue < 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/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/requests/sqs/create_queue.rb b/lib/fog/aws/requests/sqs/create_queue.rb new file mode 100644 index 000000000..bb151ae62 --- /dev/null +++ b/lib/fog/aws/requests/sqs/create_queue.rb @@ -0,0 +1,28 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/create_queue' + + def create_queue(name) + request({ + 'Action' => 'CreateQueue', + 'QueueName' => name, + :parser => Fog::Parsers::AWS::SQS::CreateQueue.new + }) + end + + end + + class Mock + + def create_queue(name) + Fog::Mock.not_implemented + 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..3271e0ef0 --- /dev/null +++ b/lib/fog/aws/requests/sqs/delete_queue.rb @@ -0,0 +1,40 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/list_queues' + require 'fog/aws/parsers/sqs/delete_queue' + + def delete_queue(name) + url = extract_url_with_name_from_list(name) + path = extract_path_from_url(url) + + request({ + 'Action' => 'DeleteQueue', + :parser => Fog::Parsers::AWS::SQS::DeleteQueue.new, + :path => path + }) + end + + protected + + def extract_url_with_name_from_list(name) + list_queues.body['QueueUrls'].detect { |url| url.match(/\/#{name}$/) } + end + + def extract_path_from_url(url) + url.gsub(/.*\.com/, '') + end + end + + class Mock + + def delete_queue(name) + Fog::Mock.not_implemented + 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..59536164a --- /dev/null +++ b/lib/fog/aws/requests/sqs/list_queues.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/list_queues' + + def list_queues + request({ + 'Action' => 'ListQueues', + :parser => Fog::Parsers::AWS::SQS::ListQueues.new + }) + end + end + + class Mock + + def list_queues + Fog::Mock.not_implemented + 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..4ca4bb45d --- /dev/null +++ b/lib/fog/aws/sqs.rb @@ -0,0 +1,105 @@ +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 :create_queue + request :list_queues + request :delete_queue + + 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 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/providers/aws.rb b/lib/fog/providers/aws.rb index fa804e483..61ed67899 100644 --- a/lib/fog/providers/aws.rb +++ b/lib/fog/providers/aws.rb @@ -19,6 +19,7 @@ module Fog service(:rds, 'aws/rds') service(:ses, 'aws/ses') service(:simpledb, 'aws/simpledb') + service(:sqs, 'aws/sqs') service(:storage, 'storage/aws') def self.indexed_param(key, values) From 9462528dc99ef38aba7969be3f0ada1d5cb88f00 Mon Sep 17 00:00:00 2001 From: Jon Crosby Date: Sat, 5 Feb 2011 20:17:47 -0800 Subject: [PATCH 09/37] Continued SQS support * Add send_message * Add receive_message * Add delete_message --- lib/fog/aws/parsers/sqs/delete_message.rb | 23 +++++++++++++ lib/fog/aws/parsers/sqs/receive_message.rb | 36 +++++++++++++++++++++ lib/fog/aws/parsers/sqs/send_message.rb | 28 ++++++++++++++++ lib/fog/aws/requests/sqs/delete_message.rb | 28 ++++++++++++++++ lib/fog/aws/requests/sqs/delete_queue.rb | 15 +-------- lib/fog/aws/requests/sqs/receive_message.rb | 29 +++++++++++++++++ lib/fog/aws/requests/sqs/send_message.rb | 29 +++++++++++++++++ lib/fog/aws/sqs.rb | 18 ++++++++++- 8 files changed, 191 insertions(+), 15 deletions(-) create mode 100644 lib/fog/aws/parsers/sqs/delete_message.rb create mode 100644 lib/fog/aws/parsers/sqs/receive_message.rb create mode 100644 lib/fog/aws/parsers/sqs/send_message.rb create mode 100644 lib/fog/aws/requests/sqs/delete_message.rb create mode 100644 lib/fog/aws/requests/sqs/receive_message.rb create mode 100644 lib/fog/aws/requests/sqs/send_message.rb diff --git a/lib/fog/aws/parsers/sqs/delete_message.rb b/lib/fog/aws/parsers/sqs/delete_message.rb new file mode 100644 index 000000000..121a8cd0c --- /dev/null +++ b/lib/fog/aws/parsers/sqs/delete_message.rb @@ -0,0 +1,23 @@ +module Fog + module Parsers + module AWS + module SQS + class DeleteMessage < 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/receive_message.rb b/lib/fog/aws/parsers/sqs/receive_message.rb new file mode 100644 index 000000000..564604e87 --- /dev/null +++ b/lib/fog/aws/parsers/sqs/receive_message.rb @@ -0,0 +1,36 @@ +module Fog + module Parsers + module AWS + module SQS + + class ReceiveMessage < Fog::Parsers::Base + + def reset + @response = { 'ResponseMetadata' => {}, 'Message' => {'Attributes' => {}}} + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata']['RequestId'] = @value + when 'MessageId' + @response['Message']['MessageId'] = @value + when 'ReceiptHandle' + @response['Message']['ReceiptHandle'] = @value + when 'MD5OfBody' + @response['Message']['MD5OfBody'] = @value + when 'Body' + @response['Message']['Body'] = @value + when 'Name' + @current_attribute_name = @value + when 'Value' + @response['Message']['Attributes'][@current_attribute_name] = @value + 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/sqs/delete_message.rb b/lib/fog/aws/requests/sqs/delete_message.rb new file mode 100644 index 000000000..d9500d952 --- /dev/null +++ b/lib/fog/aws/requests/sqs/delete_message.rb @@ -0,0 +1,28 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/delete_message' + + def delete_message(queue_name, receipt_handle) + request({ + 'Action' => 'DeleteMessage', + 'ReceiptHandle' => receipt_handle, + :parser => Fog::Parsers::AWS::SQS::DeleteMessage.new, + :path => path_from_queue_name(queue_name) + }) + end + + end + + class Mock + + def delete_message(queue_name, receipt_handle) + Fog::Mock.not_implemented + 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 index 3271e0ef0..4074d37c4 100644 --- a/lib/fog/aws/requests/sqs/delete_queue.rb +++ b/lib/fog/aws/requests/sqs/delete_queue.rb @@ -3,29 +3,16 @@ module Fog class SQS class Real - require 'fog/aws/parsers/sqs/list_queues' require 'fog/aws/parsers/sqs/delete_queue' def delete_queue(name) - url = extract_url_with_name_from_list(name) - path = extract_path_from_url(url) - request({ 'Action' => 'DeleteQueue', :parser => Fog::Parsers::AWS::SQS::DeleteQueue.new, - :path => path + :path => path_from_queue_name(name) }) end - protected - - def extract_url_with_name_from_list(name) - list_queues.body['QueueUrls'].detect { |url| url.match(/\/#{name}$/) } - end - - def extract_path_from_url(url) - url.gsub(/.*\.com/, '') - end end class Mock 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..483415d8c --- /dev/null +++ b/lib/fog/aws/requests/sqs/receive_message.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/receive_message' + + def receive_message(queue_name) + request({ + 'Action' => 'ReceiveMessage', + 'AttributeName' => 'All', + :path => path_from_queue_name(queue_name), + :parser => Fog::Parsers::AWS::SQS::ReceiveMessage.new + }) + end + + end + + class Mock + + def receive_message(queue_name) + Fog::Mock.not_implemented + 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..003673173 --- /dev/null +++ b/lib/fog/aws/requests/sqs/send_message.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/send_message' + + def send_message(queue_name, message) + request({ + 'Action' => 'SendMessage', + 'MessageBody' => message, + :path => path_from_queue_name(queue_name), + :parser => Fog::Parsers::AWS::SQS::SendMessage.new + }) + end + + end + + class Mock + + def send_message(queue_name, message) + Fog::Mock.not_implemented + end + + end + + end + end +end diff --git a/lib/fog/aws/sqs.rb b/lib/fog/aws/sqs.rb index 4ca4bb45d..4fbf264b4 100644 --- a/lib/fog/aws/sqs.rb +++ b/lib/fog/aws/sqs.rb @@ -7,8 +7,11 @@ module Fog request_path 'fog/aws/requests/sqs' request :create_queue - request :list_queues + request :delete_message request :delete_queue + request :list_queues + request :receive_message + request :send_message class Mock @@ -66,6 +69,19 @@ module Fog private + def extract_url_with_name_from_list(name) + list_queues.body['QueueUrls'].detect { |url| url.match(/\/#{name}$/) } + end + + def extract_path_from_url(url) + url.gsub(/.*\.com/, '') + end + + def path_from_queue_name(name) + url = extract_url_with_name_from_list(name) + path = extract_path_from_url(url) + end + def request(params) idempotent = params.delete(:idempotent) parser = params.delete(:parser) From 6bd3e794484a02c26d860143168a307d549cc944 Mon Sep 17 00:00:00 2001 From: Jon Crosby Date: Sat, 5 Feb 2011 20:33:53 -0800 Subject: [PATCH 10/37] Add SQS get_queue_attributes --- .../aws/parsers/sqs/get_queue_attributes.rb | 28 ++++++++++++++++++ .../aws/requests/sqs/get_queue_attributes.rb | 29 +++++++++++++++++++ lib/fog/aws/sqs.rb | 1 + 3 files changed, 58 insertions(+) create mode 100644 lib/fog/aws/parsers/sqs/get_queue_attributes.rb create mode 100644 lib/fog/aws/requests/sqs/get_queue_attributes.rb 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..c5ad20cdb --- /dev/null +++ b/lib/fog/aws/parsers/sqs/get_queue_attributes.rb @@ -0,0 +1,28 @@ +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' + @response['Attributes'][@current_attribute_name] = @value + end + end + + 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..0b4ddaf0d --- /dev/null +++ b/lib/fog/aws/requests/sqs/get_queue_attributes.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class SQS + class Real + + require 'fog/aws/parsers/sqs/get_queue_attributes' + + def get_queue_attributes(name) + request({ + 'Action' => 'GetQueueAttributes', + 'AttributeName' => 'All', + :path => path_from_queue_name(name), + :parser => Fog::Parsers::AWS::SQS::GetQueueAttributes.new + }) + end + + end + + class Mock + + def get_queue_attributes(name) + Fog::Mock.not_implemented + end + + end + + end + end +end diff --git a/lib/fog/aws/sqs.rb b/lib/fog/aws/sqs.rb index 4fbf264b4..0ffc396b7 100644 --- a/lib/fog/aws/sqs.rb +++ b/lib/fog/aws/sqs.rb @@ -9,6 +9,7 @@ module Fog request :create_queue request :delete_message request :delete_queue + request :get_queue_attributes request :list_queues request :receive_message request :send_message From c30357d63861e22f1ea11af644f391b7be62e283 Mon Sep 17 00:00:00 2001 From: geemus Date: Tue, 19 Jul 2011 15:10:26 -0500 Subject: [PATCH 11/37] [AWS|SQS] flesh out basics --- .../parsers/sqs/{delete_queue.rb => basic.rb} | 2 +- lib/fog/aws/parsers/sqs/delete_message.rb | 23 -------- .../aws/parsers/sqs/get_queue_attributes.rb | 9 ++- lib/fog/aws/parsers/sqs/receive_message.rb | 25 ++++---- .../elb/delete_load_balancer_listeners.rb | 2 +- .../requests/sqs/change_message_visibility.rb | 33 +++++++++++ lib/fog/aws/requests/sqs/create_queue.rb | 23 ++++---- lib/fog/aws/requests/sqs/delete_message.rb | 25 ++++---- lib/fog/aws/requests/sqs/delete_queue.rb | 24 ++++---- .../aws/requests/sqs/get_queue_attributes.rb | 26 +++++---- lib/fog/aws/requests/sqs/list_queues.rb | 22 +++---- lib/fog/aws/requests/sqs/receive_message.rb | 27 +++++---- lib/fog/aws/requests/sqs/send_message.rb | 22 +++---- .../aws/requests/sqs/set_queue_attributes.rb | 33 +++++++++++ lib/fog/aws/sqs.rb | 15 ++--- lib/fog/bin/aws.rb | 4 ++ tests/aws/requests/sqs/helper.rb | 15 +++++ tests/aws/requests/sqs/message_tests.rb | 57 +++++++++++++++++++ tests/aws/requests/sqs/queue_tests.rb | 55 ++++++++++++++++++ tests/helpers/formats_helper.rb | 2 +- tests/helpers/formats_helper_tests.rb | 4 ++ 21 files changed, 325 insertions(+), 123 deletions(-) rename lib/fog/aws/parsers/sqs/{delete_queue.rb => basic.rb} (88%) delete mode 100644 lib/fog/aws/parsers/sqs/delete_message.rb create mode 100644 lib/fog/aws/requests/sqs/change_message_visibility.rb create mode 100644 lib/fog/aws/requests/sqs/set_queue_attributes.rb create mode 100644 tests/aws/requests/sqs/helper.rb create mode 100644 tests/aws/requests/sqs/message_tests.rb create mode 100644 tests/aws/requests/sqs/queue_tests.rb diff --git a/lib/fog/aws/parsers/sqs/delete_queue.rb b/lib/fog/aws/parsers/sqs/basic.rb similarity index 88% rename from lib/fog/aws/parsers/sqs/delete_queue.rb rename to lib/fog/aws/parsers/sqs/basic.rb index 0eb113c8f..f99763114 100644 --- a/lib/fog/aws/parsers/sqs/delete_queue.rb +++ b/lib/fog/aws/parsers/sqs/basic.rb @@ -2,7 +2,7 @@ module Fog module Parsers module AWS module SQS - class DeleteQueue < Fog::Parsers::Base + class Basic < Fog::Parsers::Base def reset @response = { 'ResponseMetadata' => {} } diff --git a/lib/fog/aws/parsers/sqs/delete_message.rb b/lib/fog/aws/parsers/sqs/delete_message.rb deleted file mode 100644 index 121a8cd0c..000000000 --- a/lib/fog/aws/parsers/sqs/delete_message.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Fog - module Parsers - module AWS - module SQS - class DeleteMessage < 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/get_queue_attributes.rb b/lib/fog/aws/parsers/sqs/get_queue_attributes.rb index c5ad20cdb..dbbd65511 100644 --- a/lib/fog/aws/parsers/sqs/get_queue_attributes.rb +++ b/lib/fog/aws/parsers/sqs/get_queue_attributes.rb @@ -16,7 +16,14 @@ module Fog when 'Name' @current_attribute_name = @value when 'Value' - @response['Attributes'][@current_attribute_name] = @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 diff --git a/lib/fog/aws/parsers/sqs/receive_message.rb b/lib/fog/aws/parsers/sqs/receive_message.rb index 564604e87..391c00dd8 100644 --- a/lib/fog/aws/parsers/sqs/receive_message.rb +++ b/lib/fog/aws/parsers/sqs/receive_message.rb @@ -6,25 +6,30 @@ module Fog class ReceiveMessage < Fog::Parsers::Base def reset - @response = { 'ResponseMetadata' => {}, 'Message' => {'Attributes' => {}}} + @message = { 'Attributes' => {} } + @response = { 'ResponseMetadata' => {}, 'Message' => []} end def end_element(name) case name when 'RequestId' @response['ResponseMetadata']['RequestId'] = @value - when 'MessageId' - @response['Message']['MessageId'] = @value - when 'ReceiptHandle' - @response['Message']['ReceiptHandle'] = @value - when 'MD5OfBody' - @response['Message']['MD5OfBody'] = @value - when 'Body' - @response['Message']['Body'] = @value + when 'Message' + @response['Message'] << @message + @message = { 'Attributes' => {} } + when 'Body', 'MD5OfBody', 'MessageId', 'ReceiptHandle' + @message[name] = @value when 'Name' @current_attribute_name = @value when 'Value' - @response['Message']['Attributes'][@current_attribute_name] = @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 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/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 index bb151ae62..610dd7946 100644 --- a/lib/fog/aws/requests/sqs/create_queue.rb +++ b/lib/fog/aws/requests/sqs/create_queue.rb @@ -5,20 +5,23 @@ module Fog require 'fog/aws/parsers/sqs/create_queue' - def create_queue(name) + # 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 - }) - end - - end - - class Mock - - def create_queue(name) - Fog::Mock.not_implemented + }.merge!(options)) end end diff --git a/lib/fog/aws/requests/sqs/delete_message.rb b/lib/fog/aws/requests/sqs/delete_message.rb index d9500d952..c17e65dfe 100644 --- a/lib/fog/aws/requests/sqs/delete_message.rb +++ b/lib/fog/aws/requests/sqs/delete_message.rb @@ -3,26 +3,29 @@ module Fog class SQS class Real - require 'fog/aws/parsers/sqs/delete_message' + require 'fog/aws/parsers/sqs/basic' - def delete_message(queue_name, receipt_handle) + # 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::DeleteMessage.new, - :path => path_from_queue_name(queue_name) + :parser => Fog::Parsers::AWS::SQS::Basic.new, + :path => path_from_queue_url(queue_url), }) end end - class Mock - - def delete_message(queue_name, receipt_handle) - Fog::Mock.not_implemented - 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 index 4074d37c4..2b5d93a27 100644 --- a/lib/fog/aws/requests/sqs/delete_queue.rb +++ b/lib/fog/aws/requests/sqs/delete_queue.rb @@ -3,25 +3,27 @@ module Fog class SQS class Real - require 'fog/aws/parsers/sqs/delete_queue' + require 'fog/aws/parsers/sqs/basic' - def delete_queue(name) + # 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::DeleteQueue.new, - :path => path_from_queue_name(name) + :parser => Fog::Parsers::AWS::SQS::Basic.new, + :path => path_from_queue_url(queue_url), }) end end - class Mock - - def delete_queue(name) - Fog::Mock.not_implemented - 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 index 0b4ddaf0d..16e9204eb 100644 --- a/lib/fog/aws/requests/sqs/get_queue_attributes.rb +++ b/lib/fog/aws/requests/sqs/get_queue_attributes.rb @@ -5,21 +5,23 @@ module Fog require 'fog/aws/parsers/sqs/get_queue_attributes' - def get_queue_attributes(name) + # Get attributes of a queue + # + # ==== Parameters + # * queue_url<~String> - Url of queue to get attributes for + # * attributes<~Array> - List of attributes 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, attributes) + attributes = Fog::AWS.indexed_param('AttributeName', [*attributes]) request({ 'Action' => 'GetQueueAttributes', - 'AttributeName' => 'All', - :path => path_from_queue_name(name), + :path => path_from_queue_url(queue_url), :parser => Fog::Parsers::AWS::SQS::GetQueueAttributes.new - }) - end - - end - - class Mock - - def get_queue_attributes(name) - Fog::Mock.not_implemented + }.merge(attributes)) end end diff --git a/lib/fog/aws/requests/sqs/list_queues.rb b/lib/fog/aws/requests/sqs/list_queues.rb index 59536164a..05364cc67 100644 --- a/lib/fog/aws/requests/sqs/list_queues.rb +++ b/lib/fog/aws/requests/sqs/list_queues.rb @@ -5,22 +5,24 @@ module Fog require 'fog/aws/parsers/sqs/list_queues' - def 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 - class Mock - - def list_queues - Fog::Mock.not_implemented - 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 index 483415d8c..b01c42a59 100644 --- a/lib/fog/aws/requests/sqs/receive_message.rb +++ b/lib/fog/aws/requests/sqs/receive_message.rb @@ -5,21 +5,26 @@ module Fog require 'fog/aws/parsers/sqs/receive_message' - def receive_message(queue_name) + # 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_name(queue_name), + :path => path_from_queue_url(queue_url), :parser => Fog::Parsers::AWS::SQS::ReceiveMessage.new - }) - end - - end - - class Mock - - def receive_message(queue_name) - Fog::Mock.not_implemented + }.merge!(options)) end end diff --git a/lib/fog/aws/requests/sqs/send_message.rb b/lib/fog/aws/requests/sqs/send_message.rb index 003673173..e066d6202 100644 --- a/lib/fog/aws/requests/sqs/send_message.rb +++ b/lib/fog/aws/requests/sqs/send_message.rb @@ -5,25 +5,27 @@ module Fog require 'fog/aws/parsers/sqs/send_message' - def send_message(queue_name, 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_name(queue_name), + :path => path_from_queue_url(queue_url), :parser => Fog::Parsers::AWS::SQS::SendMessage.new }) end end - class Mock - - def send_message(queue_name, message) - Fog::Mock.not_implemented - 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/sqs.rb b/lib/fog/aws/sqs.rb index 0ffc396b7..b568a7b6c 100644 --- a/lib/fog/aws/sqs.rb +++ b/lib/fog/aws/sqs.rb @@ -6,6 +6,7 @@ module Fog 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 @@ -13,6 +14,7 @@ module Fog request :list_queues request :receive_message request :send_message + request :set_queue_attributes class Mock @@ -70,17 +72,8 @@ module Fog private - def extract_url_with_name_from_list(name) - list_queues.body['QueueUrls'].detect { |url| url.match(/\/#{name}$/) } - end - - def extract_path_from_url(url) - url.gsub(/.*\.com/, '') - end - - def path_from_queue_name(name) - url = extract_url_with_name_from_list(name) - path = extract_path_from_url(url) + def path_from_queue_url(queue_url) + queue_url.split('.com', 2).last end def request(params) diff --git a/lib/fog/bin/aws.rb b/lib/fog/bin/aws.rb index 46091d5cd..9dd813cac 100644 --- a/lib/fog/bin/aws.rb +++ b/lib/fog/bin/aws.rb @@ -23,6 +23,8 @@ 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 @@ -65,6 +67,8 @@ 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') 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..00d954460 --- /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/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/formats_helper_tests.rb b/tests/helpers/formats_helper_tests.rb index 64ff8cc93..37813294c 100644 --- a/tests/helpers/formats_helper_tests.rb +++ b/tests/helpers/formats_helper_tests.rb @@ -16,6 +16,10 @@ Shindo.tests('test_helper', 'meta') do formats_kernel({:a => {:b => :c}}, {:a => {:b => Symbol}}) end + test('when format of nested hash with anonymous key and value') do + formats_kernel({:a => {:b => :c}}, {:a => {Symbol => Symbol}}) + end + test('when format of an array') do formats_kernel([{:a => :b}], [{:a => Symbol}]) end From 8ad32285c199eaef0c5fc52312ab9b9c4bf4aee9 Mon Sep 17 00:00:00 2001 From: phiggins Date: Sun, 9 Jan 2011 22:12:48 -0800 Subject: [PATCH 12/37] Fix a bunch of paths. --- lib/fog/providers/aws.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index 61ed67899..4e8fa0432 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 From f48af55118e4e76bae70b619fb4c44a3dede4b93 Mon Sep 17 00:00:00 2001 From: phiggins Date: Fri, 14 Jan 2011 00:55:33 -0800 Subject: [PATCH 13/37] Start of SNS. --- lib/fog/aws/parsers/sns/list_topics.rb | 28 ++++++++ lib/fog/aws/requests/sns/list_topics.rb | 50 ++++++++++++++ lib/fog/aws/sns.rb | 87 +++++++++++++++++++++++++ lib/fog/providers/aws.rb | 3 +- 4 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 lib/fog/aws/parsers/sns/list_topics.rb create mode 100644 lib/fog/aws/requests/sns/list_topics.rb create mode 100644 lib/fog/aws/sns.rb 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..213530f1e --- /dev/null +++ b/lib/fog/aws/parsers/sns/list_topics.rb @@ -0,0 +1,28 @@ +module Fog + module Parsers + module AWS + module SNS + + class ListTopics < Fog::Parsers::Base + + def reset + @user = {} + @response = { 'Topics' => [] } + end + + def end_element(name) + case name + when 'TopicARN' + @response['Topics'] << @user + @user = {} + when 'NextToken', 'RequestId' + response[name] = @value + end + end + + 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..8aef92094 --- /dev/null +++ b/lib/fog/aws/requests/sns/list_topics.rb @@ -0,0 +1,50 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/list_topics' + + # List users + # + # ==== Parameters + # * options<~Hash>: + # * 'Marker'<~String>: used to paginate subsequent requests + # * 'MaxItems'<~Integer>: limit results to this number per page + # * 'PathPrefix'<~String>: prefix for filtering results + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'Users'<~Array> - Matching groups + # * user<~Hash>: + # * Arn<~String> - + # * Path<~String> - + # * UserId<~String> - + # * UserName<~String> - + # * 'IsTruncated<~Boolean> - Whether or not results were truncated + # * 'Marker'<~String> - appears when IsTruncated is true as the next marker to use + # * 'RequestId'<~String> - Id of the request + # + # ==== See Also + # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_ListUsers.html + # + def list_topics(options = {}) + request({ + 'Action' => 'ListTopics', + :parser => Fog::Parsers::AWS::SNS::ListTopics.new + }.merge!(options)) + end + + end + + class Mock + + def list_topics(options = {}) + Fog::Mock.not_implemented + 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..fce1d7d8d --- /dev/null +++ b/lib/fog/aws/sns.rb @@ -0,0 +1,87 @@ +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 :list_topics + + 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 '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) + @host = options[:host] || 'sns.amazonaws.com' + @path = options[:path] || '/' + @port = options[:port] || 443 + @scheme = options[:scheme] || 'https' + @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent]) + end + + def reload + @connection.reset + end + + private + + def request(params) + idempotent = params.delete(:idempotent) + parser = params.delete(:parser) + + body = AWS.signed_params( + params, + { + :aws_access_key_id => @aws_access_key_id, + :hmac => @hmac, + :host => @host, + :path => @path, + :port => @port, + #:version => '2010-05-08' + } + ) + + response = @connection.request({ + :body => body, + :expects => 200, + :idempotent => idempotent, + #:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, + :host => @host, + :method => 'POST', + :parser => parser + }) + + response + end + + end + end + end +end diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index 4e8fa0432..e818ee302 100644 --- a/lib/fog/providers/aws.rb +++ b/lib/fog/providers/aws.rb @@ -11,13 +11,14 @@ 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') From adc20b5d447792516e897faf18dbb52530266d96 Mon Sep 17 00:00:00 2001 From: phiggins Date: Tue, 1 Feb 2011 00:49:32 -0800 Subject: [PATCH 14/37] Working ListUsers for SNS. --- lib/fog/aws/parsers/sns/list_topics.rb | 6 ++---- lib/fog/aws/sns.rb | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/fog/aws/parsers/sns/list_topics.rb b/lib/fog/aws/parsers/sns/list_topics.rb index 213530f1e..efef64c6a 100644 --- a/lib/fog/aws/parsers/sns/list_topics.rb +++ b/lib/fog/aws/parsers/sns/list_topics.rb @@ -6,15 +6,13 @@ module Fog class ListTopics < Fog::Parsers::Base def reset - @user = {} @response = { 'Topics' => [] } end def end_element(name) case name - when 'TopicARN' - @response['Topics'] << @user - @user = {} + when 'TopicArn' + @response['Topics'] << @value when 'NextToken', 'RequestId' response[name] = @value end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index fce1d7d8d..be9ff2865 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -39,7 +39,21 @@ module Fog @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) - @host = options[:host] || 'sns.amazonaws.com' + + 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' @@ -63,8 +77,7 @@ module Fog :hmac => @hmac, :host => @host, :path => @path, - :port => @port, - #:version => '2010-05-08' + :port => @port } ) @@ -72,7 +85,7 @@ module Fog :body => body, :expects => 200, :idempotent => idempotent, - #:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, + :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, :host => @host, :method => 'POST', :parser => parser From 729da56d61159521c10442811b68a3ec6519220d Mon Sep 17 00:00:00 2001 From: phiggins Date: Tue, 1 Feb 2011 22:20:08 -0800 Subject: [PATCH 15/37] Remove copied-and-pasted documentation. --- lib/fog/aws/requests/sns/list_topics.rb | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/lib/fog/aws/requests/sns/list_topics.rb b/lib/fog/aws/requests/sns/list_topics.rb index 8aef92094..77452fea3 100644 --- a/lib/fog/aws/requests/sns/list_topics.rb +++ b/lib/fog/aws/requests/sns/list_topics.rb @@ -5,30 +5,6 @@ module Fog require 'fog/aws/parsers/sns/list_topics' - # List users - # - # ==== Parameters - # * options<~Hash>: - # * 'Marker'<~String>: used to paginate subsequent requests - # * 'MaxItems'<~Integer>: limit results to this number per page - # * 'PathPrefix'<~String>: prefix for filtering results - # - # ==== Returns - # * response<~Excon::Response>: - # * body<~Hash>: - # * 'Users'<~Array> - Matching groups - # * user<~Hash>: - # * Arn<~String> - - # * Path<~String> - - # * UserId<~String> - - # * UserName<~String> - - # * 'IsTruncated<~Boolean> - Whether or not results were truncated - # * 'Marker'<~String> - appears when IsTruncated is true as the next marker to use - # * 'RequestId'<~String> - Id of the request - # - # ==== See Also - # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_ListUsers.html - # def list_topics(options = {}) request({ 'Action' => 'ListTopics', From 4b6cbb6912df156ff7e65d6f8e66467305e0c8be Mon Sep 17 00:00:00 2001 From: phiggins Date: Tue, 1 Feb 2011 22:20:44 -0800 Subject: [PATCH 16/37] Add SNS's get_topic_attributes command. --- .../aws/parsers/sns/get_topic_attributes.rb | 27 +++++++++++++++++++ .../aws/requests/sns/get_topic_attributes.rb | 27 +++++++++++++++++++ lib/fog/aws/sns.rb | 1 + 3 files changed, 55 insertions(+) create mode 100644 lib/fog/aws/parsers/sns/get_topic_attributes.rb create mode 100644 lib/fog/aws/requests/sns/get_topic_attributes.rb 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..043a54f59 --- /dev/null +++ b/lib/fog/aws/parsers/sns/get_topic_attributes.rb @@ -0,0 +1,27 @@ +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 + when "value" + @response['Attributes'][@key] = @value + when 'RequestId' + @response[name] = @value + end + end + 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..218022051 --- /dev/null +++ b/lib/fog/aws/requests/sns/get_topic_attributes.rb @@ -0,0 +1,27 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/get_topic_attributes' + + def get_topic_attributes(options = {}) + request({ + 'Action' => 'GetTopicAttributes', + :parser => Fog::Parsers::AWS::SNS::GetTopicAttributes.new + }.merge!(options)) + end + + end + + class Mock + + def get_topic_attributes + Fog::Mock.not_implemented + end + + end + + end + end +end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index be9ff2865..50efbb978 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -7,6 +7,7 @@ module Fog request_path 'fog/aws/requests/sns' request :list_topics + request :get_topic_attributes class Mock From 967a686bc9ae87f3a1f8dff96559381002427617 Mon Sep 17 00:00:00 2001 From: phiggins Date: Wed, 2 Feb 2011 00:40:13 -0800 Subject: [PATCH 17/37] SNS ListSubscriptions --- lib/fog/aws/parsers/sns/list_subscriptions.rb | 29 +++++++++++++++++++ .../aws/requests/sns/list_subscriptions.rb | 27 +++++++++++++++++ lib/fog/aws/sns.rb | 3 +- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 lib/fog/aws/parsers/sns/list_subscriptions.rb create mode 100644 lib/fog/aws/requests/sns/list_subscriptions.rb 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..c6c757e50 --- /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 + when "member" + @response['Subscriptions'] << @subscription + @subscription = {} + when 'RequestId', 'NextToken' + @response[name] = @value + end + end + 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..0cc2de20d --- /dev/null +++ b/lib/fog/aws/requests/sns/list_subscriptions.rb @@ -0,0 +1,27 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/list_subscriptions' + + def list_subscriptions(options = {}) + request({ + 'Action' => 'ListSubscriptions', + :parser => Fog::Parsers::AWS::SNS::ListSubscriptions.new + }.merge!(options)) + end + + end + + class Mock + + def list_subscriptions + Fog::Mock.not_implemented + end + + end + + end + end +end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index 50efbb978..7fca78265 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -6,8 +6,9 @@ module Fog recognizes :host, :path, :port, :scheme, :persistent request_path 'fog/aws/requests/sns' - request :list_topics request :get_topic_attributes + request :list_subscriptions + request :list_topics class Mock From 2870fdea5688f3f9cf4258f5ee8e51708157b0bb Mon Sep 17 00:00:00 2001 From: phiggins Date: Wed, 2 Feb 2011 00:49:04 -0800 Subject: [PATCH 18/37] SNS ListSubscriptionsByTopic --- .../sns/list_subscriptions_by_topic.rb | 29 +++++++++++++++++++ .../sns/list_subscriptions_by_topic.rb | 27 +++++++++++++++++ lib/fog/aws/sns.rb | 1 + 3 files changed, 57 insertions(+) create mode 100644 lib/fog/aws/parsers/sns/list_subscriptions_by_topic.rb create mode 100644 lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb diff --git a/lib/fog/aws/parsers/sns/list_subscriptions_by_topic.rb b/lib/fog/aws/parsers/sns/list_subscriptions_by_topic.rb new file mode 100644 index 000000000..db44bf5cf --- /dev/null +++ b/lib/fog/aws/parsers/sns/list_subscriptions_by_topic.rb @@ -0,0 +1,29 @@ +module Fog + module Parsers + module AWS + module SNS + + class ListSubscriptionsByTopic < Fog::Parsers::Base + + def reset + @response = { 'Subscriptions' => [] } + @subscription = {} + end + + def end_element(name) + case name + when "TopicArn", "Protocol", "SubscriptionArn", "Owner", "Endpoint" + @subscription[name] = @value + when "member" + @response['Subscriptions'] << @subscription + @subscription = {} + when 'RequestId', 'NextToken' + @response[name] = @value + end + end + 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..795ce688c --- /dev/null +++ b/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb @@ -0,0 +1,27 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/list_subscriptions_by_topic' + + def list_subscriptions_by_topic(options = {}) + request({ + 'Action' => 'ListSubscriptionsByTopic', + :parser => Fog::Parsers::AWS::SNS::ListSubscriptionsByTopic.new + }.merge!(options)) + end + + end + + class Mock + + def list_subscriptions_by_topic + Fog::Mock.not_implemented + end + + end + + end + end +end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index 7fca78265..fe7ea6941 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -8,6 +8,7 @@ module Fog request_path 'fog/aws/requests/sns' request :get_topic_attributes request :list_subscriptions + request :list_subscriptions_by_topic request :list_topics class Mock From e92ca191d78d66eb6ac0028ce0b4079e0ceed9b2 Mon Sep 17 00:00:00 2001 From: phiggins Date: Wed, 2 Feb 2011 23:26:28 -0800 Subject: [PATCH 19/37] SNS CreateTopic and DeleteTopic --- lib/fog/aws/parsers/sns/create_topic.rb | 24 ++++++++++++++++++++++ lib/fog/aws/parsers/sns/delete_topic.rb | 24 ++++++++++++++++++++++ lib/fog/aws/requests/sns/create_topic.rb | 26 ++++++++++++++++++++++++ lib/fog/aws/requests/sns/delete_topic.rb | 26 ++++++++++++++++++++++++ lib/fog/aws/sns.rb | 2 ++ 5 files changed, 102 insertions(+) create mode 100644 lib/fog/aws/parsers/sns/create_topic.rb create mode 100644 lib/fog/aws/parsers/sns/delete_topic.rb create mode 100644 lib/fog/aws/requests/sns/create_topic.rb create mode 100644 lib/fog/aws/requests/sns/delete_topic.rb 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..5b11350e9 --- /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 + 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/requests/sns/create_topic.rb b/lib/fog/aws/requests/sns/create_topic.rb new file mode 100644 index 000000000..ec864acaa --- /dev/null +++ b/lib/fog/aws/requests/sns/create_topic.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/create_topic' + + def create_topic(options = {}) + request({ + 'Action' => 'CreateTopic', + :parser => Fog::Parsers::AWS::SNS::CreateTopic.new + }.merge!(options)) + end + + end + + class Mock + + def create_topic(options = {}) + Fog::Mock.not_implemented + 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..ba9972399 --- /dev/null +++ b/lib/fog/aws/requests/sns/delete_topic.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/delete_topic' + + def delete_topic(options = {}) + request({ + 'Action' => 'DeleteTopic', + :parser => Fog::Parsers::AWS::SNS::DeleteTopic.new + }.merge!(options)) + end + + end + + class Mock + + def delete_topic(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index fe7ea6941..56e08bd47 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -6,6 +6,8 @@ module Fog recognizes :host, :path, :port, :scheme, :persistent request_path 'fog/aws/requests/sns' + request :create_topic + request :delete_topic request :get_topic_attributes request :list_subscriptions request :list_subscriptions_by_topic From e92d4edb6de5894fe3207e9ea0c6544010914837 Mon Sep 17 00:00:00 2001 From: phiggins Date: Thu, 3 Feb 2011 16:10:39 -0800 Subject: [PATCH 20/37] SNS Publish --- lib/fog/aws/parsers/sns/publish.rb | 24 ++++++++++++++++++++++++ lib/fog/aws/requests/sns/publish.rb | 26 ++++++++++++++++++++++++++ lib/fog/aws/sns.rb | 1 + 3 files changed, 51 insertions(+) create mode 100644 lib/fog/aws/parsers/sns/publish.rb create mode 100644 lib/fog/aws/requests/sns/publish.rb diff --git a/lib/fog/aws/parsers/sns/publish.rb b/lib/fog/aws/parsers/sns/publish.rb new file mode 100644 index 000000000..f232b5a94 --- /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 + end + end + + 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..3643bf5ca --- /dev/null +++ b/lib/fog/aws/requests/sns/publish.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/publish' + + def publish(options = {}) + request({ + 'Action' => 'Publish', + :parser => Fog::Parsers::AWS::SNS::Publish.new + }.merge!(options)) + end + + end + + class Mock + + def publish(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index 56e08bd47..a11a4a910 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -12,6 +12,7 @@ module Fog request :list_subscriptions request :list_subscriptions_by_topic request :list_topics + request :publish class Mock From 5fbb645e577c13b7374ae427a5b1f8d197322598 Mon Sep 17 00:00:00 2001 From: phiggins Date: Thu, 3 Feb 2011 16:53:23 -0800 Subject: [PATCH 21/37] SNS AddPermission --- lib/fog/aws/parsers/sns/add_permission.rb | 24 ++++++++++++++++++++ lib/fog/aws/requests/sns/add_permission.rb | 26 ++++++++++++++++++++++ lib/fog/aws/sns.rb | 1 + 3 files changed, 51 insertions(+) create mode 100644 lib/fog/aws/parsers/sns/add_permission.rb create mode 100644 lib/fog/aws/requests/sns/add_permission.rb 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/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/sns.rb b/lib/fog/aws/sns.rb index a11a4a910..7ca6c2676 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -6,6 +6,7 @@ module Fog recognizes :host, :path, :port, :scheme, :persistent request_path 'fog/aws/requests/sns' + request :add_permission request :create_topic request :delete_topic request :get_topic_attributes From 5cd1285575c188bf40fc6f7b2eb21bf705ccb4a6 Mon Sep 17 00:00:00 2001 From: phiggins Date: Thu, 3 Feb 2011 16:57:20 -0800 Subject: [PATCH 22/37] SNS RemovePermission --- lib/fog/aws/parsers/sns/remove_permission.rb | 24 +++++++++++++++++ lib/fog/aws/requests/sns/remove_permission.rb | 26 +++++++++++++++++++ lib/fog/aws/sns.rb | 1 + 3 files changed, 51 insertions(+) create mode 100644 lib/fog/aws/parsers/sns/remove_permission.rb create mode 100644 lib/fog/aws/requests/sns/remove_permission.rb 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/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/sns.rb b/lib/fog/aws/sns.rb index 7ca6c2676..992d8d8ea 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -14,6 +14,7 @@ module Fog request :list_subscriptions_by_topic request :list_topics request :publish + request :remove_permission class Mock From a9b57c91731c7a31f194a3ab7c09ef45d7def4fd Mon Sep 17 00:00:00 2001 From: phiggins Date: Thu, 3 Feb 2011 17:09:04 -0800 Subject: [PATCH 23/37] SNS SetTopicAttributes --- .../aws/parsers/sns/set_topic_attributes.rb | 24 +++++++++++++++++ .../aws/requests/sns/set_topic_attributes.rb | 26 +++++++++++++++++++ lib/fog/aws/sns.rb | 1 + 3 files changed, 51 insertions(+) create mode 100644 lib/fog/aws/parsers/sns/set_topic_attributes.rb create mode 100644 lib/fog/aws/requests/sns/set_topic_attributes.rb 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/requests/sns/set_topic_attributes.rb b/lib/fog/aws/requests/sns/set_topic_attributes.rb new file mode 100644 index 000000000..404ba3f64 --- /dev/null +++ b/lib/fog/aws/requests/sns/set_topic_attributes.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/set_topic_attributes' + + def set_topic_attributes(options = {}) + request({ + 'Action' => 'SetTopicAttributes', + :parser => Fog::Parsers::AWS::SNS::SetTopicAttributes.new + }.merge!(options)) + end + + end + + class Mock + + def set_topic_attributes(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index 992d8d8ea..66b06f8fd 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -15,6 +15,7 @@ module Fog request :list_topics request :publish request :remove_permission + request :set_topic_attributes class Mock From 71b7a44132c37fb7b32e7140bb7f648ff88a16a2 Mon Sep 17 00:00:00 2001 From: phiggins Date: Thu, 3 Feb 2011 17:29:42 -0800 Subject: [PATCH 24/37] SNS Subscribe --- lib/fog/aws/parsers/sns/subscribe.rb | 24 ++++++++++++++++++++++++ lib/fog/aws/requests/sns/subscribe.rb | 26 ++++++++++++++++++++++++++ lib/fog/aws/sns.rb | 1 + 3 files changed, 51 insertions(+) create mode 100644 lib/fog/aws/parsers/sns/subscribe.rb create mode 100644 lib/fog/aws/requests/sns/subscribe.rb diff --git a/lib/fog/aws/parsers/sns/subscribe.rb b/lib/fog/aws/parsers/sns/subscribe.rb new file mode 100644 index 000000000..6eb3fc564 --- /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 + end + end + + 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..c8e198596 --- /dev/null +++ b/lib/fog/aws/requests/sns/subscribe.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/subscribe' + + def subscribe(options = {}) + request({ + 'Action' => 'Subscribe', + :parser => Fog::Parsers::AWS::SNS::Subscribe.new + }.merge!(options)) + end + + end + + class Mock + + def subscribe(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index 66b06f8fd..429bd533b 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -16,6 +16,7 @@ module Fog request :publish request :remove_permission request :set_topic_attributes + request :subscribe class Mock From f3f965089680ab5058017a2a5b477fc79d409c4b Mon Sep 17 00:00:00 2001 From: phiggins Date: Thu, 3 Feb 2011 17:34:46 -0800 Subject: [PATCH 25/37] SNS ConfirmSubscription and Unsubscribe --- .../aws/parsers/sns/confirm_subscription.rb | 24 +++++++++++++++++ lib/fog/aws/parsers/sns/unsubscribe.rb | 24 +++++++++++++++++ .../aws/requests/sns/confirm_subscription.rb | 26 +++++++++++++++++++ lib/fog/aws/requests/sns/unsubscribe.rb | 26 +++++++++++++++++++ lib/fog/aws/sns.rb | 2 ++ 5 files changed, 102 insertions(+) create mode 100644 lib/fog/aws/parsers/sns/confirm_subscription.rb create mode 100644 lib/fog/aws/parsers/sns/unsubscribe.rb create mode 100644 lib/fog/aws/requests/sns/confirm_subscription.rb create mode 100644 lib/fog/aws/requests/sns/unsubscribe.rb 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..e719d22d2 --- /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 + 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/requests/sns/confirm_subscription.rb b/lib/fog/aws/requests/sns/confirm_subscription.rb new file mode 100644 index 000000000..d9142406f --- /dev/null +++ b/lib/fog/aws/requests/sns/confirm_subscription.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/confirm_subscription' + + def confirm_subscription(options = {}) + request({ + 'Action' => 'ConfirmSubscription', + :parser => Fog::Parsers::AWS::SNS::ConfirmSubscription.new + }.merge!(options)) + end + + end + + class Mock + + def confirm_subscription(options = {}) + Fog::Mock.not_implemented + 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..18a11fb97 --- /dev/null +++ b/lib/fog/aws/requests/sns/unsubscribe.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class SNS + class Real + + require 'fog/aws/parsers/sns/unsubscribe' + + def unsubscribe(options = {}) + request({ + 'Action' => 'Unsubscribe', + :parser => Fog::Parsers::AWS::SNS::Unsubscribe.new + }.merge!(options)) + end + + end + + class Mock + + def unsubscribe(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index 429bd533b..58ea011e1 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -7,6 +7,7 @@ module Fog request_path 'fog/aws/requests/sns' request :add_permission + request :confirm_subscription request :create_topic request :delete_topic request :get_topic_attributes @@ -17,6 +18,7 @@ module Fog request :remove_permission request :set_topic_attributes request :subscribe + request :unsubscribe class Mock From 542cffe5b03991662912c57b41b9f1a2aa60afb2 Mon Sep 17 00:00:00 2001 From: phiggins Date: Thu, 17 Mar 2011 22:43:59 -0700 Subject: [PATCH 26/37] Add sns to fog bin. --- lib/fog/bin/aws.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/fog/bin/aws.rb b/lib/fog/bin/aws.rb index 9dd813cac..58820663f 100644 --- a/lib/fog/bin/aws.rb +++ b/lib/fog/bin/aws.rb @@ -29,6 +29,8 @@ class AWS < Fog::Bin 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: @@ -72,6 +74,8 @@ class AWS < Fog::Bin 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 From 9c78523e5ed9dd7396e962cc0c101009425a9b02 Mon Sep 17 00:00:00 2001 From: phiggins Date: Thu, 17 Mar 2011 22:44:28 -0700 Subject: [PATCH 27/37] Start SNS tests. --- tests/aws/requests/sns/helper.rb | 9 ++++++ .../aws/requests/sns/topic_lifecycle_tests.rb | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/aws/requests/sns/helper.rb create mode 100644 tests/aws/requests/sns/topic_lifecycle_tests.rb 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/topic_lifecycle_tests.rb b/tests/aws/requests/sns/topic_lifecycle_tests.rb new file mode 100644 index 000000000..877d5e43a --- /dev/null +++ b/tests/aws/requests/sns/topic_lifecycle_tests.rb @@ -0,0 +1,28 @@ +Shindo.tests('AWS::SES | topic lifecycle tests', ['aws', 'sns']) do + + tests('success') do + + tests("#create_topic('TopicArn' => 'example-topic')").formats(AWS::SNS::Formats::BASIC.merge('TopicArn' => String)) do + pending if Fog.mocking? + body = AWS[:sns].create_topic('Name' => 'example-topic').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("#delete_topic('TopicArn' => 'example-topic')").formats(AWS::SNS::Formats::BASIC) do + pending if Fog.mocking? + AWS[:sns].delete_topic('TopicArn' => @topic_arn).body + end + + end + + tests('failure') do + + end + +end From dc78e464bc737f3f39c6e7ba6a662e653d8add48 Mon Sep 17 00:00:00 2001 From: geemus Date: Tue, 19 Jul 2011 17:53:26 -0500 Subject: [PATCH 28/37] [AWS|SNS] flesh out basics --- .../aws/parsers/sns/confirm_subscription.rb | 2 +- lib/fog/aws/parsers/sns/create_topic.rb | 2 +- .../aws/parsers/sns/get_topic_attributes.rb | 13 ++- lib/fog/aws/parsers/sns/list_subscriptions.rb | 4 +- .../sns/list_subscriptions_by_topic.rb | 29 ------- lib/fog/aws/parsers/sns/publish.rb | 2 +- lib/fog/aws/parsers/sns/subscribe.rb | 2 +- .../aws/requests/sns/confirm_subscription.rb | 27 ++++--- lib/fog/aws/requests/sns/create_topic.rb | 21 ++--- lib/fog/aws/requests/sns/delete_topic.rb | 25 +++--- .../aws/requests/sns/get_topic_attributes.rb | 26 +++--- .../aws/requests/sns/list_subscriptions.rb | 18 +++-- .../sns/list_subscriptions_by_topic.rb | 28 ++++--- lib/fog/aws/requests/sns/list_topics.rb | 17 ++-- lib/fog/aws/requests/sns/publish.rb | 28 ++++--- .../aws/requests/sns/set_topic_attributes.rb | 29 ++++--- lib/fog/aws/requests/sns/subscribe.rb | 29 ++++--- lib/fog/aws/requests/sns/unsubscribe.rb | 25 +++--- .../aws/requests/sqs/get_queue_attributes.rb | 8 +- lib/fog/aws/sns.rb | 2 +- lib/fog/core.rb | 2 +- tests/aws/requests/sns/subscription_tests.rb | 81 +++++++++++++++++++ .../aws/requests/sns/topic_lifecycle_tests.rb | 28 ------- tests/aws/requests/sns/topic_tests.rb | 50 ++++++++++++ tests/aws/requests/sqs/queue_tests.rb | 4 +- 25 files changed, 315 insertions(+), 187 deletions(-) delete mode 100644 lib/fog/aws/parsers/sns/list_subscriptions_by_topic.rb create mode 100644 tests/aws/requests/sns/subscription_tests.rb delete mode 100644 tests/aws/requests/sns/topic_lifecycle_tests.rb create mode 100644 tests/aws/requests/sns/topic_tests.rb diff --git a/lib/fog/aws/parsers/sns/confirm_subscription.rb b/lib/fog/aws/parsers/sns/confirm_subscription.rb index e719d22d2..15631cc51 100644 --- a/lib/fog/aws/parsers/sns/confirm_subscription.rb +++ b/lib/fog/aws/parsers/sns/confirm_subscription.rb @@ -12,7 +12,7 @@ module Fog def end_element(name) case name when 'SubscriptionArn', 'RequestId' - @response[name] = @value + @response[name] = @value.rstrip end end diff --git a/lib/fog/aws/parsers/sns/create_topic.rb b/lib/fog/aws/parsers/sns/create_topic.rb index 5b11350e9..ee842d399 100644 --- a/lib/fog/aws/parsers/sns/create_topic.rb +++ b/lib/fog/aws/parsers/sns/create_topic.rb @@ -12,7 +12,7 @@ module Fog def end_element(name) case name when 'TopicArn', 'RequestId' - @response[name] = @value + @response[name] = @value.rstrip end end diff --git a/lib/fog/aws/parsers/sns/get_topic_attributes.rb b/lib/fog/aws/parsers/sns/get_topic_attributes.rb index 043a54f59..ea974f5d9 100644 --- a/lib/fog/aws/parsers/sns/get_topic_attributes.rb +++ b/lib/fog/aws/parsers/sns/get_topic_attributes.rb @@ -11,10 +11,15 @@ module Fog def end_element(name) case name - when "key" - @key = @value - when "value" - @response['Attributes'][@key] = @value + 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 diff --git a/lib/fog/aws/parsers/sns/list_subscriptions.rb b/lib/fog/aws/parsers/sns/list_subscriptions.rb index c6c757e50..07424a680 100644 --- a/lib/fog/aws/parsers/sns/list_subscriptions.rb +++ b/lib/fog/aws/parsers/sns/list_subscriptions.rb @@ -13,12 +13,12 @@ module Fog def end_element(name) case name when "TopicArn", "Protocol", "SubscriptionArn", "Owner", "Endpoint" - @subscription[name] = @value + @subscription[name] = @value.rstrip when "member" @response['Subscriptions'] << @subscription @subscription = {} when 'RequestId', 'NextToken' - @response[name] = @value + @response[name] = @value.rstrip end end end diff --git a/lib/fog/aws/parsers/sns/list_subscriptions_by_topic.rb b/lib/fog/aws/parsers/sns/list_subscriptions_by_topic.rb deleted file mode 100644 index db44bf5cf..000000000 --- a/lib/fog/aws/parsers/sns/list_subscriptions_by_topic.rb +++ /dev/null @@ -1,29 +0,0 @@ -module Fog - module Parsers - module AWS - module SNS - - class ListSubscriptionsByTopic < Fog::Parsers::Base - - def reset - @response = { 'Subscriptions' => [] } - @subscription = {} - end - - def end_element(name) - case name - when "TopicArn", "Protocol", "SubscriptionArn", "Owner", "Endpoint" - @subscription[name] = @value - when "member" - @response['Subscriptions'] << @subscription - @subscription = {} - when 'RequestId', 'NextToken' - @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 index f232b5a94..91b2a62ee 100644 --- a/lib/fog/aws/parsers/sns/publish.rb +++ b/lib/fog/aws/parsers/sns/publish.rb @@ -12,7 +12,7 @@ module Fog def end_element(name) case name when 'MessageId', 'RequestId' - @response[name] = @value + @response[name] = @value.rstrip end end diff --git a/lib/fog/aws/parsers/sns/subscribe.rb b/lib/fog/aws/parsers/sns/subscribe.rb index 6eb3fc564..8f209daa0 100644 --- a/lib/fog/aws/parsers/sns/subscribe.rb +++ b/lib/fog/aws/parsers/sns/subscribe.rb @@ -12,7 +12,7 @@ module Fog def end_element(name) case name when 'SubscriptionArn', 'RequestId' - @response[name] = @value + @response[name] = @value.rstrip end end diff --git a/lib/fog/aws/requests/sns/confirm_subscription.rb b/lib/fog/aws/requests/sns/confirm_subscription.rb index d9142406f..862f2d97e 100644 --- a/lib/fog/aws/requests/sns/confirm_subscription.rb +++ b/lib/fog/aws/requests/sns/confirm_subscription.rb @@ -5,22 +5,29 @@ module Fog require 'fog/aws/parsers/sns/confirm_subscription' - def confirm_subscription(options = {}) + # 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', - :parser => Fog::Parsers::AWS::SNS::ConfirmSubscription.new + 'Action' => 'ConfirmSubscription', + 'Token' => token, + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::ConfirmSubscription.new }.merge!(options)) end end - class Mock - - def confirm_subscription(options = {}) - Fog::Mock.not_implemented - 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 index ec864acaa..b44b6fa78 100644 --- a/lib/fog/aws/requests/sns/create_topic.rb +++ b/lib/fog/aws/requests/sns/create_topic.rb @@ -5,22 +5,25 @@ module Fog require 'fog/aws/parsers/sns/create_topic' - def create_topic(options = {}) + # 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 - }.merge!(options)) + }) end end - class Mock - - def create_topic(options = {}) - Fog::Mock.not_implemented - 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 index ba9972399..c5b71a865 100644 --- a/lib/fog/aws/requests/sns/delete_topic.rb +++ b/lib/fog/aws/requests/sns/delete_topic.rb @@ -5,22 +5,25 @@ module Fog require 'fog/aws/parsers/sns/delete_topic' - def delete_topic(options = {}) + # 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', - :parser => Fog::Parsers::AWS::SNS::DeleteTopic.new - }.merge!(options)) + 'Action' => 'DeleteTopic', + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::DeleteTopic.new + }) end end - class Mock - - def delete_topic(options = {}) - Fog::Mock.not_implemented - 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 index 218022051..34a3336f7 100644 --- a/lib/fog/aws/requests/sns/get_topic_attributes.rb +++ b/lib/fog/aws/requests/sns/get_topic_attributes.rb @@ -5,19 +5,21 @@ module Fog require 'fog/aws/parsers/sns/get_topic_attributes' - def get_topic_attributes(options = {}) + # 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', - :parser => Fog::Parsers::AWS::SNS::GetTopicAttributes.new - }.merge!(options)) - end - - end - - class Mock - - def get_topic_attributes - Fog::Mock.not_implemented + 'Action' => 'GetTopicAttributes', + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::GetTopicAttributes.new + }) end end diff --git a/lib/fog/aws/requests/sns/list_subscriptions.rb b/lib/fog/aws/requests/sns/list_subscriptions.rb index 0cc2de20d..223d7311e 100644 --- a/lib/fog/aws/requests/sns/list_subscriptions.rb +++ b/lib/fog/aws/requests/sns/list_subscriptions.rb @@ -5,6 +5,16 @@ module Fog 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', @@ -14,14 +24,6 @@ module Fog end - class Mock - - def list_subscriptions - Fog::Mock.not_implemented - 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 index 795ce688c..7b19df2ed 100644 --- a/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb +++ b/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb @@ -3,25 +3,29 @@ module Fog class SNS class Real - require 'fog/aws/parsers/sns/list_subscriptions_by_topic' + require 'fog/aws/parsers/sns/list_subscriptions' - def list_subscriptions_by_topic(options = {}) + # 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', - :parser => Fog::Parsers::AWS::SNS::ListSubscriptionsByTopic.new + 'Action' => 'ListSubscriptionsByTopic', + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::ListSubscriptions.new }.merge!(options)) end end - class Mock - - def list_subscriptions_by_topic - Fog::Mock.not_implemented - 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 index 77452fea3..fdd9fd07e 100644 --- a/lib/fog/aws/requests/sns/list_topics.rb +++ b/lib/fog/aws/requests/sns/list_topics.rb @@ -5,6 +5,16 @@ module Fog 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', @@ -14,13 +24,6 @@ module Fog end - class Mock - - def list_topics(options = {}) - Fog::Mock.not_implemented - end - - end end end end diff --git a/lib/fog/aws/requests/sns/publish.rb b/lib/fog/aws/requests/sns/publish.rb index 3643bf5ca..790d5e44d 100644 --- a/lib/fog/aws/requests/sns/publish.rb +++ b/lib/fog/aws/requests/sns/publish.rb @@ -5,22 +5,30 @@ module Fog require 'fog/aws/parsers/sns/publish' - def publish(options = {}) + # 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', - :parser => Fog::Parsers::AWS::SNS::Publish.new + 'Action' => 'Publish', + 'Message' => message, + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::Publish.new }.merge!(options)) end end - class Mock - - def publish(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 index 404ba3f64..99f4e2d6f 100644 --- a/lib/fog/aws/requests/sns/set_topic_attributes.rb +++ b/lib/fog/aws/requests/sns/set_topic_attributes.rb @@ -5,22 +5,29 @@ module Fog require 'fog/aws/parsers/sns/set_topic_attributes' - def set_topic_attributes(options = {}) + # 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', - :parser => Fog::Parsers::AWS::SNS::SetTopicAttributes.new - }.merge!(options)) + 'Action' => 'SetTopicAttributes', + 'AttributeName' => attribute_name, + 'AttributeValue' => attribute_value, + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::SetTopicAttributes.new + }) end end - class Mock - - def set_topic_attributes(options = {}) - Fog::Mock.not_implemented - end - - end end end end diff --git a/lib/fog/aws/requests/sns/subscribe.rb b/lib/fog/aws/requests/sns/subscribe.rb index c8e198596..91beec446 100644 --- a/lib/fog/aws/requests/sns/subscribe.rb +++ b/lib/fog/aws/requests/sns/subscribe.rb @@ -5,22 +5,29 @@ module Fog require 'fog/aws/parsers/sns/subscribe' - def subscribe(options = {}) + # 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', - :parser => Fog::Parsers::AWS::SNS::Subscribe.new - }.merge!(options)) + 'Action' => 'Subscribe', + 'Endpoint' => endpoint, + 'Protocol' => protocol, + 'TopicArn' => arn, + :parser => Fog::Parsers::AWS::SNS::Subscribe.new + }) end end - class Mock - - def subscribe(options = {}) - Fog::Mock.not_implemented - end - - end end end end diff --git a/lib/fog/aws/requests/sns/unsubscribe.rb b/lib/fog/aws/requests/sns/unsubscribe.rb index 18a11fb97..29ca5df73 100644 --- a/lib/fog/aws/requests/sns/unsubscribe.rb +++ b/lib/fog/aws/requests/sns/unsubscribe.rb @@ -5,22 +5,25 @@ module Fog require 'fog/aws/parsers/sns/unsubscribe' - def unsubscribe(options = {}) + # 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', - :parser => Fog::Parsers::AWS::SNS::Unsubscribe.new - }.merge!(options)) + 'Action' => 'Unsubscribe', + 'SubscriptionArn' => arn, + :parser => Fog::Parsers::AWS::SNS::Unsubscribe.new + }) end end - class Mock - - def unsubscribe(options = {}) - Fog::Mock.not_implemented - 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 index 16e9204eb..ff88b57eb 100644 --- a/lib/fog/aws/requests/sqs/get_queue_attributes.rb +++ b/lib/fog/aws/requests/sqs/get_queue_attributes.rb @@ -9,19 +9,19 @@ module Fog # # ==== Parameters # * queue_url<~String> - Url of queue to get attributes for - # * attributes<~Array> - List of attributes to return, in ['All', 'ApproximateNumberOfMessages', 'ApproximateNumberOfMessagesNotVisible', 'CreatedTimestamp', 'LastModifiedTimestamp', 'MaximumMessageSize', 'MessageRetentionPeriod', 'Policy', 'QueueArn', 'VisibilityTimeout'] + # * 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, attributes) - attributes = Fog::AWS.indexed_param('AttributeName', [*attributes]) + 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 - }.merge(attributes)) + }) end end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index 58ea011e1..7ac11d6fa 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -47,7 +47,7 @@ module Fog # ==== Returns # * SNS object with connection to AWS. def initialize(options={}) - require 'json' + 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) 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/tests/aws/requests/sns/subscription_tests.rb b/tests/aws/requests/sns/subscription_tests.rb new file mode 100644 index 000000000..dff251d6a --- /dev/null +++ b/tests/aws/requests/sns/subscription_tests.rb @@ -0,0 +1,81 @@ +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 + AWS[:sns].list_subscriptions.body + end + + tests("#list_subscriptions_by_topic('#{@topic_arn}')").formats(list_subscriptions_format) do + 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 + body = AWS[:sns].publish(@topic_arn, 'message').body + end + + tests("#receive_message('#{@queue_url}')...").returns('message') do + 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 + 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_lifecycle_tests.rb b/tests/aws/requests/sns/topic_lifecycle_tests.rb deleted file mode 100644 index 877d5e43a..000000000 --- a/tests/aws/requests/sns/topic_lifecycle_tests.rb +++ /dev/null @@ -1,28 +0,0 @@ -Shindo.tests('AWS::SES | topic lifecycle tests', ['aws', 'sns']) do - - tests('success') do - - tests("#create_topic('TopicArn' => 'example-topic')").formats(AWS::SNS::Formats::BASIC.merge('TopicArn' => String)) do - pending if Fog.mocking? - body = AWS[:sns].create_topic('Name' => 'example-topic').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("#delete_topic('TopicArn' => 'example-topic')").formats(AWS::SNS::Formats::BASIC) do - pending if Fog.mocking? - AWS[:sns].delete_topic('TopicArn' => @topic_arn).body - end - - end - - tests('failure') do - - 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/queue_tests.rb b/tests/aws/requests/sqs/queue_tests.rb index 00d954460..6ba418e0d 100644 --- a/tests/aws/requests/sqs/queue_tests.rb +++ b/tests/aws/requests/sqs/queue_tests.rb @@ -40,9 +40,9 @@ Shindo.tests('AWS::SQS | queue requests', ['aws']) do } }) - tests("#get_queue_attributes('#{@queue_url}', ['All'])").formats(get_queue_attributes_format) do + 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 + AWS[:sqs].get_queue_attributes(@queue_url, 'All').body end tests("#delete_queue('#{@queue_url}')").formats(AWS::SQS::Formats::BASIC) do From 7cbf1861aaedad39d3b941f74c6539a4b39b7897 Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 20 Jul 2011 11:08:11 -0500 Subject: [PATCH 29/37] [misc] to_json calls to use MultiJson --- bin/fog | 5 ++++- lib/fog/aws/requests/iam/put_group_policy.rb | 2 +- lib/fog/aws/requests/iam/put_user_policy.rb | 2 +- lib/fog/cdn/rackspace.rb | 2 +- lib/fog/compute/bluebox.rb | 2 +- lib/fog/compute/brightbox.rb | 6 +++--- lib/fog/compute/go_grid.rb | 2 +- lib/fog/compute/linode.rb | 2 +- lib/fog/compute/models/aws/server.rb | 2 +- lib/fog/compute/models/bluebox/server.rb | 2 +- lib/fog/compute/models/go_grid/server.rb | 4 ++-- lib/fog/compute/models/rackspace/server.rb | 4 ++-- lib/fog/compute/models/slicehost/server.rb | 2 +- lib/fog/compute/models/virtual_box/server.rb | 4 ++-- lib/fog/compute/ninefold.rb | 2 +- lib/fog/compute/rackspace.rb | 2 +- .../compute/requests/brightbox/activate_console_server.rb | 2 +- .../requests/brightbox/add_listeners_load_balancer.rb | 2 +- .../compute/requests/brightbox/add_nodes_load_balancer.rb | 2 +- lib/fog/compute/requests/brightbox/create_api_client.rb | 2 +- lib/fog/compute/requests/brightbox/create_cloud_ip.rb | 2 +- lib/fog/compute/requests/brightbox/create_image.rb | 2 +- lib/fog/compute/requests/brightbox/create_load_balancer.rb | 2 +- lib/fog/compute/requests/brightbox/create_server.rb | 2 +- lib/fog/compute/requests/brightbox/destroy_api_client.rb | 2 +- lib/fog/compute/requests/brightbox/destroy_cloud_ip.rb | 2 +- lib/fog/compute/requests/brightbox/destroy_image.rb | 2 +- lib/fog/compute/requests/brightbox/destroy_load_balancer.rb | 2 +- lib/fog/compute/requests/brightbox/destroy_server.rb | 2 +- lib/fog/compute/requests/brightbox/get_account.rb | 2 +- lib/fog/compute/requests/brightbox/get_api_client.rb | 2 +- lib/fog/compute/requests/brightbox/get_cloud_ip.rb | 2 +- lib/fog/compute/requests/brightbox/get_image.rb | 2 +- lib/fog/compute/requests/brightbox/get_interface.rb | 2 +- lib/fog/compute/requests/brightbox/get_load_balancer.rb | 2 +- lib/fog/compute/requests/brightbox/get_server.rb | 2 +- lib/fog/compute/requests/brightbox/get_server_type.rb | 2 +- lib/fog/compute/requests/brightbox/get_user.rb | 2 +- lib/fog/compute/requests/brightbox/get_zone.rb | 2 +- lib/fog/compute/requests/brightbox/list_api_clients.rb | 2 +- lib/fog/compute/requests/brightbox/list_cloud_ips.rb | 2 +- lib/fog/compute/requests/brightbox/list_images.rb | 2 +- lib/fog/compute/requests/brightbox/list_load_balancers.rb | 2 +- lib/fog/compute/requests/brightbox/list_server_types.rb | 2 +- lib/fog/compute/requests/brightbox/list_servers.rb | 2 +- lib/fog/compute/requests/brightbox/list_users.rb | 2 +- lib/fog/compute/requests/brightbox/list_zones.rb | 2 +- lib/fog/compute/requests/brightbox/map_cloud_ip.rb | 2 +- .../requests/brightbox/remove_listeners_load_balancer.rb | 2 +- .../requests/brightbox/remove_nodes_load_balancer.rb | 2 +- .../requests/brightbox/reset_ftp_password_account.rb | 2 +- lib/fog/compute/requests/brightbox/resize_server.rb | 2 +- lib/fog/compute/requests/brightbox/shutdown_server.rb | 2 +- lib/fog/compute/requests/brightbox/snapshot_server.rb | 2 +- lib/fog/compute/requests/brightbox/start_server.rb | 2 +- lib/fog/compute/requests/brightbox/stop_server.rb | 2 +- lib/fog/compute/requests/brightbox/unmap_cloud_ip.rb | 2 +- lib/fog/compute/requests/brightbox/update_account.rb | 2 +- lib/fog/compute/requests/brightbox/update_api_client.rb | 2 +- lib/fog/compute/requests/brightbox/update_image.rb | 2 +- lib/fog/compute/requests/brightbox/update_load_balancer.rb | 2 +- lib/fog/compute/requests/brightbox/update_server.rb | 2 +- lib/fog/compute/requests/brightbox/update_user.rb | 2 +- .../requests/linode/linode_disk_createfromstackscript.rb | 2 +- lib/fog/compute/requests/rackspace/create_image.rb | 2 +- lib/fog/compute/requests/rackspace/create_server.rb | 2 +- lib/fog/compute/requests/rackspace/server_action.rb | 4 ++-- lib/fog/compute/requests/rackspace/update_server.rb | 2 +- .../compute/requests/storm_on_demand/add_balancer_node.rb | 2 +- lib/fog/compute/requests/storm_on_demand/clone_server.rb | 2 +- lib/fog/compute/requests/storm_on_demand/create_server.rb | 2 +- lib/fog/compute/requests/storm_on_demand/delete_server.rb | 2 +- lib/fog/compute/requests/storm_on_demand/get_server.rb | 2 +- lib/fog/compute/requests/storm_on_demand/get_stats.rb | 2 +- lib/fog/compute/requests/storm_on_demand/list_balancers.rb | 2 +- lib/fog/compute/requests/storm_on_demand/list_configs.rb | 2 +- lib/fog/compute/requests/storm_on_demand/list_images.rb | 2 +- .../compute/requests/storm_on_demand/list_private_ips.rb | 2 +- lib/fog/compute/requests/storm_on_demand/list_servers.rb | 2 +- lib/fog/compute/requests/storm_on_demand/list_templates.rb | 2 +- lib/fog/compute/requests/storm_on_demand/reboot_server.rb | 2 +- .../requests/storm_on_demand/remove_balancer_node.rb | 2 +- lib/fog/compute/requests/storm_on_demand/resize_server.rb | 2 +- lib/fog/compute/storm_on_demand.rb | 2 +- lib/fog/core/collection.rb | 2 +- lib/fog/core/model.rb | 2 +- lib/fog/dns/dnsimple.rb | 2 +- lib/fog/dns/dnsmadeeasy.rb | 2 +- lib/fog/dns/linode.rb | 2 +- lib/fog/dns/requests/dnsimple/create_domain.rb | 2 +- lib/fog/dns/requests/dnsimple/create_record.rb | 2 +- lib/fog/dns/requests/dnsimple/update_record.rb | 2 +- lib/fog/dns/requests/dnsmadeeasy/create_record.rb | 2 +- lib/fog/dns/requests/dnsmadeeasy/create_secondary.rb | 2 +- lib/fog/dns/requests/dnsmadeeasy/update_record.rb | 2 +- lib/fog/dns/requests/dnsmadeeasy/update_secondary.rb | 2 +- lib/fog/storage/rackspace.rb | 2 +- lib/fog/storage/requests/aws/get_bucket_policy.rb | 2 +- lib/fog/storage/requests/aws/post_object_hidden_fields.rb | 2 +- lib/fog/storage/requests/aws/put_bucket_policy.rb | 2 +- tests/aws/requests/sns/subscription_tests.rb | 4 ++-- 101 files changed, 111 insertions(+), 108 deletions(-) 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/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/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/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/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/core/collection.rb b/lib/fog/core/collection.rb index 15d6f26e0..eca40d970 100644 --- a/lib/fog/core/collection.rb +++ b/lib/fog/core/collection.rb @@ -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/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/requests/sns/subscription_tests.rb b/tests/aws/requests/sns/subscription_tests.rb index dff251d6a..54b377d06 100644 --- a/tests/aws/requests/sns/subscription_tests.rb +++ b/tests/aws/requests/sns/subscription_tests.rb @@ -7,7 +7,7 @@ Shindo.tests('AWS::SES | topic lifecycle tests', ['aws', 'sns']) do AWS[:sqs].set_queue_attributes( @queue_url, 'Policy', - ::MultiJson.encode({ + MultiJson.encode({ 'Id' => @topic_arn, 'Statement' => { 'Action' => 'sqs:SendMessage', @@ -60,7 +60,7 @@ Shindo.tests('AWS::SES | topic lifecycle tests', ['aws', 'sns']) do Fog.wait_for do message = AWS[:sqs].receive_message(@queue_url).body['Message'].first end - ::MultiJson.decode(message['Body'])['Message'] + MultiJson.decode(message['Body'])['Message'] end tests("#unsubscribe('#{@subscription_arn}')").formats(AWS::SNS::Formats::BASIC) do From 1aa69c83a29bc84400a0cf747aebc1da57051e92 Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 20 Jul 2011 12:08:48 -0500 Subject: [PATCH 30/37] [aws|elb] fix listener defaults to use merge_attributes and therefore aliases --- lib/fog/aws/models/elb/listener.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 2da3af865f4c34e61fa57fab57c1e753a765d257 Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 20 Jul 2011 12:09:13 -0500 Subject: [PATCH 31/37] [aws|simpledb] fix get_attributes mock deprecation --- lib/fog/aws/requests/simpledb/get_attributes.rb | 2 +- tests/aws/requests/simpledb/attributes_tests.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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/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 From 7620662c878934708b9f625202c25187d00e7dec Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 20 Jul 2011 12:11:10 -0500 Subject: [PATCH 32/37] [tests] make unimplemented mock tests pending --- lib/fog/compute/vcloud.rb | 6 +++-- .../get_metric_statistics_tests.rb | 6 ++--- .../requests/cloud_watch/list_metrics_test.rb | 14 +++++++----- .../cloud_watch/put_metric_data_tests.rb | 17 ++++++++------ tests/aws/requests/elb/listener_tests.rb | 1 - tests/aws/requests/sns/subscription_tests.rb | 5 +++++ tests/compute/models/vcloud/helper.rb | 22 ++++++++++++++----- tests/compute/requests/aws/address_tests.rb | 2 +- .../requests/vcloud/disk_configure_tests.rb | 15 +++++++++---- tests/helpers/formats_helper_tests.rb | 4 ---- tests/helpers/mock_helper.rb | 5 +++++ .../models/ninefold/file_update_tests.rb | 1 + .../ninefold/nested_directories_tests.rb | 4 ++++ .../requests/rackspace/large_object_tests.rb | 18 +++++++++------ 14 files changed, 80 insertions(+), 40 deletions(-) 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/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 9c4d0c9fb..0208149c6 100644 --- a/tests/aws/requests/elb/listener_tests.rb +++ b/tests/aws/requests/elb/listener_tests.rb @@ -12,7 +12,6 @@ Shindo.tests('AWS::ELB | listener_tests', ['aws', 'elb']) do {'Protocol' => 'HTTP', 'LoadBalancerPort' => 80, 'InstancePort' => 80} ] response = AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body - puts response.inspect response end diff --git a/tests/aws/requests/sns/subscription_tests.rb b/tests/aws/requests/sns/subscription_tests.rb index 54b377d06..028eccece 100644 --- a/tests/aws/requests/sns/subscription_tests.rb +++ b/tests/aws/requests/sns/subscription_tests.rb @@ -44,18 +44,22 @@ Shindo.tests('AWS::SES | topic lifecycle tests', ['aws', 'sns']) do }) 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 @@ -64,6 +68,7 @@ Shindo.tests('AWS::SES | topic lifecycle tests', ['aws', 'sns']) do end tests("#unsubscribe('#{@subscription_arn}')").formats(AWS::SNS::Formats::BASIC) do + pending if Fog.mocking? AWS[:sns].unsubscribe(@subscription_arn).body end 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/helpers/formats_helper_tests.rb b/tests/helpers/formats_helper_tests.rb index 37813294c..64ff8cc93 100644 --- a/tests/helpers/formats_helper_tests.rb +++ b/tests/helpers/formats_helper_tests.rb @@ -16,10 +16,6 @@ Shindo.tests('test_helper', 'meta') do formats_kernel({:a => {:b => :c}}, {:a => {:b => Symbol}}) end - test('when format of nested hash with anonymous key and value') do - formats_kernel({:a => {:b => :c}}, {:a => {Symbol => Symbol}}) - end - test('when format of an array') do formats_kernel([{:a => :b}], [{:a => Symbol}]) 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 From 8be455e4a7f730052dfbc0618a10c8b731500d96 Mon Sep 17 00:00:00 2001 From: geemus Date: Thu, 28 Apr 2011 22:29:48 -0700 Subject: [PATCH 33/37] make collection class_eval more consistent --- lib/fog/core/collection.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fog/core/collection.rb b/lib/fog/core/collection.rb index eca40d970..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) From 8923984644f0d171c786f17c1fe07d112684d72d Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 20 Jul 2011 16:51:12 -0500 Subject: [PATCH 34/37] [misc] update gem deps to latest/greatest --- fog.gemspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From 21606743c24996603463301957522c48f26f0c1a Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 20 Jul 2011 17:11:15 -0500 Subject: [PATCH 35/37] [release] remove problematic pbcopy from changelog rake task --- Rakefile | 3 --- 1 file changed, 3 deletions(-) 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 From 72778886a10c04647edbe1ddc4c180bcde9e991e Mon Sep 17 00:00:00 2001 From: Brian Hartsock Date: Wed, 20 Jul 2011 18:18:05 -0400 Subject: [PATCH 36/37] Fixed #444 - Unable to squash kvp with false values --- lib/fog/core/attributes.rb | 6 ++++-- tests/core/attribute_tests.rb | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) 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/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 From cb8004024e6bbdad39058918f33190812e90e9cc Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 20 Jul 2011 17:34:18 -0500 Subject: [PATCH 37/37] [tests] fix collection helper to play nice with numeric ids --- tests/helpers/collection_helper.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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