vault-tools 0.5.15 → 0.5.16
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -3
- data/lib/vault-tools/log.rb +1 -0
- data/lib/vault-tools/version.rb +1 -1
- data/lib/vault-tools/web.rb +36 -0
- data/test/web_test.rb +36 -0
- data/vault-tools.gemspec +1 -0
- metadata +24 -2
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vault-tools (0.5.
|
4
|
+
vault-tools (0.5.16)
|
5
5
|
aws-sdk
|
6
|
+
excon
|
6
7
|
fernet (= 2.0.rc2)
|
7
8
|
heroku-api
|
8
9
|
honeybadger
|
@@ -25,7 +26,7 @@ GEM
|
|
25
26
|
celluloid (0.16.0)
|
26
27
|
timers (~> 4.0.0)
|
27
28
|
coderay (1.1.0)
|
28
|
-
excon (0.
|
29
|
+
excon (0.42.1)
|
29
30
|
fernet (2.0.rc2)
|
30
31
|
valcro (= 0.1)
|
31
32
|
ffi (1.9.6)
|
@@ -72,7 +73,7 @@ GEM
|
|
72
73
|
rb-fsevent (0.9.4)
|
73
74
|
rb-inotify (0.9.5)
|
74
75
|
ffi (>= 0.5.0)
|
75
|
-
rdoc (4.
|
76
|
+
rdoc (4.2.0)
|
76
77
|
json (~> 1.4)
|
77
78
|
rr (1.1.2)
|
78
79
|
scrolls (0.3.8)
|
data/lib/vault-tools/log.rb
CHANGED
@@ -59,6 +59,7 @@ module Vault
|
|
59
59
|
def self.log(data, &block)
|
60
60
|
data['source'] ||= Config.app_deploy if Config.app_deploy
|
61
61
|
data['app'] ||= Config.app_name if Config.app_name
|
62
|
+
data['request-id'] = Thread.current[:request_id] if Thread.current[:request_id]
|
62
63
|
Scrolls.log(data, &block)
|
63
64
|
end
|
64
65
|
end
|
data/lib/vault-tools/version.rb
CHANGED
data/lib/vault-tools/web.rb
CHANGED
@@ -6,7 +6,43 @@ module Vault
|
|
6
6
|
# List of paths that are not protected thus overriding protected!
|
7
7
|
set :unprotected_paths, []
|
8
8
|
|
9
|
+
# Work with request id out of the box
|
10
|
+
def call(env)
|
11
|
+
Thread.current[:request_id] = env['HTTP_X_REQUEST_ID'] || SecureRandom.uuid
|
12
|
+
if defined? Excon
|
13
|
+
decorate_excon!
|
14
|
+
Excon.defaults[:headers]['X-Request-ID'] = Thread.current[:request_id]
|
15
|
+
end
|
16
|
+
env['HTTP_X_REQUEST_ID'] = Thread.current[:request_id]
|
17
|
+
status, headers, response = super(env)
|
18
|
+
headers['Request-ID'] = Thread.current[:request_id]
|
19
|
+
[status, headers, response]
|
20
|
+
end
|
21
|
+
|
22
|
+
def decorate_excon!
|
23
|
+
return unless defined? Excon
|
24
|
+
begin
|
25
|
+
return if Excon.request_id_decorated?
|
26
|
+
rescue
|
27
|
+
Excon.module_eval do
|
28
|
+
def self.request_id_decorated?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
Excon::Connection.class_eval do
|
33
|
+
alias :stock_initialize :initialize
|
34
|
+
def initialize(params={})
|
35
|
+
stock_initialize(params)
|
36
|
+
if Excon.defaults[:headers].key? 'X-Request-ID'
|
37
|
+
@data[:headers]['X-Request-ID'] ||= Excon.defaults[:headers]['X-Request-ID']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
9
44
|
class << self
|
45
|
+
|
10
46
|
# Store the action for logging purposes.
|
11
47
|
def route(verb, action, *)
|
12
48
|
condition { @action = action }
|
data/test/web_test.rb
CHANGED
@@ -22,6 +22,7 @@ class WebTest < Vault::TestCase
|
|
22
22
|
# Always reload the web class to eliminate test leakage
|
23
23
|
def setup
|
24
24
|
super
|
25
|
+
Excon.defaults[:mock] = true
|
25
26
|
set_env('APP_NAME', 'test-app')
|
26
27
|
set_env('APP_DEPLOY', 'testing')
|
27
28
|
reload_web!
|
@@ -29,6 +30,7 @@ class WebTest < Vault::TestCase
|
|
29
30
|
|
30
31
|
def teardown
|
31
32
|
super
|
33
|
+
Excon.stubs.clear
|
32
34
|
@app = nil
|
33
35
|
end
|
34
36
|
|
@@ -194,4 +196,38 @@ class WebTest < Vault::TestCase
|
|
194
196
|
get '/health'
|
195
197
|
assert_equal(200, last_response.status)
|
196
198
|
end
|
199
|
+
|
200
|
+
def test_that_request_id_gets_logged
|
201
|
+
request_id = 'JKJK-123'
|
202
|
+
mock(Scrolls).log({
|
203
|
+
'request-id' => request_id,
|
204
|
+
'msg' => 'Hit logging test!',
|
205
|
+
'source' => 'testing',
|
206
|
+
'app' => 'test-app'
|
207
|
+
})
|
208
|
+
app.get '/logging-test' do
|
209
|
+
Vault::Log.log('msg' => 'Hit logging test!')
|
210
|
+
end
|
211
|
+
|
212
|
+
header 'X_REQUEST_ID', request_id
|
213
|
+
get '/logging-test'
|
214
|
+
assert_equal request_id, last_response.headers['Request-ID']
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_that_excon_proxies_request_id
|
218
|
+
request_id = 'JKJK-123'
|
219
|
+
Excon.stub(
|
220
|
+
{ method: :get, host: 'example.com', path: '/',
|
221
|
+
headers: {'X-Request-ID' => request_id}},
|
222
|
+
{ body: request_id, status: 200 })
|
223
|
+
app.get '/proxy-test' do
|
224
|
+
conn = Excon.new('http://example.com/')
|
225
|
+
conn.get.body
|
226
|
+
end
|
227
|
+
|
228
|
+
header 'X_REQUEST_ID', request_id
|
229
|
+
get '/proxy-test'
|
230
|
+
assert_equal request_id, last_response.headers['Request-ID']
|
231
|
+
assert_equal request_id, last_response.body
|
232
|
+
end
|
197
233
|
end
|
data/vault-tools.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vault-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.16
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: scrolls
|
@@ -172,6 +172,22 @@ dependencies:
|
|
172
172
|
- - ! '>='
|
173
173
|
- !ruby/object:Gem::Version
|
174
174
|
version: '0'
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: excon
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
179
|
+
requirements:
|
180
|
+
- - ! '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
type: :runtime
|
184
|
+
prerelease: false
|
185
|
+
version_requirements: !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - ! '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
175
191
|
description: Basic tools for Heroku Vault's Ruby projects
|
176
192
|
email:
|
177
193
|
- christopher.continanza@gmail.com
|
@@ -241,12 +257,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
241
257
|
- - ! '>='
|
242
258
|
- !ruby/object:Gem::Version
|
243
259
|
version: '0'
|
260
|
+
segments:
|
261
|
+
- 0
|
262
|
+
hash: 1742273413553349512
|
244
263
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
245
264
|
none: false
|
246
265
|
requirements:
|
247
266
|
- - ! '>='
|
248
267
|
- !ruby/object:Gem::Version
|
249
268
|
version: '0'
|
269
|
+
segments:
|
270
|
+
- 0
|
271
|
+
hash: 1742273413553349512
|
250
272
|
requirements: []
|
251
273
|
rubyforge_project:
|
252
274
|
rubygems_version: 1.8.23
|