diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-25 13:29:15 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-25 13:29:15 -0800 |
commit | f923755a505c31745f6df14e201149128ba4ebec (patch) | |
tree | edd23cb1045b3da3666a3531a84e1636763ed14c | |
parent | 008e33f7f458562f1a390413800afbbd07c2cf3a (diff) | |
parent | fa92e55c8c6c9ca5e72b91b1f3b996068c5281e7 (diff) | |
download | chef-f923755a505c31745f6df14e201149128ba4ebec.tar.gz |
Merge pull request #2806 from chef/lcg/2411
Lcg/2411
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/chef/knife/raw.rb | 17 | ||||
-rw-r--r-- | spec/unit/knife/raw_spec.rb | 43 |
3 files changed, 58 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index dc6bab12cc..8e2eae350b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ * suppress 3694 warnings on the most trivial resource cloning * fixed bugs in the deep_merge_cache logic introduced in 12.0.0 around `node['foo']` vs `node[:foo]` vs. `node.foo` * add `include_recipe "::recipe"` sugar to reference a recipe in the current cookbook +* Add --proxy-auth option to `knife raw` ## 12.0.3 * [**Phil Dibowitz**](https://github.com/jaymzh): diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb index 954d46beee..601cfcef9b 100644 --- a/lib/chef/knife/raw.rb +++ b/lib/chef/knife/raw.rb @@ -32,6 +32,12 @@ class Chef :short => '-i FILE', :description => "Name of file to use for PUT or POST" + option :proxy_auth, + :long => '--proxy-auth', + :boolean => true, + :default => false, + :description => "Use webui proxy authentication. Client key must be the webui key." + class RawInputServerAPI < Chef::HTTP def initialize(options = {}) options[:client_name] ||= Chef::Config[:node_name] @@ -64,15 +70,21 @@ class Chef begin method = config[:method].to_sym + headers = {'Content-Type' => 'application/json'} + + if config[:proxy_auth] + headers['x-ops-request-source'] = 'web' + end + if config[:pretty] chef_rest = RawInputServerAPI.new - result = chef_rest.request(method, name_args[0], {'Content-Type' => 'application/json'}, data) + result = chef_rest.request(method, name_args[0], headers, data) unless result.is_a?(String) result = Chef::JSONCompat.to_json_pretty(result) end else chef_rest = RawInputServerAPI.new(:raw_output => true) - result = chef_rest.request(method, name_args[0], {'Content-Type' => 'application/json'}, data) + result = chef_rest.request(method, name_args[0], headers, data) end output result rescue Timeout::Error => e @@ -88,4 +100,3 @@ class Chef end # class Raw end end - diff --git a/spec/unit/knife/raw_spec.rb b/spec/unit/knife/raw_spec.rb new file mode 100644 index 0000000000..ab929abd39 --- /dev/null +++ b/spec/unit/knife/raw_spec.rb @@ -0,0 +1,43 @@ +# +# Author:: Steven Danna (<steve@getchef.com>) +# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'spec_helper' + +describe Chef::Knife::Raw do + let(:rest) do + r = double('Chef::Knife::Raw::RawInputServerAPI') + allow(Chef::Knife::Raw::RawInputServerAPI).to receive(:new).and_return(r) + r + end + + let(:knife) do + k = Chef::Knife::Raw.new + k.config[:method] = "GET" + k.name_args = [ "/nodes" ] + k + end + + describe "run" do + it "should set the x-ops-request-source header when --proxy-auth is set" do + knife.config[:proxy_auth] = true + expect(rest).to receive(:request).with(:GET, "/nodes", + { 'Content-Type' => 'application/json', + 'x-ops-request-source' => 'web'}, false) + knife.run + end + end +end |