Allow user to specify a configuration file in VMPOOLER_CONFIG_FILE

variable

Previously, there were two ways to configure Vmpooler, either by
changing the contents of vmpooler.yaml or by assigning the raw YAML
to the VMPOOLER_CONFIG environment variable. This commit adds a new
environment variable called VMPOOLER_CONFIG_FILE that can be assigned
the name of a config file to use. Also fixes #240 by whitelisting the
Symbol class when calling YAML.safe_load in Vmpooler.config.
This commit is contained in:
adamdav 2017-10-06 17:09:31 -07:00 committed by mattkirby
parent 28922df28e
commit 878c93f646
8 changed files with 152 additions and 13 deletions

View file

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