Module: WGU::ChefComms

Defined in:
lib/pps_commons/chef_comms.rb

Class Method Summary collapse

Class Method Details

.global_config(client, group_name, message) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pps_commons/chef_comms.rb', line 5

def self.global_config(client, group_name, message)
  # search through global config indexes for a match
  config =
    client.data_bags.find { |d_b| d_b.name =~ /#{group_name}/ }

  if config.nil?
    config = client.roles.fetch(group_name)

    unless config.nil?
      stop = Regexp.union([/for\s/, /with\s/, /using\s/])
      location =
        message.gsub(/.*\sdata\sstore\sunder\s(\w+)\s#{stop}.*/, '\1')
      usable_role =
        config.default_attributes[group_name][location].key?('java_opts')
    end

    usable_role ? [config, 'role'] : []
  else
    [config, 'data bag']
  end
end