summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortylercloke <tylercloke@gmail.com>2015-04-30 15:06:17 -0700
committertylercloke <tylercloke@gmail.com>2015-05-04 13:18:30 -0700
commitddf2135f147eca68490829dd96c65690c27f8d04 (patch)
tree50d01383e922c208625cb5ffa8c47855ccad71c0
parentc6c7329ff54851390e0e84d0b681ee8396b3f34c (diff)
downloadchef-ddf2135f147eca68490829dd96c65690c27f8d04.tar.gz
Implemented X-Ops-Server-API-Version in Chef requests.
This takes advantage of Chef::HTTP::Authenticator.handle_request. After the authentication_headers have been merged, it adds: {'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION} Chef::HTTP::Authenticator::SERVER_API_VERSION should corrospond to the max version of the server the client is compatible with. We are starting at "0". I also removed outer level lets :base_header and :req_with_body_headers from rest_spec.rb as they were never used anywhere. Another :base_header was defined in a tighter part of the spec and was only used in that scope, and :req_with_body_headers was never used anywhere.
-rw-r--r--lib/chef/http/authenticator.rb3
-rw-r--r--spec/unit/knife_spec.rb3
-rw-r--r--spec/unit/rest_spec.rb30
3 files changed, 15 insertions, 21 deletions
diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb
index 4255f18cbd..4ec35add34 100644
--- a/lib/chef/http/authenticator.rb
+++ b/lib/chef/http/authenticator.rb
@@ -24,6 +24,8 @@ class Chef
class HTTP
class Authenticator
+ SERVER_API_VERSION = "0"
+
attr_reader :signing_key_filename
attr_reader :raw_key
attr_reader :attr_names
@@ -41,6 +43,7 @@ class Chef
def handle_request(method, url, headers={}, data=false)
headers.merge!(authentication_headers(method, url, data)) if sign_requests?
+ headers.merge!({'X-Ops-Server-API-Version' => SERVER_API_VERSION})
[method, url, headers, data]
end
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb
index b748232081..cb7d5e0b9e 100644
--- a/spec/unit/knife_spec.rb
+++ b/spec/unit/knife_spec.rb
@@ -130,7 +130,8 @@ describe Chef::Knife do
"Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'X-Chef-Version' => Chef::VERSION,
"Host"=>"api.opscode.piab",
- "X-REMOTE-REQUEST-ID"=>request_id}}
+ "X-REMOTE-REQUEST-ID"=>request_id,
+ 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}}
let(:request_id) {"1234"}
diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb
index 85c9e3df8f..b4f8f336a9 100644
--- a/spec/unit/rest_spec.rb
+++ b/spec/unit/rest_spec.rb
@@ -69,8 +69,8 @@ describe Chef::REST do
rest
end
- let(:standard_read_headers) {{"Accept"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id}}
- let(:standard_write_headers) {{"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id}}
+ let(:standard_read_headers) {{"Accept"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}}
+ let(:standard_write_headers) {{"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}}
before(:each) do
Chef::Log.init(log_stringio)
@@ -277,19 +277,6 @@ describe Chef::REST do
rest
end
- let(:base_headers) do
- {
- 'Accept' => 'application/json',
- 'X-Chef-Version' => Chef::VERSION,
- 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
- 'X-REMOTE-REQUEST-ID' => request_id
- }
- end
-
- let (:req_with_body_headers) do
- base_headers.merge("Content-Type" => "application/json", "Content-Length" => '13')
- end
-
before(:each) do
Chef::Config[:ssl_client_cert] = nil
Chef::Config[:ssl_client_key] = nil
@@ -304,7 +291,8 @@ describe Chef::REST do
'X-Chef-Version' => Chef::VERSION,
'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
'Host' => host_header,
- 'X-REMOTE-REQUEST-ID' => request_id
+ 'X-REMOTE-REQUEST-ID' => request_id,
+ 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION
}
end
@@ -548,7 +536,7 @@ describe Chef::REST do
end
end
end
- end
+ end # as JSON API requests
context "when streaming downloads to a tempfile" do
let!(:tempfile) { Tempfile.open("chef-rspec-rest_spec-line-@{__LINE__}--") }
@@ -586,7 +574,8 @@ describe Chef::REST do
'X-Chef-Version' => Chef::VERSION,
'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
'Host' => host_header,
- 'X-REMOTE-REQUEST-ID'=> request_id
+ 'X-REMOTE-REQUEST-ID'=> request_id,
+ 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION
}
expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock)
rest.streaming_request(url, {})
@@ -597,7 +586,8 @@ describe Chef::REST do
'X-Chef-Version' => Chef::VERSION,
'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
'Host' => host_header,
- 'X-REMOTE-REQUEST-ID'=> request_id
+ 'X-REMOTE-REQUEST-ID'=> request_id,
+ 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION
}
expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock)
rest.streaming_request(url, {})
@@ -695,7 +685,7 @@ describe Chef::REST do
expect(block_called).to be_truthy
end
end
- end
+ end # when making REST requests
context "when following redirects" do
let(:rest) do