securenative 0.1.22 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +62 -64
  3. data/lib/config/configuration_builder.rb +4 -3
  4. data/lib/config/configuration_manager.rb +2 -1
  5. data/lib/config/securenative_options.rb +4 -3
  6. data/lib/utils/request_utils.rb +20 -5
  7. data/out/production/securenative-ruby/api_manager.rb +13 -5
  8. data/out/production/securenative-ruby/config/configuration_builder.rb +6 -9
  9. data/out/production/securenative-ruby/config/configuration_manager.rb +24 -23
  10. data/out/production/securenative-ruby/config/securenative_options.rb +8 -5
  11. data/out/production/securenative-ruby/context/hanami_context.rb +42 -0
  12. data/out/production/securenative-ruby/context/rails_context.rb +44 -0
  13. data/out/production/securenative-ruby/context/securenative_context.rb +35 -8
  14. data/out/production/securenative-ruby/context/sinatra_context.rb +42 -0
  15. data/out/production/securenative-ruby/event_manager.rb +15 -14
  16. data/out/production/securenative-ruby/http/{http_response.rb → secure_native_http_response.rb} +1 -1
  17. data/out/production/securenative-ruby/http/securenative_http_client.rb +23 -5
  18. data/out/production/securenative-ruby/models/event_options.rb +23 -1
  19. data/out/production/securenative-ruby/models/request_context.rb +2 -2
  20. data/out/production/securenative-ruby/models/sdk_event.rb +22 -6
  21. data/out/production/securenative-ruby/models/user_traits.rb +1 -1
  22. data/out/production/securenative-ruby/models/verify_result.rb +5 -1
  23. data/out/production/securenative-ruby/securenative.rb +2 -10
  24. data/out/production/securenative-ruby/utils/date_utils.rb +1 -1
  25. data/out/production/securenative-ruby/utils/encryption_utils.rb +38 -24
  26. data/out/production/securenative-ruby/utils/request_utils.rb +53 -7
  27. data/out/production/securenative-ruby/utils/secure_native_logger.rb +6 -6
  28. data/out/production/securenative-ruby/utils/version_utils.rb +5 -6
  29. data/out/test/securenative-ruby/spec_api_manager.rb +37 -31
  30. data/out/test/securenative-ruby/spec_context_builder.rb +52 -34
  31. data/out/test/securenative-ruby/spec_encryption_utils.rb +13 -13
  32. data/out/test/securenative-ruby/spec_event_manager.rb +49 -15
  33. data/out/test/securenative-ruby/spec_helper.rb +8 -0
  34. data/out/test/securenative-ruby/spec_request_utils.rb +25 -0
  35. data/out/test/securenative-ruby/spec_sdk_event.rb +24 -0
  36. data/out/test/securenative-ruby/spec_securenative.rb +35 -39
  37. data/out/test/securenative-ruby/spec_securenative_http_client.rb +13 -5
  38. data/out/test/securenative-ruby/spec_signature_utils.rb +1 -1
  39. data/out/test/securenative-ruby/spec_version_util.rb +10 -0
  40. data/securenative.gemspec +1 -1
  41. metadata +9 -4
  42. data/out/production/securenative-ruby/event_options.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b61f74882bbf23be71999125df784a88a509c29ef3ca5cee0569ebdaa2063f32
4
- data.tar.gz: c6305ecadb3bf5d45245b54dfa336fc7d8b2774b0ceb7fc8997c2cdb1060a4a1
3
+ metadata.gz: 7ba285b1ac9a68c9cb1143ab595a4c052636e47b8d4cc39e16821e0582e06a62
4
+ data.tar.gz: c6295e963d7440c4dc8be4046077cafb4af96311f500fa2220717bf726b0ffba
5
5
  SHA512:
6
- metadata.gz: 0a46b6fed3c5478412f1e437142e2c74bc8e27d8213c0c8af8d08c4ad2dbfc71c13cf8695cd31a406d1600eb5005ce206ee7b3613b4dbb436cb072a199e3a7a2
7
- data.tar.gz: c14bdfe15041f74dc7b899f8b8eac5b8d3228a5f638a1d0edd347a4793bbdf7ce9bc9c39e78d7a38b595feb0044337e2e2e73679dd804364ccc79057fb7f8c89
6
+ metadata.gz: 7f78c7385e543d75dd106611eb77f71004fcb12d10702ae99a02af27cf3273bd45fcb2d5c7725a7001f143973f1cf2d70c19b3d57e3222d0b7965a40ec343f2c
7
+ data.tar.gz: fada20df309348b5e74a8886fb5855d51aed1ad4ba2245dd23df60f409b1fd6e3bc11efd829b4b21a2b0fa9cf2dac45c08628f088e49879a09a45853aee52ef7
@@ -1,61 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- securenative (0.1.22)
4
+ securenative (0.1.23)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actioncable (6.0.3.2)
10
- actionpack (= 6.0.3.2)
9
+ actioncable (6.0.3.3)
10
+ actionpack (= 6.0.3.3)
11
11
  nio4r (~> 2.0)
12
12
  websocket-driver (>= 0.6.1)
13
- actionmailbox (6.0.3.2)
14
- actionpack (= 6.0.3.2)
15
- activejob (= 6.0.3.2)
16
- activerecord (= 6.0.3.2)
17
- activestorage (= 6.0.3.2)
18
- activesupport (= 6.0.3.2)
13
+ actionmailbox (6.0.3.3)
14
+ actionpack (= 6.0.3.3)
15
+ activejob (= 6.0.3.3)
16
+ activerecord (= 6.0.3.3)
17
+ activestorage (= 6.0.3.3)
18
+ activesupport (= 6.0.3.3)
19
19
  mail (>= 2.7.1)
20
- actionmailer (6.0.3.2)
21
- actionpack (= 6.0.3.2)
22
- actionview (= 6.0.3.2)
23
- activejob (= 6.0.3.2)
20
+ actionmailer (6.0.3.3)
21
+ actionpack (= 6.0.3.3)
22
+ actionview (= 6.0.3.3)
23
+ activejob (= 6.0.3.3)
24
24
  mail (~> 2.5, >= 2.5.4)
25
25
  rails-dom-testing (~> 2.0)
26
- actionpack (6.0.3.2)
27
- actionview (= 6.0.3.2)
28
- activesupport (= 6.0.3.2)
26
+ actionpack (6.0.3.3)
27
+ actionview (= 6.0.3.3)
28
+ activesupport (= 6.0.3.3)
29
29
  rack (~> 2.0, >= 2.0.8)
30
30
  rack-test (>= 0.6.3)
31
31
  rails-dom-testing (~> 2.0)
32
32
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
33
- actiontext (6.0.3.2)
34
- actionpack (= 6.0.3.2)
35
- activerecord (= 6.0.3.2)
36
- activestorage (= 6.0.3.2)
37
- activesupport (= 6.0.3.2)
33
+ actiontext (6.0.3.3)
34
+ actionpack (= 6.0.3.3)
35
+ activerecord (= 6.0.3.3)
36
+ activestorage (= 6.0.3.3)
37
+ activesupport (= 6.0.3.3)
38
38
  nokogiri (>= 1.8.5)
39
- actionview (6.0.3.2)
40
- activesupport (= 6.0.3.2)
39
+ actionview (6.0.3.3)
40
+ activesupport (= 6.0.3.3)
41
41
  builder (~> 3.1)
42
42
  erubi (~> 1.4)
43
43
  rails-dom-testing (~> 2.0)
44
44
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
45
- activejob (6.0.3.2)
46
- activesupport (= 6.0.3.2)
45
+ activejob (6.0.3.3)
46
+ activesupport (= 6.0.3.3)
47
47
  globalid (>= 0.3.6)
48
- activemodel (6.0.3.2)
49
- activesupport (= 6.0.3.2)
50
- activerecord (6.0.3.2)
51
- activemodel (= 6.0.3.2)
52
- activesupport (= 6.0.3.2)
53
- activestorage (6.0.3.2)
54
- actionpack (= 6.0.3.2)
55
- activejob (= 6.0.3.2)
56
- activerecord (= 6.0.3.2)
48
+ activemodel (6.0.3.3)
49
+ activesupport (= 6.0.3.3)
50
+ activerecord (6.0.3.3)
51
+ activemodel (= 6.0.3.3)
52
+ activesupport (= 6.0.3.3)
53
+ activestorage (6.0.3.3)
54
+ actionpack (= 6.0.3.3)
55
+ activejob (= 6.0.3.3)
56
+ activerecord (= 6.0.3.3)
57
57
  marcel (~> 0.3.1)
58
- activesupport (6.0.3.2)
58
+ activesupport (6.0.3.3)
59
59
  concurrent-ruby (~> 1.0, >= 1.0.2)
60
60
  i18n (>= 0.7, < 2)
61
61
  minitest (~> 5.1)
@@ -64,11 +64,9 @@ GEM
64
64
  addressable (2.7.0)
65
65
  public_suffix (>= 2.0.2, < 5.0)
66
66
  builder (3.2.4)
67
- codecov (0.2.6)
68
- colorize
67
+ codecov (0.2.11)
69
68
  json
70
69
  simplecov
71
- colorize (0.8.1)
72
70
  concurrent-ruby (1.1.7)
73
71
  crack (0.4.3)
74
72
  safe_yaml (~> 1.0.0)
@@ -157,7 +155,7 @@ GEM
157
155
  concurrent-ruby (~> 1.0)
158
156
  inflecto (0.0.2)
159
157
  json (2.3.1)
160
- loofah (2.6.0)
158
+ loofah (2.7.0)
161
159
  crass (~> 1.0.2)
162
160
  nokogiri (>= 1.5.9)
163
161
  mail (2.7.1)
@@ -168,41 +166,41 @@ GEM
168
166
  mimemagic (0.3.5)
169
167
  mini_mime (1.0.2)
170
168
  mini_portile2 (2.4.0)
171
- minitest (5.14.1)
169
+ minitest (5.14.2)
172
170
  mustermann (1.1.1)
173
171
  ruby2_keywords (~> 0.0.1)
174
- nio4r (2.5.2)
172
+ nio4r (2.5.4)
175
173
  nokogiri (1.10.10)
176
174
  mini_portile2 (~> 2.4.0)
177
- public_suffix (4.0.5)
175
+ public_suffix (4.0.6)
178
176
  rack (2.2.3)
179
- rack-protection (2.0.8.1)
177
+ rack-protection (2.1.0)
180
178
  rack
181
179
  rack-test (1.1.0)
182
180
  rack (>= 1.0, < 3)
183
- rails (6.0.3.2)
184
- actioncable (= 6.0.3.2)
185
- actionmailbox (= 6.0.3.2)
186
- actionmailer (= 6.0.3.2)
187
- actionpack (= 6.0.3.2)
188
- actiontext (= 6.0.3.2)
189
- actionview (= 6.0.3.2)
190
- activejob (= 6.0.3.2)
191
- activemodel (= 6.0.3.2)
192
- activerecord (= 6.0.3.2)
193
- activestorage (= 6.0.3.2)
194
- activesupport (= 6.0.3.2)
181
+ rails (6.0.3.3)
182
+ actioncable (= 6.0.3.3)
183
+ actionmailbox (= 6.0.3.3)
184
+ actionmailer (= 6.0.3.3)
185
+ actionpack (= 6.0.3.3)
186
+ actiontext (= 6.0.3.3)
187
+ actionview (= 6.0.3.3)
188
+ activejob (= 6.0.3.3)
189
+ activemodel (= 6.0.3.3)
190
+ activerecord (= 6.0.3.3)
191
+ activestorage (= 6.0.3.3)
192
+ activesupport (= 6.0.3.3)
195
193
  bundler (>= 1.3.0)
196
- railties (= 6.0.3.2)
194
+ railties (= 6.0.3.3)
197
195
  sprockets-rails (>= 2.0.0)
198
196
  rails-dom-testing (2.0.3)
199
197
  activesupport (>= 4.2.0)
200
198
  nokogiri (>= 1.6)
201
199
  rails-html-sanitizer (1.3.0)
202
200
  loofah (~> 2.3)
203
- railties (6.0.3.2)
204
- actionpack (= 6.0.3.2)
205
- activesupport (= 6.0.3.2)
201
+ railties (6.0.3.3)
202
+ actionpack (= 6.0.3.3)
203
+ activesupport (= 6.0.3.3)
206
204
  method_source
207
205
  rake (>= 0.8.7)
208
206
  thor (>= 0.20.3, < 2.0)
@@ -226,15 +224,15 @@ GEM
226
224
  docile (~> 1.1)
227
225
  simplecov-html (~> 0.11)
228
226
  simplecov-html (0.12.2)
229
- sinatra (2.0.8.1)
227
+ sinatra (2.1.0)
230
228
  mustermann (~> 1.0)
231
- rack (~> 2.0)
232
- rack-protection (= 2.0.8.1)
229
+ rack (~> 2.2)
230
+ rack-protection (= 2.1.0)
233
231
  tilt (~> 2.0)
234
232
  sprockets (4.0.2)
235
233
  concurrent-ruby (~> 1.0)
236
234
  rack (> 1, < 3)
237
- sprockets-rails (3.2.1)
235
+ sprockets-rails (3.2.2)
238
236
  actionpack (>= 4.0)
239
237
  activesupport (>= 4.0)
240
238
  sprockets (>= 3.0.0)
@@ -246,7 +244,7 @@ GEM
246
244
  thread_safe (~> 0.1)
247
245
  url_mount (0.2.1)
248
246
  rack
249
- webmock (3.8.3)
247
+ webmock (3.9.1)
250
248
  addressable (>= 2.3.6)
251
249
  crack (>= 0.3.2)
252
250
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -3,12 +3,12 @@
3
3
  require 'enums/failover_strategy'
4
4
 
5
5
  class ConfigurationBuilder
6
- attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
7
- attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
6
+ attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
7
+ attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
8
8
 
9
9
  def initialize(api_key: nil, api_url: 'https://api.securenative.com/collector/api/v1', interval: 1000,
10
10
  max_events: 1000, timeout: 1500, auto_send: true, disable: false, log_level: 'FATAL',
11
- fail_over_strategy: FailOverStrategy::FAIL_OPEN)
11
+ fail_over_strategy: FailOverStrategy::FAIL_OPEN, proxy_headers: nil)
12
12
  @api_key = api_key
13
13
  @api_url = api_url
14
14
  @interval = interval
@@ -18,6 +18,7 @@ class ConfigurationBuilder
18
18
  @disable = disable
19
19
  @log_level = log_level
20
20
  @fail_over_strategy = fail_over_strategy
21
+ @proxy_headers = proxy_headers
21
22
  end
22
23
 
23
24
  def self.default_securenative_options
@@ -50,6 +50,7 @@ class ConfigurationManager
50
50
  auto_send: _get_env_or_default(properties, 'SECURENATIVE_AUTO_SEND', options.auto_send),
51
51
  disable: _get_env_or_default(properties, 'SECURENATIVE_DISABLE', options.disable),
52
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))
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))
54
55
  end
55
56
  end
@@ -3,12 +3,12 @@
3
3
  require 'enums/failover_strategy'
4
4
 
5
5
  class SecureNativeOptions
6
- attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
7
- attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
6
+ attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
7
+ attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
8
8
 
9
9
  def initialize(api_key: nil, api_url: "https://api.securenative.com/collector/api/v1", interval: 1000,
10
10
  max_events: 1000, timeout: 1500, auto_send: true, disable: false, log_level: "FATAL",
11
- fail_over_strategy: FailOverStrategy::FAIL_OPEN)
11
+ fail_over_strategy: FailOverStrategy::FAIL_OPEN, proxy_headers: nil)
12
12
  @api_key = api_key
13
13
  @api_url = api_url
14
14
  @interval = interval
@@ -18,5 +18,6 @@ class SecureNativeOptions
18
18
  @disable = disable
19
19
  @log_level = log_level
20
20
  @fail_over_strategy = fail_over_strategy
21
+ @proxy_headers = proxy_headers
21
22
  end
22
23
  end
@@ -13,7 +13,7 @@ class RequestUtils
13
13
  []
14
14
  end
15
15
 
16
- def self.get_client_ip_from_request(request)
16
+ def self.get_client_ip_from_request(request, options = nil)
17
17
  begin
18
18
  return request.ip unless request.ip.nil?
19
19
  rescue NoMethodError
@@ -21,26 +21,41 @@ class RequestUtils
21
21
 
22
22
  begin
23
23
  x_forwarded_for = request.env['HTTP_X_FORWARDED_FOR']
24
- return x_forwarded_for unless x_forwarded_for.nil?
24
+ return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
25
25
  rescue NoMethodError
26
26
  begin
27
27
  x_forwarded_for = request['HTTP_X_FORWARDED_FOR']
28
- return x_forwarded_for unless x_forwarded_for.nil?
28
+ return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
29
29
  rescue NoMethodError
30
30
  end
31
31
  end
32
32
 
33
33
  begin
34
34
  x_forwarded_for = request.env['REMOTE_ADDR']
35
- return x_forwarded_for unless x_forwarded_for.nil?
35
+ return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
36
36
  rescue NoMethodError
37
37
  begin
38
38
  x_forwarded_for = request['REMOTE_ADDR']
39
- return x_forwarded_for unless x_forwarded_for.nil?
39
+ return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
40
40
  rescue NoMethodError
41
41
  end
42
42
  end
43
43
 
44
+ unless options.nil?
45
+ for header in options.proxy_headers do
46
+ begin
47
+ h = request.env[header]
48
+ return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
49
+ rescue NoMethodError
50
+ begin
51
+ h = request[header]
52
+ return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
53
+ rescue NoMethodError
54
+ end
55
+ end
56
+ end
57
+ end
58
+
44
59
  ''
45
60
  end
46
61
 
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'models/sdk_event'
4
+ require 'enums/failover_strategy'
5
+ require 'enums/risk_level'
6
+ require 'enums/api_route'
7
+ require 'models/verify_result'
3
8
  require 'json'
4
9
 
5
10
  class ApiManager
@@ -19,13 +24,16 @@ class ApiManager
19
24
  event = SDKEvent.new(event_options, @options)
20
25
 
21
26
  begin
22
- res = JSON.parse(@event_manager.send_sync(event, ApiRoute::VERIFY, false))
23
- return VerifyResult.new(res['riskLevel'], res['score'], res['triggers'])
27
+ res = @event_manager.send_sync(event, ApiRoute::VERIFY, false)
28
+ ver_result = JSON.parse(res.body)
29
+ return VerifyResult.new(risk_level: ver_result['riskLevel'], score: ver_result['score'], triggers: ver_result['triggers'])
24
30
  rescue StandardError => e
25
- SecureNativeLogger.debug('Failed to call verify; {}'.format(e))
31
+ SecureNativeLogger.debug("Failed to call verify; #{e}")
32
+ end
33
+ if @options.fail_over_strategy == FailOverStrategy::FAIL_OPEN
34
+ return VerifyResult.new(risk_level: RiskLevel::LOW, score: 0, triggers: nil)
26
35
  end
27
- return VerifyResult.new(RiskLevel::LOW, 0, nil) if @options.fail_over_strategy == FailOverStrategy::FAIL_OPEN
28
36
 
29
- VerifyResult.new(RiskLevel::HIGH, 1, nil)
37
+ VerifyResult.new(risk_level: RiskLevel::HIGH, score: 1, triggers: nil)
30
38
  end
31
39
  end
@@ -3,12 +3,12 @@
3
3
  require 'enums/failover_strategy'
4
4
 
5
5
  class ConfigurationBuilder
6
- attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
7
- attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy
6
+ attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
7
+ attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
8
8
 
9
- def initialize(api_key = nil, api_url = 'https://api.securenative.com/collector/api/v1', interval = 1000,
10
- max_events = 1000, timeout = 1500, auto_send = true, disable = false, log_level = 'FATAL',
11
- fail_over_strategy = FailOverStrategy::FAIL_OPEN)
9
+ def initialize(api_key: nil, api_url: 'https://api.securenative.com/collector/api/v1', interval: 1000,
10
+ max_events: 1000, timeout: 1500, auto_send: true, disable: false, log_level: 'FATAL',
11
+ fail_over_strategy: FailOverStrategy::FAIL_OPEN, proxy_headers: [])
12
12
  @api_key = api_key
13
13
  @api_url = api_url
14
14
  @interval = interval
@@ -18,10 +18,7 @@ class ConfigurationBuilder
18
18
  @disable = disable
19
19
  @log_level = log_level
20
20
  @fail_over_strategy = fail_over_strategy
21
- end
22
-
23
- def self.default_config_builder
24
- ConfigurationBuilder.new
21
+ @proxy_headers = proxy_headers
25
22
  end
26
23
 
27
24
  def self.default_securenative_options
@@ -1,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'parseconfig'
3
+ require 'yaml'
4
+ require 'config/configuration_builder'
4
5
 
5
6
  class 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'
8
9
  @config = nil
9
10
 
10
11
  def self.read_resource_file(resource_path)
11
- @config = ParseConfig.new(resource_path)
12
-
13
12
  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
19
19
  properties
20
20
  end
21
21
 
@@ -24,32 +24,33 @@ class ConfigurationManager
24
24
  end
25
25
 
26
26
  def self.config_builder
27
- ConfigurationBuilder.default_config_builder
27
+ ConfigurationBuilder.new
28
28
  end
29
29
 
30
30
  def self._get_env_or_default(properties, key, default)
31
- return Env[key] if Env[key]
31
+ return ENV[key] if ENV[key]
32
32
  return properties[key] if properties[key]
33
33
 
34
34
  default
35
35
  end
36
36
 
37
37
  def self.load_config
38
- options = ConfigurationBuilder().default_securenative_options
38
+ options = ConfigurationBuilder.default_securenative_options
39
39
 
40
40
  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?
42
42
 
43
43
  properties = read_resource_file(resource_path)
44
44
 
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))
54
55
  end
55
56
  end