Files
Packer-Cn/builder/amazon/instance/step_upload_x509_cert.go
T

52 lines
1.4 KiB
Go
Raw Normal View History

2013-07-20 21:00:12 -07:00
package instance
import (
2018-01-22 15:32:33 -08:00
"context"
2013-07-20 21:00:12 -07:00
"fmt"
2018-01-22 15:32:33 -08:00
"os"
2018-01-19 16:18:44 -08:00
"github.com/hashicorp/packer/helper/multistep"
2017-04-04 13:39:01 -07:00
"github.com/hashicorp/packer/packer"
2013-07-20 21:00:12 -07:00
)
type StepUploadX509Cert struct{}
func (s *StepUploadX509Cert) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2013-08-31 13:03:13 -07:00
comm := state.Get("communicator").(packer.Communicator)
config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui)
2013-07-20 21:00:12 -07:00
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 {
2013-08-31 13:03:13 -07:00
state.Put("error", fmt.Errorf("Error uploading X509 cert: %s", err))
ui.Error(state.Get("error").(error).Error())
2013-07-20 21:00:12 -07:00
return multistep.ActionHalt
}
if err := s.uploadSingle(comm, x509RemoteKeyPath, config.X509KeyPath); err != nil {
2013-08-31 13:03:13 -07:00
state.Put("error", fmt.Errorf("Error uploading X509 cert: %s", err))
ui.Error(state.Get("error").(error).Error())
2013-07-20 21:00:12 -07:00
return multistep.ActionHalt
}
2013-08-31 13:03:13 -07:00
state.Put("x509RemoteCertPath", x509RemoteCertPath)
state.Put("x509RemoteKeyPath", x509RemoteKeyPath)
return multistep.ActionContinue
2013-07-20 21:00:12 -07:00
}
2013-08-31 13:03:13 -07:00
func (s *StepUploadX509Cert) Cleanup(multistep.StateBag) {}
2013-07-20 21:00:12 -07:00
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, nil)
2013-07-20 21:00:12 -07:00
}