Module: GClouder::Resources::Validate::Remote

Includes:
Config::CLIArgs, Config::Project, Logging
Defined in:
lib/gclouder/resources/validate/remote.rb

Class Method Summary collapse

Methods included from Config::CLIArgs

check, #cli_args, cli_args, included, load, valid_resources

Methods included from Config::Project

load, #project, project

Methods included from Helpers

#hash_to_args, included, #module_exists?, #to_arg, #to_deep_merge_hash, #valid_json?

Methods included from Logging

#add, #bad, #change, #debug, #error, #fatal, #good, included, #info, log, loggers, #remove, report, #resource_state, setup, #warn, #warning

Class Method Details

.instances(local, remote, skip_keys: []) ⇒ Object



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
# File 'lib/gclouder/resources/validate/remote.rb', line 11

def self.instances(local, remote, skip_keys: [])
  remote.each do |region, resources|
    info region, heading: true, indent: 2
    resources.each do |resource|
      #FIXME: This won't work with duplicate names
      local_config = local.fetch(region, []).select {|s| s["name"] == resource["name"] }.first

      failure = false

      next unless local_config

      info resource["name"], indent: 3, heading: true

      local_config.each do |key, value|
        skipped = false
        skip_message = nil

        # FIXME: we should recurse down into the data structure and check the values..
        if value.is_a?(Hash) || value.is_a?(Array)
          skip_message ||= "(can't validate complex object)"
          skipped = true
        end

        if skip_keys.include?(key)
          skip_message ||= "(skip_keys in resource definition)"
          skipped = true
        else
          if !resource.key?(key)
            bad "#{key} (missing key)", indent: 4

            failure = true
            next
          end

          if value != resource[key]
            bad "#{key} (\"#{value.to_s.truncate(30)}\" != \"#{resource[key].to_s.truncate(30)}\")", indent: 4

            failure = true
            next
          end
        end

        message = "#{key}" " (#{value.to_s.truncate(60)})"
        message += " [skipped]" if skipped
        message += " #{skip_message}" if skip_message

        good message, indent: 4
      end

      next unless failure

      info
      info "local config:"
      pp local_config.sort.to_h
      info

      info "remote config:"
      pp resource.sort.to_h
      info

      fatal "error: immutable remote resource differs from local definition for resource: #{region}/#{resource["name"]}"
    end
  end
end