2013-07-21 00:00:12 -04:00
|
|
|
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)
|
2013-07-21 14:32:59 -04:00
|
|
|
ui.Error(state["error"].(error).Error())
|
2013-07-21 00:00:12 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.uploadSingle(comm, x509RemoteKeyPath, config.X509KeyPath); err != nil {
|
|
|
|
state["error"] = fmt.Errorf("Error uploading X509 cert: %s", err)
|
2013-07-21 14:32:59 -04:00
|
|
|
ui.Error(state["error"].(error).Error())
|
2013-07-21 00:00:12 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-07-21 00:03:29 -04:00
|
|
|
return multistep.ActionContinue
|
2013-07-21 00:00:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|