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
2efab467
Commit
2efab467
authored
May 20, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazonebs: Switch from json to mapstructure for decode
parent
bee26600
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
18 deletions
+9
-18
builder/amazonebs/builder.go
builder/amazonebs/builder.go
+6
-15
builder/amazonebs/builder_test.go
builder/amazonebs/builder_test.go
+3
-3
No files found.
builder/amazonebs/builder.go
View file @
2efab467
...
...
@@ -6,21 +6,21 @@
package
amazonebs
import
(
"encoding/json"
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"log"
"time"
)
type
config
struct
{
AccessKey
string
`
json
:"access_key"`
AMIName
string
`
json
:"ami_name"`
AccessKey
string
`
mapstructure
:"access_key"`
AMIName
string
`
mapstructure
:"ami_name"`
Region
string
SecretKey
string
`
json
:"secret_key"`
SourceAmi
string
`
json
:"source_ami"`
SecretKey
string
`
mapstructure
:"secret_key"`
SourceAmi
string
`
mapstructure
:"source_ami"`
}
type
Builder
struct
{
...
...
@@ -28,16 +28,7 @@ type Builder struct {
}
func
(
b
*
Builder
)
Prepare
(
raw
interface
{})
(
err
error
)
{
// Marshal and unmarshal the raw configuration as a way to get it
// into our "config" struct.
// TODO: Use the reflection package and provide this as an API for
// better error messages
jsonBytes
,
err
:=
json
.
Marshal
(
raw
)
if
err
!=
nil
{
return
}
err
=
json
.
Unmarshal
(
jsonBytes
,
&
b
.
config
)
err
=
mapstructure
.
Decode
(
raw
,
&
b
.
config
)
if
err
!=
nil
{
return
}
...
...
builder/amazonebs/builder_test.go
View file @
2efab467
...
...
@@ -14,15 +14,15 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
}
func
TestBuilder_Prepare_BadType
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
b
:=
&
Builder
{}
c
:=
map
[
string
]
interface
{}{
"access_key"
:
[]
string
{},
}
err
:=
b
.
Prepare
(
c
)
assert
.
NotNil
(
err
,
"should have an error"
)
if
err
==
nil
{
t
.
Fatalf
(
"prepare should fail"
)
}
}
func
TestBuilder_Prepare_Good
(
t
*
testing
.
T
)
{
...
...
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