File: trusted_advisor_check.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (65 lines) | stat: -rw-r--r-- 2,099 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
module Fog
  module AWS
    class Support
      class TrustedAdvisorCheck < Fog::Model
        identity :id, :aliases => 'checkId'

        attribute :name
        attribute :category
        attribute :description
        attribute :metadata
        attribute :flagged_resources,         :aliases => 'flaggedResources'
        attribute :resources_summary,         :aliases => 'resourcesSummary'
        attribute :status
        attribute :timestamp
        attribute :category_specific_summary, :aliases => 'categorySpecificSummary'

        def populate_extended_attributes(lazy=false)
          return if lazy == true
          data = service.describe_trusted_advisor_check_result(:id => self.identity).body["result"]
          merge_attributes(data)
        end

        def flagged_resources(lazy=true)
          if attributes[:flagged_resources].nil?
            populate_extended_attributes(lazy)

            if attributes[:flagged_resources]
              map_flagged_resources!
              service.flagged_resources.load(attributes[:flagged_resources])
            else
              nil
            end
          else
            if attributes[:flagged_resources].first['metadata'].is_a?(Array)
              map_flagged_resources!
            end
            service.flagged_resources.load(attributes[:flagged_resources])
          end
        end

        def category_specific_summary(lazy=true)
          populate_extended_attributes(lazy) if attributes[:category_specific_summary].nil?
          attributes[:category_stecific_summary]
        end

        def resources_summary(lazy=true)
          populate_extended_attributes(lazy) if attributes[:resources_summary].nil?
          attributes[:resources_summary]
        end

        private

        def map_flagged_resources!
          attributes[:flagged_resources].map! do |fr|
            fr['metadata'] = fr['metadata'].each_with_index.inject({}) do |hash,(data,index)|
              hash[self.metadata[index]] = data
              hash
            end
            fr
          end
        end
      end
    end
  end
end