11# frozen_string_literal: true
22
3- require 'parseconfig'
3+ require 'yaml'
4+ require 'config/configuration_builder'
45
56class ConfigurationManager
6- DEFAULT_CONFIG_FILE = 'securenative.cfg '
7- CUSTOM_CONFIG_FILE_ENV_NAME = 'SECURENATIVE_COMFIG_FILE '
7+ DEFAULT_CONFIG_FILE = 'securenative.yml '
8+ CUSTOM_CONFIG_FILE_ENV_NAME = 'SECURENATIVE_CONFIG_FILE '
89 @config = nil
910
1011 def self . read_resource_file ( resource_path )
11- @config = ParseConfig . new ( resource_path )
12-
1312 properties = { }
14- @config . get_groups . each { |group |
15- group . each do |key , value |
16- properties [ key . upcase ] = value
17- end
18- }
13+ begin
14+ @config = YAML . load_file ( resource_path )
15+ properties = @config unless @config . nil?
16+ rescue StandardError => e
17+ SecureNativeLogger . error ( "Could not parse config file #{ resource_path } ; #{ e } " )
18+ end
1919 properties
2020 end
2121
@@ -24,32 +24,33 @@ def self._get_resource_path(env_name)
2424 end
2525
2626 def self . config_builder
27- ConfigurationBuilder . default_config_builder
27+ ConfigurationBuilder . new
2828 end
2929
3030 def self . _get_env_or_default ( properties , key , default )
31- return Env [ key ] if Env [ key ]
31+ return ENV [ key ] if ENV [ key ]
3232 return properties [ key ] if properties [ key ]
3333
3434 default
3535 end
3636
3737 def self . load_config
38- options = ConfigurationBuilder ( ) . default_securenative_options
38+ options = ConfigurationBuilder . default_securenative_options
3939
4040 resource_path = DEFAULT_CONFIG_FILE
41- resource_path = Env [ CUSTOM_CONFIG_FILE_ENV_NAME ] if Env [ CUSTOM_CONFIG_FILE_ENV_NAME ]
41+ resource_path = ENV [ CUSTOM_CONFIG_FILE_ENV_NAME ] unless ENV [ CUSTOM_CONFIG_FILE_ENV_NAME ] . nil?
4242
4343 properties = read_resource_file ( resource_path )
4444
45- ConfigurationBuilder ( _get_env_or_default ( properties , 'SECURENATIVE_API_KEY' , options . api_key ) ,
46- _get_env_or_default ( properties , 'SECURENATIVE_API_URL' , options . api_url ) ,
47- _get_env_or_default ( properties , 'SECURENATIVE_INTERVAL' , options . interval ) ,
48- _get_env_or_default ( properties , 'SECURENATIVE_MAX_EVENTS' , options . max_events ) ,
49- _get_env_or_default ( properties , 'SECURENATIVE_TIMEOUT' , options . timeout ) ,
50- _get_env_or_default ( properties , 'SECURENATIVE_AUTO_SEND' , options . auto_send ) ,
51- _get_env_or_default ( properties , 'SECURENATIVE_DISABLE' , options . disable ) ,
52- _get_env_or_default ( properties , 'SECURENATIVE_LOG_LEVEL' , options . log_level ) ,
53- _get_env_or_default ( properties , 'SECURENATIVE_FAILOVER_STRATEGY' , options . fail_over_strategy ) )
45+ ConfigurationBuilder . new ( api_key : _get_env_or_default ( properties , 'SECURENATIVE_API_KEY' , options . api_key ) ,
46+ api_url : _get_env_or_default ( properties , 'SECURENATIVE_API_URL' , options . api_url ) ,
47+ interval : _get_env_or_default ( properties , 'SECURENATIVE_INTERVAL' , options . interval ) ,
48+ max_events : _get_env_or_default ( properties , 'SECURENATIVE_MAX_EVENTS' , options . max_events ) ,
49+ timeout : _get_env_or_default ( properties , 'SECURENATIVE_TIMEOUT' , options . timeout ) ,
50+ auto_send : _get_env_or_default ( properties , 'SECURENATIVE_AUTO_SEND' , options . auto_send ) ,
51+ disable : _get_env_or_default ( properties , 'SECURENATIVE_DISABLE' , options . disable ) ,
52+ log_level : _get_env_or_default ( properties , 'SECURENATIVE_LOG_LEVEL' , options . log_level ) ,
53+ fail_over_strategy : _get_env_or_default ( properties , 'SECURENATIVE_FAILOVER_STRATEGY' , options . fail_over_strategy ) ,
54+ proxy_headers : _get_env_or_default ( properties , 'SECURENATIVE_PROXY_HEADERS' , options . proxy_headers ) )
5455 end
5556end
0 commit comments