From 40be46d78da19fee5d7bf5e05282443c384feb32 Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Mon, 16 Nov 2015 12:20:48 -0800 Subject: [PATCH] Load configuration when running `chef update` Similar to `chef install`, `chef update` does not have any direct configurables, but may rely on configuration being loaded in order to configure SSL to correctly verify connections to a private supermarket. --- lib/chef-dk/command/update.rb | 19 +++++++++++++++++++ spec/unit/command/update_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/chef-dk/command/update.rb b/lib/chef-dk/command/update.rb index 32b9a49cc..452a9027c 100644 --- a/lib/chef-dk/command/update.rb +++ b/lib/chef-dk/command/update.rb @@ -19,12 +19,15 @@ require 'chef-dk/ui' require 'chef-dk/policyfile_services/install' require 'chef-dk/policyfile_services/update_attributes' +require 'chef-dk/configurable' module ChefDK module Command class Update < Base + include Configurable + banner(<<-BANNER) Usage: chef update [ POLICY_FILE ] [options] @@ -45,6 +48,11 @@ class Update < Base BANNER + option :config_file, + short: "-c CONFIG_FILE", + long: "--config CONFIG_FILE", + description: "Path to configuration file" + option :debug, short: "-D", long: "--debug", @@ -74,6 +82,13 @@ def initialize(*args) def run(params = []) return 1 unless apply_params!(params) + + # Force config file to be loaded. We don't use the configuration + # directly, but the user may have SSL configuration options that they + # need to talk to a private supermarket (e.g., trusted_certs or + # ssl_verify_mode) + chef_config + if update_attributes? attributes_updater.run else @@ -98,6 +113,10 @@ def debug? !!config[:debug] end + def config_path + config[:config_file] + end + def update_attributes? !!config[:update_attributes] end diff --git a/spec/unit/command/update_spec.rb b/spec/unit/command/update_spec.rb index 996c49b18..6face3ff4 100644 --- a/spec/unit/command/update_spec.rb +++ b/spec/unit/command/update_spec.rb @@ -39,6 +39,10 @@ expect(command.debug?).to be(false) end + it "doesn't set a config path by default" do + expect(command.config_path).to be_nil + end + context "when debug mode is set" do let(:params) { [ "-D" ] } @@ -48,6 +52,26 @@ end end + context "when an explicit config file path is given" do + + let(:params) { %w[ -c ~/.chef/alternate_config.rb ] } + + let(:chef_config_loader) { instance_double("Chef::WorkstationConfigLoader") } + + it "sets the config file path to the given value" do + expect(command.config_path).to eq("~/.chef/alternate_config.rb") + end + + it "loads the config from the given path" do + expect(Chef::WorkstationConfigLoader).to receive(:new). + with("~/.chef/alternate_config.rb"). + and_return(chef_config_loader) + expect(chef_config_loader).to receive(:load) + expect(command.chef_config).to eq(Chef::Config) + end + + end + context "when attributes update mode is set" do let(:params) { ["-a"] }