(POOLER-103) Fix configuration file loading

This commit updates the method used to load a configuration file to use
YAML.load_file, which is how it was configured previously. The
capability to specify an alternate configuration file via the
VMPOOLER_CONFIG_FILE is retained, and now works as expected.
This commit is contained in:
kirby@puppetlabs.com 2018-04-17 15:22:17 -07:00 committed by mattkirby
parent 356c541fdc
commit 00970ffc9e

View file

@ -22,17 +22,18 @@ module Vmpooler
def self.config(filepath = 'vmpooler.yaml') def self.config(filepath = 'vmpooler.yaml')
# Take the config either from an ENV config variable or from a config file # Take the config either from an ENV config variable or from a config file
config_string = ENV['VMPOOLER_CONFIG'] || begin if ENV['VMPOOLER_CONFIG']
config_string = ENV['VMPOOLER_CONFIG']
# Parse the YAML config into a Hash
# Whitelist the Symbol class
parsed_config = YAML.safe_load(config_string, [Symbol])
else
# Take the name of the config file either from an ENV variable or from the filepath argument # Take the name of the config file either from an ENV variable or from the filepath argument
config_file = ENV['VMPOOLER_CONFIG_FILE'] || filepath config_file = ENV['VMPOOLER_CONFIG_FILE'] || filepath
parsed_config = YAML.load_file(config_file)
# Return the contents of the config file
File.read(File.expand_path(config_file))
end end
# Parse the YAML config into a Hash exit unless parsed_config
# Whitelist the Symbol class
parsed_config = YAML.safe_load(config_string, [Symbol])
# Bail out if someone attempts to start vmpooler with dummy authentication # Bail out if someone attempts to start vmpooler with dummy authentication
# without enbaling debug mode. # without enbaling debug mode.