Skip to content

Commit

Permalink
refactor: fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Nov 3, 2023
1 parent 6e3034c commit 623efc8
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions builder/hcloud/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hetznercloud/hcloud-go/v2/hcloud"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/packer-plugin-hcloud/version"
)

Expand Down Expand Up @@ -41,7 +41,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
opts := []hcloud.ClientOption{
hcloud.WithToken(b.config.HCloudToken),
hcloud.WithEndpoint(b.config.Endpoint),
hcloud.WithPollInterval(b.config.PollInterval),
hcloud.WithBackoffFunc(hcloud.ConstantBackoff(b.config.PollInterval)),
hcloud.WithApplication("hcloud-packer", version.PluginVersion.String()),
}
b.hcloudClient = hcloud.NewClient(opts...)
Expand Down
3 changes: 2 additions & 1 deletion builder/hcloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
"github.com/hashicorp/packer-plugin-sdk/uuid"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/mitchellh/mapstructure"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

type Config struct {
Expand Down
9 changes: 5 additions & 4 deletions builder/hcloud/step_create_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ package hcloud
import (
"context"
"fmt"
"io/ioutil"
"os"
"sort"
"strings"

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

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

Expand All @@ -30,7 +31,7 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu

userData := c.UserData
if c.UserDataFile != "" {
contents, err := ioutil.ReadFile(c.UserDataFile)
contents, err := os.ReadFile(c.UserDataFile)
if err != nil {
state.Put("error", fmt.Errorf("Problem reading user data file: %s", err))
return multistep.ActionHalt
Expand Down Expand Up @@ -85,7 +86,7 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
}

if c.UpgradeServerType != "" {
serverCreateOpts.StartAfterCreate = hcloud.Bool(false)
serverCreateOpts.StartAfterCreate = hcloud.Ptr(false)
}

serverCreateResult, _, err := client.Server.Create(ctx, serverCreateOpts)
Expand Down Expand Up @@ -199,7 +200,7 @@ func (s *stepCreateServer) Cleanup(state multistep.StateBag) {

// Destroy the server we just created
ui.Say("Destroying server...")
_, err := client.Server.Delete(context.TODO(), &hcloud.Server{ID: s.serverId})
_, _, err := client.Server.DeleteWithResult(context.TODO(), &hcloud.Server{ID: s.serverId})
if err != nil {
ui.Error(fmt.Sprintf(
"Error destroying server. Please destroy it manually: %s", err))
Expand Down
2 changes: 1 addition & 1 deletion builder/hcloud/step_create_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

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

"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)
Expand Down Expand Up @@ -142,7 +143,6 @@ func setupStepCreateServer(
checker Checker,
) (*multistep.BasicStateBag, func()) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

buf, err := io.ReadAll(r.Body)
if err != nil {
errors <- fmt.Errorf("fake server: reading request: %s", err)
Expand Down
3 changes: 2 additions & 1 deletion builder/hcloud/step_create_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

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

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

Expand All @@ -28,7 +29,7 @@ func (s *stepCreateSnapshot) Run(ctx context.Context, state multistep.StateBag)
result, _, err := client.Server.CreateImage(ctx, &hcloud.Server{ID: serverID}, &hcloud.ServerCreateImageOpts{
Type: hcloud.ImageTypeSnapshot,
Labels: c.SnapshotLabels,
Description: hcloud.String(c.SnapshotName),
Description: hcloud.Ptr(c.SnapshotName),
})
if err != nil {
err := fmt.Errorf("Error creating snapshot: %s", err)
Expand Down
9 changes: 6 additions & 3 deletions builder/hcloud/step_create_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

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

"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)
Expand Down Expand Up @@ -127,29 +128,31 @@ func setupStepCreateSnapshot(
Status: "success",
}

if r.Method == http.MethodPost && r.URL.Path == "/servers/42/actions/create_image" {
switch {
case r.Method == http.MethodPost && r.URL.Path == "/servers/42/actions/create_image":
if failCause == FailCreateImage {
w.WriteHeader(http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
response = schema.ServerActionCreateImageResponse{Action: action}
} else if r.Method == http.MethodGet && r.URL.Path == "/actions/13" {
case r.Method == http.MethodGet && r.URL.Path == "/actions/13":
if failCause == FailWatchProgress {
w.WriteHeader(http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
response = schema.ActionGetResponse{Action: action}
} else if r.Method == http.MethodDelete && r.URL.Path == "/images/33" {
case r.Method == http.MethodDelete && r.URL.Path == "/images/33":
if failCause == FailDeleteImage {
w.WriteHeader(http.StatusBadRequest)
return
}
w.WriteHeader(http.StatusNoContent)
return
default:
}

if response != nil {
Expand Down
1 change: 1 addition & 0 deletions builder/hcloud/step_create_sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/uuid"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

Expand Down
1 change: 1 addition & 0 deletions builder/hcloud/step_pre_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

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

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

Expand Down
1 change: 1 addition & 0 deletions builder/hcloud/step_pre_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

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

"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)
Expand Down
2 changes: 1 addition & 1 deletion builder/hcloud/step_shutdown_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

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

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

Expand Down Expand Up @@ -43,7 +44,6 @@ func (s *stepShutdownServer) Run(ctx context.Context, state multistep.StateBag)
ui.Error(err.Error())
return multistep.ActionHalt
}

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"fmt"
"os"

"github.com/hashicorp/packer-plugin-sdk/plugin"

"github.com/hetznercloud/packer-plugin-hcloud/builder/hcloud"
"github.com/hetznercloud/packer-plugin-hcloud/version"

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

func main() {
Expand Down

0 comments on commit 623efc8

Please sign in to comment.