Class: SecureNative::ConfigurationManager
- Inherits:
-
Object
- Object
- SecureNative::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
31 32 33 34 35 36 |
# File 'lib/securenative/config/configuration_manager.rb', line 31 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
23 24 25 |
# File 'lib/securenative/config/configuration_manager.rb', line 23 def self._get_resource_path(env_name) Env.fetch(env_name, ENV[DEFAULT_CONFIG_FILE]) end |
.config_builder ⇒ Object
27 28 29 |
# File 'lib/securenative/config/configuration_manager.rb', line 27 def self.config_builder ConfigurationBuilder.new end |
.load_config ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/securenative/config/configuration_manager.rb', line 38 def self.load_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) 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
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/securenative/config/configuration_manager.rb', line 12 def self.read_resource_file(resource_path) properties = {} begin @config = YAML.load_file(resource_path) properties = @config unless @config.nil? rescue StandardError => e SecureNativeLogger.error("Could not parse securenative.config file #{resource_path}; #{e}") end properties end |