mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
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:
parent
28922df28e
commit
878c93f646
8 changed files with 152 additions and 13 deletions
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue