Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
5835ca42
Commit
5835ca42
authored
Oct 14, 2014
by
Josh Frye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move quoting to else block only for valid vars. Add test case.
parent
a667282e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
7 deletions
+22
-7
provisioner/shell/provisioner.go
provisioner/shell/provisioner.go
+4
-7
provisioner/shell/provisioner_test.go
provisioner/shell/provisioner_test.go
+18
-0
No files found.
provisioner/shell/provisioner.go
View file @
5835ca42
...
@@ -170,20 +170,17 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
...
@@ -170,20 +170,17 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
}
}
// Do a check for bad environment variables, such as '=foo', 'foobar'
// Do a check for bad environment variables, such as '=foo', 'foobar'
for
_
,
kv
:=
range
p
.
config
.
Vars
{
for
idx
,
kv
:=
range
p
.
config
.
Vars
{
vs
:=
strings
.
SplitN
(
kv
,
"="
,
2
)
vs
:=
strings
.
SplitN
(
kv
,
"="
,
2
)
if
len
(
vs
)
!=
2
||
vs
[
0
]
==
""
{
if
len
(
vs
)
!=
2
||
vs
[
0
]
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Environment variable not in format 'key=value': %s"
,
kv
))
fmt
.
Errorf
(
"Environment variable not in format 'key=value': %s"
,
kv
))
}
else
{
// Single quote env var values
p
.
config
.
Vars
[
idx
]
=
fmt
.
Sprintf
(
"%s='%s'"
,
vs
[
0
],
vs
[
1
])
}
}
}
}
// Single quote env var values
for
key
:=
range
p
.
config
.
Vars
{
vs
:=
strings
.
SplitN
(
p
.
config
.
Vars
[
key
],
"="
,
2
)
p
.
config
.
Vars
[
key
]
=
fmt
.
Sprintf
(
"%s='%s'"
,
vs
[
0
],
vs
[
1
])
}
if
p
.
config
.
RawStartRetryTimeout
!=
""
{
if
p
.
config
.
RawStartRetryTimeout
!=
""
{
p
.
config
.
startRetryTimeout
,
err
=
time
.
ParseDuration
(
p
.
config
.
RawStartRetryTimeout
)
p
.
config
.
startRetryTimeout
,
err
=
time
.
ParseDuration
(
p
.
config
.
RawStartRetryTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
provisioner/shell/provisioner_test.go
View file @
5835ca42
...
@@ -199,3 +199,21 @@ func TestProvisionerPrepare_EnvironmentVars(t *testing.T) {
...
@@ -199,3 +199,21 @@ func TestProvisionerPrepare_EnvironmentVars(t *testing.T) {
t
.
Fatalf
(
"should not have error: %s"
,
err
)
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
}
}
func
TestProvisionerQuote_EnvironmentVars
(
t
*
testing
.
T
)
{
config
:=
testConfig
()
config
[
"environment_vars"
]
=
[]
string
{
"keyone=valueone"
,
"keytwo=value
\n
two"
}
p
:=
new
(
Provisioner
)
p
.
Prepare
(
config
)
expectedValue
:=
"keyone='valueone'"
if
p
.
config
.
Vars
[
0
]
!=
expectedValue
{
t
.
Fatalf
(
"%s should be equal to %s"
,
p
.
config
.
Vars
[
0
],
expectedValue
)
}
expectedValue
=
"keytwo='value
\n
two'"
if
p
.
config
.
Vars
[
1
]
!=
expectedValue
{
t
.
Fatalf
(
"%s should be equal to %s"
,
p
.
config
.
Vars
[
1
],
expectedValue
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment