github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/builder/amazon/instance/step_upload_x509_cert.go (about) 1 package instance 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "os" 8 ) 9 10 type StepUploadX509Cert struct{} 11 12 func (s *StepUploadX509Cert) Run(state map[string]interface{}) multistep.StepAction { 13 comm := state["communicator"].(packer.Communicator) 14 config := state["config"].(*Config) 15 ui := state["ui"].(packer.Ui) 16 17 x509RemoteCertPath := config.X509UploadPath + "/cert.pem" 18 x509RemoteKeyPath := config.X509UploadPath + "/key.pem" 19 20 ui.Say("Uploading X509 Certificate...") 21 if err := s.uploadSingle(comm, x509RemoteCertPath, config.X509CertPath); err != nil { 22 state["error"] = fmt.Errorf("Error uploading X509 cert: %s", err) 23 ui.Error(state["error"].(error).Error()) 24 return multistep.ActionHalt 25 } 26 27 if err := s.uploadSingle(comm, x509RemoteKeyPath, config.X509KeyPath); err != nil { 28 state["error"] = fmt.Errorf("Error uploading X509 cert: %s", err) 29 ui.Error(state["error"].(error).Error()) 30 return multistep.ActionHalt 31 } 32 33 state["x509RemoteCertPath"] = x509RemoteCertPath 34 state["x509RemoteKeyPath"] = x509RemoteKeyPath 35 36 return multistep.ActionContinue 37 } 38 39 func (s *StepUploadX509Cert) Cleanup(map[string]interface{}) {} 40 41 func (s *StepUploadX509Cert) uploadSingle(comm packer.Communicator, dst, src string) error { 42 f, err := os.Open(src) 43 if err != nil { 44 return err 45 } 46 defer f.Close() 47 48 return comm.Upload(dst, f) 49 }