cassieq-client 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cassieq/authentication.rb +17 -7
- data/lib/cassieq/client.rb +14 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccb1bf9d217348ce9f96c072173cd3a5a403a8c9
|
4
|
+
data.tar.gz: a69c0ccc5d7b1dc49a873e5ce132b338580457ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9c61c987b6119314622da59e6f12e87ef75d534aff680b2aa2d62f5e5dc843418a0ece534de89e2ee570e4f559383bfded633de6f66ce1d51f3845eeeefb57b
|
7
|
+
data.tar.gz: 91b118383123db8969db63b0dbfea77287ecb047338a6fd8dcf4fdad0880bc7434974876fedbf2c66fbf56ac1541a919fa63dd1ab88df837e11b6e1220944610
|
@@ -3,23 +3,33 @@ require "openssl"
|
|
3
3
|
require "time"
|
4
4
|
|
5
5
|
module Cassieq
|
6
|
-
|
7
|
-
|
6
|
+
class Authentication
|
7
|
+
attr_reader :key, :account
|
8
|
+
|
9
|
+
def self.generate_auth_headers(key, account, method, path)
|
10
|
+
new(key, account).auth_headers(method, path)
|
11
|
+
end
|
8
12
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
13
|
+
def initialize(key, account)
|
14
|
+
@key = key
|
15
|
+
@account = account
|
16
|
+
end
|
17
|
+
|
18
|
+
def auth_headers(method, path, request_time = formated_time_now)
|
19
|
+
auth_signature = signature_from_key(method, path, request_time)
|
12
20
|
|
13
21
|
{ "X-Cassieq-Request-Time" => request_time, "Authorization" => "Signed #{auth_signature}" }
|
14
22
|
end
|
15
23
|
|
16
|
-
def
|
24
|
+
def signature_from_key(method, path, request_time = formated_time_now)
|
17
25
|
key_bytes = Base64.urlsafe_decode64("#{key}==")
|
18
|
-
string_to_sign = [account,
|
26
|
+
string_to_sign = [account, method.to_s.upcase, path, request_time].join("\n")
|
19
27
|
hmac = OpenSSL::HMAC.digest("sha256", key_bytes, string_to_sign)
|
20
28
|
Base64.urlsafe_encode64(hmac).gsub(/=+$/, "")
|
21
29
|
end
|
22
30
|
|
31
|
+
private
|
32
|
+
|
23
33
|
def formated_time_now
|
24
34
|
Time.now.utc.iso8601
|
25
35
|
end
|
data/lib/cassieq/client.rb
CHANGED
@@ -12,16 +12,15 @@ module Cassieq
|
|
12
12
|
include Cassieq::Client::Queues
|
13
13
|
include Cassieq::Client::Messages
|
14
14
|
include Cassieq::Client::Statistics
|
15
|
-
include Cassieq::Authentication
|
16
15
|
include Cassieq::Utils
|
17
16
|
|
18
17
|
attr_accessor :host, :account, :port, :key, :provided_params
|
19
18
|
|
20
19
|
def initialize(params = {})
|
21
|
-
@host = params
|
22
|
-
@key = params
|
23
|
-
@provided_params = params
|
24
|
-
@account = params
|
20
|
+
@host = params[:host]
|
21
|
+
@key = params[:key]
|
22
|
+
@provided_params = params[:provided_params]
|
23
|
+
@account = params[:account]
|
25
24
|
@port = params.fetch(:port, 8080)
|
26
25
|
yield(self) if block_given?
|
27
26
|
end
|
@@ -43,21 +42,21 @@ module Cassieq
|
|
43
42
|
"/api/v1/accounts/#{account}"
|
44
43
|
end
|
45
44
|
|
46
|
-
def
|
47
|
-
"#{path_prefix}/#{path}"
|
48
|
-
end
|
49
|
-
|
50
|
-
def request(method, path, body = nil, params = nil)
|
45
|
+
def request(method, path, body = nil, params = {})
|
51
46
|
handle_response do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
req.
|
56
|
-
req.headers
|
47
|
+
request_path = "#{path_prefix}/#{path}"
|
48
|
+
connection.run_request(method, request_path, body, nil) do |req|
|
49
|
+
req.params.merge!(params)
|
50
|
+
req.headers.merge!(generate_auth_headers(method, request_path)) unless key.nil?
|
51
|
+
req.headers.merge!("Content-Type" => "application/json") unless body.nil?
|
57
52
|
end
|
58
53
|
end
|
59
54
|
end
|
60
55
|
|
56
|
+
def generate_auth_headers(method, path)
|
57
|
+
Cassieq::Authentication.generate_auth_headers(key, account, method, path)
|
58
|
+
end
|
59
|
+
|
61
60
|
def handle_response(&request_block)
|
62
61
|
response = request_block.call
|
63
62
|
Cassieq::Error.from_status_and_body(response)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassieq-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Conroy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|