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
c7b10cb2
Commit
c7b10cb2
authored
Sep 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: detect invalid versions
parent
6965af29
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
8 deletions
+46
-8
CHANGELOG.md
CHANGELOG.md
+1
-0
packer/plugin/client.go
packer/plugin/client.go
+18
-4
packer/plugin/client_test.go
packer/plugin/client_test.go
+15
-0
packer/plugin/plugin.go
packer/plugin/plugin.go
+6
-1
packer/plugin/plugin_test.go
packer/plugin/plugin_test.go
+6
-3
No files found.
CHANGELOG.md
View file @
c7b10cb2
...
...
@@ -15,6 +15,7 @@ IMPROVEMENTS:
*
core: User variables can now be used for integer, boolean, etc.
values. [GH-418]
*
core: Plugins made with incompatible versions will no longer load.
*
builder/amazon/all: Interrupts work while waiting for AMI to be ready.
*
provisioner/shell: Script line-endings are automatically converted to
Unix-style line-endings. Can be disabled by setting "binary" to "true".
...
...
packer/plugin/client.go
View file @
c7b10cb2
...
...
@@ -317,10 +317,24 @@ func (c *Client) Start() (address string, err error) {
err
=
errors
.
New
(
"timeout while waiting for plugin to start"
)
case
<-
exitCh
:
err
=
errors
.
New
(
"plugin exited before we could connect"
)
case
line
:=
<-
linesCh
:
// Trim the address and reset the err since we were able
// to read some sort of address.
c
.
address
=
strings
.
TrimSpace
(
string
(
line
))
case
lineBytes
:=
<-
linesCh
:
// Trim the line and split by "|" in order to get the parts of
// the output.
line
:=
strings
.
TrimSpace
(
string
(
lineBytes
))
parts
:=
strings
.
SplitN
(
line
,
"|"
,
2
)
if
len
(
parts
)
<
2
{
err
=
fmt
.
Errorf
(
"Unrecognized remote plugin message: %s"
,
line
)
return
}
// Test the API version
if
parts
[
0
]
!=
APIVersion
{
err
=
fmt
.
Errorf
(
"Incompatible API version with plugin. "
+
"Plugin version: %s, Ours: %s"
,
parts
[
0
],
APIVersion
)
return
}
c
.
address
=
parts
[
1
]
address
=
c
.
address
}
...
...
packer/plugin/client_test.go
View file @
c7b10cb2
...
...
@@ -37,6 +37,21 @@ func TestClient(t *testing.T) {
}
}
func
TestClientStart_badVersion
(
t
*
testing
.
T
)
{
config
:=
&
ClientConfig
{
Cmd
:
helperProcess
(
"bad-version"
),
StartTimeout
:
50
*
time
.
Millisecond
,
}
c
:=
NewClient
(
config
)
defer
c
.
Kill
()
_
,
err
:=
c
.
Start
()
if
err
==
nil
{
t
.
Fatal
(
"err should not be nil"
)
}
}
func
TestClient_Start_Timeout
(
t
*
testing
.
T
)
{
config
:=
&
ClientConfig
{
Cmd
:
helperProcess
(
"start-timeout"
),
...
...
packer/plugin/plugin.go
View file @
c7b10cb2
...
...
@@ -30,6 +30,11 @@ var Interrupts int32 = 0
const
MagicCookieKey
=
"PACKER_PLUGIN_MAGIC_COOKIE"
const
MagicCookieValue
=
"d602bf8f470bc67ca7faa0386276bbdd4330efaf76d1a219cb4d6991ca9872b2"
// The APIVersion is outputted along with the RPC address. The plugin
// client validates this API version and will show an error if it doesn't
// know how to speak it.
const
APIVersion
=
"1"
// This serves a single RPC connection on the given RPC server on
// a random port.
func
serve
(
server
*
rpc
.
Server
)
(
err
error
)
{
...
...
@@ -77,7 +82,7 @@ func serve(server *rpc.Server) (err error) {
// Output the address to stdout
log
.
Printf
(
"Plugin address: %s
\n
"
,
address
)
fmt
.
Print
ln
(
address
)
fmt
.
Print
f
(
"%s|%s
\n
"
,
APIVersion
,
address
)
os
.
Stdout
.
Sync
()
// Accept a connection
...
...
packer/plugin/plugin_test.go
View file @
c7b10cb2
...
...
@@ -50,6 +50,9 @@ func TestHelperProcess(*testing.T) {
cmd
,
args
:=
args
[
0
],
args
[
1
:
]
switch
cmd
{
case
"bad-version"
:
fmt
.
Printf
(
"%s1|:1234
\n
"
,
APIVersion
)
<-
make
(
chan
int
)
case
"builder"
:
ServeBuilder
(
new
(
helperBuilder
))
case
"command"
:
...
...
@@ -59,7 +62,7 @@ func TestHelperProcess(*testing.T) {
case
"invalid-rpc-address"
:
fmt
.
Println
(
"lolinvalid"
)
case
"mock"
:
fmt
.
Print
ln
(
":1234"
)
fmt
.
Print
f
(
"%s|:1234
\n
"
,
APIVersion
)
<-
make
(
chan
int
)
case
"post-processor"
:
ServePostProcessor
(
new
(
helperPostProcessor
))
...
...
@@ -69,11 +72,11 @@ func TestHelperProcess(*testing.T) {
time
.
Sleep
(
1
*
time
.
Minute
)
os
.
Exit
(
1
)
case
"stderr"
:
fmt
.
Print
ln
(
":1234"
)
fmt
.
Print
f
(
"%s|:1234
\n
"
,
APIVersion
)
log
.
Println
(
"HELLO"
)
log
.
Println
(
"WORLD"
)
case
"stdin"
:
fmt
.
Print
ln
(
":1234"
)
fmt
.
Print
f
(
"%s|:1234
\n
"
,
APIVersion
)
data
:=
make
([]
byte
,
5
)
if
_
,
err
:=
os
.
Stdin
.
Read
(
data
);
err
!=
nil
{
log
.
Printf
(
"stdin read error: %s"
,
err
)
...
...
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