github.com/vijayrajah/packer@v1.3.2/post-processor/vagrant-cloud/step_prepare_upload.go (about) 1 package vagrantcloud 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/hashicorp/packer/helper/multistep" 8 "github.com/hashicorp/packer/packer" 9 ) 10 11 type Upload struct { 12 UploadPath string `json:"upload_path"` 13 } 14 15 type stepPrepareUpload struct { 16 } 17 18 func (s *stepPrepareUpload) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 19 client := state.Get("client").(*VagrantCloudClient) 20 ui := state.Get("ui").(packer.Ui) 21 box := state.Get("box").(*Box) 22 version := state.Get("version").(*Version) 23 provider := state.Get("provider").(*Provider) 24 artifactFilePath := state.Get("artifactFilePath").(string) 25 26 path := fmt.Sprintf("box/%s/version/%v/provider/%s/upload", box.Tag, version.Version, provider.Name) 27 upload := &Upload{} 28 29 ui.Say(fmt.Sprintf("Preparing upload of box: %s", artifactFilePath)) 30 31 resp, err := client.Get(path) 32 33 if err != nil || (resp.StatusCode != 200) { 34 if resp == nil || resp.Body == nil { 35 state.Put("error", "No response from server.") 36 } else { 37 cloudErrors := &VagrantCloudErrors{} 38 err = decodeBody(resp, cloudErrors) 39 state.Put("error", fmt.Errorf("Error preparing upload: %s", cloudErrors.FormatErrors())) 40 } 41 return multistep.ActionHalt 42 } 43 44 if err = decodeBody(resp, upload); err != nil { 45 state.Put("error", fmt.Errorf("Error parsing upload response: %s", err)) 46 return multistep.ActionHalt 47 } 48 49 // Save the upload details to the state 50 state.Put("upload", upload) 51 52 return multistep.ActionContinue 53 } 54 55 func (s *stepPrepareUpload) Cleanup(state multistep.StateBag) { 56 // No cleanup 57 }