Class: ApiAuth::RequestDrivers::RestClientRequest
- Inherits:
-
Object
- Object
- ApiAuth::RequestDrivers::RestClientRequest
show all
- Includes:
- Helpers
- Defined in:
- lib/api_auth/request_drivers/rest_client.rb
Overview
Instance Method Summary
collapse
Methods included from Helpers
#b64_encode, #capitalize_keys, #sha256_base64digest
Constructor Details
Returns a new instance of RestClientRequest.
9
10
11
12
13
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 9
def initialize(request)
@request = request
@headers =
true
end
|
Instance Method Details
79
80
81
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 79
def
%w[Authorization AUTHORIZATION HTTP_AUTHORIZATION]
end
|
#calculated_hash ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 21
def calculated_hash
if @request.payload
body = @request.payload.read
@request.payload.instance_variable_get(:@stream).seek(0)
else
body = ''
end
sha256_base64digest(body)
end
|
#content_hash ⇒ Object
58
59
60
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 58
def content_hash
(%w[X-AUTHORIZATION-CONTENT-SHA256])
end
|
#content_hash_mismatch? ⇒ Boolean
38
39
40
41
42
43
44
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 38
def content_hash_mismatch?
if %w[post put].include?(@request.method.to_s)
calculated_hash != content_hash
else
false
end
end
|
#content_type ⇒ Object
54
55
56
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 54
def content_type
(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE])
end
|
46
47
48
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 46
def
capitalize_keys @request.
end
|
#http_method ⇒ Object
50
51
52
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 50
def http_method
@request.method.to_s.upcase
end
|
#original_uri ⇒ Object
62
63
64
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 62
def original_uri
(%w[X-ORIGINAL-URI X_ORIGINAL_URI HTTP_X_ORIGINAL_URI])
end
|
#populate_content_hash ⇒ Object
31
32
33
34
35
36
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 31
def populate_content_hash
return unless %w[post put].include?(@request.method.to_s)
@request.['X-Authorization-Content-SHA256'] = calculated_hash
end
|
#request_uri ⇒ Object
66
67
68
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 66
def request_uri
@request.url
end
|
15
16
17
18
19
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 15
def ()
@request.['Authorization'] =
@request
end
|
#set_date ⇒ Object
70
71
72
73
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 70
def set_date
@request.['DATE'] = Time.now.utc.httpdate
end
|
#timestamp ⇒ Object
75
76
77
|
# File 'lib/api_auth/request_drivers/rest_client.rb', line 75
def timestamp
(%w[DATE HTTP_DATE])
end
|