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
e84669aa
Commit
e84669aa
authored
Jul 19, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/common: extract out decode config
parent
b2397f4f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
15 deletions
+77
-15
builder/amazon/ebs/builder.go
builder/amazon/ebs/builder.go
+1
-15
builder/common/config.go
builder/common/config.go
+31
-0
builder/common/config_test.go
builder/common/config_test.go
+45
-0
No files found.
builder/amazon/ebs/builder.go
View file @
e84669aa
...
...
@@ -10,7 +10,6 @@ import (
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/builder/common"
"github.com/mitchellh/packer/packer"
...
...
@@ -53,24 +52,11 @@ type Builder struct {
}
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
error
{
var
md
mapstructure
.
Metadata
decoderConfig
:=
&
mapstructure
.
DecoderConfig
{
Metadata
:
&
md
,
Result
:
&
b
.
config
,
}
decoder
,
err
:=
mapstructure
.
NewDecoder
(
decoderConfig
)
md
,
err
:=
common
.
DecodeConfig
(
&
b
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
}
for
_
,
raw
:=
range
raws
{
err
:=
decoder
.
Decode
(
raw
)
if
err
!=
nil
{
return
err
}
}
// Accumulate any errors
errs
:=
make
([]
error
,
0
)
...
...
builder/common/config.go
0 → 100644
View file @
e84669aa
package
common
import
(
"github.com/mitchellh/mapstructure"
)
// DecodeConfig is a helper that handles decoding raw configuration using
// mapstructure. It returns the metadata and any errors that may happen.
// If you need extra configuration for mapstructure, you should configure
// it manually and not use this helper function.
func
DecodeConfig
(
target
interface
{},
raws
...
interface
{})
(
*
mapstructure
.
Metadata
,
error
)
{
var
md
mapstructure
.
Metadata
decoderConfig
:=
&
mapstructure
.
DecoderConfig
{
Metadata
:
&
md
,
Result
:
target
,
}
decoder
,
err
:=
mapstructure
.
NewDecoder
(
decoderConfig
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
raw
:=
range
raws
{
err
:=
decoder
.
Decode
(
raw
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
&
md
,
nil
}
builder/common/config_test.go
0 → 100644
View file @
e84669aa
package
common
import
(
"reflect"
"testing"
)
func
TestDecodeConfig
(
t
*
testing
.
T
)
{
type
Local
struct
{
Foo
string
Bar
string
}
raws
:=
[]
interface
{}{
map
[
string
]
interface
{}{
"foo"
:
"bar"
,
},
map
[
string
]
interface
{}{
"bar"
:
"baz"
,
"baz"
:
"what"
,
},
}
var
result
Local
md
,
err
:=
DecodeConfig
(
&
result
,
raws
...
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
result
.
Foo
!=
"bar"
{
t
.
Fatalf
(
"invalid: %#v"
,
result
.
Foo
)
}
if
result
.
Bar
!=
"baz"
{
t
.
Fatalf
(
"invalid: %#v"
,
result
.
Bar
)
}
if
md
==
nil
{
t
.
Fatal
(
"metadata should not be nil"
)
}
if
!
reflect
.
DeepEqual
(
md
.
Unused
,
[]
string
{
"baz"
})
{
t
.
Fatalf
(
"unused: %#v"
,
md
.
Unused
)
}
}
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