From 5b66328a70f322e98b4d478d0d8174e773b4b881 Mon Sep 17 00:00:00 2001 From: Benton Roberts Date: Tue, 27 Sep 2011 11:03:11 -0400 Subject: [PATCH] [aws|elasticache] refactor acs->elasticache --- lib/fog/aws/{acs.rb => elasticache.rb} | 4 +-- .../{acs => elasticache}/security_group.rb | 0 .../{acs => elasticache}/security_groups.rb | 8 ++--- .../authorize_cache_security_group_ingress.rb | 6 ++-- lib/fog/aws/parsers/elasticache/base.rb | 34 +++++++++++++++++++ .../describe_security_groups.rb | 4 +-- .../security_group_parser.rb | 3 +- .../single_security_group.rb | 4 +-- .../authorize_cache_security_group_ingress.rb | 6 ++-- .../create_cache_security_group.rb | 6 ++-- .../delete_cache_security_group.rb | 31 +++++++++++++++++ .../describe_cache_security_groups.rb | 6 ++-- .../revoke_cache_security_group_ingress.rb | 6 ++-- lib/fog/bin/aws.rb | 8 ++--- .../{acs => elasticache}/security_groups.rb | 8 ++--- .../requests/{acs => elasticache}/helper.rb | 2 +- .../security_group_tests.rb | 30 ++++++++-------- 17 files changed, 116 insertions(+), 50 deletions(-) rename lib/fog/aws/{acs.rb => elasticache.rb} (97%) rename lib/fog/aws/models/{acs => elasticache}/security_group.rb (100%) rename lib/fog/aws/models/{acs => elasticache}/security_groups.rb (73%) rename lib/fog/aws/parsers/{acs => elasticache}/authorize_cache_security_group_ingress.rb (75%) create mode 100644 lib/fog/aws/parsers/elasticache/base.rb rename lib/fog/aws/parsers/{acs => elasticache}/describe_security_groups.rb (84%) rename lib/fog/aws/parsers/{acs => elasticache}/security_group_parser.rb (92%) rename lib/fog/aws/parsers/{acs => elasticache}/single_security_group.rb (87%) rename lib/fog/aws/requests/{acs => elasticache}/authorize_cache_security_group_ingress.rb (85%) rename lib/fog/aws/requests/{acs => elasticache}/create_cache_security_group.rb (82%) create mode 100644 lib/fog/aws/requests/elasticache/delete_cache_security_group.rb rename lib/fog/aws/requests/{acs => elasticache}/describe_cache_security_groups.rb (82%) rename lib/fog/aws/requests/{acs => elasticache}/revoke_cache_security_group_ingress.rb (85%) rename tests/aws/models/{acs => elasticache}/security_groups.rb (69%) rename tests/aws/requests/{acs => elasticache}/helper.rb (95%) rename tests/aws/requests/{acs => elasticache}/security_group_tests.rb (62%) diff --git a/lib/fog/aws/acs.rb b/lib/fog/aws/elasticache.rb similarity index 97% rename from lib/fog/aws/acs.rb rename to lib/fog/aws/elasticache.rb index 9ef6c1d80..24d519bfd 100644 --- a/lib/fog/aws/acs.rb +++ b/lib/fog/aws/elasticache.rb @@ -7,7 +7,7 @@ module Fog requires :aws_access_key_id, :aws_secret_access_key recognizes :region, :host, :path, :port, :scheme, :persistent - request_path 'fog/aws/requests/acs' + request_path 'fog/aws/requests/elasticache' #request :create_cache_cluster #request :delete_cache_cluster @@ -31,7 +31,7 @@ module Fog #request :describe_events - model_path 'fog/aws/models/acs' + model_path 'fog/aws/models/elasticache' # model :server # collection :servers model :security_group diff --git a/lib/fog/aws/models/acs/security_group.rb b/lib/fog/aws/models/elasticache/security_group.rb similarity index 100% rename from lib/fog/aws/models/acs/security_group.rb rename to lib/fog/aws/models/elasticache/security_group.rb diff --git a/lib/fog/aws/models/acs/security_groups.rb b/lib/fog/aws/models/elasticache/security_groups.rb similarity index 73% rename from lib/fog/aws/models/acs/security_groups.rb rename to lib/fog/aws/models/elasticache/security_groups.rb index cf06dbc1a..e6b0dc91a 100644 --- a/lib/fog/aws/models/acs/security_groups.rb +++ b/lib/fog/aws/models/elasticache/security_groups.rb @@ -1,12 +1,12 @@ require 'fog/core/collection' -require 'fog/aws/models/acs/security_group' +require 'fog/aws/models/elasticache/security_group' module Fog module AWS - class ACS + class Elasticache class SecurityGroups < Fog::Collection - model Fog::AWS::ACS::SecurityGroup + model Fog::AWS::Elasticache::SecurityGroup def all data = connection.describe_cache_security_groups.body['CacheSecurityGroups'] @@ -16,7 +16,7 @@ module Fog def get(identity) data = connection.describe_cache_security_groups('CacheSecurityGroupName' => identity).body['CacheSecurityGroups'].first new(data) - rescue Fog::AWS::ACS::NotFound + rescue Fog::AWS::Elasticache::NotFound nil end end diff --git a/lib/fog/aws/parsers/acs/authorize_cache_security_group_ingress.rb b/lib/fog/aws/parsers/elasticache/authorize_cache_security_group_ingress.rb similarity index 75% rename from lib/fog/aws/parsers/acs/authorize_cache_security_group_ingress.rb rename to lib/fog/aws/parsers/elasticache/authorize_cache_security_group_ingress.rb index 51113c7ce..c3aaf99d8 100644 --- a/lib/fog/aws/parsers/acs/authorize_cache_security_group_ingress.rb +++ b/lib/fog/aws/parsers/elasticache/authorize_cache_security_group_ingress.rb @@ -1,11 +1,11 @@ module Fog module Parsers module AWS - module ACS + module Elasticache - require 'fog/aws/parsers/acs/security_group_parser' + require 'fog/aws/parsers/elasticache/security_group_parser' - class AuthorizeCacheSecurityGroupIngress < Fog::Parsers::AWS::ACS::SecurityGroupParser + class AuthorizeCacheSecurityGroupIngress < Fog::Parsers::AWS::Elasticache::SecurityGroupParser def end_element(name) case name diff --git a/lib/fog/aws/parsers/elasticache/base.rb b/lib/fog/aws/parsers/elasticache/base.rb new file mode 100644 index 000000000..6e5238c01 --- /dev/null +++ b/lib/fog/aws/parsers/elasticache/base.rb @@ -0,0 +1,34 @@ +module Fog + module Parsers + module AWS + module Elasticache + + require 'fog/aws/parsers/elasticache/base' + + # Base parser for ResponseMetadata, RequestId + class Base < Fog::Parsers::Base + + def reset + super + @response = { 'ResponseMetadata' => {} } + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = value + else + super + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/acs/describe_security_groups.rb b/lib/fog/aws/parsers/elasticache/describe_security_groups.rb similarity index 84% rename from lib/fog/aws/parsers/acs/describe_security_groups.rb rename to lib/fog/aws/parsers/elasticache/describe_security_groups.rb index 8ccd3488a..70942a4e1 100644 --- a/lib/fog/aws/parsers/acs/describe_security_groups.rb +++ b/lib/fog/aws/parsers/elasticache/describe_security_groups.rb @@ -1,8 +1,8 @@ module Fog module Parsers module AWS - module ACS - require 'fog/aws/parsers/acs/security_group_parser' + module Elasticache + require 'fog/aws/parsers/elasticache/security_group_parser' class DescribeSecurityGroups < SecurityGroupParser diff --git a/lib/fog/aws/parsers/acs/security_group_parser.rb b/lib/fog/aws/parsers/elasticache/security_group_parser.rb similarity index 92% rename from lib/fog/aws/parsers/acs/security_group_parser.rb rename to lib/fog/aws/parsers/elasticache/security_group_parser.rb index cf577121b..b33ec87e1 100644 --- a/lib/fog/aws/parsers/acs/security_group_parser.rb +++ b/lib/fog/aws/parsers/elasticache/security_group_parser.rb @@ -1,7 +1,8 @@ module Fog module Parsers module AWS - module ACS + module Elasticache + require 'fog/aws/parsers/elasticache/base' class SecurityGroupParser < Fog::Parsers::Base diff --git a/lib/fog/aws/parsers/acs/single_security_group.rb b/lib/fog/aws/parsers/elasticache/single_security_group.rb similarity index 87% rename from lib/fog/aws/parsers/acs/single_security_group.rb rename to lib/fog/aws/parsers/elasticache/single_security_group.rb index 8e7b638a1..5d80778b0 100644 --- a/lib/fog/aws/parsers/acs/single_security_group.rb +++ b/lib/fog/aws/parsers/elasticache/single_security_group.rb @@ -1,8 +1,8 @@ module Fog module Parsers module AWS - module ACS - require 'fog/aws/parsers/acs/security_group_parser' + module Elasticache + require 'fog/aws/parsers/elasticache/security_group_parser' class SingleSecurityGroup < SecurityGroupParser diff --git a/lib/fog/aws/requests/acs/authorize_cache_security_group_ingress.rb b/lib/fog/aws/requests/elasticache/authorize_cache_security_group_ingress.rb similarity index 85% rename from lib/fog/aws/requests/acs/authorize_cache_security_group_ingress.rb rename to lib/fog/aws/requests/elasticache/authorize_cache_security_group_ingress.rb index a3a4b4185..06b19d6f4 100644 --- a/lib/fog/aws/requests/acs/authorize_cache_security_group_ingress.rb +++ b/lib/fog/aws/requests/elasticache/authorize_cache_security_group_ingress.rb @@ -1,9 +1,9 @@ module Fog module AWS - class ACS + class Elasticache class Real - require 'fog/aws/parsers/acs/single_security_group' + require 'fog/aws/parsers/elasticache/single_security_group' # Authorize ingress to a CacheSecurityGroup using EC2 Security Groups # @@ -20,7 +20,7 @@ module Fog 'CacheSecurityGroupName' => name, 'EC2SecurityGroupName' => ec2_name, 'EC2SecurityGroupOwnerId' => ec2_owner_id, - :parser => Fog::Parsers::AWS::ACS::SingleSecurityGroup.new + :parser => Fog::Parsers::AWS::Elasticache::SingleSecurityGroup.new }) end diff --git a/lib/fog/aws/requests/acs/create_cache_security_group.rb b/lib/fog/aws/requests/elasticache/create_cache_security_group.rb similarity index 82% rename from lib/fog/aws/requests/acs/create_cache_security_group.rb rename to lib/fog/aws/requests/elasticache/create_cache_security_group.rb index 7c504cb2e..296218e78 100644 --- a/lib/fog/aws/requests/acs/create_cache_security_group.rb +++ b/lib/fog/aws/requests/elasticache/create_cache_security_group.rb @@ -1,9 +1,9 @@ module Fog module AWS - class ACS + class Elasticache class Real - require 'fog/aws/parsers/acs/single_security_group' + require 'fog/aws/parsers/elasticache/single_security_group' # creates a cache security group # @@ -18,7 +18,7 @@ module Fog 'Action' => 'CreateCacheSecurityGroup', 'CacheSecurityGroupName' => name, 'Description' => description, - :parser => Fog::Parsers::AWS::ACS::SingleSecurityGroup.new + :parser => Fog::Parsers::AWS::Elasticache::SingleSecurityGroup.new }) end end diff --git a/lib/fog/aws/requests/elasticache/delete_cache_security_group.rb b/lib/fog/aws/requests/elasticache/delete_cache_security_group.rb new file mode 100644 index 000000000..840f9d568 --- /dev/null +++ b/lib/fog/aws/requests/elasticache/delete_cache_security_group.rb @@ -0,0 +1,31 @@ +module Fog + module AWS + class Elasticache + class Real + + require 'fog/aws/parsers/elasticache/base' + + # deletes a cache security group + # + # === Parameters + # * name <~String> - The name for the Cache Security Group + # === Returns + # * response <~Excon::Response>: + # * body <~Hash> + def delete_cache_security_group(name) + request({ + 'Action' => 'DeleteCacheSecurityGroup', + 'CacheSecurityGroupName' => name, + :parser => Fog::Parsers::AWS::Elasticache::Base.new + }) + end + end + + class Mock + def delete_cache_security_group(name) + Fog::Mock.not_implemented + end + end + end + end +end diff --git a/lib/fog/aws/requests/acs/describe_cache_security_groups.rb b/lib/fog/aws/requests/elasticache/describe_cache_security_groups.rb similarity index 82% rename from lib/fog/aws/requests/acs/describe_cache_security_groups.rb rename to lib/fog/aws/requests/elasticache/describe_cache_security_groups.rb index a71e94ee5..707c96fca 100644 --- a/lib/fog/aws/requests/acs/describe_cache_security_groups.rb +++ b/lib/fog/aws/requests/elasticache/describe_cache_security_groups.rb @@ -1,9 +1,9 @@ module Fog module AWS - class ACS + class Elasticache class Real - require 'fog/aws/parsers/acs/describe_security_groups' + require 'fog/aws/parsers/elasticache/describe_security_groups' # Returns a list of CacheSecurityGroup descriptions # @@ -18,7 +18,7 @@ module Fog def describe_cache_security_groups(options = {}) request({ 'Action' => 'DescribeCacheSecurityGroups', - :parser => Fog::Parsers::AWS::ACS::DescribeSecurityGroups.new + :parser => Fog::Parsers::AWS::Elasticache::DescribeSecurityGroups.new }.merge(options)) end diff --git a/lib/fog/aws/requests/acs/revoke_cache_security_group_ingress.rb b/lib/fog/aws/requests/elasticache/revoke_cache_security_group_ingress.rb similarity index 85% rename from lib/fog/aws/requests/acs/revoke_cache_security_group_ingress.rb rename to lib/fog/aws/requests/elasticache/revoke_cache_security_group_ingress.rb index 5f87667f2..7607b588a 100644 --- a/lib/fog/aws/requests/acs/revoke_cache_security_group_ingress.rb +++ b/lib/fog/aws/requests/elasticache/revoke_cache_security_group_ingress.rb @@ -1,10 +1,10 @@ module Fog module AWS - class ACS + class Elasticache class Real - require 'fog/aws/parsers/acs/single_security_group' + require 'fog/aws/parsers/elasticache/single_security_group' # Revoke ingress to a CacheSecurityGroup using EC2 Security Groups # @@ -21,7 +21,7 @@ module Fog 'CacheSecurityGroupName' => name, 'EC2SecurityGroupName' => ec2_name, 'EC2SecurityGroupOwnerId' => ec2_owner_id, - :parser => Fog::Parsers::AWS::ACS::SingleSecurityGroup.new + :parser => Fog::Parsers::AWS::Elasticache::SingleSecurityGroup.new }) end diff --git a/lib/fog/bin/aws.rb b/lib/fog/bin/aws.rb index d55a6c182..cb746a5df 100644 --- a/lib/fog/bin/aws.rb +++ b/lib/fog/bin/aws.rb @@ -3,8 +3,8 @@ class AWS < Fog::Bin def class_for(key) case key - when :acs - Fog::AWS::ACS + when :elasticache + Fog::AWS::Elasticache when :auto_scaling Fog::AWS::AutoScaling when :cdn @@ -44,8 +44,8 @@ class AWS < Fog::Bin def [](service) @@connections ||= Hash.new do |hash, key| hash[key] = case key - when :acs - Fog::AWS::ACS.new + when :elasticache + Fog::AWS::Elasticache.new when :auto_scaling Fog::AWS::AutoScaling.new when :cdn diff --git a/tests/aws/models/acs/security_groups.rb b/tests/aws/models/elasticache/security_groups.rb similarity index 69% rename from tests/aws/models/acs/security_groups.rb rename to tests/aws/models/elasticache/security_groups.rb index 4f2773355..b93176f16 100644 --- a/tests/aws/models/acs/security_groups.rb +++ b/tests/aws/models/elasticache/security_groups.rb @@ -1,13 +1,13 @@ -Shindo.tests('AWS::ACS | security groups', ['aws', 'acs']) do +Shindo.tests('AWS::Elasticache | security groups', ['aws', 'elasticache']) do group_name = 'fog-test' description = 'Fog Test' pending if Fog.mocking? - model_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false) do + model_tests(AWS[:elasticache].security_groups, {:id => group_name, :description => description}, false) do # An EC2 group to authorize - ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-acs', :description => 'fog test') + ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-elasticache', :description => 'fog test') # Reload to get the instance owner_id @instance.reload @@ -29,5 +29,5 @@ Shindo.tests('AWS::ACS | security groups', ['aws', 'acs']) do ec2_group.destroy end - collection_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false) + collection_tests(AWS[:elasticache].security_groups, {:id => group_name, :description => description}, false) end diff --git a/tests/aws/requests/acs/helper.rb b/tests/aws/requests/elasticache/helper.rb similarity index 95% rename from tests/aws/requests/acs/helper.rb rename to tests/aws/requests/elasticache/helper.rb index e6cdfca75..bc10d55b9 100644 --- a/tests/aws/requests/acs/helper.rb +++ b/tests/aws/requests/elasticache/helper.rb @@ -1,5 +1,5 @@ class AWS - module ACS + module Elasticache module Formats BASIC = { diff --git a/tests/aws/requests/acs/security_group_tests.rb b/tests/aws/requests/elasticache/security_group_tests.rb similarity index 62% rename from tests/aws/requests/acs/security_group_tests.rb rename to tests/aws/requests/elasticache/security_group_tests.rb index e443c3752..f986f5a53 100644 --- a/tests/aws/requests/acs/security_group_tests.rb +++ b/tests/aws/requests/elasticache/security_group_tests.rb @@ -1,4 +1,4 @@ -Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do +Shindo.tests('AWS::Elasticache | security group requests', ['aws', 'elasticache']) do tests('success') do pending if Fog.mocking? @@ -6,8 +6,8 @@ Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do name = 'fog-test' description = 'Fog Test Group' - tests('#create_cache_security_group').formats(AWS::ACS::Formats::SINGLE_SECURITY_GROUP) do - body = AWS[:acs].create_cache_security_group(name, description).body + tests('#create_cache_security_group').formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do + body = AWS[:elasticache].create_cache_security_group(name, description).body group = body['CacheSecurityGroup'] returns(name) { group['CacheSecurityGroupName'] } returns(description) { group['Description'] } @@ -15,28 +15,28 @@ Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do body end - tests('#describe_cache_security_groups without options').formats(AWS::ACS::Formats::DESCRIBE_SECURITY_GROUPS) do - body = AWS[:acs].describe_cache_security_groups.body + tests('#describe_cache_security_groups without options').formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do + body = AWS[:elasticache].describe_cache_security_groups.body returns(true, "has #{name}") do body['CacheSecurityGroups'].any? {|group| group['CacheSecurityGroupName'] == name } end body end - tests('#describe_cache_security_groups with name').formats(AWS::ACS::Formats::DESCRIBE_SECURITY_GROUPS) do - body = AWS[:acs].describe_cache_security_groups('CacheSecurityGroupName' => name).body + tests('#describe_cache_security_groups with name').formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do + body = AWS[:elasticache].describe_cache_security_groups('CacheSecurityGroupName' => name).body returns(1, "size of 1") { body['CacheSecurityGroups'].size } returns(name, "has #{name}") { body['CacheSecurityGroups'].first['CacheSecurityGroupName'] } body end tests('authorization') do - ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-acs', :description => 'Fog Test ACS') + ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-elasticache', :description => 'Fog Test Elasticache') # Reload to get the owner_id ec2_group.reload - tests('#authorize_cache_security_group_ingress').formats(AWS::ACS::Formats::SINGLE_SECURITY_GROUP) do - body = AWS[:acs].authorize_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body + tests('#authorize_cache_security_group_ingress').formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do + body = AWS[:elasticache].authorize_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body group = body['CacheSecurityGroup'] expected_ec2_groups = [{'Status' => 'authorizing', 'EC2SecurityGroupName' => ec2_group.name, 'EC2SecurityGroupOwnerId' => ec2_group.owner_id}] returns(expected_ec2_groups, 'has correct EC2 groups') { group['EC2SecurityGroups'] } @@ -45,12 +45,12 @@ Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do # Wait for the state to be active Fog.wait_for do - group = AWS[:acs].describe_cache_security_groups('CacheSecurityGroupName' => name).body['CacheSecurityGroups'].first + group = AWS[:elasticache].describe_cache_security_groups('CacheSecurityGroupName' => name).body['CacheSecurityGroups'].first group['EC2SecurityGroups'].all? {|ec2| ec2['Status'] == 'authorized'} end - tests('#revoke_cache_security_group_ingress').formats(AWS::ACS::Formats::SINGLE_SECURITY_GROUP) do - body = AWS[:acs].revoke_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body + tests('#revoke_cache_security_group_ingress').formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do + body = AWS[:elasticache].revoke_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body group = body['CacheSecurityGroup'] expected_ec2_groups = [{'Status' => 'revoking', 'EC2SecurityGroupName' => ec2_group.name, 'EC2SecurityGroupOwnerId' => ec2_group.owner_id}] returns(expected_ec2_groups, 'has correct EC2 groups') { group['EC2SecurityGroups'] } @@ -61,8 +61,8 @@ Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do ec2_group.destroy end - tests('#delete_cache_security_group').formats(AWS::ACS::Formats::BASIC) do - body = AWS[:acs].delete_cache_security_group(name).body + tests('#delete_cache_security_group').formats(AWS::Elasticache::Formats::BASIC) do + body = AWS[:elasticache].delete_cache_security_group(name).body end end