liveqa 1.4.6 → 1.8.3
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/.rubocop.yml +2 -0
- data/.travis.yml +1 -0
- data/README.md +94 -7
- data/lib/liveqa/api_operation/delete.rb +38 -0
- data/lib/liveqa/api_resource.rb +7 -6
- data/lib/liveqa/async_handlers/base.rb +1 -3
- data/lib/liveqa/config.rb +35 -11
- data/lib/liveqa/event.rb +4 -10
- data/lib/liveqa/group.rb +14 -0
- data/lib/liveqa/identity.rb +16 -0
- data/lib/liveqa/liveqa_object.rb +48 -8
- data/lib/liveqa/message.rb +31 -10
- data/lib/liveqa/plugins/rack/middleware.rb +50 -36
- data/lib/liveqa/plugins/rails/data.rb +19 -0
- data/lib/liveqa/plugins/rails/middleware_data.rb +2 -18
- data/lib/liveqa/plugins/sidekiq/client_middleware.rb +1 -1
- data/lib/liveqa/plugins/sidekiq/server_middleware.rb +2 -2
- data/lib/liveqa/plugins.rb +1 -0
- data/lib/liveqa/request.rb +2 -0
- data/lib/liveqa/store.rb +1 -1
- data/lib/liveqa/util.rb +81 -1
- data/lib/liveqa/version.rb +1 -1
- data/lib/liveqa/watcher.rb +15 -0
- data/lib/liveqa.rb +82 -4
- data/spec/lib/liveqa/api_resource_spec.rb +109 -0
- data/spec/lib/liveqa/async_handlers/base_spec.rb +13 -3
- data/spec/lib/liveqa/config_spec.rb +8 -6
- data/spec/lib/liveqa/event_spec.rb +2 -23
- data/spec/lib/liveqa/group_spec.rb +15 -0
- data/spec/lib/liveqa/identity_spec.rb +15 -0
- data/spec/lib/liveqa/liveqa_object_spec.rb +53 -2
- data/spec/lib/liveqa/message_spec.rb +75 -8
- data/spec/lib/liveqa/plugins/rack/middleware_spec.rb +8 -2
- data/spec/lib/liveqa/plugins/rails/data_spec.rb +22 -0
- data/spec/lib/liveqa/plugins/rails/middleware_data_spec.rb +2 -23
- data/spec/lib/liveqa/plugins/sidekiq/server_middleware_spec.rb +6 -12
- data/spec/lib/liveqa/util_spec.rb +40 -0
- data/spec/lib/liveqa/watcher_spec.rb +25 -0
- data/spec/lib/liveqa_spec.rb +88 -5
- data/spec/spec_helper.rb +3 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eedcd2fa28e813d0ebde999b52507b9dd8517668
|
4
|
+
data.tar.gz: a7739558d0b587260136c1d9a364dead5c283d43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd51dba298a81bc4f67a98db6ec8a2adc0cb418f9c474f787c39b6ffa9ed57393dff40c4d1e333f9afdebac25003872c9cbac51e34c53dddb754e18bde58eeb1
|
7
|
+
data.tar.gz: ecbb7fa596f45776d43abb4b7fc3c2e1f2d5b4e2853b6702da72a045c22d963a32a964e108c7075fe228dbbd09715130b4eb4147c4820fc640d1ac86d1ad78bf
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -20,19 +20,106 @@ gem 'liveqa'
|
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
LiveQA.configure do |config|
|
23
|
-
|
23
|
+
##
|
24
|
+
# Account token can be found inside your environment settings
|
25
|
+
config.account_token = 'acc_xx'
|
26
|
+
|
27
|
+
##
|
28
|
+
# The name of your space
|
29
|
+
config.space_name = 'LiveQA'
|
30
|
+
|
31
|
+
##
|
32
|
+
# The name of your environement
|
33
|
+
config.environment_name = 'production'
|
34
|
+
|
35
|
+
##
|
36
|
+
# If you use a proxy.
|
37
|
+
# default: nil
|
38
|
+
# config.proxy_url = ENV['HTTP_PROXY']
|
39
|
+
|
40
|
+
##
|
41
|
+
# If enabled is set to false nothing is send to the server
|
42
|
+
# default: true
|
43
|
+
# config.enabled = true
|
44
|
+
|
45
|
+
##
|
46
|
+
# Extra attributes to be obfuscated
|
47
|
+
# default: []
|
48
|
+
# config.obfuscated_fields = ['credit_card_number']
|
49
|
+
|
50
|
+
##
|
51
|
+
# Use an async handler to send data to the liveqa to
|
52
|
+
# avoid slowing down your application
|
53
|
+
# available option: :sidekiq
|
54
|
+
# default: nil
|
55
|
+
# config.async_handler = :sidekiq
|
56
|
+
|
57
|
+
##
|
58
|
+
# Options to be passed to the async handler
|
59
|
+
# default: {}
|
60
|
+
# config.async_options = { queue: 'liveqa' }
|
61
|
+
|
62
|
+
##
|
63
|
+
# Metadata is passed with every request to the server
|
64
|
+
# default: nil
|
65
|
+
# config.metadata = {
|
66
|
+
#. customer: -> { current_customer.id},
|
67
|
+
#. version: 42
|
68
|
+
# }
|
69
|
+
#
|
24
70
|
end
|
25
71
|
```
|
26
72
|
|
27
73
|
## Usage
|
28
74
|
|
75
|
+
### Track
|
76
|
+
|
77
|
+
Track an event
|
78
|
+
|
79
|
+
Attributes:
|
80
|
+
|
81
|
+
* `String` event name
|
82
|
+
* `Hash` event attributes
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
LiveQA.track('my event',
|
86
|
+
user_id: 42,
|
87
|
+
properties: {
|
88
|
+
order_id: 84
|
89
|
+
}
|
90
|
+
);
|
91
|
+
```
|
92
|
+
|
93
|
+
### Identify
|
94
|
+
|
95
|
+
Identify a user
|
96
|
+
|
97
|
+
Attributes:
|
98
|
+
|
99
|
+
* `String` user id from your database
|
100
|
+
* `Hash` user attributes
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
LiveQA.identify(42,
|
104
|
+
properties: {
|
105
|
+
name: 'John Doe'
|
106
|
+
}
|
107
|
+
);
|
108
|
+
```
|
109
|
+
|
110
|
+
### Watch
|
111
|
+
|
112
|
+
Create a watcher
|
113
|
+
|
114
|
+
Attributes:
|
115
|
+
|
116
|
+
* `String|Integer` template flow name or id
|
117
|
+
* `Hash` watcher attributes
|
118
|
+
|
29
119
|
```ruby
|
30
|
-
LiveQA.
|
31
|
-
|
32
|
-
|
33
|
-
order_id: 84
|
34
|
-
}
|
35
|
-
});
|
120
|
+
LiveQA.watch('My Flow',
|
121
|
+
expected_times: 42
|
122
|
+
);
|
36
123
|
```
|
37
124
|
|
38
125
|
## Issues
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module LiveQA
|
2
|
+
class APIOperation
|
3
|
+
##
|
4
|
+
# == Delete a resource for the API
|
5
|
+
#
|
6
|
+
module Delete
|
7
|
+
module ClassMethods
|
8
|
+
##
|
9
|
+
# Delete an API Resource
|
10
|
+
#
|
11
|
+
# @param [String] id for the request
|
12
|
+
# @param [Hash] Additional options for the request
|
13
|
+
#
|
14
|
+
# @return [LiveQA::Object] response from the API
|
15
|
+
def delete(id, options = {})
|
16
|
+
response = request(:delete, "#{resource_path}/#{id}", options)
|
17
|
+
initialize_from(response)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Delete an API Resources
|
23
|
+
#
|
24
|
+
# @param [Hash] Additional options for the request
|
25
|
+
#
|
26
|
+
# @return [LiveQA::Object] response from the API
|
27
|
+
def destroy(options = {})
|
28
|
+
response = request(:delete, "#{resource_path}/#{id}", {}, options)
|
29
|
+
update_from(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.included(base)
|
33
|
+
base.extend(ClassMethods)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/liveqa/api_resource.rb
CHANGED
@@ -71,12 +71,11 @@ module LiveQA
|
|
71
71
|
payload: payload.to_json,
|
72
72
|
proxy: configurations.proxy_url,
|
73
73
|
use_ssl: configurations.http_secure
|
74
|
-
).merge(headers).merge(options)
|
74
|
+
).merge(headers(options)).merge(options)
|
75
75
|
|
76
|
-
Request.execute(request_options)
|
76
|
+
Request.execute(request_options).body
|
77
77
|
rescue LiveQA::RequestError => error
|
78
78
|
return error.http_body if error.http_status == 422
|
79
|
-
raise
|
80
79
|
end
|
81
80
|
|
82
81
|
private
|
@@ -104,12 +103,14 @@ module LiveQA
|
|
104
103
|
}
|
105
104
|
end
|
106
105
|
|
107
|
-
def headers
|
106
|
+
def headers(options)
|
108
107
|
{
|
109
108
|
headers: {
|
110
|
-
accept:
|
109
|
+
accept: 'application/json',
|
111
110
|
content_type: 'application/json',
|
112
|
-
|
111
|
+
x_account_token: options.delete(:account_token) || configurations.account_token,
|
112
|
+
x_space_name: options.delete(:space_name) || configurations.space_name,
|
113
|
+
x_environment_name: options.delete(:environment_name) || configurations.environment_name
|
113
114
|
}
|
114
115
|
}
|
115
116
|
end
|
data/lib/liveqa/config.rb
CHANGED
@@ -27,8 +27,16 @@ module LiveQA
|
|
27
27
|
].freeze
|
28
28
|
|
29
29
|
##
|
30
|
-
# @return [String] API
|
31
|
-
attr_accessor :
|
30
|
+
# @return [String] API account token
|
31
|
+
attr_accessor :account_token
|
32
|
+
|
33
|
+
##
|
34
|
+
# @return [String] API space name
|
35
|
+
attr_accessor :space_name
|
36
|
+
|
37
|
+
##
|
38
|
+
# @return [String] API environment name
|
39
|
+
attr_accessor :environment_name
|
32
40
|
|
33
41
|
##
|
34
42
|
# @return [String] API host
|
@@ -62,20 +70,36 @@ module LiveQA
|
|
62
70
|
# @return [Hash] options for asynchronous handler
|
63
71
|
attr_accessor :async_options
|
64
72
|
|
73
|
+
##
|
74
|
+
# @return [Hash] custom object properties
|
75
|
+
attr_accessor :custom_object_properties
|
76
|
+
|
77
|
+
##
|
78
|
+
# @return [Hash] metadata to be attach to the payload
|
79
|
+
attr_accessor :metadata
|
80
|
+
|
65
81
|
##
|
66
82
|
# @param [Hash{Symbol=>Object}]
|
67
83
|
# Initialize and validate the configuration
|
84
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
85
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
68
86
|
def initialize(options = {})
|
69
|
-
self.
|
70
|
-
self.
|
71
|
-
self.
|
72
|
-
self.
|
73
|
-
self.
|
74
|
-
self.
|
87
|
+
self.account_token = options[:account_token]
|
88
|
+
self.space_name = options[:space_name]
|
89
|
+
self.environment_name = options[:environment_name]
|
90
|
+
self.api_host = options[:api_host] || 'api.liveqa.io'
|
91
|
+
self.api_version = options[:api_version] || 'v1'
|
92
|
+
self.proxy_url = options[:proxy_url]
|
93
|
+
self.http_secure = options[:http_secure] || true
|
94
|
+
self.enabled = options[:enabled] || true
|
75
95
|
self.obfuscated_fields = options[:obfuscated_fields] || []
|
76
|
-
self.async_handler
|
77
|
-
self.async_options
|
96
|
+
self.async_handler = options[:async_handler]
|
97
|
+
self.async_options = options[:async_options] || {}
|
98
|
+
self.custom_object_properties = options[:custom_object_properties] || {}
|
99
|
+
self.metadata = options[:metadata]
|
78
100
|
end
|
101
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
102
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
79
103
|
|
80
104
|
##
|
81
105
|
# validate the configuration
|
@@ -84,7 +108,7 @@ module LiveQA
|
|
84
108
|
def valid!
|
85
109
|
format!
|
86
110
|
|
87
|
-
%i[
|
111
|
+
%i[account_token space_name environment_name api_host api_version].each do |field|
|
88
112
|
validate_presence(field)
|
89
113
|
end
|
90
114
|
|
data/lib/liveqa/event.rb
CHANGED
@@ -2,21 +2,15 @@ module LiveQA
|
|
2
2
|
##
|
3
3
|
# == LiveQA \Event
|
4
4
|
#
|
5
|
+
# Accepted Methods:
|
6
|
+
#
|
7
|
+
# * update
|
8
|
+
#
|
5
9
|
# @example: Usage
|
6
10
|
#
|
7
11
|
# request = LiveQA::Event.create('Event Name') #=> #<LiveQA::Response...>
|
8
12
|
#
|
9
13
|
class Event < APIResource
|
10
14
|
include LiveQA::APIOperation::Save
|
11
|
-
|
12
|
-
class << self
|
13
|
-
|
14
|
-
def build_payload(payload)
|
15
|
-
Message
|
16
|
-
.to_h
|
17
|
-
.merge(payload)
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
15
|
end
|
22
16
|
end
|
data/lib/liveqa/group.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module LiveQA
|
2
|
+
##
|
3
|
+
# == LiveQA \Group
|
4
|
+
#
|
5
|
+
# Create and update groups
|
6
|
+
#
|
7
|
+
# @example: Usage
|
8
|
+
#
|
9
|
+
# request = LiveQA::Group.update('dc0b28d8a220', properties: { name: 'My Group' }) #=> #<LiveQA::Response...>
|
10
|
+
#
|
11
|
+
class Group < APIResource
|
12
|
+
include LiveQA::APIOperation::Save
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module LiveQA
|
2
|
+
##
|
3
|
+
# == LiveQA \Identity
|
4
|
+
#
|
5
|
+
# Create and update groups
|
6
|
+
#
|
7
|
+
# @example: Usage
|
8
|
+
#
|
9
|
+
# request = LiveQA::Identity.update('dc0b28d8a220', properties: { name: 'My Identity' }) #=> #<LiveQA::Response...>
|
10
|
+
#
|
11
|
+
class Identity < APIResource
|
12
|
+
@resource_name = 'identities'
|
13
|
+
|
14
|
+
include LiveQA::APIOperation::Save
|
15
|
+
end
|
16
|
+
end
|
data/lib/liveqa/liveqa_object.rb
CHANGED
@@ -12,27 +12,48 @@ module LiveQA
|
|
12
12
|
# @return [Hash] JSON parsed response
|
13
13
|
attr_reader :data
|
14
14
|
|
15
|
-
attr_reader :accepted
|
16
|
-
alias accepted? accepted
|
17
|
-
|
18
15
|
attr_reader :errors
|
19
16
|
|
17
|
+
attr_reader :successful
|
18
|
+
alias successful? successful
|
19
|
+
|
20
20
|
class << self
|
21
21
|
|
22
22
|
##
|
23
23
|
# Initialize from the API response
|
24
24
|
#
|
25
25
|
# @return [LiveQA::LiveQAObject]
|
26
|
-
def initialize_from(
|
27
|
-
object
|
26
|
+
def initialize_from(response, object = new)
|
27
|
+
object.load_response_api(response.is_a?(Hash) ? response : Util.safe_json_parse(response))
|
28
|
+
object.update_attributes(LiveQA::Util.except_keys(object.raw, :data))
|
29
|
+
if object.raw[:object] == 'list'
|
30
|
+
object.raw[:data].each do |response_object|
|
31
|
+
data = object.type_from_string_object(response_object[:object]).initialize_from(response_object)
|
28
32
|
|
29
|
-
|
33
|
+
object.add_data(data)
|
34
|
+
end
|
35
|
+
end
|
30
36
|
|
31
37
|
object
|
32
38
|
end
|
33
39
|
|
34
40
|
end
|
35
41
|
|
42
|
+
##
|
43
|
+
# Update the object based on the response from the API
|
44
|
+
# Remove and new accessor
|
45
|
+
#
|
46
|
+
# @param [Hash] response
|
47
|
+
#
|
48
|
+
# @return [LiveQA::LiveQAObject]
|
49
|
+
def update_from(response)
|
50
|
+
self.class.initialize_from(response, self)
|
51
|
+
|
52
|
+
(@values.keys - raw.keys).each { |key| remove_accessor(key) }
|
53
|
+
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
36
57
|
##
|
37
58
|
# Initialize and create accessor for values
|
38
59
|
#
|
@@ -70,7 +91,7 @@ module LiveQA
|
|
70
91
|
|
71
92
|
##
|
72
93
|
# @return [JSON] values to JSON
|
73
|
-
def to_json
|
94
|
+
def to_json(_object = nil)
|
74
95
|
JSON.generate(@values)
|
75
96
|
end
|
76
97
|
|
@@ -84,6 +105,15 @@ module LiveQA
|
|
84
105
|
end
|
85
106
|
end
|
86
107
|
|
108
|
+
##
|
109
|
+
# Load the root components for the API response
|
110
|
+
#
|
111
|
+
# @param [Hash] values
|
112
|
+
def load_response_api(response)
|
113
|
+
@raw = LiveQA::Util.deep_underscore_key(response)
|
114
|
+
@successful = true
|
115
|
+
end
|
116
|
+
|
87
117
|
##
|
88
118
|
# Add data for sub-object
|
89
119
|
#
|
@@ -92,7 +122,17 @@ module LiveQA
|
|
92
122
|
@data << data
|
93
123
|
end
|
94
124
|
|
95
|
-
|
125
|
+
##
|
126
|
+
# Create an object from a string
|
127
|
+
#
|
128
|
+
# @param [String] object to be build
|
129
|
+
#
|
130
|
+
# @return [Object]
|
131
|
+
def type_from_string_object(string_object)
|
132
|
+
klass_name = LiveQA::Util.camelize(string_object.to_s)
|
133
|
+
|
134
|
+
Object.const_get("LiveQA::#{klass_name}")
|
135
|
+
end
|
96
136
|
|
97
137
|
def inspect
|
98
138
|
id_string = respond_to?(:id) && !id.nil? ? " id=#{id}" : ''
|
data/lib/liveqa/message.rb
CHANGED
@@ -6,27 +6,31 @@ module LiveQA
|
|
6
6
|
class Message
|
7
7
|
class << self
|
8
8
|
|
9
|
-
def
|
9
|
+
def base
|
10
10
|
Util.deep_compact(
|
11
|
-
tracker_id: tracker_id,
|
12
11
|
message_id: SecureRandom.uuid,
|
13
|
-
timestamp: Time.now.utc.iso8601,
|
14
|
-
session_tracker_id:
|
12
|
+
timestamp: Time.now.utc.iso8601(3),
|
13
|
+
session_tracker_id: session_tracker_id,
|
14
|
+
metadata: metadata
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def extended
|
19
|
+
Util.deep_compact(
|
15
20
|
library: library,
|
16
21
|
server: server,
|
17
22
|
request: LiveQA::Store.get(:request),
|
18
23
|
worker: LiveQA::Store.get(:worker),
|
19
|
-
|
20
|
-
|
21
|
-
)
|
24
|
+
environment: LiveQA::Store.get(:environment)
|
25
|
+
).merge(base)
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
25
29
|
|
26
|
-
def
|
27
|
-
return LiveQA::Store.get(:
|
30
|
+
def session_tracker_id
|
31
|
+
return LiveQA::Store.get(:session_tracker_id) if LiveQA::Store.exist?(:session_tracker_id)
|
28
32
|
|
29
|
-
LiveQA::Store.set(:
|
33
|
+
LiveQA::Store.set(:session_tracker_id, SecureRandom.uuid)
|
30
34
|
end
|
31
35
|
|
32
36
|
def library
|
@@ -45,6 +49,23 @@ module LiveQA
|
|
45
49
|
}
|
46
50
|
end
|
47
51
|
|
52
|
+
def metadata
|
53
|
+
return nil if LiveQA.configurations.metadata.nil?
|
54
|
+
|
55
|
+
LiveQA.configurations.metadata.each_with_object({}) do |(key, value), hash|
|
56
|
+
if value.is_a?(Proc)
|
57
|
+
begin
|
58
|
+
hash[key] = value.call
|
59
|
+
rescue
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
next
|
63
|
+
end
|
64
|
+
|
65
|
+
hash[key] = value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
48
69
|
end
|
49
70
|
end
|
50
71
|
end
|
@@ -18,15 +18,12 @@ module LiveQA
|
|
18
18
|
request = ::Rack::Request.new(env)
|
19
19
|
|
20
20
|
store_tracker(request)
|
21
|
-
store_request_data(request)
|
22
|
-
store_stack
|
21
|
+
store_request_data(request, env)
|
23
22
|
|
24
23
|
LiveQA::Plugins::Rails::MiddlewareData.store_data(request) if defined?(::Rails)
|
25
|
-
|
26
24
|
status, headers, body = @app.call(env)
|
27
25
|
|
28
|
-
|
29
|
-
|
26
|
+
write_cookie_session_tracker_id!(headers, env)
|
30
27
|
[status, headers, body]
|
31
28
|
ensure
|
32
29
|
LiveQA::Store.clear!
|
@@ -34,19 +31,18 @@ module LiveQA
|
|
34
31
|
|
35
32
|
private
|
36
33
|
|
37
|
-
def
|
34
|
+
def session_tracker_id_name
|
38
35
|
'liveqa_tracker_id'.freeze
|
39
36
|
end
|
40
37
|
|
41
38
|
def store_tracker(request)
|
42
39
|
LiveQA::Store.set(
|
43
|
-
:
|
44
|
-
request.cookies[
|
40
|
+
:session_tracker_id,
|
41
|
+
request.cookies[session_tracker_id_name] || SecureRandom.uuid
|
45
42
|
)
|
46
43
|
end
|
47
44
|
|
48
|
-
|
49
|
-
def store_request_data(request)
|
45
|
+
def store_request_data(request, env)
|
50
46
|
LiveQA::Store.set(
|
51
47
|
:request,
|
52
48
|
url: obfuscate_uri(request.url),
|
@@ -59,40 +55,23 @@ module LiveQA
|
|
59
55
|
xhr: request.xhr?,
|
60
56
|
user_agent: request.user_agent,
|
61
57
|
ip: request.ip,
|
62
|
-
get_params:
|
63
|
-
|
64
|
-
|
65
|
-
),
|
66
|
-
post_params: Util.deep_obfuscate_value(
|
67
|
-
request.POST,
|
68
|
-
LiveQA.configurations.obfuscated_fields
|
69
|
-
)
|
58
|
+
get_params: obfuscation_get_params(request, 'GET'),
|
59
|
+
post_params: obfuscation_get_params(request, 'POST'),
|
60
|
+
headers: obfuscate_headers(env)
|
70
61
|
)
|
71
62
|
|
72
63
|
LiveQA::Store.bulk_set(
|
73
64
|
server_software: request.env['SERVER_SOFTWARE']
|
74
65
|
)
|
75
66
|
end
|
76
|
-
# rubocop:enable Metrics/MethodLength
|
77
67
|
|
78
|
-
def
|
79
|
-
stack = LiveQA::Store.get(:stack) || []
|
80
|
-
|
81
|
-
LiveQA::Store.set(
|
82
|
-
:stack,
|
83
|
-
stack.push(
|
84
|
-
name: 'rack',
|
85
|
-
version: ::Rack.version
|
86
|
-
)
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
def write_cookie_tracker_id!(headers)
|
68
|
+
def write_cookie_session_tracker_id!(headers, env)
|
91
69
|
::Rack::Utils.set_cookie_header!(
|
92
70
|
headers || {},
|
93
|
-
|
94
|
-
value: LiveQA::Store.get(:
|
95
|
-
path: '/'
|
71
|
+
session_tracker_id_name,
|
72
|
+
value: LiveQA::Store.get(:session_tracker_id),
|
73
|
+
path: '/',
|
74
|
+
secure: https_request?(env)
|
96
75
|
)
|
97
76
|
end
|
98
77
|
|
@@ -106,7 +85,7 @@ module LiveQA
|
|
106
85
|
'HIDDEN'
|
107
86
|
)
|
108
87
|
|
109
|
-
return url if params.
|
88
|
+
return url if params.empty?
|
110
89
|
|
111
90
|
uri.merge(
|
112
91
|
"?#{::Rack::Utils.build_query(params)}"
|
@@ -115,6 +94,41 @@ module LiveQA
|
|
115
94
|
''
|
116
95
|
end
|
117
96
|
|
97
|
+
def obfuscation_get_params(request, type)
|
98
|
+
Util.deep_obfuscate_value(
|
99
|
+
request.send(type),
|
100
|
+
LiveQA.configurations.obfuscated_fields
|
101
|
+
)
|
102
|
+
rescue
|
103
|
+
{}
|
104
|
+
end
|
105
|
+
|
106
|
+
# determines if a request is HTTPS based on headers and env variabled
|
107
|
+
def https_request?(env)
|
108
|
+
env['HTTPS'] == 'on' ||
|
109
|
+
env['HTTP_X_FORWARDED_SSL'] == 'on' ||
|
110
|
+
env['HTTP_X_FORWARDED_PROTO'].to_s.split(',').first == 'https' ||
|
111
|
+
env['rack.url_scheme'] == 'https'
|
112
|
+
end
|
113
|
+
|
114
|
+
def obfuscate_headers(env)
|
115
|
+
skip_headers = %w[HTTP_USER_AGENT HTTP_COOKIE HTTP_REFERER HTTP_HOST]
|
116
|
+
|
117
|
+
headers = env.keys.grep(/^HTTP_|^CONTENT_TYPE$|^CONTENT_LENGTH$/).each_with_object({}) do |key, hash|
|
118
|
+
next if skip_headers.include?(key)
|
119
|
+
name = key.gsub(/^HTTP_/, '').split('_').map(&:capitalize).join('-')
|
120
|
+
|
121
|
+
hash[name] = env[key]
|
122
|
+
end
|
123
|
+
|
124
|
+
Util.deep_obfuscate_value(
|
125
|
+
headers,
|
126
|
+
LiveQA.configurations.obfuscated_fields
|
127
|
+
)
|
128
|
+
rescue
|
129
|
+
{}
|
130
|
+
end
|
131
|
+
|
118
132
|
end
|
119
133
|
end
|
120
134
|
end
|