From d232f34b4c0b8b2a2b4272c06421d4af1eb08ed1 Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Fri, 20 Oct 2017 11:26:23 +0200 Subject: [PATCH] Extend openstack_command This patch extends openstack_command to accept an array in addition to a string as an argument. This allows the use of openstack_command in cases where an argument contains protected spaces. Examples: mistral execution-create my_workflow \ '{"names": ["John", "Mistral", "Ivan", "Crystal"]}' barbican secret list --name chef_test_secret --format value -c"Secret href" Without this patch, all arguments have to be passed as a single string which openstack_command splits on white space regardless of any quotation marks. Therefore, the examples above will fail. Change-Id: I0419a1526beb103839a3cf235eba6c41d9d946d5 Closes-Bug: #1723949 --- libraries/cli.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/cli.rb b/libraries/cli.rb index 840f3c5f..41d68719 100644 --- a/libraries/cli.rb +++ b/libraries/cli.rb @@ -63,7 +63,10 @@ module ::Openstack openstackcmd << "--#{key}" openstackcmd << val.to_s unless val.to_s.empty? end - openstackcmd = openstackcmd.concat(options.split) + # If options is a string, split on whitespace into array; otherwise, assume + # it is an array already and leave it untouched. + options = options.split if options.instance_of? String + openstackcmd = openstackcmd.concat(options) Chef::Log.debug("Running openstack command: #{openstackcmd} with environment: #{env}") result = shell_out(openstackcmd, env: env) Chef::Log.debug("Output for command: #{cmd}:\n#{result.stdout}\n#{result.stderr}")