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
39b3b18d
Commit
39b3b18d
authored
Jul 20, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/instance: upload x509 cert
parent
42f78804
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
156 additions
and
2 deletions
+156
-2
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+27
-1
builder/amazon/instance/builder_test.go
builder/amazon/instance/builder_test.go
+85
-1
builder/amazon/instance/step_upload_x509_cert.go
builder/amazon/instance/step_upload_x509_cert.go
+44
-0
No files found.
builder/amazon/instance/builder.go
View file @
39b3b18d
...
...
@@ -3,6 +3,8 @@
package
instance
import
(
"errors"
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
...
...
@@ -10,6 +12,7 @@ import (
"github.com/mitchellh/packer/builder/common"
"github.com/mitchellh/packer/packer"
"log"
"os"
)
// The unique ID for this builder
...
...
@@ -21,6 +24,10 @@ type Config struct {
common
.
PackerConfig
`mapstructure:",squash"`
awscommon
.
AccessConfig
`mapstructure:",squash"`
awscommon
.
RunConfig
`mapstructure:",squash"`
X509CertPath
string
`mapstructure:"x509_cert_path"`
X509KeyPath
string
`mapstructure:"x509_key_path"`
X509UploadPath
string
`mapstructure:"x509_upload_path"`
}
type
Builder
struct
{
...
...
@@ -39,6 +46,24 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
AccessConfig
.
Prepare
()
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
()
...
)
if
b
.
config
.
X509CertPath
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"x509_cert_path is required"
))
}
else
if
_
,
err
:=
os
.
Stat
(
b
.
config
.
X509CertPath
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"x509_cert_path points to bad file: %s"
,
err
))
}
if
b
.
config
.
X509KeyPath
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"x509_key_path is required"
))
}
else
if
_
,
err
:=
os
.
Stat
(
b
.
config
.
X509KeyPath
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"x509_key_path points to bad file: %s"
,
err
))
}
if
b
.
config
.
X509UploadPath
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"x509_upload_path is required"
))
}
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
errs
}
...
...
@@ -62,7 +87,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Setup the state bag and initial state for the steps
state
:=
make
(
map
[
string
]
interface
{})
state
[
"config"
]
=
b
.
config
state
[
"config"
]
=
&
b
.
config
state
[
"ec2"
]
=
ec2conn
state
[
"hook"
]
=
hook
state
[
"ui"
]
=
ui
...
...
@@ -85,6 +110,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SSHWaitTimeout
:
b
.
config
.
SSHTimeout
(),
},
&
common
.
StepProvision
{},
&
StepUploadX509Cert
{},
}
// Run!
...
...
builder/amazon/instance/builder_test.go
View file @
39b3b18d
...
...
@@ -2,11 +2,26 @@ package instance
import
(
"github.com/mitchellh/packer/packer"
"io/ioutil"
"os"
"testing"
)
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{}
tf
,
err
:=
ioutil
.
TempFile
(
""
,
"packer"
)
if
err
!=
nil
{
panic
(
err
)
}
return
map
[
string
]
interface
{}{
"instance_type"
:
"m1.small"
,
"region"
:
"us-east-1"
,
"source_ami"
:
"foo"
,
"ssh_username"
:
"bob"
,
"x509_cert_path"
:
tf
.
Name
(),
"x509_key_path"
:
tf
.
Name
(),
"x509_upload_path"
:
"/foo"
,
}
}
func
TestBuilder_ImplementsBuilder
(
t
*
testing
.
T
)
{
...
...
@@ -28,3 +43,72 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
t
.
Fatal
(
"should have error"
)
}
}
func
TestBuilderPrepare_X509CertPath
(
t
*
testing
.
T
)
{
b
:=
&
Builder
{}
config
:=
testConfig
()
config
[
"x509_cert_path"
]
=
""
err
:=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
config
[
"x509_cert_path"
]
=
"i/am/a/file/that/doesnt/exist"
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Error
(
"should have error"
)
}
tf
,
err
:=
ioutil
.
TempFile
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"error tempfile: %s"
,
err
)
}
defer
os
.
Remove
(
tf
.
Name
())
config
[
"x509_cert_path"
]
=
tf
.
Name
()
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_X509KeyPath
(
t
*
testing
.
T
)
{
b
:=
&
Builder
{}
config
:=
testConfig
()
config
[
"x509_key_path"
]
=
""
err
:=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
config
[
"x509_key_path"
]
=
"i/am/a/file/that/doesnt/exist"
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Error
(
"should have error"
)
}
tf
,
err
:=
ioutil
.
TempFile
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"error tempfile: %s"
,
err
)
}
defer
os
.
Remove
(
tf
.
Name
())
config
[
"x509_key_path"
]
=
tf
.
Name
()
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_X509UploadPath
(
t
*
testing
.
T
)
{
b
:=
&
Builder
{}
config
:=
testConfig
()
config
[
"x509_upload_path"
]
=
""
err
:=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
}
builder/amazon/instance/step_upload_x509_cert.go
0 → 100644
View file @
39b3b18d
package
instance
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os"
)
type
StepUploadX509Cert
struct
{}
func
(
s
*
StepUploadX509Cert
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
Config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
x509RemoteCertPath
:=
config
.
X509UploadPath
+
"/cert.pem"
x509RemoteKeyPath
:=
config
.
X509UploadPath
+
"/key.pem"
ui
.
Say
(
"Uploading X509 Certificate..."
)
if
err
:=
s
.
uploadSingle
(
comm
,
x509RemoteCertPath
,
config
.
X509CertPath
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error uploading X509 cert: %s"
,
err
)
return
multistep
.
ActionHalt
}
if
err
:=
s
.
uploadSingle
(
comm
,
x509RemoteKeyPath
,
config
.
X509KeyPath
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error uploading X509 cert: %s"
,
err
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionHalt
}
func
(
s
*
StepUploadX509Cert
)
Cleanup
(
map
[
string
]
interface
{})
{}
func
(
s
*
StepUploadX509Cert
)
uploadSingle
(
comm
packer
.
Communicator
,
dst
,
src
string
)
error
{
f
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
return
comm
.
Upload
(
dst
,
f
)
}
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