<commit_before>package vagrantcloud

import (
	"context"
	"fmt"

	"github.com/hashicorp/packer-plugin-sdk/multistep"
	packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)

type stepConfirmUpload struct {
}

func (s *stepConfirmUpload) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
	client := state.Get("client").(*VagrantCloudClient)
	ui := state.Get("ui").(packersdk.Ui)
	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
}
<commit_msg>Check configuration before running callback for upload confirmation<commit_after>package vagrantcloud

import (
	"context"
	"fmt"

	"github.com/hashicorp/packer-plugin-sdk/multistep"
	packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)

type stepConfirmUpload struct {
}

func (s *stepConfirmUpload) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
	client := state.Get("client").(*VagrantCloudClient)
	ui := state.Get("ui").(packersdk.Ui)
	upload := state.Get("upload").(*Upload)
	url := upload.CallbackPath
	config := state.Get("config").(*Config)

	if config.NoDirectUpload {
		return multistep.ActionContinue
	}

	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", fmt.Errorf("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
}

{'fraction_non_alphanumeric': 0.14373213556553696, 'fraction_numerical': 0.002449979583503471, 'mean_word_length': 4.593607305936073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7243949', 'n_tokens_mistral': 863, 'n_tokens_neox': 801, 'n_words': 177}