Skip to content

Commit 1798668

Browse files
authored
Merge pull request #862 from puppetlabs/revert-811-shellescape
Revert "docker_run_flags: Shellescape any provided values"
2 parents 92e58f2 + 1152542 commit 1798668

File tree

4 files changed

+16
-59
lines changed

4 files changed

+16
-59
lines changed

lib/puppet/parser/functions/docker_run_flags.rb

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
# frozen_string_literal: true
22

3+
require 'shellwords'
34
#
45
# docker_run_flags.rb
56
#
67
module Puppet::Parser::Functions
7-
newfunction(:'docker::escape', type: :rvalue) do |args|
8-
subject = args[0]
9-
10-
escape_function = if self['facts'] && self['facts']['os']['family'] == 'windows'
11-
'powershell_escape'
12-
else
13-
'shell_escape'
14-
end
15-
16-
call_function(escape_function, subject)
17-
end
18-
198
# Transforms a hash into a string of docker flags
209
newfunction(:docker_run_flags, type: :rvalue) do |args|
2110
opts = args[0] || {}
2211
flags = []
2312

2413
if opts['username']
25-
flags << "-u #{call_function('docker::escape', [opts['username']])}"
14+
flags << "-u '#{opts['username'].shellescape}'"
2615
end
2716

2817
if opts['hostname']
29-
flags << "-h #{call_function('docker::escape', [opts['hostname']])}"
18+
flags << "-h '#{opts['hostname'].shellescape}'"
3019
end
3120

3221
if opts['restart']
@@ -35,9 +24,9 @@ module Puppet::Parser::Functions
3524

3625
if opts['net']
3726
if opts['net'].is_a? String
38-
flags << "--net #{call_function('docker::escape', [opts['net']])}"
27+
flags << "--net #{opts['net'].shellescape}"
3928
elsif opts['net'].is_a? Array
40-
flags += opts['net'].map { |item| ["--net #{call_function('docker::escape', [item])}"] }
29+
flags << "--net #{opts['net'].join(' --net ').shellescape}"
4130
end
4231
end
4332

@@ -83,17 +72,17 @@ module Puppet::Parser::Functions
8372

8473
multi_flags = ->(values, fmt) {
8574
filtered = [values].flatten.compact
86-
filtered.map { |val| (fmt + params_join_char) % call_function('docker::escape', [val]) }
75+
filtered.map { |val| (fmt + params_join_char) % val }
8776
}
8877

8978
[
9079
['--dns %s', 'dns'],
9180
['--dns-search %s', 'dns_search'],
9281
['--expose=%s', 'expose'],
9382
['--link %s', 'links'],
94-
['--lxc-conf=%s', 'lxc_conf'],
83+
['--lxc-conf="%s"', 'lxc_conf'],
9584
['--volumes-from %s', 'volumes_from'],
96-
['-e %s', 'env'],
85+
['-e "%s"', 'env'],
9786
['--env-file %s', 'env_file'],
9887
['-p %s', 'ports'],
9988
['-l %s', 'labels'],

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"dependencies": [
1111
{
1212
"name": "puppetlabs/stdlib",
13-
"version_requirement": ">= 8.2.0 < 9.0.0"
13+
"version_requirement": ">= 4.24.0 < 9.0.0"
1414
},
1515
{
1616
"name": "puppetlabs/apt",

spec/acceptance/docker_params_changed_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
else
2424
docker_args = ''
2525
docker_network = 'bridge'
26-
volume_location = '/opt/'
26+
volume_location = '/opt'
2727
docker_image = 'hello-world:linux'
2828
end
2929

@@ -33,8 +33,8 @@
3333
install_pp = "class { 'docker': #{docker_args}}"
3434
apply_manifest(install_pp)
3535
end
36-
run_shell("mkdir #{volume_location}volume_1")
37-
run_shell("mkdir #{volume_location}volume_2")
36+
run_shell("mkdir #{volume_location}/volume_1")
37+
run_shell("mkdir #{volume_location}/volume_2")
3838
end
3939

4040
context 'when image is changed' do
@@ -78,8 +78,8 @@ class {'docker': #{docker_args}}
7878
volumes1 = "volumes => ['volume-1:C:\\volume_1']"
7979
volumes2 = "volumes => ['volume-1:C:\\volume_1', 'volume-2:C:\\volume_2']"
8080
else
81-
volumes1 = "volumes => ['volume-1:#{volume_location}volume_1']"
82-
volumes2 = "volumes => ['volume-1:#{volume_location}volume_1', 'volume-2:#{volume_location}volume_2']"
81+
volumes1 = "volumes => ['volume-1:#{volume_location}/volume_1']"
82+
volumes2 = "volumes => ['volume-1:#{volume_location}/volume_1', 'volume-2:#{volume_location}/volume_2']"
8383
end
8484

8585
let(:pp1) do
@@ -143,7 +143,7 @@ class {'docker': #{docker_args}}
143143
end
144144

145145
after(:all) do
146-
run_shell("rm -r #{volume_location}volume_1")
147-
run_shell("rm -r #{volume_location}volume_2")
146+
run_shell("rm -r #{volume_location}/volume_1")
147+
run_shell("rm -r #{volume_location}/volume_2")
148148
end
149149
end

spec/unit/lib/puppet/parser/functions/docker_run_flags_spec.rb

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)