Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup some lints #40

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion builder/scaleway/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,23 @@ func (a *Artifact) State(name string) interface{} {
}

func (a *Artifact) Destroy() error {
log.Printf("Destroying image: %s (%s)", a.imageID, a.imageName)
instanceAPI := instance.NewAPI(a.client)

log.Printf("Destroying image: %s (%s)", a.imageID, a.imageName)
err := instanceAPI.DeleteImage(&instance.DeleteImageRequest{
ImageID: a.imageID,
})
if err != nil {
return err
}

log.Printf("Destroying snapshot: %s (%s)", a.snapshotID, a.snapshotName)
err = instanceAPI.DeleteSnapshot(&instance.DeleteSnapshotRequest{
SnapshotID: a.snapshotID,
})
if err != nil {
return err
}

return nil
}
2 changes: 1 addition & 1 deletion builder/scaleway/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/scaleway/scaleway-sdk-go/scw"
)

// The unique id for the builder
// BuilderId is the unique id for the builder
const BuilderId = "hashicorp.scaleway"

type Builder struct {
Expand Down
8 changes: 4 additions & 4 deletions builder/scaleway/step_create_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *stepImage) Run(ctx context.Context, state multistep.StateBag) multistep
CommercialType: c.CommercialType,
})
if err != nil {
err := fmt.Errorf("Error getting initial image info from marketplace: %s", err)
err := fmt.Errorf("error getting initial image info from marketplace: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -47,7 +47,7 @@ func (s *stepImage) Run(ctx context.Context, state multistep.StateBag) multistep
ImageID: imageID,
}, scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("Error getting initial image info: %s", err)
err := fmt.Errorf("error getting initial image info: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -64,7 +64,7 @@ func (s *stepImage) Run(ctx context.Context, state multistep.StateBag) multistep
RootVolume: snapshotID,
}, scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("Error creating image: %s", err)
err := fmt.Errorf("error creating image: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -79,6 +79,6 @@ func (s *stepImage) Run(ctx context.Context, state multistep.StateBag) multistep
return multistep.ActionContinue
}

func (s *stepImage) Cleanup(state multistep.StateBag) {
func (s *stepImage) Cleanup(_ multistep.StateBag) {
// no cleanup
}
8 changes: 4 additions & 4 deletions builder/scaleway/step_create_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
instanceAPI := instance.NewAPI(state.Get("client").(*scw.Client))
ui := state.Get("ui").(packersdk.Ui)
c := state.Get("config").(*Config)
tags := []string{}
var tags []string
var bootscript *string

ui.Say("Creating server...")
Expand Down Expand Up @@ -54,7 +54,7 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu

createServerResp, err := instanceAPI.CreateServer(createServerReq, scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("Error creating server: %s", err)
err := fmt.Errorf("error creating server: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -65,7 +65,7 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
ServerID: createServerResp.Server.ID,
}, scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("Error starting server: %s", err)
err := fmt.Errorf("error starting server: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -75,7 +75,7 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu

state.Put("server_id", createServerResp.Server.ID)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
// instance id inside the provisioners, used in step_provision.
state.Put("instance_id", s.serverID)

return multistep.ActionContinue
Expand Down
18 changes: 9 additions & 9 deletions builder/scaleway/step_create_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func (s *stepCreateSSHKey) Run(ctx context.Context, state multistep.StateBag) mu
}

// ASN.1 DER encoded form
priv_der := x509.MarshalPKCS1PrivateKey(priv)
priv_blk := pem.Block{
privateDER := x509.MarshalPKCS1PrivateKey(priv)
privateBlock := pem.Block{
Type: "RSA PRIVATE KEY",
Headers: nil,
Bytes: priv_der,
Bytes: privateDER,
}

pub, err := ssh.NewPublicKey(&priv.PublicKey)
Expand All @@ -68,29 +68,29 @@ func (s *stepCreateSSHKey) Run(ctx context.Context, state multistep.StateBag) mu
log.Printf("temporary ssh key created")

// Remember some state for the future
config.Comm.SSHPrivateKey = pem.EncodeToMemory(&priv_blk)
config.Comm.SSHPrivateKey = pem.EncodeToMemory(&privateBlock)
config.Comm.SSHPublicKey = ssh.MarshalAuthorizedKey(pub)

// If we're in debug mode, output the private key to the working directory.
if s.Debug {
ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath))
f, err := os.Create(s.DebugKeyPath)
if err != nil {
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
state.Put("error", fmt.Errorf("error saving debug key: %s", err))
return multistep.ActionHalt
}
defer f.Close()

// Write the key out
if _, err := f.Write(pem.EncodeToMemory(&priv_blk)); err != nil {
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
if _, err := f.Write(pem.EncodeToMemory(&privateBlock)); err != nil {
state.Put("error", fmt.Errorf("error saving debug key: %s", err))
return multistep.ActionHalt
}

// Chmod it so that it is SSH ready
if runtime.GOOS != "windows" {
if err := f.Chmod(0600); err != nil {
state.Put("error", fmt.Errorf("Error setting permissions of debug key: %s", err))
state.Put("error", fmt.Errorf("error setting permissions of debug key: %s", err))
return multistep.ActionHalt
}
}
Expand All @@ -99,6 +99,6 @@ func (s *stepCreateSSHKey) Run(ctx context.Context, state multistep.StateBag) mu
return multistep.ActionContinue
}

func (s *stepCreateSSHKey) Cleanup(state multistep.StateBag) {
func (s *stepCreateSSHKey) Cleanup(_ multistep.StateBag) {
// SSH key is passed via tag. Nothing to do here.
}
15 changes: 8 additions & 7 deletions builder/scaleway/step_pre_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// StepPreValidate provides an opportunity to pre-validate any configuration for
// the build before actually doing any time consuming work
// the build before actually doing any time-consuming work
//
type stepPreValidate struct {
Force bool
Expand All @@ -23,7 +23,7 @@ func (s *stepPreValidate) Run(ctx context.Context, state multistep.StateBag) mul
ui := state.Get("ui").(packersdk.Ui)

if s.Force {
ui.Say("Force flag found, skipping prevalidating image name")
ui.Say("Force flag found, skipping pre-validating image name")
return multistep.ActionContinue
}

Expand All @@ -34,15 +34,15 @@ func (s *stepPreValidate) Run(ctx context.Context, state multistep.StateBag) mul
&instance.ListImagesRequest{Name: &s.ImageName},
scw.WithAllPages(), scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("Error: getting image list: %s", err)
err := fmt.Errorf("error: getting image list: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

for _, im := range images.Images {
if im.Name == s.ImageName {
err := fmt.Errorf("Error: image name: '%s' is used by existing image with ID %s",
err := fmt.Errorf("error: image name: '%s' is used by existing image with ID %s",
s.ImageName, im.ID)
state.Put("error", err)
ui.Error(err.Error())
Expand All @@ -56,15 +56,15 @@ func (s *stepPreValidate) Run(ctx context.Context, state multistep.StateBag) mul
&instance.ListSnapshotsRequest{Name: &s.SnapshotName},
scw.WithAllPages(), scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("Error: getting snapshot list: %s", err)
err := fmt.Errorf("error: getting snapshot list: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

for _, sn := range snapshots.Snapshots {
if sn.Name == s.SnapshotName {
err := fmt.Errorf("Error: snapshot name: '%s' is used by existing snapshot with ID %s",
err := fmt.Errorf("error: snapshot name: '%s' is used by existing snapshot with ID %s",
s.SnapshotName, sn.ID)
state.Put("error", err)
ui.Error(err.Error())
Expand All @@ -76,5 +76,6 @@ func (s *stepPreValidate) Run(ctx context.Context, state multistep.StateBag) mul
return multistep.ActionContinue
}

func (s *stepPreValidate) Cleanup(multistep.StateBag) {
func (s *stepPreValidate) Cleanup(_ multistep.StateBag) {
// no cleanup
}
2 changes: 1 addition & 1 deletion builder/scaleway/step_remove_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *stepRemoveVolume) Cleanup(state multistep.StateBag) {
VolumeID: volumeID,
})
if err != nil {
err := fmt.Errorf("Error removing volume: %s", err)
err := fmt.Errorf("error removing volume: %s", err)
state.Put("error", err)
ui.Error(fmt.Sprintf("Error removing volume: %s. (Ignored)", err))
}
Expand Down
8 changes: 4 additions & 4 deletions builder/scaleway/step_server_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ func (s *stepServerInfo) Run(ctx context.Context, state multistep.StateBag) mult
ServerID: serverID,
})
if err != nil {
err := fmt.Errorf("Error waiting for server to become booted: %s", err)
err := fmt.Errorf("error waiting for server to become booted: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

if instanceResp.State != instance.ServerStateRunning {
err := fmt.Errorf("Server is in state %s", instanceResp.State.String())
err := fmt.Errorf("server is in state %s", instanceResp.State.String())
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

if instanceResp.PublicIP == nil {
err := fmt.Errorf("Server does not have a public IP")
err := fmt.Errorf("server does not have a public IP")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -49,6 +49,6 @@ func (s *stepServerInfo) Run(ctx context.Context, state multistep.StateBag) mult
return multistep.ActionContinue
}

func (s *stepServerInfo) Cleanup(state multistep.StateBag) {
func (s *stepServerInfo) Cleanup(_ multistep.StateBag) {
// no cleanup
}
8 changes: 4 additions & 4 deletions builder/scaleway/step_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (s *stepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
ServerID: serverID,
}, scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("Error stopping server: %s", err)
err := fmt.Errorf("error stopping server: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -49,14 +49,14 @@ func (s *stepShutdown) Run(ctx context.Context, state multistep.StateBag) multis

instanceResp, err := instanceAPI.WaitForServer(waitRequest)
if err != nil {
err := fmt.Errorf("Error shutting down server: %s", err)
err := fmt.Errorf("error shutting down server: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

if instanceResp.State != instance.ServerStateStopped {
err := fmt.Errorf("Server is in state %s instead of stopped", instanceResp.State.String())
err := fmt.Errorf("server is in state %s instead of stopped", instanceResp.State.String())
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -65,6 +65,6 @@ func (s *stepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
return multistep.ActionContinue
}

func (s *stepShutdown) Cleanup(state multistep.StateBag) {
func (s *stepShutdown) Cleanup(_ multistep.StateBag) {
// no cleanup
}
8 changes: 4 additions & 4 deletions builder/scaleway/step_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (s *stepSnapshot) Run(ctx context.Context, state multistep.StateBag) multis
VolumeID: volumeID,
}, scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("Error creating snapshot: %s", err)
err := fmt.Errorf("error creating snapshot: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -35,14 +35,14 @@ func (s *stepSnapshot) Run(ctx context.Context, state multistep.StateBag) multis
SnapshotID: createSnapshotResp.Snapshot.ID,
})
if err != nil {
err := fmt.Errorf("Snapshot is not available: %s", err)
err := fmt.Errorf("snapshot is not available: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

if snapshot.State != instance.SnapshotStateAvailable {
err := fmt.Errorf("Snapshot is in error state")
err := fmt.Errorf("snapshot is in error state")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -57,6 +57,6 @@ func (s *stepSnapshot) Run(ctx context.Context, state multistep.StateBag) multis
return multistep.ActionContinue
}

func (s *stepSnapshot) Cleanup(state multistep.StateBag) {
func (s *stepSnapshot) Cleanup(_ multistep.StateBag) {
// no cleanup
}