shutl_resource 1.8.0 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -2
- data/.ruby-version +1 -1
- data/lib/shutl/resource/default_logger.rb +15 -24
- data/lib/shutl/resource/version.rb +1 -1
- data/shutl_resource.gemspec +0 -2
- data/spec/default_logger_spec.rb +82 -0
- metadata +5 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 500c2ab1f17cb6cf8130a6add480df375ddb3820
|
4
|
+
data.tar.gz: 15799d11ac8846e9451b9ac4c1f1c265cf971137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98e554b684023c9a6ab7f74039d1e1d7152f4839d90272c723b2ca411ddc3f23665e53f0cca6d100d770612c6cef57f63c0e4ea7c0f791f6dc9a88a8f6754ae4
|
7
|
+
data.tar.gz: c2355f511c325103a30888fb5285af2759c199184686bcba8f873f7c0478eb681c3b3b7b11787072cc1607c257dd8e749d6683b9895493bb12785c42f9c52a05
|
data/.rspec
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.3
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
|
-
|
4
|
-
class Middleware
|
5
|
-
class DefaultLogger < Faraday::Middleware
|
3
|
+
class DefaultLogger < Faraday::Middleware
|
6
4
|
extend Forwardable
|
7
5
|
|
8
6
|
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
@@ -18,30 +16,30 @@ module Faraday
|
|
18
16
|
def call(env)
|
19
17
|
start_time = Time.now
|
20
18
|
info request_info(env)
|
21
|
-
|
19
|
+
request_debug(env)
|
22
20
|
|
23
21
|
@app.call(env).on_complete do
|
24
22
|
end_time = Time.now
|
25
23
|
response_time = end_time - start_time
|
26
24
|
info response_info(env, response_time)
|
27
|
-
|
25
|
+
response_debug(env)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
29
|
private
|
32
30
|
|
33
31
|
def request_info(env)
|
34
|
-
"
|
32
|
+
"Started %s request to: %s" % [ env[:method].to_s.upcase, env[:url] ]
|
35
33
|
end
|
36
34
|
|
37
35
|
def response_info(env, response_time)
|
38
|
-
"
|
36
|
+
"Response from %s; Status: %d; Time: %.1fms" % [ env[:url], env[:status], (response_time * 1_000.0) ]
|
39
37
|
end
|
40
38
|
|
41
39
|
def request_debug(env)
|
42
40
|
request_headers = obfuscate_auth env[:request_headers]
|
43
41
|
|
44
|
-
|
42
|
+
debug_request_response("Request", request_headers, env[:body])
|
45
43
|
end
|
46
44
|
|
47
45
|
def obfuscate_auth(headers)
|
@@ -54,25 +52,18 @@ module Faraday
|
|
54
52
|
end
|
55
53
|
|
56
54
|
def response_debug(env)
|
57
|
-
|
55
|
+
debug_request_response("Response", env[:response_headers], env[:body])
|
58
56
|
end
|
59
57
|
|
60
|
-
def
|
61
|
-
|
62
|
-
#{name}
|
63
|
-
----------------
|
64
|
-
#{format_headers(headers)}
|
65
|
-
|
66
|
-
#{name} Body:
|
67
|
-
-------------
|
68
|
-
#{body}
|
69
|
-
MESSAGE
|
58
|
+
def debug_request_response(name, headers, body)
|
59
|
+
debug "#{name} headers: #{JSON.generate headers}"
|
60
|
+
debug "#{name} body: #{format_body body}"
|
70
61
|
end
|
71
62
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
63
|
+
def format_body(body)
|
64
|
+
return '' unless body
|
65
|
+
JSON.generate JSON.parse Array(body).join("\n")
|
66
|
+
rescue JSON::ParserError
|
67
|
+
Array(body).join("\n").gsub /\n/, '\n'
|
75
68
|
end
|
76
69
|
end
|
77
|
-
end
|
78
|
-
end
|
data/shutl_resource.gemspec
CHANGED
@@ -26,8 +26,6 @@ Gem::Specification.new do |gem|
|
|
26
26
|
|
27
27
|
gem.add_development_dependency 'rake'
|
28
28
|
gem.add_development_dependency 'rspec', '~> 2.11.0'
|
29
|
-
gem.add_development_dependency 'debugger' if $platform.to_s == 'ruby'
|
30
|
-
gem.add_development_dependency 'ruby-debug' if $platform.to_s == 'java'
|
31
29
|
|
32
30
|
gem.add_development_dependency 'webmock', '~> 1.8.7'
|
33
31
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
describe DefaultLogger do
|
6
|
+
|
7
|
+
def conn(logger, logger_options={})
|
8
|
+
rubbles = ['Barney', 'Betty', 'Bam Bam']
|
9
|
+
|
10
|
+
Faraday.new do |b|
|
11
|
+
b.use DefaultLogger, logger: @logger
|
12
|
+
b.adapter :test do |stubs|
|
13
|
+
stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
|
14
|
+
stubs.post('/ohai') { [200, {'Content-Type' => 'text/html'}, 'fred'] }
|
15
|
+
stubs.get('/ohno') { [200, {'Content-Type' => 'text/html'}, 'wilma'] }
|
16
|
+
stubs.post('/ohyes') { [200, {'Content-Type' => 'text/html'}, 'pebbles'] }
|
17
|
+
stubs.get('/rubbles') { [200, {'Content-Type' => 'application/json'}, rubbles] }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
@io = StringIO.new
|
24
|
+
@logger = Logger.new(@io)
|
25
|
+
@logger.level = Logger::DEBUG
|
26
|
+
|
27
|
+
@conn = conn(@logger)
|
28
|
+
@resp = @conn.get '/hello', nil, :accept => 'text/html'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "still returns output" do
|
32
|
+
expect(@resp.body).to eq 'hello'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "logss method and url" do
|
36
|
+
expect(@io.string).to match 'Started GET request to:'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "logss request headers" do
|
40
|
+
expect(@io.string).to match %("Accept":"text/html")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "logs response headers" do
|
44
|
+
expect(@io.string).to match %("Content-Type":"text/html")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "logs request body" do
|
48
|
+
app = conn(@logger, :bodies => { :request => true })
|
49
|
+
app.post '/ohyes', 'name=Tamago', :accept => 'text/html'
|
50
|
+
|
51
|
+
expect(@io.string).to match %(name=Tamago)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "logs response body" do
|
55
|
+
app = conn(@logger, :bodies => { :response => true })
|
56
|
+
app.get '/ohno', :accept => 'text/html'
|
57
|
+
|
58
|
+
expect(@io.string).to match %(wilma)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "logs request and response body" do
|
62
|
+
app = conn(@logger, :bodies => true)
|
63
|
+
app.post '/ohyes', 'name=Ebi', :accept => 'text/html'
|
64
|
+
|
65
|
+
expect(@io.string).to match %(name=Ebi)
|
66
|
+
expect(@io.string).to match %(pebbles)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "logs response body object" do
|
70
|
+
app = conn(@logger, :bodies => true)
|
71
|
+
app.get '/rubbles', nil, :accept => 'text/html'
|
72
|
+
|
73
|
+
expect(@io.string).to match %([\"Barney\", \"Betty\", \"Bam Bam\"]\n)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'obfuscates the token in the header' do
|
77
|
+
app = conn(@logger, :bodies => true)
|
78
|
+
@conn.post '/ohai', 'name=Toro', :accept => 'text/html', :authorization => 'Bearer 1234567890'
|
79
|
+
|
80
|
+
expect(@io.string).to_not match %(1234567890)
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shutl_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Rouchy
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2015-09-
|
16
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: shutl_auth
|
@@ -113,20 +113,6 @@ dependencies:
|
|
113
113
|
- - "~>"
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: 2.11.0
|
116
|
-
- !ruby/object:Gem::Dependency
|
117
|
-
name: debugger
|
118
|
-
requirement: !ruby/object:Gem::Requirement
|
119
|
-
requirements:
|
120
|
-
- - ">="
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: '0'
|
123
|
-
type: :development
|
124
|
-
prerelease: false
|
125
|
-
version_requirements: !ruby/object:Gem::Requirement
|
126
|
-
requirements:
|
127
|
-
- - ">="
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version: '0'
|
130
116
|
- !ruby/object:Gem::Dependency
|
131
117
|
name: webmock
|
132
118
|
requirement: !ruby/object:Gem::Requirement
|
@@ -177,6 +163,7 @@ files:
|
|
177
163
|
- shutl_resource.gemspec
|
178
164
|
- spec/configuration_spec.rb
|
179
165
|
- spec/configured_base_uri_spec.rb
|
166
|
+
- spec/default_logger_spec.rb
|
180
167
|
- spec/dynamic_resource_spec.rb
|
181
168
|
- spec/error_spec.rb
|
182
169
|
- spec/remote_url_spec.rb
|
@@ -205,13 +192,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
192
|
version: '0'
|
206
193
|
requirements: []
|
207
194
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.
|
195
|
+
rubygems_version: 2.4.5.1
|
209
196
|
signing_key:
|
210
197
|
specification_version: 4
|
211
198
|
summary: Manage Shutl Rest resource. Parse/Serialize JSON
|
212
199
|
test_files:
|
213
200
|
- spec/configuration_spec.rb
|
214
201
|
- spec/configured_base_uri_spec.rb
|
202
|
+
- spec/default_logger_spec.rb
|
215
203
|
- spec/dynamic_resource_spec.rb
|
216
204
|
- spec/error_spec.rb
|
217
205
|
- spec/remote_url_spec.rb
|