summaryrefslogtreecommitdiff
path: root/lib/mixlib
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-11-18 13:30:09 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2015-11-30 09:03:01 -0800
commit09d47bde7f833fb13c59dac1fa12bd8a5c209106 (patch)
tree9aa1dd6bd3ebb1e22ca2f6aed4e835d7220ad5f1 /lib/mixlib
parentcceeaa705b4bea1c201d174a3f3f85c87a2034ac (diff)
downloadmixlib-authentication-09d47bde7f833fb13c59dac1fa12bd8a5c209106.tar.gz
Sign x-ops-server-api-version header
Diffstat (limited to 'lib/mixlib')
-rw-r--r--lib/mixlib/authentication/http_authentication_request.rb6
-rw-r--r--lib/mixlib/authentication/signatureverification.rb2
-rw-r--r--lib/mixlib/authentication/signedheaderauth.rb21
3 files changed, 23 insertions, 6 deletions
diff --git a/lib/mixlib/authentication/http_authentication_request.rb b/lib/mixlib/authentication/http_authentication_request.rb
index cc6b566..efa8d80 100644
--- a/lib/mixlib/authentication/http_authentication_request.rb
+++ b/lib/mixlib/authentication/http_authentication_request.rb
@@ -64,6 +64,10 @@ module Mixlib
headers[:x_ops_content_hash].chomp
end
+ def server_api_version
+ (headers[:x_ops_server_api_version] || '0').chomp
+ end
+
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 <=> y.to_s}.map { |i| i[1] }.join("\n")
@@ -80,8 +84,6 @@ module Mixlib
raise MissingAuthenticationHeader, "missing required authentication header(s) '#{missing_headers.join("', '")}'"
end
end
-
-
end
end
end
diff --git a/lib/mixlib/authentication/signatureverification.rb b/lib/mixlib/authentication/signatureverification.rb
index e3e2ae9..3c35c28 100644
--- a/lib/mixlib/authentication/signatureverification.rb
+++ b/lib/mixlib/authentication/signatureverification.rb
@@ -48,6 +48,8 @@ module Mixlib
def_delegator :@auth_request, :request
+ def_delegator :@auth_request, :server_api_version
+
include Mixlib::Authentication::SignedHeaderAuth
def initialize(request=nil)
diff --git a/lib/mixlib/authentication/signedheaderauth.rb b/lib/mixlib/authentication/signedheaderauth.rb
index dbb6b3f..27e0e6a 100644
--- a/lib/mixlib/authentication/signedheaderauth.rb
+++ b/lib/mixlib/authentication/signedheaderauth.rb
@@ -44,6 +44,7 @@ module Mixlib
DEFAULT_SIGN_ALGORITHM = 'sha1'.freeze
DEFAULT_PROTO_VERSION = '1.0'.freeze
+ DEFAULT_SERVER_API_VERSION = '0'
# === signing_object
# This is the intended interface for signing requests with the
@@ -82,7 +83,8 @@ module Mixlib
args[:user_id],
args[:file],
args[:proto_version],
- args[:signing_algorithm]
+ args[:signing_algorithm],
+ args[:headers]
)
end
@@ -201,7 +203,8 @@ module Mixlib
"X-Ops-Content-Hash:#{hashed_body(digest)}",
"X-Ops-Sign:algorithm=#{sign_algorithm};version=#{sign_version}",
"X-Ops-Timestamp:#{canonical_time}",
- "X-Ops-UserId:#{canonical_x_ops_user_id}"
+ "X-Ops-UserId:#{canonical_x_ops_user_id}",
+ "X-Ops-Server-API-Version:#{server_api_version}",
].join("\n")
else
[
@@ -263,7 +266,7 @@ module Mixlib
# provides a more convenient interface to the constructor.
class SigningObject < Struct.new(:http_method, :path, :body, :host,
:timestamp, :user_id, :file, :proto_version,
- :signing_algorithm)
+ :signing_algorithm, :headers)
include SignedHeaderAuth
def proto_version
@@ -282,7 +285,17 @@ module Mixlib
end
end
end
- end
+ def server_api_version
+ key = (self[:headers] || {}).keys.select do |k|
+ k.downcase == 'x-ops-server-api-version'
+ end.first
+ if key
+ self[:headers][key]
+ else
+ DEFAULT_SERVER_API_VERSION
+ end
+ end
+ end
end
end