faraday_middleware-escher 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/VERSION +1 -1
- data/lib/faraday/middleware/escher/request_signer.rb +6 -6
- data/prototype/client.rb +1 -1
- data/prototype/config.ru +5 -55
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fe9901e5decc91e4e641aeeb1cfaac184b4ea1c
|
4
|
+
data.tar.gz: 82a99dd84d75edb245588862316e33908b8f316f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 285d0b641dd6add2c9865e2c38c0ba9026a742f850c6db3eda56d386b7a75ee820d6d926d4f537ef107f5963b406e19bc975e85929b567eed7089827c942c2b8
|
7
|
+
data.tar.gz: a8863c672ac73ac275a5c52d3b75687ce535faabbba7a2af101f7e537f43036951ed18dc9d5534448bbe28d08915851d30d78cd68aec1cdcb91454253482b4b3
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'faraday/middleware/escher'
|
2
2
|
class Faraday::Middleware::Escher::RequestSigner < Faraday::Middleware::Escher::Base
|
3
3
|
|
4
|
-
def initialize(app,options={}
|
4
|
+
def initialize(app, options={}, &active_key)
|
5
5
|
|
6
|
-
super(app,options)
|
6
|
+
super(app, options)
|
7
7
|
|
8
8
|
active_key_cons = active_key || options[:active_key] || options[:key]
|
9
9
|
raise('Escher active key constructor must be a lambda/block') unless active_key_cons.is_a?(Proc)
|
@@ -17,11 +17,11 @@ class Faraday::Middleware::Escher::RequestSigner < Faraday::Middleware::Escher::
|
|
17
17
|
|
18
18
|
uri_path = env[:url].path
|
19
19
|
endpoint = uri_path.empty? ? '/' : uri_path
|
20
|
-
endpoint_with_query = [endpoint,env[:url].query].join('?')
|
20
|
+
endpoint_with_query = [endpoint, env[:url].query].join('?')
|
21
21
|
|
22
|
-
request_headers = Hash[env[:request_headers].map{|k,v| [k,v] }]
|
22
|
+
request_headers = Hash[env[:request_headers].map { |k, v| [k.to_s.downcase, v] }]
|
23
23
|
request_headers['host'] ||= @host || env[:url].host
|
24
|
-
|
24
|
+
|
25
25
|
request_data = {
|
26
26
|
uri: endpoint_with_query,
|
27
27
|
method: env[:method].to_s.upcase,
|
@@ -33,7 +33,7 @@ class Faraday::Middleware::Escher::RequestSigner < Faraday::Middleware::Escher::
|
|
33
33
|
escher.sign!(
|
34
34
|
request_data,
|
35
35
|
@escher_active_key_constructor.call,
|
36
|
-
request_data[:headers].map{|ary| ary[0] }
|
36
|
+
request_data[:headers].map { |ary| ary[0] }
|
37
37
|
)
|
38
38
|
|
39
39
|
env[:request_headers].merge!(request_data[:headers])
|
data/prototype/client.rb
CHANGED
@@ -8,7 +8,7 @@ conn = Faraday.new(url: 'http://localhost:9292') do |builder|
|
|
8
8
|
builder.use FaradayMiddleware::Escher::RequestSigner,
|
9
9
|
credential_scope: CredentialScope,
|
10
10
|
options: AuthOptions,
|
11
|
-
active_key: -> { Escher::Keypool.new.get_active_key('EscherExample') }
|
11
|
+
active_key: -> { p Escher::Keypool.new.get_active_key('EscherExample') }
|
12
12
|
|
13
13
|
builder.adapter :net_http
|
14
14
|
|
data/prototype/config.ru
CHANGED
@@ -4,7 +4,7 @@ require 'rack'
|
|
4
4
|
require 'escher/rack_middleware'
|
5
5
|
Escher::RackMiddleware.config do |c|
|
6
6
|
c.add_escher_authenticator { Escher::Auth.new(CredentialScope, AuthOptions) }
|
7
|
-
c.add_credential_updater { Escher::Keypool.new.get_key_db }
|
7
|
+
c.add_credential_updater { p Escher::Keypool.new.get_key_db }
|
8
8
|
end
|
9
9
|
|
10
10
|
require 'socket'
|
@@ -13,32 +13,7 @@ class YourAwesomeApp
|
|
13
13
|
def call(env)
|
14
14
|
|
15
15
|
response = Rack::Response.new
|
16
|
-
|
17
|
-
|
18
|
-
escher = ::Escher::Auth.new(CredentialScope, AuthOptions)
|
19
|
-
|
20
|
-
request_data = {
|
21
|
-
|
22
|
-
uri: '/',
|
23
|
-
method: 'GET',
|
24
|
-
headers: [['host',Socket.gethostname]],
|
25
|
-
body: response_payload
|
26
|
-
|
27
|
-
}
|
28
|
-
|
29
|
-
escher.sign!(
|
30
|
-
request_data,
|
31
|
-
Escher::Keypool.new.get_active_key( env['escher.request.api_key_id'] ),
|
32
|
-
response.headers.map { |k, _| k }
|
33
|
-
)
|
34
|
-
|
35
|
-
request_data[:headers].each do |key,value|
|
36
|
-
response.headers[key]=value
|
37
|
-
end
|
38
|
-
|
39
|
-
response.headers['kutya']='cica'
|
40
|
-
|
41
|
-
response.write response_payload
|
16
|
+
response.write 'OK'
|
42
17
|
response.status = 200
|
43
18
|
response.finish
|
44
19
|
|
@@ -46,33 +21,8 @@ class YourAwesomeApp
|
|
46
21
|
|
47
22
|
end
|
48
23
|
|
49
|
-
require 'yaml'
|
50
|
-
class EscherResponseSigner
|
51
|
-
|
52
|
-
def initialize(app,options={})
|
53
|
-
@app = app
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def call(env)
|
59
|
-
rstatus,rheaders,rbody = @app.call(env)
|
60
|
-
response = Rack::Response.new(rbody,rstatus,rheaders)
|
61
|
-
|
62
|
-
<<-YAML
|
63
|
-
|
64
|
-
YAML
|
65
|
-
|
66
|
-
puts YAML.dump response
|
67
|
-
# puts YAML.dump response
|
68
|
-
|
69
|
-
|
70
|
-
response
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
use EscherResponseSigner
|
76
24
|
use Escher::RackMiddleware
|
25
|
+
run YourAwesomeApp.new
|
77
26
|
|
78
|
-
|
27
|
+
#Rack::Server.start :app => YourAwesomeApp,
|
28
|
+
# :Port => ARGV[0].to_i
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday_middleware-escher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -144,6 +144,7 @@ extensions: []
|
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
146
|
- ".gitignore"
|
147
|
+
- ".ruby-version"
|
147
148
|
- Gemfile
|
148
149
|
- LICENSE
|
149
150
|
- LICENSE.txt
|
@@ -182,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
183
|
version: '0'
|
183
184
|
requirements: []
|
184
185
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.
|
186
|
+
rubygems_version: 2.4.8
|
186
187
|
signing_key:
|
187
188
|
specification_version: 4
|
188
189
|
summary: escher sign and validation for faraday http rest client
|
@@ -190,4 +191,3 @@ test_files:
|
|
190
191
|
- spec/escher/base_spec.rb
|
191
192
|
- spec/escher/request_signer_spec.rb
|
192
193
|
- spec/spec_helper.rb
|
193
|
-
has_rdoc:
|