lib/liberty_buildpack/util/service_configuration_utils.rb
# Loads a configuration file from the service buildpack configuration directory.  If the configuration file does not
# exist, returns an empty.
#
# @param [String] key the identifier of the configuration to load
# @param [Boolean] clean_nil_values whether empty/nil values should be removed along with their keys from the
#                                  returned configuration.
# @param [Boolean] should_log whether the contents of the configuration file should be logged.  This value
#                             should be left to its default and exists to allow the logger to use the utility.
# @return [Hash] the configuration or an empty hash if the configuration file does not exist
Loads a configuration file from the service buildpack configuration directory.  If the configuration file does not
exist, returns an empty.
Loads a configuration file from the service buildpack configuration directory . If the configuration file does not exist returns an empty .
def load_user_conf(key, config, file, clean_nil_values, should_log)
          var_name = environment_variable_name(key)
          user_provided = ENV[var_name]
          logger.debug { "loading service config for #{key} from #{file}" } if should_log
          config[key] = File.open(file, 'r:utf-8') { |yf| YAML.load(yf) }
          if user_provided
            begin
              user_provided_value = YAML.load(user_provided)
              config[key] = merge_configuration(config[key], user_provided_value, var_name, should_log)
            rescue Psych::SyntaxError => ex
              raise "User service configuration value in environment variable #{var_name} has invalid syntax: #{ex}"
            end
            logger.debug { "Service configuration from #{file} modified with: #{user_provided}" } if should_log
          end
          clean_nil_values config[key] if clean_nil_values && !config[key].nil?
          config[key]
        end
def load_user_conf ( key , config , file , clean_nil_values , should_log ) var_name = environment_variable_name ( key ) user_provided = ENV [ var_name ] logger . debug { "loading service config for #{key} from #{file}" } if should_log config [ key ] = File . open ( file , 'r:utf-8' ) { | yf | YAML . load ( yf ) } if user_provided begin user_provided_value = YAML . load ( user_provided ) config [ key ] = merge_configuration ( config [ key ] , user_provided_value , var_name , should_log ) rescue Psych :: SyntaxError => ex raise "User service configuration value in environment variable #{var_name} has invalid syntax: #{ex}" end logger . debug { "Service configuration from #{file} modified with: #{user_provided}" } if should_log end clean_nil_values config [ key ] if clean_nil_values && ! config [ key ] . nil? config [ key ] end
Loads a configuration file from the service buildpack configuration directory.
Loads a configuration file from the service buildpack configuration directory .
the configuration or an empty hash if the configuration file does not exist
the configuration or an empty hash if the configuration file does not exist
Hash
key
config
file
clean_nil_values
should_log
should_log whether the contents of the configuration file should be logged. This value should be left to its default and exists to allow the logger to use the utility.
should_log whether the contents of the configuration file should be logged . This value should be left to its default and exists to allow the logger to use the utility .