File: describe_cache_security_groups.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (64 lines) | stat: -rw-r--r-- 2,575 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
module Fog
  module AWS
    class Elasticache
      class Real
        require 'fog/aws/parsers/elasticache/describe_security_groups'

        # Returns a list of CacheSecurityGroup descriptions
        #
        # === Parameters (optional)
        # * name <~String> - The name of an existing cache security group
        # * options <~Hash> (optional):
        # *  :marker <~String> - marker provided in the previous request
        # *  :max_records <~Integer> - the maximum number of records to include
        def describe_cache_security_groups(name = nil, options = {})
          request({
            'Action'                  => 'DescribeCacheSecurityGroups',
            'CacheSecurityGroupName'  => name,
            'Marker'                  => options[:marker],
            'MaxRecords'              => options[:max_records],
            :parser => Fog::Parsers::AWS::Elasticache::DescribeSecurityGroups.new
          }.merge(options))
        end
      end

      class Mock
        def describe_cache_security_groups(name = nil, opts={})
          if name
            sec_group_set = [self.data[:security_groups][name]].compact
            raise Fog::AWS::Elasticache::NotFound.new("Security Group #{name} not found") if sec_group_set.empty?
          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

          Excon::Response.new(
              {
                  :status => 200,
                  :body => {
                      "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
                      "CacheSecurityGroups" => sec_group_set
                  }
              }
          )
        end
      end
    end
  end
end