File: describe_db_security_groups.rb

package info (click to toggle)
ruby-fog-aws 3.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,092 kB
  • sloc: ruby: 72,795; javascript: 14; makefile: 9; sh: 4
file content (80 lines) | stat: -rw-r--r-- 3,365 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
80
module Fog
  module AWS
    class RDS
      class Real
        require 'fog/aws/parsers/rds/describe_db_security_groups'

        # Describe all or specified db security groups
        # 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
        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
      end
    end
  end
end