appoxy_rails 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/api/api_controller.rb +23 -16
- data/lib/api/client.rb +1 -1
- metadata +3 -3
data/lib/api/api_controller.rb
CHANGED
@@ -26,35 +26,42 @@ module Appoxy
|
|
26
26
|
end
|
27
27
|
|
28
28
|
#operation = "#{controller_name}/#{action_name}"
|
29
|
-
operation = request.env["PATH_INFO"].gsub(/\/api\//, "")# here we're getting original request url'
|
30
|
-
puts "XXX " + operation
|
29
|
+
#operation = request.env["PATH_INFO"].gsub(/\/api\//, "")# here we're getting original request url'
|
31
30
|
|
32
|
-
#getting clean params (without parsed via routes)
|
33
|
-
params_for_signature = params2||request.query_parameters
|
34
|
-
#removing mandatory params
|
35
|
-
params_for_signature = params_for_signature.delete_if {|key, value| ["access_key", "sigv", "sig", "timestamp"].include? key}
|
31
|
+
# #getting clean params (without parsed via routes)
|
32
|
+
# params_for_signature = params2||request.query_parameters
|
33
|
+
# #removing mandatory params
|
34
|
+
# params_for_signature = params_for_signature.delete_if {|key, value| ["access_key", "sigv", "sig", "timestamp"].include? key}
|
36
35
|
|
37
36
|
|
38
|
-
#
|
37
|
+
#puts "params " +operation+Appoxy::Api::Signatures.hash_to_s(params_for_signature)
|
39
38
|
access_key = params["access_key"]
|
40
39
|
sigv = params["sigv"]
|
41
40
|
timestamp = params["timestamp"]
|
42
41
|
sig = params["sig"]
|
43
|
-
|
42
|
+
signature = ""
|
43
|
+
case sigv
|
44
|
+
when "0.1"
|
45
|
+
puts "outdated version of client"
|
46
|
+
signature = "#{controller_name}/#{action_name}"
|
47
|
+
when "0.2"
|
48
|
+
puts "new version of client"
|
49
|
+
operation = request.env["PATH_INFO"].gsub(/\/api\//, "")# here we're getting original request url'
|
50
|
+
params_for_signature = params2||request.query_parameters
|
51
|
+
params_for_signature = params_for_signature.delete_if {|key, value| ["access_key", "sigv", "sig", "timestamp"].include? key}
|
52
|
+
signature = operation+Appoxy::Api::Signatures.hash_to_s(params_for_signature)
|
53
|
+
end
|
54
|
+
# puts "signature " + signature
|
44
55
|
raise Appoxy::Api::ApiError, "No access_key" if access_key.nil?
|
45
56
|
raise Appoxy::Api::ApiError, "No sigv" if sigv.nil?
|
46
57
|
raise Appoxy::Api::ApiError, "No timestamp" if timestamp.nil?
|
47
58
|
raise Appoxy::Api::ApiError, "No sig" if sig.nil?
|
48
59
|
timestamp2 = Appoxy::Api::Signatures.generate_timestamp(Time.now.gmtime)
|
49
60
|
raise Appoxy::Api::ApiError, "Request timed out!" unless (Time.parse(timestamp2)-Time.parse(timestamp))<60 # deny all requests older than 60 seconds
|
50
|
-
|
51
|
-
secret_key = secret_key_for_signature(access_key)
|
52
|
-
sig2 = Appoxy::Api::Signatures.generate_signature(operation+Appoxy::Api::Signatures.hash_to_s(params_for_signature), timestamp, secret_key)
|
53
|
-
#p "signature 1 " + sig2 + " signature 2 " + sig
|
61
|
+
sig2 = Appoxy::Api::Signatures.generate_signature(signature, timestamp, secret_key_for_signature(access_key))
|
54
62
|
raise Appoxy::Api::ApiError, "Invalid signature!" unless sig == sig2
|
55
63
|
|
56
|
-
puts '
|
57
|
-
true
|
64
|
+
puts 'Signature OK'
|
58
65
|
|
59
66
|
end
|
60
67
|
|
@@ -68,8 +75,8 @@ module Appoxy
|
|
68
75
|
response_as_string = '' # in case we want to add debugging or something
|
69
76
|
# respond_to do |format|
|
70
77
|
# format.json { render :json=>msg }
|
71
|
-
response_as_string = render_to_string :json => msg
|
72
|
-
render :json =>
|
78
|
+
# response_as_string = render_to_string :json => msg
|
79
|
+
render :json => msg
|
73
80
|
# end
|
74
81
|
true
|
75
82
|
end
|
data/lib/api/client.rb
CHANGED
@@ -70,7 +70,7 @@ module Appoxy
|
|
70
70
|
ts = Appoxy::Api::Signatures.generate_timestamp(Time.now.gmtime)
|
71
71
|
#p "hash_to s" + command_path + Appoxy::Api::Signatures.hash_to_s(hash)
|
72
72
|
sig = Appoxy::Api::Signatures.generate_signature(command_path + Appoxy::Api::Signatures.hash_to_s(hash), ts, secret_key)
|
73
|
-
extra_params = {'sigv'=>"0.
|
73
|
+
extra_params = {'sigv'=>"0.2", 'sig' => sig, 'timestamp' => ts, 'access_key' => access_key}
|
74
74
|
hash.merge!(extra_params)
|
75
75
|
|
76
76
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 9
|
9
|
+
version: 0.0.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Travis Reeder
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-28 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|