lib/chef-api/authentication.rb in chef-infra-api-0.10.0 vs lib/chef-api/authentication.rb in chef-infra-api-0.10.2

- old
+ new

@@ -1,9 +1,9 @@ -require 'base64' -require 'digest' -require 'openssl' -require 'time' +require "base64" +require "digest" +require "openssl" +require "time" # # DEBUG steps: # # check .chomp @@ -15,18 +15,18 @@ # @todo: Enable this in the future when Mixlib::Authentication supports # signing the full request body instead of just the uploaded file parameter. SIGN_FULL_BODY = false - SIGNATURE = 'algorithm=sha1;version=1.0;'.freeze + SIGNATURE = "algorithm=sha1;version=1.0;".freeze # Headers - X_OPS_SIGN = 'X-Ops-Sign'.freeze - X_OPS_USERID = 'X-Ops-Userid'.freeze - X_OPS_TIMESTAMP = 'X-Ops-Timestamp'.freeze - X_OPS_CONTENT_HASH = 'X-Ops-Content-Hash'.freeze - X_OPS_AUTHORIZATION = 'X-Ops-Authorization'.freeze + X_OPS_SIGN = "X-Ops-Sign".freeze + X_OPS_USERID = "X-Ops-Userid".freeze + X_OPS_TIMESTAMP = "X-Ops-Timestamp".freeze + X_OPS_CONTENT_HASH = "X-Ops-Content-Hash".freeze + X_OPS_AUTHORIZATION = "X-Ops-Authorization".freeze class << self # # Create a new signing object from the given options. All options are # required. @@ -94,13 +94,13 @@ # @return [Hash] # the signing headers # def headers { - X_OPS_SIGN => SIGNATURE, - X_OPS_USERID => @user, - X_OPS_TIMESTAMP => canonical_timestamp, + X_OPS_SIGN => SIGNATURE, + X_OPS_USERID => @user, + X_OPS_TIMESTAMP => canonical_timestamp, X_OPS_CONTENT_HASH => content_hash, }.merge(signature_lines) end # @@ -112,19 +112,19 @@ # def content_hash return @content_hash if @content_hash if SIGN_FULL_BODY - @content_hash = hash(@body || '').chomp + @content_hash = hash(@body || "").chomp else if @body.is_a?(Multipart::MultiIO) filepart = @body.ios.find { |io| io.is_a?(Multipart::MultiIO) } file = filepart.ios.find { |io| !io.is_a?(StringIO) } @content_hash = hash(file).chomp else - @content_hash = hash(@body || '').chomp + @content_hash = hash(@body || "").chomp end end @content_hash end @@ -150,17 +150,17 @@ log.info "Parsing private key..." if @key.nil? log.warn "No private key given!" - raise 'No private key given!' + raise "No private key given!" end if @key.is_a?(OpenSSL::PKey::RSA) log.debug "Detected private key is an OpenSSL Ruby object" @canonical_key = @key - elsif @key =~ /(.+)\.pem$/ || File.exists?(File.expand_path(@key)) + elsif @key =~ /(.+)\.pem$/ || File.exist?(File.expand_path(@key)) log.debug "Detected private key is the path to a file" contents = File.read(File.expand_path(@key)) @canonical_key = OpenSSL::PKey::RSA.new(contents) else log.debug "Detected private key was the literal string key" @@ -168,21 +168,20 @@ end @canonical_key end - # # The canonical path, with duplicate and trailing slashes removed. This # value is then hashed. # # @example # "/zip//zap/foo" #=> "/zip/zap/foo" # # @return [String] # def canonical_path - @canonical_path ||= hash(@path.squeeze('/').gsub(/(\/)+$/,'')).chomp + @canonical_path ||= hash(@path.squeeze("/").gsub(%r{(/)+$}, "")).chomp end # # The iso8601 timestamp for this request. This value must be cached so it # is persisted throughout this entire request.