mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|acs] Create ACS security_group model and collection
This commit is contained in:
parent
9f106afcd3
commit
83f1a6adeb
4 changed files with 99 additions and 5 deletions
|
@ -29,11 +29,11 @@ module Fog
|
|||
|
||||
#request :describe_events
|
||||
|
||||
# model_path 'fog/aws/models/acs'
|
||||
model_path 'fog/aws/models/acs'
|
||||
# model :server
|
||||
# collection :servers
|
||||
# model :security_group
|
||||
# collection :security_groups
|
||||
model :security_group
|
||||
collection :security_groups
|
||||
# model :parameter_group
|
||||
# collection :parameter_groups
|
||||
|
||||
|
@ -96,8 +96,20 @@ module Fog
|
|||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
# TODO: handle not found errors
|
||||
raise
|
||||
if match = error.message.match(/<Code>(.*)<\/Code>/m)
|
||||
case match[1]
|
||||
when 'CacheSecurityGroupNotFound'
|
||||
raise Fog::AWS::ACS::NotFound
|
||||
when 'CacheSecurityGroupAlreadyExists'
|
||||
raise Fog::AWS::ACS::IndentifierTaken
|
||||
when 'InvalidParameterValue'
|
||||
raise Fog::AWS::ACE::InvalidInstance
|
||||
else
|
||||
raise
|
||||
end
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
response
|
||||
|
|
42
lib/fog/aws/models/acs/security_group.rb
Normal file
42
lib/fog/aws/models/acs/security_group.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class ACS
|
||||
|
||||
class SecurityGroup < Fog::Model
|
||||
|
||||
identity :id, :aliases => 'CacheSecurityGroupName'
|
||||
attribute :description, :aliases => 'CacheSecurityGroupDescription'
|
||||
attribute :ec2_security_group, :aliases => 'EC2SecurityGroups', :type => :array
|
||||
attribute :owner_id, :aliases => 'OwnerId'
|
||||
|
||||
def ready?
|
||||
ec2_security_groups.all?{|ingress| ingress['Status'] == 'authorized'}
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.delete_cache_security_group(id)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
requires :id
|
||||
requires :description
|
||||
connection.create_cache_security_group(id, description)
|
||||
end
|
||||
|
||||
def authorize_ec2_group(group_name, group_owner_id=owner_id)
|
||||
connection.authorize_ec2_security_group(id, group_name, group_owner_id)
|
||||
end
|
||||
|
||||
def revoke_ec2_group(group_name, group_owner_id=owner_id)
|
||||
connection.revoke_ec2_security_group(id, group_name, group_owner_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/aws/models/acs/security_groups.rb
Normal file
26
lib/fog/aws/models/acs/security_groups.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/aws/models/acs/security_group'
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class ACS
|
||||
|
||||
class SecurityGroups < Fog::Collection
|
||||
model Fog::AWS::ACS::SecurityGroup
|
||||
|
||||
def all
|
||||
data = connection.describe_cache_security_groups.body['CacheSecurityGroups']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(identity)
|
||||
data = connection.describe_cache_security_groups('CacheSecurityGroupName' => identity).body['CacheSecurityGroups'].first
|
||||
new(data)
|
||||
rescue Fog::AWS::ACS::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
14
tests/aws/models/acs/security_groups.rb
Normal file
14
tests/aws/models/acs/security_groups.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
Shindo.tests('AWS::ACS | security groups', ['aws', 'acs']) 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
|
||||
# TODO:
|
||||
# test authorize_ec2_group
|
||||
# test revoke_ec2_group
|
||||
end
|
||||
|
||||
collection_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false)
|
||||
end
|
Loading…
Add table
Reference in a new issue