Class: SecureNative::Config::ConfigurationManager
- Inherits:
-
Object
- Object
- SecureNative::Config::ConfigurationManager
- Defined in:
- lib/securenative/config/configuration_manager.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
'securenative.yml'- CUSTOM_CONFIG_FILE_ENV_NAME =
'SECURENATIVE_CONFIG_FILE'
Class Method Summary collapse
- ._get_env_or_default(properties, key, default) ⇒ Object
- ._get_resource_path(env_name) ⇒ Object
- .config_builder ⇒ Object
- .load_config ⇒ Object
- .read_resource_file(resource_path) ⇒ Object
Class Method Details
._get_env_or_default(properties, key, default) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/securenative/config/configuration_manager.rb', line 29 def self._get_env_or_default(properties, key, default) return ENV[key] if ENV[key] return properties[key] if properties[key] default end |
._get_resource_path(env_name) ⇒ Object
21 22 23 |
# File 'lib/securenative/config/configuration_manager.rb', line 21 def self._get_resource_path(env_name) Env.fetch(env_name, ENV[DEFAULT_CONFIG_FILE]) end |
.config_builder ⇒ Object
25 26 27 |
# File 'lib/securenative/config/configuration_manager.rb', line 25 def self.config_builder SecureNative::Config::ConfigurationBuilder.new end |
.load_config ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/securenative/config/configuration_manager.rb', line 36 def self.load_config = SecureNative::Config::ConfigurationBuilder. resource_path = DEFAULT_CONFIG_FILE resource_path = ENV[CUSTOM_CONFIG_FILE_ENV_NAME] unless ENV[CUSTOM_CONFIG_FILE_ENV_NAME].nil? properties = read_resource_file(resource_path) SecureNative::Config::ConfigurationBuilder.new(api_key: _get_env_or_default(properties, 'SECURENATIVE_API_KEY', .api_key), api_url: _get_env_or_default(properties, 'SECURENATIVE_API_URL', .api_url), interval: _get_env_or_default(properties, 'SECURENATIVE_INTERVAL', .interval), max_events: _get_env_or_default(properties, 'SECURENATIVE_MAX_EVENTS', .max_events), timeout: _get_env_or_default(properties, 'SECURENATIVE_TIMEOUT', .timeout), auto_send: _get_env_or_default(properties, 'SECURENATIVE_AUTO_SEND', .auto_send), disable: _get_env_or_default(properties, 'SECURENATIVE_DISABLE', .disable), log_level: _get_env_or_default(properties, 'SECURENATIVE_LOG_LEVEL', .log_level), fail_over_strategy: _get_env_or_default(properties, 'SECURENATIVE_FAILOVER_STRATEGY', .fail_over_strategy), proxy_headers: _get_env_or_default(properties, 'SECURENATIVE_PROXY_HEADERS', .proxy_headers)) end |
.read_resource_file(resource_path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/securenative/config/configuration_manager.rb', line 10 def self.read_resource_file(resource_path) properties = {} begin @config = YAML.load_file(resource_path) properties = @config unless @config.nil? rescue StandardError => e SecureNative::Log.error("Could not parse securenative.config file #{resource_path}; #{e}") end properties end |