securenative 0.1.27 → 0.1.28

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d18bd4d9d663ea3a9c66c02568a6bb7da1c51184025aaad518e54581098ea6fb
4
- data.tar.gz: 1f6ef18b8eeda3e0db99439b61e74bf752cd249551aafb7a84c36a22a23a6243
3
+ metadata.gz: 8db01a77009f99eaaa24d39ef0e4cc5f82605a9c5c731e0b0e02cacd8464f278
4
+ data.tar.gz: eb61f6a0b0213109c1bb4bd8546d2bd6389d93b9920a84f8852c3a4c39ecab65
5
5
  SHA512:
6
- metadata.gz: 51fefc82971f4be81fc80e53e8df4ae49defb30a773af44ad08da9adad03e4a14d5c6b68b4a24ef30b3948b854f7b4efa442eb946e68e7ca4dc972f1e951804a
7
- data.tar.gz: 1a407b96bc50cc0f8db661d70d39a5106e8bc40e37b27e820976c1d989179eca194e866a160e021f1b044a7e066dc6a2c3e06f6ee86fbb553213cb559592cd47
6
+ metadata.gz: 94a26461c6294bb08264809675d5885fb9a7f6041d5a0a4c689b5eac7d656da2e319894ace2eea25dbd24216c046bf704eee91003b03be94d96592934c4e87ed
7
+ data.tar.gz: f7c2b7361351c10a7035288a7832b38cc5695c75f82b8d2d4bfa55e870a8280d1f5ceea3f98ba9212532d73506cbb99cb67c3d3800b033b254e005549b6fafc6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- securenative (0.1.27)
4
+ securenative (0.1.28)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- next unless !@queue.empty? && @send_enabled
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
- return res
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, "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.22',
21
- 'User-Agent'=>'SecureNative-ruby'
22
- }).
23
- to_return(status: 200, body: "", headers: {})
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
 
@@ -6,7 +6,7 @@ require_relative 'lib/securenative/utils/version_utils'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'securenative'
9
- spec.version = '0.1.27'
9
+ spec.version = '0.1.28'
10
10
  spec.authors = ['SecureNative']
11
11
  spec.email = ['support@securenative.com']
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: securenative
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.27
4
+ version: 0.1.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - SecureNative