File: describe_event_subscriptions.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 (61 lines) | stat: -rw-r--r-- 2,329 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
module Fog
  module AWS
    class RDS
      class Real
        require 'fog/aws/parsers/rds/describe_event_subscriptions'

        # Describe all or specified event notifications
        # http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeEventSubscriptions.html
        # === Parameters
        # * Marker <~String> - An optional pagination token provided by a previous DescribeOrderableDBInstanceOptions request
        # * MaxRecords <~String> - The maximum number of records to include in the response (20-100)
        # * SubscriptionName <~String> - The name of the RDS event notification subscription you want to describe
        # === Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>
        def describe_event_subscriptions(options={})
          if options[:max_records]
            params['MaxRecords'] = options[:max_records]
          end

          request({
            'Action' => 'DescribeEventSubscriptions',
            :parser  => Fog::Parsers::AWS::RDS::DescribeEventSubscriptions.new
          }.merge(options))
        end
      end

      class Mock
        def describe_event_subscriptions(options={})
          response = Excon::Response.new
          name     = options['SubscriptionName']

          subscriptions = self.data[:event_subscriptions].values
          subscriptions = subscriptions.select { |s| s['CustSubscriptionId'] == name } if name

          non_active = self.data[:event_subscriptions].values.select { |s| s['Status'] != 'active' }

          non_active.each do |s|
            name = s['CustSubscriptionId']
            if s['Status'] == 'creating'
              s['Status'] = 'active'
              self.data[:event_subscriptions][name] = s
            elsif s['Status'] == 'deleting'
              self.data[:event_subscriptions].delete(name)
            end
          end

          if options['SubscriptionName'] && subscriptions.empty?
            raise Fog::AWS::RDS::NotFound.new("Event Subscription #{options['SubscriptionName']} not found.")
          end

          response.body = {
            "ResponseMetadata" => {"RequestId" => Fog::AWS::Mock.request_id},
            "DescribeEventSubscriptionsResult" => {"EventSubscriptionsList" => subscriptions}
          }
          response
        end
      end
    end
  end
end