securenative 0.1.20 → 0.1.26
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 +0 -1
- data/Gemfile.lock +76 -82
- data/README.md +45 -40
- 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 +71 -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 +9 -2
- data/{lib → out/production/securenative-ruby}/context/rails_context.rb +4 -1
- data/out/production/securenative-ruby/context/securenative_context.rb +35 -8
- data/{lib → out/production/securenative-ruby}/context/sinatra_context.rb +11 -4
- 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 -45
- data/VERSION +0 -1
- data/lib/api_manager.rb +0 -35
- data/lib/config/configuration_builder.rb +0 -30
- 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 -156
- data/lib/event_options.rb +0 -32
- data/lib/http/securenative_http_client.rb +0 -38
- data/lib/models/client_token.rb +0 -12
- data/lib/models/device.rb +0 -10
- data/lib/models/event_options.rb +0 -15
- data/lib/models/request_context.rb +0 -18
- data/lib/models/request_options.rb +0 -12
- data/lib/models/sdk_event.rb +0 -35
- data/lib/models/user_traits.rb +0 -13
- data/lib/models/verify_result.rb +0 -12
- data/lib/securenative.rb +0 -95
- data/lib/utils/date_utils.rb +0 -9
- data/lib/utils/encryption_utils.rb +0 -35
- 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 -12
- data/out/production/securenative-ruby/event_options.rb +0 -32
- data/out/production/securenative-ruby/http/http_response.rb +0 -12
data/lib/event_manager.rb
DELETED
@@ -1,156 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'utils/secure_native_logger'
|
4
|
-
require 'config/securenative_options'
|
5
|
-
require 'http/securenative_http_client'
|
6
|
-
require 'errors/securenative_sdk_error'
|
7
|
-
|
8
|
-
class QueueItem
|
9
|
-
attr_reader :url, :body, :retry_sending
|
10
|
-
attr_writer :url, :body, :retry_sending
|
11
|
-
|
12
|
-
def initialize(url, body, retry_sending)
|
13
|
-
@url = url
|
14
|
-
@body = body
|
15
|
-
@retry = retry_sending
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class EventManager
|
20
|
-
def initialize(options = SecureNativeOptions.new, http_client = nil)
|
21
|
-
if options.api_key.nil?
|
22
|
-
raise SecureNativeSDKError, 'API key cannot be None, please get your API key from SecureNative console.'
|
23
|
-
end
|
24
|
-
|
25
|
-
@http_client = if http_client.nil?
|
26
|
-
SecureNativeHttpClient.new(options)
|
27
|
-
else
|
28
|
-
http_client
|
29
|
-
end
|
30
|
-
|
31
|
-
@queue = []
|
32
|
-
@semaphore = Mutex.new
|
33
|
-
@interval = options.interval
|
34
|
-
@options = options
|
35
|
-
@send_enabled = false
|
36
|
-
@attempt = 0
|
37
|
-
@coefficients = [1, 1, 2, 3, 5, 8, 13]
|
38
|
-
|
39
|
-
@thread = Thread.new { run }
|
40
|
-
end
|
41
|
-
|
42
|
-
def send_async(event, resource_path)
|
43
|
-
if @options.disable
|
44
|
-
SecureNativeLogger.warning('SDK is disabled. no operation will be performed')
|
45
|
-
return
|
46
|
-
end
|
47
|
-
|
48
|
-
item = QueueItem.new(resource_path, EventManager.serialize(event).to_json, false)
|
49
|
-
@queue.append(item)
|
50
|
-
end
|
51
|
-
|
52
|
-
def flush
|
53
|
-
@queue.each do |item|
|
54
|
-
@http_client.post(item.url, item.body)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def send_sync(event, resource_path, retry_sending)
|
59
|
-
if @options.disable
|
60
|
-
SecureNativeLogger.warning('SDK is disabled. no operation will be performed')
|
61
|
-
return
|
62
|
-
end
|
63
|
-
|
64
|
-
SecureNativeLogger.debug("Attempting to send event #{event}")
|
65
|
-
res = @http_client.post(resource_path, EventManager.serialize(event).to_json)
|
66
|
-
|
67
|
-
if res.code != 200
|
68
|
-
SecureNativeLogger.info("SecureNative failed to call endpoint #{resource_path} with event #{event}. adding back to queue")
|
69
|
-
item = QueueItem.new(resource_path, EventManager.serialize(event).to_json, retry_sending)
|
70
|
-
@queue.append(item)
|
71
|
-
end
|
72
|
-
|
73
|
-
res
|
74
|
-
end
|
75
|
-
|
76
|
-
def run
|
77
|
-
loop do
|
78
|
-
@semaphore.synchronize do
|
79
|
-
next unless !@queue.empty? && @send_enabled
|
80
|
-
|
81
|
-
@queue.each do |item|
|
82
|
-
begin
|
83
|
-
res = @http_client.post(item.url, item.body)
|
84
|
-
if res.status_code == 401
|
85
|
-
item.retry_sending = false
|
86
|
-
elsif res.status_code != 200
|
87
|
-
raise SecureNativeHttpError, res.status_code
|
88
|
-
end
|
89
|
-
SecureNativeLogger.debug("Event successfully sent; #{item.body}")
|
90
|
-
return res
|
91
|
-
rescue StandardError => e
|
92
|
-
SecureNativeLogger.error("Failed to send event; #{e}")
|
93
|
-
if item.retry_sending
|
94
|
-
@attempt = 0 if @coefficients.length == @attempt + 1
|
95
|
-
|
96
|
-
back_off = @coefficients[@attempt] * @options.interval
|
97
|
-
SecureNativeLogger.debug("Automatic back-off of #{back_off}")
|
98
|
-
@send_enabled = false
|
99
|
-
sleep back_off
|
100
|
-
@send_enabled = true
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
sleep @interval / 1000
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def start_event_persist
|
110
|
-
SecureNativeLogger.debug('Starting automatic event persistence')
|
111
|
-
if @options.auto_send || @send_enabled
|
112
|
-
@send_enabled = true
|
113
|
-
else
|
114
|
-
SecureNativeLogger.debug('Automatic event persistence is disabled, you should persist events manually')
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def stop_event_persist
|
119
|
-
if @send_enabled
|
120
|
-
SecureNativeLogger.debug('Attempting to stop automatic event persistence')
|
121
|
-
begin
|
122
|
-
flush
|
123
|
-
@thread&.stop?
|
124
|
-
SecureNativeLogger.debug('Stopped event persistence')
|
125
|
-
rescue StandardError => e
|
126
|
-
SecureNativeLogger.error("Could not stop event scheduler; #{e}")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def self.serialize(obj)
|
132
|
-
{
|
133
|
-
rid: obj.rid,
|
134
|
-
eventType: obj.event_type,
|
135
|
-
userId: obj.user_id,
|
136
|
-
userTraits: {
|
137
|
-
name: obj.user_traits.name,
|
138
|
-
email: obj.user_traits.email,
|
139
|
-
phone: obj.user_traits.phone,
|
140
|
-
createdAt: obj.user_traits.created_at
|
141
|
-
},
|
142
|
-
request: {
|
143
|
-
cid: obj.request.cid,
|
144
|
-
vid: obj.request.vid,
|
145
|
-
fp: obj.request.fp,
|
146
|
-
ip: obj.request.ip,
|
147
|
-
remoteIp: obj.request.remote_ip,
|
148
|
-
http_method: obj.request.http_method,
|
149
|
-
url: obj.request.url,
|
150
|
-
headers: obj.request.headers
|
151
|
-
},
|
152
|
-
timestamp: obj.timestamp,
|
153
|
-
properties: obj.properties
|
154
|
-
}
|
155
|
-
end
|
156
|
-
end
|
data/lib/event_options.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class EventOptions
|
4
|
-
MAX_PROPERTIES_SIZE = 10
|
5
|
-
|
6
|
-
def initialize(event_type, user_id, user_traits, user_name, email, phone, created_at, context, properties, timestamp)
|
7
|
-
traits = UserTraits(user_name)
|
8
|
-
if user_name && email && phone && created_at
|
9
|
-
traits = UserTraits(user_name, email, phone, created_at)
|
10
|
-
elsif user_name && email && phone
|
11
|
-
traits = UserTraits(user_name, email, phone)
|
12
|
-
elsif user_name && email
|
13
|
-
traits = UserTraits(user_name, email)
|
14
|
-
end
|
15
|
-
|
16
|
-
@event_options = EventOptions(event_type)
|
17
|
-
@event_options.user_id = user_id
|
18
|
-
@event_options.user_traits = user_traits if user_traits
|
19
|
-
@event_options.user_traits = traits
|
20
|
-
@event_options.context = context
|
21
|
-
@event_options.properties = properties
|
22
|
-
@event_options.timestamp = timestamp
|
23
|
-
end
|
24
|
-
|
25
|
-
def build
|
26
|
-
if !@event_options.properties.nil? && @event_options.properties.length > MAX_PROPERTIES_SIZE
|
27
|
-
raise SecureNativeInvalidOptionsError('You can have only up to {} custom properties', MAX_PROPERTIES_SIZE)
|
28
|
-
end
|
29
|
-
|
30
|
-
@event_options
|
31
|
-
end
|
32
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'net/http'
|
4
|
-
require 'uri'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
class SecureNativeHttpClient
|
8
|
-
AUTHORIZATION_HEADER = 'Authorization'
|
9
|
-
VERSION_HEADER = 'SN-Version'
|
10
|
-
USER_AGENT_HEADER = 'User-Agent'
|
11
|
-
USER_AGENT_HEADER_VALUE = 'SecureNative-ruby'
|
12
|
-
CONTENT_TYPE_HEADER = 'Content-Type'
|
13
|
-
CONTENT_TYPE_HEADER_VALUE = 'application/json'
|
14
|
-
|
15
|
-
def initialize(securenative_options)
|
16
|
-
@options = securenative_options
|
17
|
-
end
|
18
|
-
|
19
|
-
def _headers
|
20
|
-
{
|
21
|
-
CONTENT_TYPE_HEADER => CONTENT_TYPE_HEADER_VALUE,
|
22
|
-
USER_AGENT_HEADER => USER_AGENT_HEADER_VALUE,
|
23
|
-
VERSION_HEADER => VersionUtils.version,
|
24
|
-
AUTHORIZATION_HEADER => @options.api_key
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
def post(path, body)
|
29
|
-
uri = URI.parse("#{@options.api_url}/#{path}")
|
30
|
-
headers = _headers
|
31
|
-
|
32
|
-
client = Net::HTTP.new(uri.host, uri.port)
|
33
|
-
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
34
|
-
request.body = body.to_json
|
35
|
-
|
36
|
-
client.request(request)
|
37
|
-
end
|
38
|
-
end
|
data/lib/models/client_token.rb
DELETED
data/lib/models/device.rb
DELETED
data/lib/models/event_options.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class EventOptions
|
4
|
-
attr_reader :event, :user_id, :user_traits, :context, :properties, :timestamp
|
5
|
-
attr_writer :event, :user_id, :user_traits, :context, :properties, :timestamp
|
6
|
-
|
7
|
-
def initialize(event: nil, user_id: nil, user_traits: nil, context: nil, properties: nil, timestamp: nil)
|
8
|
-
@event = event
|
9
|
-
@user_id = user_id
|
10
|
-
@user_traits = user_traits
|
11
|
-
@context = context
|
12
|
-
@properties = properties
|
13
|
-
@timestamp = timestamp
|
14
|
-
end
|
15
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class RequestContext
|
4
|
-
attr_reader :cid, :vid, :fp, :ip, :remote_ip, :headers, :url, :http_method
|
5
|
-
attr_writer :cid, :vid, :fp, :ip, :remote_ip, :headers, :url, :http_method
|
6
|
-
|
7
|
-
def initialize(cid: nil, vid: nil, fp: nil, ip: nil, remote_ip: nil, headers: nil, url: nil, http_method: nil)
|
8
|
-
@cid = cid
|
9
|
-
@vid = vid
|
10
|
-
@fp = fp
|
11
|
-
@ip = ip
|
12
|
-
@remote_ip = remote_ip
|
13
|
-
@headers = headers
|
14
|
-
@url = url
|
15
|
-
@method = http_method
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class RequestOptions
|
4
|
-
attr_reader :url, :body, :retry_sending
|
5
|
-
attr_writer :url, :body, :retry_sending
|
6
|
-
|
7
|
-
def initialize(url, body, retry_sending)
|
8
|
-
@url = url
|
9
|
-
@body = body
|
10
|
-
@retry_sending = retry_sending
|
11
|
-
end
|
12
|
-
end
|
data/lib/models/sdk_event.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'context/securenative_context'
|
4
|
-
require 'utils/encryption_utils'
|
5
|
-
|
6
|
-
class SDKEvent
|
7
|
-
attr_reader :context, :rid, :event_type, :user_id, :user_traits, :request, :timestamp, :properties
|
8
|
-
attr_writer :context, :rid, :event_type, :user_id, :user_traits, :request, :timestamp, :properties
|
9
|
-
|
10
|
-
def initialize(event_options, securenative_options)
|
11
|
-
@context = if !event_options.context.nil?
|
12
|
-
event_options.context
|
13
|
-
else
|
14
|
-
SecureNativeContext.default_context_builder
|
15
|
-
end
|
16
|
-
|
17
|
-
client_token = EncryptionUtils.decrypt(@context.client_token, securenative_options.api_key)
|
18
|
-
|
19
|
-
@rid = SecureRandom.uuid.to_str
|
20
|
-
@event_type = event_options.event
|
21
|
-
@user_id = event_options.user_id
|
22
|
-
@user_traits = event_options.user_traits
|
23
|
-
@request = RequestContext(client_token ? client_token.cid : '', client_token ? client_token.vid : '',
|
24
|
-
client_token ? client_token.fp : '', @context.ip,
|
25
|
-
@context.remote_ip, @context.headers, @context.url, @context.http_method)
|
26
|
-
|
27
|
-
@timestamp = DateUtils.to_timestamp(event_options.timestamp)
|
28
|
-
@properties = event_options.properties
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_s
|
32
|
-
"context: #{@context}, rid: #{@rid}, event_type: #{@event_type}, user_id: #{@user_id},
|
33
|
-
user_traits: #{@user_traits}, request: #{@request}, timestamp: #{@timestamp}, properties: #{@properties}"
|
34
|
-
end
|
35
|
-
end
|
data/lib/models/user_traits.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class UserTraits
|
4
|
-
attr_reader :name, :email, :phone, :created_at
|
5
|
-
attr_writer :name, :email, :phone, :created_at
|
6
|
-
|
7
|
-
def initialize(name: nil, email: nil, phone: nil, created_at: nil)
|
8
|
-
@name = name
|
9
|
-
@email = email
|
10
|
-
@created_at = created_at
|
11
|
-
@phone = phone
|
12
|
-
end
|
13
|
-
end
|
data/lib/models/verify_result.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class VerifyResult
|
4
|
-
attr_reader :risk_level, :score, :triggers
|
5
|
-
attr_writer :risk_level, :score, :triggers
|
6
|
-
|
7
|
-
def initialize(risk_level: nil, score: nil, triggers: nil)
|
8
|
-
@risk_level = risk_level
|
9
|
-
@score = score
|
10
|
-
@triggers = triggers
|
11
|
-
end
|
12
|
-
end
|
data/lib/securenative.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'utils/secure_native_logger'
|
4
|
-
require 'utils/signature_utils'
|
5
|
-
require 'utils/utils'
|
6
|
-
require 'errors/securenative_sdk_error'
|
7
|
-
require 'errors/securenative_sdk_Illegal_state_error'
|
8
|
-
require 'errors/securenative_config_error'
|
9
|
-
require 'enums/failover_strategy'
|
10
|
-
require 'config/configuration_builder'
|
11
|
-
require 'event_manager'
|
12
|
-
require 'api_manager'
|
13
|
-
|
14
|
-
class SecureNative
|
15
|
-
attr_reader :options
|
16
|
-
|
17
|
-
def initialize(options)
|
18
|
-
@securenative = nil
|
19
|
-
raise SecureNativeSDKError, 'You must pass your SecureNative api key' if Utils.null_or_empty?(options.api_key)
|
20
|
-
|
21
|
-
@options = options
|
22
|
-
@event_manager = EventManager.new(@options)
|
23
|
-
|
24
|
-
@event_manager.start_event_persist unless @options.api_url.nil?
|
25
|
-
|
26
|
-
@api_manager = ApiManager.new(@event_manager, @options)
|
27
|
-
SecureNativeLogger.init_logger(@options.log_level)
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.init_with_options(options)
|
31
|
-
if @securenative.nil?
|
32
|
-
@securenative = SecureNative.new(options)
|
33
|
-
@securenative
|
34
|
-
else
|
35
|
-
SecureNativeLogger.debug('This SDK was already initialized.')
|
36
|
-
raise SecureNativeSDKError, 'This SDK was already initialized.'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.init_with_api_key(api_key)
|
41
|
-
raise SecureNativeConfigError, 'You must pass your SecureNative api key' if Utils.null_or_empty?(api_key)
|
42
|
-
|
43
|
-
if @securenative.nil?
|
44
|
-
options = ConfigurationBuilder.new(api_key: api_key)
|
45
|
-
@securenative = SecureNative.new(options)
|
46
|
-
@securenative
|
47
|
-
else
|
48
|
-
SecureNativeLogger.debug('This SDK was already initialized.')
|
49
|
-
raise SecureNativeSDKError, 'This SDK was already initialized.'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.init
|
54
|
-
options = ConfigurationManager.load_config
|
55
|
-
init_with_options(options)
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.instance
|
59
|
-
raise SecureNativeSDKIllegalStateError if @securenative.nil?
|
60
|
-
|
61
|
-
@securenative
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.config_builder(api_key: nil, api_url: 'https://api.securenative.com/collector/api/v1', interval: 1000,
|
65
|
-
max_events: 1000, timeout: 1500, auto_send: true, disable: false, log_level: 'FATAL',
|
66
|
-
fail_over_strategy: FailOverStrategy::FAIL_OPEN)
|
67
|
-
ConfigurationBuilder.new(api_key: api_key, api_url: api_url, interval: interval, max_events: max_events,
|
68
|
-
timeout: timeout, auto_send: auto_send, disable: disable, log_level: log_level,
|
69
|
-
fail_over_strategy: fail_over_strategy)
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.context_builder(client_token: nil, ip: nil, remote_ip: nil, headers: nil, url: nil, http_method: nil, body: nil)
|
73
|
-
SecureNativeContext.new(client_token: client_token, ip: ip, remote_ip: remote_ip, headers: headers,
|
74
|
-
url: url, http_method: http_method, body: body)
|
75
|
-
end
|
76
|
-
|
77
|
-
def track(event_options)
|
78
|
-
@api_manager.track(event_options)
|
79
|
-
end
|
80
|
-
|
81
|
-
def verify(event_options)
|
82
|
-
@api_manager.verify(event_options)
|
83
|
-
end
|
84
|
-
|
85
|
-
def self._flush
|
86
|
-
@securenative = nil
|
87
|
-
end
|
88
|
-
|
89
|
-
def verify_request_payload(request)
|
90
|
-
request_signature = request.header[SignatureUtils.SIGNATURE_HEADER]
|
91
|
-
body = request.body
|
92
|
-
|
93
|
-
SignatureUtils.valid_signature?(@options.api_key, body, request_signature)
|
94
|
-
end
|
95
|
-
end
|