securenative 0.1.21 → 0.1.27
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +64 -68
- data/README.md +37 -37
- data/lib/securenative/api_manager.rb +41 -0
- data/lib/securenative/config/configuration_builder.rb +29 -0
- data/lib/securenative/config/configuration_manager.rb +58 -0
- data/lib/securenative/config/securenative_options.rb +25 -0
- data/lib/securenative/context/hanami_context.rb +44 -0
- data/lib/securenative/context/rails_context.rb +46 -0
- data/lib/securenative/context/securenative_context.rb +69 -0
- data/lib/securenative/context/sinatra_context.rb +44 -0
- data/lib/securenative/enums/api_route.rb +8 -0
- data/lib/securenative/enums/event_types.rb +25 -0
- data/lib/securenative/enums/failover_strategy.rb +8 -0
- data/lib/securenative/enums/risk_level.rb +9 -0
- data/lib/securenative/errors/securenative_config_error.rb +6 -0
- data/lib/securenative/errors/securenative_http_error.rb +6 -0
- data/lib/securenative/errors/securenative_invalid_options_error.rb +6 -0
- data/lib/securenative/errors/securenative_invalid_uri_error.rb +6 -0
- data/lib/securenative/errors/securenative_parse_error.rb +6 -0
- data/lib/securenative/errors/securenative_sdk_Illegal_state_error.rb +6 -0
- data/lib/securenative/errors/securenative_sdk_error.rb +6 -0
- data/lib/securenative/event_manager.rb +159 -0
- data/lib/securenative/http/secure_native_http_response.rb +14 -0
- data/lib/securenative/http/securenative_http_client.rb +52 -0
- data/lib/securenative/models/client_token.rb +14 -0
- data/lib/securenative/models/device.rb +12 -0
- data/lib/securenative/models/event_options.rb +39 -0
- data/lib/securenative/models/request_context.rb +20 -0
- data/lib/securenative/models/request_options.rb +14 -0
- data/lib/securenative/models/sdk_event.rb +51 -0
- data/lib/securenative/models/user_traits.rb +15 -0
- data/lib/securenative/models/verify_result.rb +18 -0
- data/lib/securenative/sdk.rb +85 -0
- data/lib/securenative/utils/date_utils.rb +11 -0
- data/lib/securenative/utils/encryption_utils.rb +51 -0
- data/lib/securenative/utils/ip_utils.rb +25 -0
- data/lib/securenative/utils/request_utils.rb +82 -0
- data/lib/securenative/utils/secure_native_logger.rb +46 -0
- data/lib/securenative/utils/signature_utils.rb +18 -0
- data/lib/securenative/utils/utils.rb +11 -0
- data/lib/securenative/utils/version_utils.rb +13 -0
- data/out/production/securenative-ruby/api_manager.rb +13 -5
- data/out/production/securenative-ruby/config/configuration_builder.rb +6 -9
- data/out/production/securenative-ruby/config/configuration_manager.rb +24 -23
- data/out/production/securenative-ruby/config/securenative_options.rb +8 -5
- data/{lib → out/production/securenative-ruby}/context/hanami_context.rb +0 -0
- data/{lib → out/production/securenative-ruby}/context/rails_context.rb +0 -0
- data/out/production/securenative-ruby/context/securenative_context.rb +35 -8
- data/{lib → out/production/securenative-ruby}/context/sinatra_context.rb +0 -0
- data/out/production/securenative-ruby/event_manager.rb +15 -14
- data/{lib → out/production/securenative-ruby}/http/secure_native_http_response.rb +0 -0
- data/out/production/securenative-ruby/http/securenative_http_client.rb +23 -5
- data/out/production/securenative-ruby/models/event_options.rb +23 -1
- data/out/production/securenative-ruby/models/request_context.rb +2 -2
- data/out/production/securenative-ruby/models/sdk_event.rb +22 -6
- data/out/production/securenative-ruby/models/user_traits.rb +1 -1
- data/out/production/securenative-ruby/models/verify_result.rb +5 -1
- data/out/production/securenative-ruby/securenative.rb +2 -10
- data/out/production/securenative-ruby/utils/date_utils.rb +1 -1
- data/out/production/securenative-ruby/utils/encryption_utils.rb +38 -24
- data/out/production/securenative-ruby/utils/request_utils.rb +53 -7
- data/out/production/securenative-ruby/utils/secure_native_logger.rb +6 -6
- data/out/production/securenative-ruby/utils/version_utils.rb +5 -6
- data/out/test/securenative-ruby/spec_api_manager.rb +37 -31
- data/out/test/securenative-ruby/spec_context_builder.rb +52 -34
- data/out/test/securenative-ruby/spec_encryption_utils.rb +13 -13
- data/out/test/securenative-ruby/spec_event_manager.rb +49 -15
- data/out/test/securenative-ruby/spec_helper.rb +8 -0
- data/out/test/securenative-ruby/spec_request_utils.rb +25 -0
- data/out/test/securenative-ruby/spec_sdk_event.rb +24 -0
- data/out/test/securenative-ruby/spec_securenative.rb +35 -39
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +13 -5
- data/out/test/securenative-ruby/spec_signature_utils.rb +1 -1
- data/out/test/securenative-ruby/spec_version_util.rb +10 -0
- data/securenative.gemspec +16 -14
- metadata +48 -43
- data/lib/api_manager.rb +0 -39
- data/lib/config/configuration_builder.rb +0 -26
- data/lib/config/configuration_manager.rb +0 -55
- data/lib/config/securenative_options.rb +0 -22
- data/lib/context/securenative_context.rb +0 -67
- data/lib/enums/api_route.rb +0 -6
- data/lib/enums/event_types.rb +0 -23
- data/lib/enums/failover_strategy.rb +0 -6
- data/lib/enums/risk_level.rb +0 -7
- data/lib/errors/securenative_config_error.rb +0 -4
- data/lib/errors/securenative_http_error.rb +0 -4
- data/lib/errors/securenative_invalid_options_error.rb +0 -4
- data/lib/errors/securenative_invalid_uri_error.rb +0 -4
- data/lib/errors/securenative_parse_error.rb +0 -4
- data/lib/errors/securenative_sdk_Illegal_state_error.rb +0 -4
- data/lib/errors/securenative_sdk_error.rb +0 -4
- data/lib/event_manager.rb +0 -157
- data/lib/http/securenative_http_client.rb +0 -50
- data/lib/models/client_token.rb +0 -12
- data/lib/models/device.rb +0 -10
- data/lib/models/event_options.rb +0 -37
- data/lib/models/request_context.rb +0 -18
- data/lib/models/request_options.rb +0 -12
- data/lib/models/sdk_event.rb +0 -40
- data/lib/models/user_traits.rb +0 -13
- data/lib/models/verify_result.rb +0 -16
- data/lib/securenative.rb +0 -83
- data/lib/utils/date_utils.rb +0 -9
- data/lib/utils/encryption_utils.rb +0 -49
- data/lib/utils/ip_utils.rb +0 -23
- data/lib/utils/request_utils.rb +0 -54
- data/lib/utils/secure_native_logger.rb +0 -44
- data/lib/utils/signature_utils.rb +0 -16
- data/lib/utils/utils.rb +0 -9
- data/lib/utils/version_utils.rb +0 -11
- data/out/production/securenative-ruby/event_options.rb +0 -32
- data/out/production/securenative-ruby/http/http_response.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d18bd4d9d663ea3a9c66c02568a6bb7da1c51184025aaad518e54581098ea6fb
|
4
|
+
data.tar.gz: 1f6ef18b8eeda3e0db99439b61e74bf752cd249551aafb7a84c36a22a23a6243
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51fefc82971f4be81fc80e53e8df4ae49defb30a773af44ad08da9adad03e4a14d5c6b68b4a24ef30b3948b854f7b4efa442eb946e68e7ca4dc972f1e951804a
|
7
|
+
data.tar.gz: 1a407b96bc50cc0f8db661d70d39a5106e8bc40e37b27e820976c1d989179eca194e866a160e021f1b044a7e066dc6a2c3e06f6ee86fbb553213cb559592cd47
|
data/Gemfile.lock
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
securenative (0.1.
|
4
|
+
securenative (0.1.27)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
actioncable (6.0.3.
|
10
|
-
actionpack (= 6.0.3.
|
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.
|
14
|
-
actionpack (= 6.0.3.
|
15
|
-
activejob (= 6.0.3.
|
16
|
-
activerecord (= 6.0.3.
|
17
|
-
activestorage (= 6.0.3.
|
18
|
-
activesupport (= 6.0.3.
|
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.
|
21
|
-
actionpack (= 6.0.3.
|
22
|
-
actionview (= 6.0.3.
|
23
|
-
activejob (= 6.0.3.
|
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.
|
27
|
-
actionview (= 6.0.3.
|
28
|
-
activesupport (= 6.0.3.
|
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.
|
34
|
-
actionpack (= 6.0.3.
|
35
|
-
activerecord (= 6.0.3.
|
36
|
-
activestorage (= 6.0.3.
|
37
|
-
activesupport (= 6.0.3.
|
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.
|
40
|
-
activesupport (= 6.0.3.
|
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.
|
46
|
-
activesupport (= 6.0.3.
|
45
|
+
activejob (6.0.3.3)
|
46
|
+
activesupport (= 6.0.3.3)
|
47
47
|
globalid (>= 0.3.6)
|
48
|
-
activemodel (6.0.3.
|
49
|
-
activesupport (= 6.0.3.
|
50
|
-
activerecord (6.0.3.
|
51
|
-
activemodel (= 6.0.3.
|
52
|
-
activesupport (= 6.0.3.
|
53
|
-
activestorage (6.0.3.
|
54
|
-
actionpack (= 6.0.3.
|
55
|
-
activejob (= 6.0.3.
|
56
|
-
activerecord (= 6.0.3.
|
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.
|
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,14 +64,11 @@ 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.
|
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
|
-
crack (0.4.
|
74
|
-
safe_yaml (~> 1.0.0)
|
71
|
+
crack (0.4.4)
|
75
72
|
crass (1.0.6)
|
76
73
|
diff-lcs (1.4.4)
|
77
74
|
docile (1.3.2)
|
@@ -157,7 +154,7 @@ GEM
|
|
157
154
|
concurrent-ruby (~> 1.0)
|
158
155
|
inflecto (0.0.2)
|
159
156
|
json (2.3.1)
|
160
|
-
loofah (2.
|
157
|
+
loofah (2.7.0)
|
161
158
|
crass (~> 1.0.2)
|
162
159
|
nokogiri (>= 1.5.9)
|
163
160
|
mail (2.7.1)
|
@@ -168,41 +165,41 @@ GEM
|
|
168
165
|
mimemagic (0.3.5)
|
169
166
|
mini_mime (1.0.2)
|
170
167
|
mini_portile2 (2.4.0)
|
171
|
-
minitest (5.14.
|
168
|
+
minitest (5.14.2)
|
172
169
|
mustermann (1.1.1)
|
173
170
|
ruby2_keywords (~> 0.0.1)
|
174
|
-
nio4r (2.5.
|
171
|
+
nio4r (2.5.4)
|
175
172
|
nokogiri (1.10.10)
|
176
173
|
mini_portile2 (~> 2.4.0)
|
177
|
-
public_suffix (4.0.
|
174
|
+
public_suffix (4.0.6)
|
178
175
|
rack (2.2.3)
|
179
|
-
rack-protection (2.0
|
176
|
+
rack-protection (2.1.0)
|
180
177
|
rack
|
181
178
|
rack-test (1.1.0)
|
182
179
|
rack (>= 1.0, < 3)
|
183
|
-
rails (6.0.3.
|
184
|
-
actioncable (= 6.0.3.
|
185
|
-
actionmailbox (= 6.0.3.
|
186
|
-
actionmailer (= 6.0.3.
|
187
|
-
actionpack (= 6.0.3.
|
188
|
-
actiontext (= 6.0.3.
|
189
|
-
actionview (= 6.0.3.
|
190
|
-
activejob (= 6.0.3.
|
191
|
-
activemodel (= 6.0.3.
|
192
|
-
activerecord (= 6.0.3.
|
193
|
-
activestorage (= 6.0.3.
|
194
|
-
activesupport (= 6.0.3.
|
180
|
+
rails (6.0.3.3)
|
181
|
+
actioncable (= 6.0.3.3)
|
182
|
+
actionmailbox (= 6.0.3.3)
|
183
|
+
actionmailer (= 6.0.3.3)
|
184
|
+
actionpack (= 6.0.3.3)
|
185
|
+
actiontext (= 6.0.3.3)
|
186
|
+
actionview (= 6.0.3.3)
|
187
|
+
activejob (= 6.0.3.3)
|
188
|
+
activemodel (= 6.0.3.3)
|
189
|
+
activerecord (= 6.0.3.3)
|
190
|
+
activestorage (= 6.0.3.3)
|
191
|
+
activesupport (= 6.0.3.3)
|
195
192
|
bundler (>= 1.3.0)
|
196
|
-
railties (= 6.0.3.
|
193
|
+
railties (= 6.0.3.3)
|
197
194
|
sprockets-rails (>= 2.0.0)
|
198
195
|
rails-dom-testing (2.0.3)
|
199
196
|
activesupport (>= 4.2.0)
|
200
197
|
nokogiri (>= 1.6)
|
201
198
|
rails-html-sanitizer (1.3.0)
|
202
199
|
loofah (~> 2.3)
|
203
|
-
railties (6.0.3.
|
204
|
-
actionpack (= 6.0.3.
|
205
|
-
activesupport (= 6.0.3.
|
200
|
+
railties (6.0.3.3)
|
201
|
+
actionpack (= 6.0.3.3)
|
202
|
+
activesupport (= 6.0.3.3)
|
206
203
|
method_source
|
207
204
|
rake (>= 0.8.7)
|
208
205
|
thor (>= 0.20.3, < 2.0)
|
@@ -221,20 +218,19 @@ GEM
|
|
221
218
|
rspec-support (~> 3.9.0)
|
222
219
|
rspec-support (3.9.3)
|
223
220
|
ruby2_keywords (0.0.2)
|
224
|
-
safe_yaml (1.0.5)
|
225
221
|
simplecov (0.19.0)
|
226
222
|
docile (~> 1.1)
|
227
223
|
simplecov-html (~> 0.11)
|
228
|
-
simplecov-html (0.12.
|
229
|
-
sinatra (2.0
|
224
|
+
simplecov-html (0.12.3)
|
225
|
+
sinatra (2.1.0)
|
230
226
|
mustermann (~> 1.0)
|
231
|
-
rack (~> 2.
|
232
|
-
rack-protection (= 2.0
|
227
|
+
rack (~> 2.2)
|
228
|
+
rack-protection (= 2.1.0)
|
233
229
|
tilt (~> 2.0)
|
234
230
|
sprockets (4.0.2)
|
235
231
|
concurrent-ruby (~> 1.0)
|
236
232
|
rack (> 1, < 3)
|
237
|
-
sprockets-rails (3.2.
|
233
|
+
sprockets-rails (3.2.2)
|
238
234
|
actionpack (>= 4.0)
|
239
235
|
activesupport (>= 4.0)
|
240
236
|
sprockets (>= 3.0.0)
|
@@ -246,7 +242,7 @@ GEM
|
|
246
242
|
thread_safe (~> 0.1)
|
247
243
|
url_mount (0.2.1)
|
248
244
|
rack
|
249
|
-
webmock (3.
|
245
|
+
webmock (3.9.1)
|
250
246
|
addressable (>= 2.3.6)
|
251
247
|
crack (>= 0.3.2)
|
252
248
|
hashdiff (>= 0.4.0, < 2.0.0)
|
data/README.md
CHANGED
@@ -50,36 +50,36 @@ To get your *API KEY*, login to your SecureNative account and go to project sett
|
|
50
50
|
SecureNative can automatically load your config from *securenative.yml* file or from the file that is specified in your *SECURENATIVE_CONFIG_FILE* env variable:
|
51
51
|
|
52
52
|
```ruby
|
53
|
-
require 'securenative'
|
53
|
+
require 'securenative/securenative'
|
54
54
|
|
55
55
|
|
56
|
-
secureative = SecureNative.init
|
56
|
+
secureative = SecureNative::SecureNative.init
|
57
57
|
```
|
58
58
|
### Option 2: Initialize via API Key
|
59
59
|
|
60
60
|
```ruby
|
61
|
-
require 'securenative'
|
61
|
+
require 'securenative/sdk'
|
62
62
|
|
63
63
|
|
64
|
-
securenative = SecureNative.init_with_api_key('YOUR_API_KEY')
|
64
|
+
securenative = SecureNative::SecureNative.init_with_api_key('YOUR_API_KEY')
|
65
65
|
```
|
66
66
|
|
67
67
|
### Option 3: Initialize via ConfigurationBuilder
|
68
68
|
```ruby
|
69
|
-
require 'securenative'
|
69
|
+
require 'securenative/sdk'
|
70
70
|
|
71
71
|
|
72
|
-
options = ConfigurationBuilder.new(api_key: 'API_KEY', max_events: 10, log_level: 'ERROR')
|
73
|
-
SecureNative.init_with_options(options)
|
72
|
+
options = SecureNative::ConfigurationBuilder.new(api_key: 'API_KEY', max_events: 10, log_level: 'ERROR')
|
73
|
+
SecureNative::SecureNative.init_with_options(options)
|
74
74
|
```
|
75
75
|
|
76
76
|
## Getting SecureNative instance
|
77
77
|
Once initialized, sdk will create a singleton instance which you can get:
|
78
78
|
```ruby
|
79
|
-
require 'securenative'
|
79
|
+
require 'securenative/sdk'
|
80
80
|
|
81
81
|
|
82
|
-
secureNative = SecureNative.instance
|
82
|
+
secureNative = SecureNative::SecureNative.instance
|
83
83
|
```
|
84
84
|
|
85
85
|
## Tracking events
|
@@ -88,19 +88,19 @@ Once the SDK has been initialized, tracking requests sent through the SDK
|
|
88
88
|
instance. Make sure you build event with the EventBuilder:
|
89
89
|
|
90
90
|
```ruby
|
91
|
-
require 'securenative'
|
92
|
-
require 'models/event_options'
|
93
|
-
require 'enums/event_types'
|
94
|
-
require 'models/user_traits'
|
91
|
+
require 'securenative/sdk'
|
92
|
+
require 'securenative/models/event_options'
|
93
|
+
require 'securenative/enums/event_types'
|
94
|
+
require 'securenative/models/user_traits'
|
95
95
|
|
96
96
|
|
97
97
|
def track
|
98
|
-
securenative = SecureNative.instance
|
99
|
-
context = SecureNativeContext.new(client_token: '
|
98
|
+
securenative = SecureNative::SecureNative.instance
|
99
|
+
context = SecureNative::SecureNativeContext.new(client_token: 'SECURED_CLIENT_TOKEN', ip: '127.0.0.1',
|
100
100
|
headers: { 'user-agent' => 'Mozilla: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.3 Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/43.4' })
|
101
101
|
|
102
|
-
event_options = EventOptions.new(event: EventTypes::LOG_IN, user_id: '1234', context: context,
|
103
|
-
user_traits: UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
102
|
+
event_options = SecureNative::EventOptions.new(event: SecureNative::EventTypes::LOG_IN, user_id: '1234', context: context,
|
103
|
+
user_traits: SecureNative::UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
104
104
|
properties: { custom_param1: 'CUSTOM_PARAM_VALUE', custom_param2: true, custom_param3: 3 })
|
105
105
|
|
106
106
|
securenative.track(event_options)
|
@@ -109,21 +109,21 @@ def track
|
|
109
109
|
end
|
110
110
|
```
|
111
111
|
|
112
|
-
You can also create request context from requests:
|
112
|
+
You can also create request securenative.context from requests:
|
113
113
|
|
114
114
|
```ruby
|
115
|
-
require 'securenative'
|
116
|
-
require 'models/event_options'
|
117
|
-
require 'enums/event_types'
|
118
|
-
require 'models/user_traits'
|
115
|
+
require 'securenative/sdk'
|
116
|
+
require 'securenative/models/event_options'
|
117
|
+
require 'securenative/enums/event_types'
|
118
|
+
require 'securenative/models/user_traits'
|
119
119
|
|
120
120
|
|
121
|
-
def track
|
122
|
-
securenative = SecureNative.instance
|
123
|
-
context = SecureNativeContext.from_http_request(request)
|
121
|
+
def track(request)
|
122
|
+
securenative = SecureNative::SecureNative.instance
|
123
|
+
context = SecureNative::SecureNativeContext.from_http_request(request)
|
124
124
|
|
125
|
-
event_options = EventOptions.new(event: EventTypes::LOG_IN, user_id: '1234', context: context,
|
126
|
-
user_traits: UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
125
|
+
event_options = SecureNative::EventOptions.new(event: SecureNative::EventTypes::LOG_IN, user_id: '1234', context: context,
|
126
|
+
user_traits: SecureNative::UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
127
127
|
properties: { custom_param1: 'CUSTOM_PARAM_VALUE', custom_param2: true, custom_param3: 3 })
|
128
128
|
|
129
129
|
securenative.track(event_options)
|
@@ -137,18 +137,18 @@ end
|
|
137
137
|
**Example**
|
138
138
|
|
139
139
|
```ruby
|
140
|
-
require 'securenative'
|
141
|
-
require 'models/event_options'
|
142
|
-
require 'enums/event_types'
|
143
|
-
require 'models/user_traits'
|
140
|
+
require 'securenative/sdk'
|
141
|
+
require 'securenative/models/event_options'
|
142
|
+
require 'securenative/enums/event_types'
|
143
|
+
require 'securenative/models/user_traits'
|
144
144
|
|
145
145
|
|
146
146
|
def verify(request)
|
147
|
-
securenative = SecureNative.instance
|
148
|
-
context = SecureNativeContext.from_http_request(request)
|
147
|
+
securenative = SecureNative::SecureNative.instance
|
148
|
+
context = SecureNative::SecureNativeContext.from_http_request(request)
|
149
149
|
|
150
|
-
event_options = EventOptions.new(event: EventTypes::LOG_IN, user_id: '1234', context: context,
|
151
|
-
user_traits: UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
150
|
+
event_options = SecureNative::EventOptions.new(event: SecureNative::EventTypes::LOG_IN, user_id: '1234', context: context,
|
151
|
+
user_traits: SecureNative::UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
152
152
|
properties: { custom_param1: 'CUSTOM_PARAM_VALUE', custom_param2: true, custom_param3: 3 })
|
153
153
|
|
154
154
|
verify_result = securenative.verify(event_options)
|
@@ -163,11 +163,11 @@ end
|
|
163
163
|
Apply our filter to verify the request is from us, for example:
|
164
164
|
|
165
165
|
```ruby
|
166
|
-
require 'securenative'
|
166
|
+
require 'securenative/sdk'
|
167
167
|
|
168
168
|
|
169
169
|
def webhook_endpoint(request)
|
170
|
-
securenative = SecureNative.instance
|
170
|
+
securenative = SecureNative::SecureNative.instance
|
171
171
|
|
172
172
|
# Checks if request is verified
|
173
173
|
is_verified = securenative.verify_request_payload(request)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securenative/models/sdk_event'
|
4
|
+
require 'securenative/enums/failover_strategy'
|
5
|
+
require 'securenative/enums/risk_level'
|
6
|
+
require 'securenative/enums/api_route'
|
7
|
+
require 'securenative/models/verify_result'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
module SecureNative
|
11
|
+
class ApiManager
|
12
|
+
def initialize(event_manager, securenative_options)
|
13
|
+
@event_manager = event_manager
|
14
|
+
@options = securenative_options
|
15
|
+
end
|
16
|
+
|
17
|
+
def track(event_options)
|
18
|
+
SecureNativeLogger.debug('Track event call')
|
19
|
+
event = SDKEvent.new(event_options, @options)
|
20
|
+
@event_manager.send_async(event, ApiRoute::TRACK)
|
21
|
+
end
|
22
|
+
|
23
|
+
def verify(event_options)
|
24
|
+
SecureNativeLogger.debug('Verify event call')
|
25
|
+
event = SDKEvent.new(event_options, @options)
|
26
|
+
|
27
|
+
begin
|
28
|
+
res = @event_manager.send_sync(event, ApiRoute::VERIFY, false)
|
29
|
+
ver_result = JSON.parse(res.body)
|
30
|
+
return VerifyResult.new(risk_level: ver_result['riskLevel'], score: ver_result['score'], triggers: ver_result['triggers'])
|
31
|
+
rescue StandardError => e
|
32
|
+
SecureNativeLogger.debug("Failed to call verify; #{e}")
|
33
|
+
end
|
34
|
+
if @options.fail_over_strategy == FailOverStrategy::FAIL_OPEN
|
35
|
+
return VerifyResult.new(risk_level: RiskLevel::LOW, score: 0, triggers: nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
VerifyResult.new(risk_level: RiskLevel::HIGH, score: 1, triggers: nil)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securenative/enums/failover_strategy'
|
4
|
+
|
5
|
+
module SecureNative
|
6
|
+
class ConfigurationBuilder
|
7
|
+
attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
|
8
|
+
attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
|
9
|
+
|
10
|
+
def initialize(api_key: nil, api_url: 'https://api.securenative.com/collector/api/v1', interval: 1000,
|
11
|
+
max_events: 1000, timeout: 1500, auto_send: true, disable: false, log_level: 'FATAL',
|
12
|
+
fail_over_strategy: FailOverStrategy::FAIL_OPEN, proxy_headers: nil)
|
13
|
+
@api_key = api_key
|
14
|
+
@api_url = api_url
|
15
|
+
@interval = interval
|
16
|
+
@max_events = max_events
|
17
|
+
@timeout = timeout
|
18
|
+
@auto_send = auto_send
|
19
|
+
@disable = disable
|
20
|
+
@log_level = log_level
|
21
|
+
@fail_over_strategy = fail_over_strategy
|
22
|
+
@proxy_headers = proxy_headers
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.default_securenative_options
|
26
|
+
SecureNativeOptions.new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'securenative/config/configuration_builder'
|
5
|
+
|
6
|
+
module SecureNative
|
7
|
+
class ConfigurationManager
|
8
|
+
DEFAULT_CONFIG_FILE = 'securenative.yml'
|
9
|
+
CUSTOM_CONFIG_FILE_ENV_NAME = 'SECURENATIVE_CONFIG_FILE'
|
10
|
+
@config = nil
|
11
|
+
|
12
|
+
def self.read_resource_file(resource_path)
|
13
|
+
properties = {}
|
14
|
+
begin
|
15
|
+
@config = YAML.load_file(resource_path)
|
16
|
+
properties = @config unless @config.nil?
|
17
|
+
rescue StandardError => e
|
18
|
+
SecureNativeLogger.error("Could not parse securenative.config file #{resource_path}; #{e}")
|
19
|
+
end
|
20
|
+
properties
|
21
|
+
end
|
22
|
+
|
23
|
+
def self._get_resource_path(env_name)
|
24
|
+
Env.fetch(env_name, ENV[DEFAULT_CONFIG_FILE])
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.config_builder
|
28
|
+
ConfigurationBuilder.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def self._get_env_or_default(properties, key, default)
|
32
|
+
return ENV[key] if ENV[key]
|
33
|
+
return properties[key] if properties[key]
|
34
|
+
|
35
|
+
default
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.load_config
|
39
|
+
options = ConfigurationBuilder.default_securenative_options
|
40
|
+
|
41
|
+
resource_path = DEFAULT_CONFIG_FILE
|
42
|
+
resource_path = ENV[CUSTOM_CONFIG_FILE_ENV_NAME] unless ENV[CUSTOM_CONFIG_FILE_ENV_NAME].nil?
|
43
|
+
|
44
|
+
properties = read_resource_file(resource_path)
|
45
|
+
|
46
|
+
ConfigurationBuilder.new(api_key: _get_env_or_default(properties, 'SECURENATIVE_API_KEY', options.api_key),
|
47
|
+
api_url: _get_env_or_default(properties, 'SECURENATIVE_API_URL', options.api_url),
|
48
|
+
interval: _get_env_or_default(properties, 'SECURENATIVE_INTERVAL', options.interval),
|
49
|
+
max_events: _get_env_or_default(properties, 'SECURENATIVE_MAX_EVENTS', options.max_events),
|
50
|
+
timeout: _get_env_or_default(properties, 'SECURENATIVE_TIMEOUT', options.timeout),
|
51
|
+
auto_send: _get_env_or_default(properties, 'SECURENATIVE_AUTO_SEND', options.auto_send),
|
52
|
+
disable: _get_env_or_default(properties, 'SECURENATIVE_DISABLE', options.disable),
|
53
|
+
log_level: _get_env_or_default(properties, 'SECURENATIVE_LOG_LEVEL', options.log_level),
|
54
|
+
fail_over_strategy: _get_env_or_default(properties, 'SECURENATIVE_FAILOVER_STRATEGY', options.fail_over_strategy),
|
55
|
+
proxy_headers: _get_env_or_default(properties, 'SECURENATIVE_PROXY_HEADERS', options.proxy_headers))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|