2020-11-05 20:01:55 -05:00
|
|
|
package vagrantcloud
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2020-11-05 20:01:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepConfirmUpload struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepConfirmUpload) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
|
|
|
client := state.Get("client").(*VagrantCloudClient)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2020-11-05 20:01:55 -05:00
|
|
|
upload := state.Get("upload").(*Upload)
|
|
|
|
url := upload.CallbackPath
|
|
|
|
|
|
|
|
ui.Say("Confirming direct box upload completion")
|
|
|
|
|
|
|
|
resp, err := client.Callback(url)
|
|
|
|
|
|
|
|
if err != nil || resp.StatusCode != 200 {
|
|
|
|
if resp == nil || resp.Body == nil {
|
|
|
|
state.Put("error", "No response from server.")
|
|
|
|
} else {
|
|
|
|
cloudErrors := &VagrantCloudErrors{}
|
|
|
|
err = decodeBody(resp, cloudErrors)
|
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("error decoding error response: %s", err))
|
|
|
|
}
|
|
|
|
state.Put("error", fmt.Errorf("Error preparing upload: %s", cloudErrors.FormatErrors()))
|
|
|
|
}
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepConfirmUpload) Cleanup(state multistep.StateBag) {
|
|
|
|
// No cleanup
|
|
|
|
}
|