summaryrefslogtreecommitdiff
path: root/lib/mixlib/authentication/signedheaderauth.rb
diff options
context:
space:
mode:
authorRyan Cragun <me@ryan.ec>2017-04-18 16:46:16 -0700
committerRyan Cragun <me@ryan.ec>2017-04-19 13:26:37 -0700
commit88ff22da3888462e23be414de46ec1a7426e69b8 (patch)
tree0b853d7616ee871deae12fc4d7db9cf967012a01 /lib/mixlib/authentication/signedheaderauth.rb
parent0c5c683a23b7d4b6fd2cbb61a2010af2e513aacf (diff)
downloadmixlib-authentication-ryan/cloud-319.tar.gz
[CLOUD-319] Make mixlib-log an optional dependencyryan/cloud-319
This change makes mixlib-log an optional dependency. When it's available in the LOAD_PATH it will be used by default, otherwise, all logging will will be forwarded to a null logger that does nothing. This is useful for cases where small utilities can consume mixlib-authentication and not have to pull in additional gems. Signed-off-by: Ryan Cragun <me@ryan.ec>
Diffstat (limited to 'lib/mixlib/authentication/signedheaderauth.rb')
-rw-r--r--lib/mixlib/authentication/signedheaderauth.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/mixlib/authentication/signedheaderauth.rb b/lib/mixlib/authentication/signedheaderauth.rb
index f107170..3119c87 100644
--- a/lib/mixlib/authentication/signedheaderauth.rb
+++ b/lib/mixlib/authentication/signedheaderauth.rb
@@ -115,7 +115,7 @@ module Mixlib
header_hash[key] = signature_lines[idx]
end
- Mixlib::Authentication::Log.debug "Header hash: #{header_hash.inspect}"
+ Mixlib::Authentication.logger.debug "Header hash: #{header_hash.inspect}"
header_hash
end
@@ -166,7 +166,8 @@ module Mixlib
# Hence, we're going to assume the one that is passed to sign is
# the correct one and needs to passed through all the functions
# that do any sort of digest.
- if @hashed_body_digest != nil && @hashed_body_digest != digest
+ @hashed_body_digest = nil unless defined?(@hashed_body_digest)
+ if !@hashed_body_digest.nil? && @hashed_body_digest != digest
raise "hashed_body must always be called with the same digest"
else
@hashed_body_digest = digest
@@ -235,7 +236,7 @@ module Mixlib
memo[field_name.to_sym] = field_value.strip
memo
end
- Mixlib::Authentication::Log.debug "Parsed signing description: #{parts.inspect}"
+ Mixlib::Authentication.logger.debug "Parsed signing description: #{parts.inspect}"
parts
end
@@ -246,7 +247,7 @@ module Mixlib
# private
def do_sign(private_key, digest, sign_algorithm, sign_version)
string_to_sign = canonicalize_request(sign_algorithm, sign_version)
- Mixlib::Authentication::Log.debug "String to sign: '#{string_to_sign}'"
+ Mixlib::Authentication.logger.debug "String to sign: '#{string_to_sign}'"
case sign_version
when "1.3"
private_key.sign(digest.new, string_to_sign)
@@ -274,7 +275,7 @@ module Mixlib
def server_api_version
key = (self[:headers] || {}).keys.select do |k|
- k.casecmp("x-ops-server-api-version").zero?
+ k.casecmp("x-ops-server-api-version") == 0
end.first
if key
self[:headers][key]