securenative 0.1.27 → 0.1.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +24 -1
- data/lib/securenative/event_manager.rb +5 -6
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +12 -12
- data/securenative.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8db01a77009f99eaaa24d39ef0e4cc5f82605a9c5c731e0b0e02cacd8464f278
|
4
|
+
data.tar.gz: eb61f6a0b0213109c1bb4bd8546d2bd6389d93b9920a84f8852c3a4c39ecab65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94a26461c6294bb08264809675d5885fb9a7f6041d5a0a4c689b5eac7d656da2e319894ace2eea25dbd24216c046bf704eee91003b03be94d96592934c4e87ed
|
7
|
+
data.tar.gz: f7c2b7361351c10a7035288a7832b38cc5695c75f82b8d2d4bfa55e870a8280d1f5ceea3f98ba9212532d73506cbb99cb67c3d3800b033b254e005549b6fafc6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -172,4 +172,27 @@ def webhook_endpoint(request)
|
|
172
172
|
# Checks if request is verified
|
173
173
|
is_verified = securenative.verify_request_payload(request)
|
174
174
|
end
|
175
|
-
```
|
175
|
+
```
|
176
|
+
|
177
|
+
## Extract proxy headers from Cloudflare
|
178
|
+
|
179
|
+
You can specify custom header keys to allow extraction of client ip from different providers.
|
180
|
+
This example demonstrates the usage of proxy headers for ip extraction from Cloudflare.
|
181
|
+
|
182
|
+
### Option 1: Using config file
|
183
|
+
```yaml
|
184
|
+
SECURENATIVE_API_KEY: dsbe27fh3437r2yd326fg3fdg36f43
|
185
|
+
SECURENATIVE_PROXY_HEADERS: ["CF-Connecting-IP"]
|
186
|
+
```
|
187
|
+
|
188
|
+
Initialize sdk as showed above.
|
189
|
+
|
190
|
+
### Options 2: Using ConfigurationBuilder
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
require 'securenative/sdk'
|
194
|
+
|
195
|
+
options = SecureNative::SecureNativeOptions.new(api_key: 'API_KEY', max_events: 10, log_level: 'ERROR', proxy_headers: ['CF-Connecting-IP'])
|
196
|
+
|
197
|
+
SecureNative::SecureNative.init_with_options(options)
|
198
|
+
```
|
@@ -78,19 +78,18 @@ module SecureNative
|
|
78
78
|
def run
|
79
79
|
loop do
|
80
80
|
@semaphore.synchronize do
|
81
|
-
|
82
|
-
|
83
|
-
@queue.each do |item|
|
81
|
+
if (item = !@queue.empty? && @send_enabled)
|
84
82
|
begin
|
83
|
+
item = @queue.shift
|
85
84
|
res = @http_client.post(item.url, item.body)
|
86
85
|
if res.code == '401'
|
87
86
|
item.retry_sending = false
|
88
87
|
elsif res.code != '200'
|
88
|
+
@queue.append(item)
|
89
89
|
raise SecureNativeHttpError, res.status_code
|
90
90
|
end
|
91
91
|
SecureNativeLogger.debug("Event successfully sent; #{item.body}")
|
92
|
-
|
93
|
-
rescue StandardError => e
|
92
|
+
rescue Exception => e
|
94
93
|
SecureNativeLogger.error("Failed to send event; #{e}")
|
95
94
|
if item.retry_sending
|
96
95
|
@attempt = 0 if @coefficients.length == @attempt + 1
|
@@ -104,7 +103,7 @@ module SecureNative
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
end
|
107
|
-
sleep @interval / 1000
|
106
|
+
sleep @interval / 1000 if @queue.empty?
|
108
107
|
end
|
109
108
|
end
|
110
109
|
|
@@ -9,18 +9,18 @@ RSpec.describe SecureNativeHttpClient do
|
|
9
9
|
it 'makes a simple post call' do
|
10
10
|
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
|
11
11
|
|
12
|
-
stub_request(:post,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/track')
|
13
|
+
.with(
|
14
|
+
body: '{"event": "SOME_EVENT_NAME"}',
|
15
|
+
headers: {
|
16
|
+
'Accept' => '*/*',
|
17
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
18
|
+
'Authorization' => 'YOUR_API_KEY',
|
19
|
+
'Content-Type' => 'application/json',
|
20
|
+
'Sn-Version' => '0.1.28',
|
21
|
+
'User-Agent' => 'SecureNative-ruby'
|
22
|
+
}
|
23
|
+
).to_return(status: 200, body: '', headers: {})
|
24
24
|
client = SecureNativeHttpClient.new(options)
|
25
25
|
payload = '{"event": "SOME_EVENT_NAME"}'
|
26
26
|
|
data/securenative.gemspec
CHANGED