2011-03-08 11:11:38 -05:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class RDS
|
|
|
|
class Real
|
|
|
|
|
|
|
|
require 'fog/aws/parsers/rds/describe_db_security_groups'
|
|
|
|
|
2012-02-25 19:03:05 -05:00
|
|
|
# Describe all or specified db security groups
|
2011-03-08 11:11:38 -05:00
|
|
|
# http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/index.html?API_DescribeDBSecurityGroups.html
|
|
|
|
# ==== Parameters
|
|
|
|
# * DBSecurityGroupName <~String> - The name of the DB Security Group to return details for.
|
|
|
|
# * Marker <~String> - An optional marker provided in the previous DescribeDBInstances request
|
|
|
|
# * MaxRecords <~Integer> - Max number of records to return (between 20 and 100)
|
|
|
|
# Only one of DBInstanceIdentifier or DBSnapshotIdentifier can be specified
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
def describe_db_security_groups(opts={})
|
|
|
|
opts = {'DBSecurityGroupName' => opts} if opts.is_a?(String)
|
|
|
|
|
|
|
|
request({
|
|
|
|
'Action' => 'DescribeDBSecurityGroups',
|
|
|
|
:parser => Fog::Parsers::AWS::RDS::DescribeDBSecurityGroups.new
|
|
|
|
}.merge(opts))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
2012-02-25 18:55:16 -05:00
|
|
|
def describe_db_security_groups(opts={})
|
2011-12-27 17:37:04 -05:00
|
|
|
response = Excon::Response.new
|
|
|
|
sec_group_set = []
|
|
|
|
if opts.is_a?(String)
|
2012-02-25 18:55:16 -05:00
|
|
|
sec_group_name = opts
|
2011-12-27 17:37:04 -05:00
|
|
|
if sec_group = self.data[:security_groups][sec_group_name]
|
|
|
|
sec_group_set << sec_group
|
|
|
|
else
|
|
|
|
raise Fog::AWS::RDS::NotFound.new("Security Group #{sec_group_name} not found")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
sec_group_set = self.data[:security_groups].values
|
|
|
|
end
|
2012-02-25 18:55:16 -05:00
|
|
|
|
2012-02-26 21:10:42 -05:00
|
|
|
# TODO: refactor to not delete items that we're iterating over. Causes
|
|
|
|
# model tests to fail (currently pending)
|
2011-12-27 17:37:04 -05:00
|
|
|
sec_group_set.each do |sec_group|
|
|
|
|
sec_group["IPRanges"].each do |iprange|
|
|
|
|
if iprange["Status"] == "authorizing" || iprange["Status"] == "revoking"
|
|
|
|
iprange[:tmp] ||= Time.now + Fog::Mock.delay * 2
|
|
|
|
if iprange[:tmp] <= Time.now
|
|
|
|
iprange["Status"] = "authorized" if iprange["Status"] == "authorizing"
|
|
|
|
iprange.delete(:tmp)
|
|
|
|
sec_group["IPRanges"].delete(iprange) if iprange["Status"] == "revoking"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-02-25 18:55:16 -05:00
|
|
|
|
2012-02-26 21:10:42 -05:00
|
|
|
# TODO: refactor to not delete items that we're iterating over. Causes
|
|
|
|
# model tests to fail (currently pending)
|
2011-12-27 17:37:04 -05:00
|
|
|
sec_group["EC2SecurityGroups"].each do |ec2_secg|
|
2012-08-08 21:44:28 -04:00
|
|
|
if ec2_secg["Status"] == "authorizing" || ec2_secg["Status"] == "revoking"
|
2011-12-27 17:37:04 -05:00
|
|
|
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
|
2012-02-25 18:55:16 -05:00
|
|
|
|
2011-12-27 17:37:04 -05:00
|
|
|
response.status = 200
|
|
|
|
response.body = {
|
|
|
|
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
|
|
|
|
"DescribeDBSecurityGroupsResult" => { "DBSecurityGroups" => sec_group_set }
|
|
|
|
}
|
|
|
|
response
|
2011-03-08 11:11:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|