rest-client-jogger 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -2
- data/.travis.yml +4 -2
- data/lib/rest_client/core_ext/logged_request.rb +2 -1
- data/lib/rest_client/jogger.rb +6 -1
- data/lib/rest_client/jogger/action.rb +22 -14
- data/lib/rest_client/jogger/filters/base.rb +1 -1
- data/lib/rest_client/jogger/filters/headers.rb +32 -0
- data/lib/rest_client/jogger/filters/json.rb +2 -2
- data/lib/rest_client/jogger/filters/query_parameters.rb +30 -0
- data/lib/rest_client/jogger/filters/xml.rb +2 -2
- data/lib/rest_client/jogger/response.rb +23 -1
- data/lib/rest_client/jogger/version.rb +1 -1
- data/lib/rest_client/templates/request_logging_template.json.jbuilder +4 -3
- data/lib/rest_client/templates/response_logging_template.json.jbuilder +8 -7
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9a0a62a17950b37627e424ef0c17fc446f51689aae27a1818d28c16f74b3852e
|
4
|
+
data.tar.gz: 052a357239835355293654cad1823ba3986b2419169381d8e4e456fd47523967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3549ff1e7d43c69b90e8b5b275274aab4e012260a28b77494f9dcb4ec34a13bf64aa7ba78a3e414ac262f17875fbc5acc18fd90d099626c3a987dd0940096e2e
|
7
|
+
data.tar.gz: 410ac3b52d87e846006061114c0f78a6e18a03d25998420cc0d80c9c0b007809f242b415ed8a787ebfa452b836c9d4767645463da6dc8685339bd73b378444d3
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.1.2
|
5
4
|
- 2.2.0
|
6
5
|
- 2.2.1
|
7
6
|
- 2.2.2
|
8
7
|
- 2.2.3
|
9
8
|
- 2.3.0
|
10
9
|
- 2.5.1
|
11
|
-
|
10
|
+
- 2.6.3
|
11
|
+
before_install: gem install bundler -v '1.17.3'
|
12
|
+
install: bundle _1.17.3_ install
|
13
|
+
script: bundle _1.17.3_ exec rake
|
@@ -30,7 +30,8 @@ module LoggedRequest
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def filtered_headers(opts)
|
33
|
-
opts.fetch(:headers
|
33
|
+
headers = opts.fetch(:headers) { {} }
|
34
|
+
RestClient::Jogger::Filters::Headers.new(data: headers).filter
|
34
35
|
end
|
35
36
|
|
36
37
|
def log_request(opts, started)
|
data/lib/rest_client/jogger.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'cgi'
|
1
2
|
require 'json'
|
3
|
+
require 'uri'
|
2
4
|
require 'mime/types'
|
3
5
|
require 'active_model'
|
4
6
|
require 'active_support/all'
|
@@ -11,16 +13,19 @@ require 'rest_client/jogger/action'
|
|
11
13
|
require 'rest_client/jogger/request'
|
12
14
|
require 'rest_client/jogger/response'
|
13
15
|
require 'rest_client/jogger/filters/base'
|
16
|
+
require 'rest_client/jogger/filters/headers'
|
14
17
|
require 'rest_client/jogger/filters/json'
|
15
18
|
require 'rest_client/jogger/filters/xml'
|
19
|
+
require 'rest_client/jogger/filters/query_parameters'
|
16
20
|
require 'rest_client/core_ext/logged_request'
|
17
21
|
|
18
22
|
module RestClient
|
19
23
|
class Request
|
20
24
|
extend LoggedRequest
|
21
25
|
end
|
22
|
-
|
26
|
+
|
23
27
|
module Jogger
|
28
|
+
AGENT_VERSION = "rest-client-jogger:#{VERSION}".freeze
|
24
29
|
ROOT_PATH = File.expand_path(File.dirname(__FILE__)).freeze
|
25
30
|
|
26
31
|
class << self
|
@@ -14,19 +14,8 @@ module RestClient
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(name, start, finish, id, payload)
|
17
|
-
|
18
|
-
|
19
|
-
args: payload,
|
20
|
-
payload: filter(payload),
|
21
|
-
verify_ssl: payload[:verify_ssl],
|
22
|
-
read_timeout: payload.fetch(:timeout) { payload[:read_timeout] },
|
23
|
-
open_timeout: payload.fetch(:timeout) { payload[:open_timeout] },
|
24
|
-
event_id: id,
|
25
|
-
timestamp: start,
|
26
|
-
time_elapsed: (finish - start_time).round(10),
|
27
|
-
ip_address: ip_address
|
28
|
-
}
|
29
|
-
json = template.render nil, render_params
|
17
|
+
params = render_params(start, finish, id, payload)
|
18
|
+
json = template.render(nil, params)
|
30
19
|
name =~ /error/ ? logger.error(json) : logger.debug(json)
|
31
20
|
rescue StandardError => e
|
32
21
|
notifier.error e, payload: payload
|
@@ -38,8 +27,27 @@ module RestClient
|
|
38
27
|
|
39
28
|
private
|
40
29
|
|
30
|
+
def render_params(start, finish, id, opts)
|
31
|
+
start_time = opts.fetch(:start_time)
|
32
|
+
url = opts.fetch(:url)
|
33
|
+
headers = opts.fetch(:headers) { {} }
|
34
|
+
{
|
35
|
+
method: opts[:method],
|
36
|
+
headers: headers,
|
37
|
+
url: RestClient::Jogger::Filters::QueryParameters.new(data: url).filter,
|
38
|
+
payload: filter(body: opts[:payload], headers: headers),
|
39
|
+
verify_ssl: opts[:verify_ssl],
|
40
|
+
read_timeout: opts.fetch(:timeout) { opts[:read_timeout] },
|
41
|
+
open_timeout: opts.fetch(:timeout) { opts[:open_timeout] },
|
42
|
+
event_id: id,
|
43
|
+
timestamp: start,
|
44
|
+
time_elapsed: (finish - start_time).round(10),
|
45
|
+
ip_address: ip_address
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
41
49
|
def filter(opts = {})
|
42
|
-
filter_class(opts
|
50
|
+
filter_class(opts.fetch(:headers)).new(data: opts[:body].to_s).filter
|
43
51
|
end
|
44
52
|
|
45
53
|
def filter_class(headers = {})
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RestClient
|
2
|
+
module Jogger
|
3
|
+
module Filters
|
4
|
+
class Headers < Base
|
5
|
+
DEFAULT_FILTERS = %w[authorization].freeze
|
6
|
+
|
7
|
+
def filter
|
8
|
+
filtered_keys = string_filters
|
9
|
+
data.each_with_object({}) do |(key, value), memo|
|
10
|
+
if filtered_keys.include?(key.to_s.downcase)
|
11
|
+
memo[key] = filter_replacement
|
12
|
+
else
|
13
|
+
memo[key] = value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def string_filters
|
21
|
+
DEFAULT_FILTERS | normalized_filters
|
22
|
+
end
|
23
|
+
|
24
|
+
def normalized_filters
|
25
|
+
filters
|
26
|
+
.select { |e| e.is_a?(Symbol) || e.is_a?(String) }
|
27
|
+
.map { |e| e.to_s.downcase }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RestClient
|
2
|
+
module Jogger
|
3
|
+
module Filters
|
4
|
+
class QueryParameters < Base
|
5
|
+
def filter
|
6
|
+
return uri.to_s if uri.query.blank?
|
7
|
+
uri.dup.tap { |u| u.query = parameters }.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def parameters
|
13
|
+
CGI.parse(uri.query.to_s).each_with_object([]) do |(key, values), memo|
|
14
|
+
values.each do |value|
|
15
|
+
memo << "#{key}=#{filtered_value(key, value)}"
|
16
|
+
end
|
17
|
+
end.join('&')
|
18
|
+
end
|
19
|
+
|
20
|
+
def filtered_value(key, value)
|
21
|
+
filters.include?(key.to_sym) ? filter_replacement : value
|
22
|
+
end
|
23
|
+
|
24
|
+
def uri
|
25
|
+
@uri ||= URI.parse(data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module RestClient
|
2
2
|
module Jogger
|
3
3
|
module Filters
|
4
|
-
class Xml <
|
4
|
+
class Xml < Base
|
5
5
|
|
6
|
-
|
6
|
+
private
|
7
7
|
|
8
8
|
def filter_data(filter)
|
9
9
|
data.gsub! /<#{filter}>(.*)<\/#{filter}>/, %{<#{filter}>#{filter_replacement}</#{filter}>}
|
@@ -2,7 +2,29 @@ module RestClient
|
|
2
2
|
module Jogger
|
3
3
|
class Response < Action
|
4
4
|
def template
|
5
|
-
Tilt::JbuilderTemplate.new
|
5
|
+
Tilt::JbuilderTemplate.new(root.join('templates', 'response_logging_template.json.jbuilder'))
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def render_params(start, finish, id, opts)
|
11
|
+
params = response_params(opts)
|
12
|
+
super.merge(params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def response_params(opts = {})
|
16
|
+
response_headers = opts[:response].try(:headers) || {}
|
17
|
+
response_body = opts[:response].try(:body).to_s.force_encoding('UTF-8')
|
18
|
+
{
|
19
|
+
exception: opts[:exception],
|
20
|
+
response_headers: filtered_headers(response_headers),
|
21
|
+
response_body: filter(body: response_body, headers: response_headers),
|
22
|
+
code: opts[:response].try(:code)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def filtered_headers(headers = {})
|
27
|
+
Filters::Headers.new(data: headers).filter
|
6
28
|
end
|
7
29
|
end
|
8
30
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
json.ignore_nil!
|
3
|
-
json.url
|
4
|
-
json.method
|
3
|
+
json.url url
|
4
|
+
json.method method
|
5
5
|
json.verifySsl verify_ssl
|
6
|
-
json.requestHeaders
|
6
|
+
json.requestHeaders headers
|
7
7
|
json.requestBody payload
|
8
8
|
json.sourceIp ip_address
|
9
9
|
json.eventName RestClient::Jogger.request_pattern
|
10
10
|
json.eventId event_id
|
11
|
+
json.eventAgent RestClient::Jogger::AGENT_VERSION
|
11
12
|
json.timeElapsed time_elapsed
|
12
13
|
json.openTimeout open_timeout
|
13
14
|
json.readTimeout read_timeout
|
@@ -1,18 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
json.ignore_nil!
|
3
|
-
json.
|
4
|
-
json.
|
5
|
-
json.method
|
3
|
+
json.url url
|
4
|
+
json.exception exception
|
5
|
+
json.method method
|
6
6
|
json.verifySsl verify_ssl
|
7
|
-
json.requestHeaders
|
8
|
-
json.responseHeaders
|
7
|
+
json.requestHeaders headers
|
8
|
+
json.responseHeaders response_headers
|
9
9
|
json.requestBody payload
|
10
|
-
json.responseBody
|
10
|
+
json.responseBody response_body
|
11
11
|
json.sourceIp ip_address
|
12
12
|
json.eventName RestClient::Jogger.response_pattern
|
13
13
|
json.eventId event_id
|
14
|
+
json.eventAgent RestClient::Jogger::AGENT_VERSION
|
14
15
|
json.timeElapsed time_elapsed
|
15
16
|
json.openTimeout open_timeout
|
16
17
|
json.readTimeout read_timeout
|
17
|
-
json.code
|
18
|
+
json.code code
|
18
19
|
json.timestamp timestamp.iso8601
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-client-jogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Babe
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-08-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -263,7 +263,9 @@ files:
|
|
263
263
|
- lib/rest_client/jogger/configuration.rb
|
264
264
|
- lib/rest_client/jogger/event_subscriber.rb
|
265
265
|
- lib/rest_client/jogger/filters/base.rb
|
266
|
+
- lib/rest_client/jogger/filters/headers.rb
|
266
267
|
- lib/rest_client/jogger/filters/json.rb
|
268
|
+
- lib/rest_client/jogger/filters/query_parameters.rb
|
267
269
|
- lib/rest_client/jogger/filters/xml.rb
|
268
270
|
- lib/rest_client/jogger/request.rb
|
269
271
|
- lib/rest_client/jogger/response.rb
|
@@ -291,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
291
293
|
version: '0'
|
292
294
|
requirements: []
|
293
295
|
rubyforge_project:
|
294
|
-
rubygems_version: 2.
|
296
|
+
rubygems_version: 2.7.6
|
295
297
|
signing_key:
|
296
298
|
specification_version: 4
|
297
299
|
summary: Logs RestClient requests in a JSON format
|