mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add fog Elasticache security group mocking
This commit is contained in:
parent
bf7d348d88
commit
826d3bb361
4 changed files with 86 additions and 6 deletions
|
@ -130,6 +130,7 @@ module Fog
|
|||
hash[region] = Hash.new do |region_hash, key|
|
||||
region_hash[key] = {
|
||||
:clusters => {}, # cache cluster data, indexed by cluster ID
|
||||
:security_groups => {}, # security groups
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,8 +27,33 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
def authorize_cache_security_group_ingress
|
||||
Fog::Mock.not_implemented
|
||||
|
||||
def authorize_cache_security_group_ingress(name, opts = {})
|
||||
unless (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId'))
|
||||
raise ArgumentError, 'Must specify and EC2SecurityGroupName and EC2SecurityGroupOwnerId'
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if sec_group = self.data[:security_groups][name]
|
||||
|
||||
if sec_group['EC2SecurityGroups'].detect{|h| h['EC2SecurityGroupName'] == opts['EC2SecurityGroupName']}
|
||||
raise Fog::AWS::Elasticache::AuthorizationAlreadyExists.new("AuthorizationAlreadyExists => #{opts['EC2SecurityGroupName']} is alreay defined")
|
||||
end
|
||||
sec_group['EC2SecurityGroups'] << opts.merge({"Status" => 'authorizing'})
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
|
||||
'AuthorizeDBSecurityGroupIngressResult' => {
|
||||
'DBSecurityGroup' => sec_group
|
||||
}
|
||||
}
|
||||
response
|
||||
else
|
||||
raise Fog::AWS::Elasticache::NotFound.new("DBSecurityGroupNotFound => #{name} not found")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,8 +24,26 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
def create_cache_security_group(name, desciption=name)
|
||||
Fog::Mock.not_implemented
|
||||
def create_cache_security_group(name, description = name)
|
||||
response = Excon::Response.new
|
||||
if self.data[:security_groups] and
|
||||
self.data[:security_groups][name]
|
||||
raise Fog::AWS::Elasticache::IdentifierTaken.new("CacheClusterAlreadyExists => The security group '#{name}' already exists")
|
||||
end
|
||||
|
||||
data = {
|
||||
'CacheSecurityGroupName' => name,
|
||||
'Description' => description,
|
||||
'EC2SecurityGroups' => [],
|
||||
'OwnerId' => '0123456789'
|
||||
}
|
||||
self.data[:security_groups][name] = data
|
||||
response.body = {
|
||||
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
|
||||
'CreateCacheSecurityGroupResult' => { 'DBSecurityGroup' => data }
|
||||
}
|
||||
response
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,8 +25,44 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
def describe_cache_security_groups(name = nil, options = {})
|
||||
Fog::Mock.not_implemented
|
||||
def describe_cache_security_groups(opts={})
|
||||
response = Excon::Response.new
|
||||
sec_group_set = []
|
||||
if opts.is_a?(String)
|
||||
sec_group_name = opts
|
||||
if sec_group = self.data[:security_groups][sec_group_name]
|
||||
sec_group_set << sec_group
|
||||
else
|
||||
raise Fog::AWS::Elasticache::NotFound.new("Security Group #{sec_group_name} not found")
|
||||
end
|
||||
else
|
||||
sec_group_set = self.data[:security_groups].values
|
||||
end
|
||||
|
||||
# TODO: refactor to not delete items that we're iterating over. Causes
|
||||
# model tests to fail (currently pending)
|
||||
sec_group_set.each do |sec_group|
|
||||
|
||||
# TODO: refactor to not delete items that we're iterating over. Causes
|
||||
# model tests to fail (currently pending)
|
||||
sec_group["EC2SecurityGroups"].each do |ec2_secg|
|
||||
if ec2_secg["Status"] == "authorizing" || ec2_secg["Status"] == "revoking"
|
||||
ec2_secg[:tmp] ||= Time.now + Fog::Mock.delay * 2
|
||||
if ec2_secg[:tmp] <= Time.now
|
||||
ec2_secg["Status"] = "authorized" if ec2_secg["Status"] == "authorizing"
|
||||
ec2_secg.delete(:tmp)
|
||||
sec_group["EC2SecurityGroups"].delete(ec2_secg) if ec2_secg["Status"] == "revoking"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
|
||||
"CacheSecurityGroups" => sec_group_set
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue