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
520a2706
Commit
520a2706
authored
Jun 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: Validate MD5
parent
4b46181f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
36 deletions
+76
-36
builder/vmware/builder.go
builder/vmware/builder.go
+6
-4
builder/vmware/builder_test.go
builder/vmware/builder_test.go
+6
-2
builder/vmware/step_download_iso.go
builder/vmware/step_download_iso.go
+64
-30
No files found.
builder/vmware/builder.go
View file @
520a2706
...
...
@@ -49,10 +49,9 @@ type config struct {
RawSSHWaitTimeout
string
`mapstructure:"ssh_wait_timeout"`
}
func
(
b
*
Builder
)
Prepare
(
raw
interface
{})
(
err
error
)
{
err
=
mapstructure
.
Decode
(
raw
,
&
b
.
config
)
if
err
!=
nil
{
return
func
(
b
*
Builder
)
Prepare
(
raw
interface
{})
error
{
if
err
:=
mapstructure
.
Decode
(
raw
,
&
b
.
config
);
err
!=
nil
{
return
err
}
if
b
.
config
.
DiskName
==
""
{
...
...
@@ -88,6 +87,7 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
}
// Accumulate any errors
var
err
error
errs
:=
make
([]
error
,
0
)
if
b
.
config
.
HTTPPortMin
>
b
.
config
.
HTTPPortMax
{
...
...
@@ -96,6 +96,8 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
if
b
.
config
.
ISOMD5
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"Due to large file sizes, an iso_md5 is required"
))
}
else
{
b
.
config
.
ISOMD5
=
strings
.
ToLower
(
b
.
config
.
ISOMD5
)
}
if
b
.
config
.
ISOUrl
==
""
{
...
...
builder/vmware/builder_test.go
View file @
520a2706
...
...
@@ -108,11 +108,15 @@ func TestBuilderPrepare_ISOMD5(t *testing.T) {
}
// Test good
config
[
"iso_md5"
]
=
"
fo
o"
config
[
"iso_md5"
]
=
"
FO
o"
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
ISOMD5
!=
"foo"
{
t
.
Fatalf
(
"should've lowercased: %s"
,
b
.
config
.
ISOMD5
)
}
}
func
TestBuilderPrepare_ISOUrl
(
t
*
testing
.
T
)
{
...
...
builder/vmware/step_download_iso.go
View file @
520a2706
package
vmware
import
(
"crypto/md5"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
...
...
@@ -9,6 +10,7 @@ import (
"net/http"
"net/url"
"os"
"strings"
"time"
)
...
...
@@ -32,6 +34,16 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction
cachePath
:=
cache
.
Lock
(
config
.
ISOUrl
)
defer
cache
.
Unlock
(
config
.
ISOUrl
)
err
:=
s
.
checkMD5
(
cachePath
,
config
.
ISOMD5
)
haveFile
:=
err
==
nil
if
err
!=
nil
{
if
!
os
.
IsNotExist
(
err
)
{
ui
.
Say
(
fmt
.
Sprintf
(
"Error validating MD5 of ISO: %s"
,
err
))
return
multistep
.
ActionHalt
}
}
if
!
haveFile
{
url
,
err
:=
url
.
Parse
(
config
.
ISOUrl
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error parsing iso_url: %s"
,
err
))
...
...
@@ -50,7 +62,7 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction
progressTimer
:=
time
.
NewTicker
(
15
*
time
.
Second
)
defer
progressTimer
.
Stop
()
DownloadWaitLoop
:
DownloadWaitLoop
:
for
{
select
{
case
<-
downloadComplete
:
...
...
@@ -71,6 +83,12 @@ DownloadWaitLoop:
return
multistep
.
ActionHalt
}
if
err
=
s
.
checkMD5
(
cachePath
,
config
.
ISOMD5
);
err
!=
nil
{
ui
.
Say
(
fmt
.
Sprintf
(
"Error validating MD5 of ISO: %s"
,
err
))
return
multistep
.
ActionHalt
}
}
log
.
Printf
(
"Path to ISO on disk: %s"
,
cachePath
)
state
[
"iso_path"
]
=
cachePath
...
...
@@ -79,6 +97,22 @@ DownloadWaitLoop:
func
(
stepDownloadISO
)
Cleanup
(
map
[
string
]
interface
{})
{}
func
(
stepDownloadISO
)
checkMD5
(
path
string
,
expected
string
)
error
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
err
}
hash
:=
md5
.
New
()
io
.
Copy
(
hash
,
f
)
result
:=
strings
.
ToLower
(
string
(
hash
.
Sum
(
nil
)))
if
result
!=
expected
{
return
fmt
.
Errorf
(
"result != expected: %s != %s"
,
result
,
expected
)
}
return
nil
}
func
(
stepDownloadISO
)
downloadUrl
(
path
string
,
url
*
url
.
URL
,
progress
*
uint
)
(
string
,
error
)
{
if
url
.
Scheme
==
"file"
{
// If it is just a file URL, then we already have the ISO
...
...
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