File: describe_stacks.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 (91 lines) | stat: -rw-r--r-- 2,742 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
81
82
83
84
85
86
87
88
89
90
91
module Fog
  module Parsers
    module AWS
      module CloudFormation
        class DescribeStacks < Fog::Parsers::Base
          def reset
            @stack = { 'Outputs' => [], 'Parameters' => [], 'Capabilities' => [], 'Tags' => [] }
            @output = {}
            @parameter = {}
            @tag = {}
            @response = { 'Stacks' => [] }
          end

          def start_element(name, attrs = [])
            super
            case name
            when 'Outputs'
              @in_outputs = true
            when 'Parameters'
              @in_parameters = true
            when 'Capabilities'
              @in_capabilities = true
            when 'Tags'
              @in_tags = true
            end
          end

          def end_element(name)
            if @in_outputs
              case name
              when 'OutputKey', 'OutputValue', 'Description'
                @output[name] = value
              when 'member'
                @stack['Outputs'] << @output
                @output = {}
              when 'Outputs'
                @in_outputs = false
              end
            elsif @in_parameters
              case name
              when 'ParameterKey', 'ParameterValue'
                @parameter[name] = value
              when 'member'
                @stack['Parameters'] << @parameter
                @parameter = {}
              when 'Parameters'
                @in_parameters = false
              end
            elsif @in_tags
              case name
              when 'Key', 'Value'
                @tag[name] = value
              when 'member'
                @stack['Tags'] << @tag
                @tag = {}
              when 'Tags'
                @in_tags = false
              end
            elsif @in_capabilities
              case name
              when 'member'
                @stack['Capabilities'] << value
              when 'Capabilities'
                @in_capabilities = false
              end
            else
              case name
              when 'member'
                @response['Stacks'] << @stack
                @stack = { 'Outputs' => [], 'Parameters' => [], 'Capabilities' => [], 'Tags' => []}
              when 'RequestId'
                @response[name] = value
              when 'CreationTime'
                @stack[name] = Time.parse(value)
              when 'DisableRollback'
                case value
                when 'false'
                  @stack[name] = false
                when 'true'
                  @stack[name] = true
                end
              when 'StackName', 'StackId', 'StackStatus'
                @stack[name] = value
              end
            end
          end
        end
      end
    end
  end
end