treblle 1.0.1 → 1.0.2
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/lib/treblle.rb +1 -1
- metadata +6 -7
- data/lib/treblle/data_builder.rb +0 -138
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c7e8150492d3a4b39eff0b9d64a12e75e459fe4d74ac42a6eb172f860f6cc6e0
|
|
4
|
+
data.tar.gz: b96ad0f8f9697838523d4db9945a3214e7810865033f9fc27fe1666f1d108589
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2aa83b4cda17c255dc307f9135fb9e60839af43abab4e39639eecc165e67b2cee4dd8b8b6dc93b0162ff6f7113722000e1b7791c6bb9d3d7d1236282f41baa97
|
|
7
|
+
data.tar.gz: 10da084dcceb356776492b26473c5564fa1675b5a801d6afc235023cc77085eeeb4b84c563aa051d8b1995dfd628e84faa5b84d29f5f97260207e441318989ce
|
data/lib/treblle.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: treblle
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hrvoje Grdic
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-07-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: TreblleSDK for ruby
|
|
14
14
|
email: hrvoje.grdic@bitlab.hr
|
|
@@ -17,12 +17,11 @@ extensions: []
|
|
|
17
17
|
extra_rdoc_files: []
|
|
18
18
|
files:
|
|
19
19
|
- lib/treblle.rb
|
|
20
|
-
- lib/treblle/data_builder.rb
|
|
21
20
|
homepage: https://rubygems.org/gems/treblle
|
|
22
21
|
licenses:
|
|
23
22
|
- MIT
|
|
24
23
|
metadata: {}
|
|
25
|
-
post_install_message:
|
|
24
|
+
post_install_message:
|
|
26
25
|
rdoc_options: []
|
|
27
26
|
require_paths:
|
|
28
27
|
- lib
|
|
@@ -37,8 +36,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
37
36
|
- !ruby/object:Gem::Version
|
|
38
37
|
version: '0'
|
|
39
38
|
requirements: []
|
|
40
|
-
rubygems_version: 3.
|
|
41
|
-
signing_key:
|
|
39
|
+
rubygems_version: 3.2.22
|
|
40
|
+
signing_key:
|
|
42
41
|
specification_version: 4
|
|
43
42
|
summary: TreblleSDK
|
|
44
43
|
test_files: []
|
data/lib/treblle/data_builder.rb
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'socket'
|
|
4
|
-
|
|
5
|
-
# Gathers and builds body payload to be sent to Treblle in json format.
|
|
6
|
-
# Hides sensitive data based on default values and additional ones provided via env variable.
|
|
7
|
-
class DataBuilder
|
|
8
|
-
DEFAULT_SENSITIVE_FIELDS = Set[
|
|
9
|
-
'card_number',
|
|
10
|
-
'cardNumber',
|
|
11
|
-
'cc',
|
|
12
|
-
'ccv',
|
|
13
|
-
'credit_score',
|
|
14
|
-
'creditScore',
|
|
15
|
-
'password',
|
|
16
|
-
'password_confirmation',
|
|
17
|
-
'passwordConfirmation',
|
|
18
|
-
'pwd',
|
|
19
|
-
'secret',
|
|
20
|
-
'ssn'
|
|
21
|
-
].freeze
|
|
22
|
-
|
|
23
|
-
attr_accessor :env, :status, :started_at, :ended_at, :request, :headers, :json_response, :exception
|
|
24
|
-
|
|
25
|
-
def initialize(params)
|
|
26
|
-
@ended_at = params[:ended_at]
|
|
27
|
-
@env = params[:env]
|
|
28
|
-
@exception = params[:exception]
|
|
29
|
-
@headers = params[:headers]
|
|
30
|
-
@json_response = params[:json_response]
|
|
31
|
-
@request = params[:request]
|
|
32
|
-
@started_at = params[:started_at]
|
|
33
|
-
@status = params[:status]
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def call
|
|
37
|
-
time_spent = ended_at - started_at
|
|
38
|
-
user_agent = env['HTTP_USER_AGENT']
|
|
39
|
-
ip = env['action_dispatch.remote_ip'].calculate_ip
|
|
40
|
-
request_method = env['REQUEST_METHOD']
|
|
41
|
-
project_id = ENV.fetch('TREBLLE_PROJECT_ID') { '' }
|
|
42
|
-
request_body = request_method.downcase == 'get' ? request.query_parameters : safe_to_json(request.raw_post)
|
|
43
|
-
|
|
44
|
-
data = {
|
|
45
|
-
api_key: ENV.fetch('TREBLLE_API_KEY') { '' },
|
|
46
|
-
project_id: project_id,
|
|
47
|
-
version: Treblle::TREBLLE_VERSION,
|
|
48
|
-
sdk: 'ruby',
|
|
49
|
-
data: {
|
|
50
|
-
server: {
|
|
51
|
-
ip: server_ip,
|
|
52
|
-
timezone: Time.zone.name,
|
|
53
|
-
software: request_headers.try(:[], 'SERVER_SOFTWARE'),
|
|
54
|
-
signature: '',
|
|
55
|
-
protocol: request_headers.try(:[], 'SERVER_PROTOCOL'),
|
|
56
|
-
os: {}
|
|
57
|
-
},
|
|
58
|
-
language: {
|
|
59
|
-
name: 'ruby',
|
|
60
|
-
version: RUBY_VERSION
|
|
61
|
-
},
|
|
62
|
-
request: {
|
|
63
|
-
timestamp: started_at.to_formatted_s(:db),
|
|
64
|
-
ip: ip,
|
|
65
|
-
url: request.original_url,
|
|
66
|
-
user_agent: user_agent,
|
|
67
|
-
method: request_method,
|
|
68
|
-
headers: request_headers,
|
|
69
|
-
body: without_sensitive_attrs(request_body)
|
|
70
|
-
},
|
|
71
|
-
response: {
|
|
72
|
-
headers: headers || {},
|
|
73
|
-
code: status,
|
|
74
|
-
size: json_response&.to_json&.bytesize || 0,
|
|
75
|
-
load_time: time_spent,
|
|
76
|
-
body: without_sensitive_attrs(json_response),
|
|
77
|
-
errors: build_error_object(exception)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
data.to_json
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
private
|
|
86
|
-
|
|
87
|
-
def without_sensitive_attrs(obj)
|
|
88
|
-
return {} unless obj.present?
|
|
89
|
-
|
|
90
|
-
obj.each do |k, v|
|
|
91
|
-
value = v || k
|
|
92
|
-
if value.is_a?(Hash) || value.is_a?(Array)
|
|
93
|
-
without_sensitive_attrs(value)
|
|
94
|
-
elsif sensitive_attrs.include?(k.to_s)
|
|
95
|
-
obj[k] = '*' * v.to_s.length
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
obj
|
|
99
|
-
rescue StandardError => e
|
|
100
|
-
Rails.logger.error e.message
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def sensitive_attrs
|
|
104
|
-
@sensitive_attrs ||= user_sensitive_fields.merge(DEFAULT_SENSITIVE_FIELDS)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def user_sensitive_fields
|
|
108
|
-
fields = ENV.fetch('TREBLLE_SENSITIVE_FIELDS') { '' }.gsub(/\s+/, '')
|
|
109
|
-
fields.split(',').to_set
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def build_error_object(exception)
|
|
113
|
-
return [] unless exception.present?
|
|
114
|
-
|
|
115
|
-
[
|
|
116
|
-
{
|
|
117
|
-
source: 'onError',
|
|
118
|
-
type: exception.class.to_s || 'Unhandled error',
|
|
119
|
-
message: exception.message,
|
|
120
|
-
file: exception.backtrace.try(:first) || ''
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def server_ip
|
|
126
|
-
Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def request_headers
|
|
130
|
-
@request_headers ||= request.headers.env.reject { |key| key.to_s.include?('.') }
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def safe_to_json(obj)
|
|
134
|
-
JSON.parse(obj)
|
|
135
|
-
rescue StandardError => e
|
|
136
|
-
{}
|
|
137
|
-
end
|
|
138
|
-
end
|