Method: Fog::AWS::RDS::Mock#describe_db_security_groups

Defined in:
lib/fog/aws/requests/rds/describe_db_security_groups.rb

#describe_db_security_groups(opts = {}) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fog/aws/requests/rds/describe_db_security_groups.rb', line 31

def describe_db_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::RDS::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|
    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

    # 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 },
    "DescribeDBSecurityGroupsResult" => { "DBSecurityGroups" => sec_group_set }
  }
  response
end