Class: Mixlib::Authentication::HTTPAuthenticationRequest
- Inherits:
-
Object
- Object
- Mixlib::Authentication::HTTPAuthenticationRequest
- Defined in:
- lib/mixlib/authentication/http_authentication_request.rb
Constant Summary collapse
- MANDATORY_HEADERS =
i{x_ops_sign x_ops_userid host x_ops_content_hash}.freeze
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #content_hash ⇒ Object
- #headers ⇒ Object
- #host ⇒ Object
- #http_method ⇒ Object
-
#initialize(request) ⇒ HTTPAuthenticationRequest
constructor
A new instance of HTTPAuthenticationRequest.
- #path ⇒ Object
- #request_signature ⇒ Object
- #server_api_version ⇒ Object
- #signing_description ⇒ Object
- #timestamp ⇒ Object
- #user_id ⇒ Object
- #validate_headers! ⇒ Object
Constructor Details
#initialize(request) ⇒ HTTPAuthenticationRequest
Returns a new instance of HTTPAuthenticationRequest.
29 30 31 32 33 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 29 def initialize(request) @request = request @request_signature = nil validate_headers! end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
27 28 29 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 27 def request @request end |
Instance Method Details
#content_hash ⇒ Object
63 64 65 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 63 def content_hash headers[:x_ops_content_hash].chomp end |
#headers ⇒ Object
35 36 37 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 35 def headers @headers ||= @request.env.inject({}) { |memo, kv| memo[$2.tr("-", "_").downcase.to_sym] = kv[1] if kv[0] =~ /^(HTTP_)(.*)/; memo } end |
#host ⇒ Object
59 60 61 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 59 def host headers[:host].chomp end |
#http_method ⇒ Object
39 40 41 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 39 def http_method @request.method.to_s end |
#path ⇒ Object
43 44 45 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 43 def path @request.path.to_s end |
#request_signature ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 71 def request_signature unless @request_signature @request_signature = headers.find_all { |h| h[0].to_s =~ /^x_ops_authorization_/ } .sort { |x, y| x.to_s[/\d+/].to_i <=> y.to_s[/\d+/].to_i }.map { |i| i[1] }.join("\n") Mixlib::Authentication::Log.trace "Reconstituted (user-supplied) request signature: #{@request_signature}" end @request_signature end |
#server_api_version ⇒ Object
67 68 69 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 67 def server_api_version (headers[:x_ops_server_api_version] || DEFAULT_SERVER_API_VERSION).chomp end |
#signing_description ⇒ Object
47 48 49 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 47 def signing_description headers[:x_ops_sign].chomp end |
#timestamp ⇒ Object
55 56 57 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 55 def headers[:x_ops_timestamp].chomp end |
#user_id ⇒ Object
51 52 53 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 51 def user_id headers[:x_ops_userid].chomp end |
#validate_headers! ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/mixlib/authentication/http_authentication_request.rb', line 80 def validate_headers! missing_headers = MANDATORY_HEADERS - headers.keys unless missing_headers.empty? missing_headers.map! { |h| h.to_s.upcase } raise MissingAuthenticationHeader, "missing required authentication header(s) '#{missing_headers.join("', '")}'" end end |