Module: ChefVault::Mixin::Helper

Defined in:
lib/chef/knife/mixin/helper.rb

Instance Method Summary collapse

Instance Method Details

#merge_values(json, file) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/chef/knife/mixin/helper.rb', line 27

def merge_values(json, file)
  values = {}
  values.merge!(values_from_file(file)) if file
  values.merge!(values_from_json(json)) if json

  values
end

#set_mode(mode) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/chef/knife/mixin/helper.rb', line 19

def set_mode(mode)
  if mode == "client"
    Chef::Config[:solo] = false
  else
    Chef::Config[:solo] = true
  end
end

#values_from_file(file) ⇒ Object



35
36
37
38
39
# File 'lib/chef/knife/mixin/helper.rb', line 35

def values_from_file(file)
  json = File.open(file){ |fh| fh.read() }

  values_from_json(json)
end

#values_from_json(json) ⇒ Object



41
42
43
44
45
# File 'lib/chef/knife/mixin/helper.rb', line 41

def values_from_json(json)
  JSON.parse(json)
rescue JSON::ParserError
  raise JSON::ParserError, "#{json} is not valid JSON!"
end