better-faraday 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 520161498209165aa279351373198c4f82936380767f5bbffa6bd02e9698527f
4
- data.tar.gz: aadd3384613e59c8855b8432895c5ac6ef2a2afbbeddd82d689ddd05022be2be
3
+ metadata.gz: e2c396050eb803fc44370487683e12b77b07b808d563264aa372c847cd5be21c
4
+ data.tar.gz: e8a5f25e26e98d39adf5cb87653fa99b25f2a365382b8996434f68c0c8215a4d
5
5
  SHA512:
6
- metadata.gz: be5bd473d0551db70328a71d4b1ae0a880de59ee0b60fc8826d2899583f771b66300d59c71c9e48ac833c16854c964cda23b6e25bad4a0811a221721b9bcb3c6
7
- data.tar.gz: e329ceb0a76522e17d52502ec5e13a2bad7d14c9b2c5b887e7a1d042e6dfb59e80ecc7b0fdd27eae50d347733c20a66d2fb255d748eee1955f294ba0a70a21c4
6
+ metadata.gz: d68b1aec17fdbc160393fad93a9afdfa5650cdab9413226830054f84568efca1315ef1a34de2b3b44075b5a843627cfb75bb8b451d03fea405c02fae634aa097
7
+ data.tar.gz: 5dfb59a2f91082cf3e305db4d965a8f7c41d7617f7642adb1f7505fac1673bcedce22124465053a950ab2434878e434a34a835d39cefaec36c343975b9d099e3
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "better-faraday"
6
- s.version = "1.0.2"
6
+ s.version = "1.0.3"
7
7
  s.author = "Yaroslav Konoplov"
8
8
  s.email = "eahome00@gmail.com"
9
9
  s.summary = "Extends Faraday with useful features."
@@ -14,4 +14,5 @@ Gem::Specification.new do |s|
14
14
  s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
15
15
  s.require_paths = ["lib"]
16
16
  s.add_dependency "faraday", "~> 0.12"
17
+ s.add_dependency "activesupport", ">= 4.0", "< 6.0"
17
18
  end
@@ -6,6 +6,7 @@ require "faraday"
6
6
  require "faraday/error"
7
7
  require "faraday/options"
8
8
  require "faraday/response"
9
+ require "active_support/core_ext/object/deep_dup"
9
10
 
10
11
  Module.new do
11
12
  def run_request(method, url, body, headers, &block)
@@ -41,6 +42,12 @@ module Faraday
41
42
  alias assert_success! assert_2xx! # Compatibility.
42
43
 
43
44
  def describe
45
+ request_headers = env.request_headers.deep_dup
46
+ request_json = parse_json(env.request_body)
47
+ response_headers = ::Hash === env.response_headers ? env.response_headers.deep_dup : {}
48
+ response_json = parse_json(env.body)
49
+ [request_headers, request_json, response_headers, response_json].compact.each { |hash| sanitize(hash) }
50
+
44
51
  [ "",
45
52
  "-- #{status} #{reason_phrase} --",
46
53
  "",
@@ -51,19 +58,34 @@ module Faraday
51
58
  env.method.to_s.upcase,
52
59
  "",
53
60
  "-- Request headers --",
54
- ::JSON.generate(env.request_headers.tap { |x| x["Authorization"] = "SECRET" if x.key?("Authorization") }),
61
+ ::JSON.generate(request_headers),
55
62
  "",
56
63
  "-- Request body --",
57
- env.request_body.to_s,
64
+ request_json ? ::JSON.generate(request_json) : env.request_body.to_s,
58
65
  "",
59
66
  "-- Response headers --",
60
- ::Hash === env.response_headers ? ::JSON.generate(env.response_headers) : "",
67
+ response_headers ? ::JSON.generate(response_headers) : env.response_headers.to_s,
61
68
  "",
62
69
  "-- Response body --",
63
- env.body.to_s,
70
+ response_json ? ::JSON.generate(response_json) : env.body.to_s,
64
71
  ""
65
72
  ].join("\n")
66
73
  end
74
+
75
+ private
76
+
77
+ def parse_json(json)
78
+ ::JSON.parse(::String === json ? json : json.to_s, quirks_mode: false)
79
+ rescue ::JSON::ParserError
80
+ nil
81
+ end
82
+
83
+ def sanitize(h)
84
+ h.keys.map(&:to_s).each do |k|
85
+ h[k] = "SECRET" if k.respond_to?(:=~) && Faraday.secrets.any? { |s| k =~ s }
86
+ sanitize(h[k]) if ::Hash === h[k]
87
+ end
88
+ end
67
89
  end
68
90
 
69
91
  class HTTP4xx < Error
@@ -73,4 +95,10 @@ module Faraday
73
95
  class HTTP422 < HTTP4xx
74
96
 
75
97
  end
98
+
99
+ class << self
100
+ attr_accessor :secrets
101
+ end
102
+
103
+ self.secrets = [/pass(?:word|phrase)/i, /authorization/i, /secret/i]
76
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better-faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Konoplov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-08 00:00:00.000000000 Z
11
+ date: 2018-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '6.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '4.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '6.0'
27
47
  description: A gem extending Faraday (popular Ruby HTTP client) with useful features
28
48
  without breaking anything.
29
49
  email: eahome00@gmail.com