From 00970ffc9e725cebbcc8a0dcf511ce6c1455306d Mon Sep 17 00:00:00 2001 From: "kirby@puppetlabs.com" Date: Tue, 17 Apr 2018 15:22:17 -0700 Subject: [PATCH] (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. --- lib/vmpooler.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/vmpooler.rb b/lib/vmpooler.rb index 7b45451..6a7c12f 100644 --- a/lib/vmpooler.rb +++ b/lib/vmpooler.rb @@ -22,17 +22,18 @@ module Vmpooler def self.config(filepath = 'vmpooler.yaml') # 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 - config_file = ENV['VMPOOLER_CONFIG_FILE'] || filepath - - # Return the contents of the config file - File.read(File.expand_path(config_file)) + config_file = ENV['VMPOOLER_CONFIG_FILE'] || filepath + parsed_config = YAML.load_file(config_file) end - # Parse the YAML config into a Hash - # Whitelist the Symbol class - parsed_config = YAML.safe_load(config_string, [Symbol]) + exit unless parsed_config # Bail out if someone attempts to start vmpooler with dummy authentication # without enbaling debug mode.