summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsonots <sonots@gmail.com>2015-01-08 20:30:57 +0900
committerBryan McLellan <btm@opscode.com>2015-02-09 21:20:34 -0500
commit955bce9ed05d6c69a37c506dc9e24a6e407e1a4d (patch)
tree8c520fcab1b61a29660446fdf55bf2794f3fddb8
parent0e13f128597cfa407f3d8377a12f4b67cf60af59 (diff)
downloadchef-955bce9ed05d6c69a37c506dc9e24a6e407e1a4d.tar.gz
add json_attribs option for chef-apply command
-rw-r--r--lib/chef/application/apply.rb18
-rw-r--r--spec/unit/application/apply_spec.rb16
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index 22d835e876..42805001d8 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -43,6 +43,12 @@ class Chef::Application::Apply < Chef::Application
:description => "Execute resources read from STDIN",
:boolean => true
+ option :json_attribs,
+ :short => "-j JSON_ATTRIBS",
+ :long => "--json-attributes JSON_ATTRIBS",
+ :description => "Load attributes from a JSON file or URL",
+ :proc => nil
+
option :log_level,
:short => "-l LEVEL",
:long => "--log_level LEVEL",
@@ -79,6 +85,8 @@ class Chef::Application::Apply < Chef::Application
:default => !Chef::Platform.windows?,
:description => "Use colored output, defaults to enabled"
+ attr_reader :json_attribs
+
def initialize
super
end
@@ -88,6 +96,14 @@ class Chef::Application::Apply < Chef::Application
Chef::Config.merge!(config)
configure_logging
configure_proxy_environment_variables
+ parse_json
+ end
+
+ def parse_json
+ if Chef::Config[:json_attribs]
+ config_fetcher = Chef::ConfigFetcher.new(Chef::Config[:json_attribs])
+ @json_attribs = config_fetcher.fetch_json
+ end
end
def read_recipe_file(file_name)
@@ -106,7 +122,7 @@ class Chef::Application::Apply < Chef::Application
def get_recipe_and_run_context
Chef::Config[:solo] = true
- @chef_client = Chef::Client.new
+ @chef_client = Chef::Client.new(@json_attribs)
@chef_client.run_ohai
@chef_client.load_node
@chef_client.build_node
diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb
index 5a6366281f..f6cd0bae03 100644
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -91,4 +91,20 @@ describe Chef::Application::Apply do
end
end
+ describe "when the json_attribs configuration option is specified" do
+ let(:json_attribs) { {"a" => "b"} }
+ let(:config_fetcher) { double(Chef::ConfigFetcher, :fetch_json => json_attribs) }
+ let(:json_source) { "https://foo.com/foo.json" }
+
+ before do
+ Chef::Config[:json_attribs] = json_source
+ expect(Chef::ConfigFetcher).to receive(:new).with(json_source).
+ and_return(config_fetcher)
+ end
+
+ it "reads the JSON attributes from the specified source" do
+ @app.reconfigure
+ expect(@app.json_attribs).to eq(json_attribs)
+ end
+ end
end