From 96e7ca96fb5aa27cf1d39dcf951b882e9067b07c Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Tue, 16 Jun 2026 16:23:03 -0400 Subject: [PATCH] migration to linodego v2 --- builder/linode/artifact.go | 2 +- builder/linode/builder.go | 7 ++- builder/linode/builder_test.go | 2 +- builder/linode/step_create_disk_config.go | 16 +++-- .../linode/step_create_disk_config_test.go | 2 +- builder/linode/step_create_image.go | 7 ++- builder/linode/step_create_linode.go | 60 +++++++++---------- builder/linode/step_create_linode_test.go | 34 +++++------ builder/linode/step_shutdown_linode.go | 7 ++- datasource/image/data.go | 7 ++- datasource/image/filter.go | 2 +- datasource/image/filter_test.go | 2 +- go.mod | 5 +- go.sum | 10 ++-- helper/client.go | 15 +++-- 15 files changed, 97 insertions(+), 81 deletions(-) diff --git a/builder/linode/artifact.go b/builder/linode/artifact.go index 839f2fe4..843044dd 100644 --- a/builder/linode/artifact.go +++ b/builder/linode/artifact.go @@ -6,7 +6,7 @@ import ( "log" registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" ) type Artifact struct { diff --git a/builder/linode/builder.go b/builder/linode/builder.go index 7506f1ad..c91f7f95 100644 --- a/builder/linode/builder.go +++ b/builder/linode/builder.go @@ -9,7 +9,7 @@ import ( "log" "github.com/hashicorp/hcl/v2/hcldec" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/hashicorp/packer-plugin-sdk/communicator" "github.com/hashicorp/packer-plugin-sdk/multistep" @@ -47,7 +47,10 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) return nil, err } } else { - client = helper.NewLinodeClient(b.config.PersonalAccessToken) + client, err = helper.NewLinodeClient(b.config.PersonalAccessToken) + if err != nil { + return nil, err + } } state := new(multistep.BasicStateBag) diff --git a/builder/linode/builder_test.go b/builder/linode/builder_test.go index 4eb66e97..bed6c753 100644 --- a/builder/linode/builder_test.go +++ b/builder/linode/builder_test.go @@ -8,7 +8,7 @@ import ( "time" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" ) func testConfig() map[string]any { diff --git a/builder/linode/step_create_disk_config.go b/builder/linode/step_create_disk_config.go index 8b88f5ca..0d71d060 100644 --- a/builder/linode/step_create_disk_config.go +++ b/builder/linode/step_create_disk_config.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/packer-plugin-sdk/multistep" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/linode/packer-plugin-linode/helper" ) @@ -297,8 +297,10 @@ func (s *stepCreateDiskConfig) Run(ctx context.Context, state multistep.StateBag return handleError(fmt.Sprintf("Failed to create disk %q", diskCfg.Label), err) } - // Wait for disk to be ready - disk, err = s.client.WaitForInstanceDiskStatus(ctx, instance.ID, disk.ID, linodego.DiskReady, int(c.StateTimeout.Seconds())) + // Wait for disk to be ready. + waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout) + disk, err = s.client.WaitForInstanceDiskStatus(waitCtx, instance.ID, disk.ID, linodego.DiskReady) + cancel() if err != nil { return handleError(fmt.Sprintf("Failed to wait for disk %q", diskCfg.Label), err) } @@ -373,13 +375,15 @@ func (s *stepCreateDiskConfig) Run(ctx context.Context, state multistep.StateBag // Boot the instance with the selected configuration profile if bootConfigID != 0 { ui.Say(fmt.Sprintf("Booting Linode with config ID %d...", bootConfigID)) - err = s.client.BootInstance(ctx, instance.ID, bootConfigID) + err = s.client.BootInstance(ctx, instance.ID, linodego.InstanceBootOptions{ConfigID: &bootConfigID}) if err != nil { return handleError("Failed to boot Linode", err) } - // Wait for instance to be running - instance, err = s.client.WaitForInstanceStatus(ctx, instance.ID, linodego.InstanceRunning, int(c.StateTimeout.Seconds())) + // Wait for instance to be running. + waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout) + instance, err = s.client.WaitForInstanceStatus(waitCtx, instance.ID, linodego.InstanceRunning) + cancel() if err != nil { return handleError("Failed to wait for Linode to be running", err) } diff --git a/builder/linode/step_create_disk_config_test.go b/builder/linode/step_create_disk_config_test.go index 28fd35a7..890da10f 100644 --- a/builder/linode/step_create_disk_config_test.go +++ b/builder/linode/step_create_disk_config_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" ) func TestResolveDiskLabel(t *testing.T) { diff --git a/builder/linode/step_create_image.go b/builder/linode/step_create_image.go index 659c877e..e63d28f7 100644 --- a/builder/linode/step_create_image.go +++ b/builder/linode/step_create_image.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/packer-plugin-sdk/multistep" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/linode/packer-plugin-linode/helper" ) @@ -41,7 +41,10 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul return handleError("Failed to create image", err) } - _, err = creationPoller.WaitForFinished(ctx, int(c.ImageCreateTimeout.Seconds())) + waitCtx, cancel := context.WithTimeout(ctx, c.ImageCreateTimeout) + defer cancel() + + _, err = creationPoller.WaitForFinished(waitCtx) if err != nil { return handleError("Failed to wait for image creation", err) } diff --git a/builder/linode/step_create_linode.go b/builder/linode/step_create_linode.go index e7202d80..435fb52f 100644 --- a/builder/linode/step_create_linode.go +++ b/builder/linode/step_create_linode.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/packer-plugin-sdk/multistep" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/linode/packer-plugin-linode/helper" ) @@ -14,12 +14,12 @@ type stepCreateLinode struct { client *linodego.Client } -func flattenConfigInterfaceIPv4(i *InterfaceIPv4) *linodego.VPCIPv4 { +func flattenConfigInterfaceIPv4(i *InterfaceIPv4) *linodego.VPCIPv4CreateOptions { if i == nil { return nil } - return &linodego.VPCIPv4{ + return &linodego.VPCIPv4CreateOptions{ VPC: i.VPC, NAT1To1: i.NAT1To1, } @@ -51,7 +51,7 @@ func flattenPublicInterface(public *PublicInterface) *linodego.PublicInterfaceCr } } result.IPv4 = &linodego.PublicInterfaceIPv4CreateOptions{ - Addresses: linodego.Pointer(addresses), + Addresses: addresses, } } if public.IPv6 != nil { @@ -62,7 +62,7 @@ func flattenPublicInterface(public *PublicInterface) *linodego.PublicInterfaceCr } } result.IPv6 = &linodego.PublicInterfaceIPv6CreateOptions{ - Ranges: linodego.Pointer(ranges), + Ranges: ranges, } } return result @@ -91,8 +91,8 @@ func flattenVPCInterface(vpc *VPCInterface) *linodego.VPCInterfaceCreateOptions } } result.IPv4 = &linodego.VPCInterfaceIPv4CreateOptions{ - Addresses: linodego.Pointer(addresses), - Ranges: linodego.Pointer(ranges), + Addresses: addresses, + Ranges: ranges, } } if vpc.IPv6 != nil { @@ -109,44 +109,38 @@ func flattenVPCInterface(vpc *VPCInterface) *linodego.VPCInterfaceCreateOptions } } result.IPv6 = &linodego.VPCInterfaceIPv6CreateOptions{ - SLAAC: linodego.Pointer(slaac), - Ranges: linodego.Pointer(ranges), + SLAAC: slaac, + Ranges: ranges, IsPublic: vpc.IPv6.IsPublic, } } return result } -func flattenVLANInterface(vlan *VLANInterface) *linodego.VLANInterface { +func flattenVLANInterface(vlan *VLANInterface) *linodego.VLANInterfaceCreateOptions { if vlan == nil { return nil } - result := &linodego.VLANInterface{ - VLANLabel: vlan.VLANLabel, + return &linodego.VLANInterfaceCreateOptions{ + VLANLabel: vlan.VLANLabel, + IPAMAddress: vlan.IPAMAddress, } - if vlan.IPAMAddress != nil { - result.IPAMAddress = vlan.IPAMAddress - } - return result } -func flattenLinodeInterface(li LinodeInterface) (opts linodego.LinodeInterfaceCreateOptions) { - if li.FirewallID != nil { - opts.FirewallID = li.FirewallID +func flattenLinodeInterface(li LinodeInterface) linodego.LinodeInterfaceCreateOptions { + opts := linodego.LinodeInterfaceCreateOptions{ + FirewallID: li.FirewallID, + Public: flattenPublicInterface(li.Public), + VPC: flattenVPCInterface(li.VPC), + VLAN: flattenVLANInterface(li.VLAN), } - if li.DefaultRoute != nil { - opts.DefaultRoute = &linodego.InterfaceDefaultRoute{ + opts.DefaultRoute = &linodego.InterfaceDefaultRouteCreateOptions{ IPv4: li.DefaultRoute.IPv4, IPv6: li.DefaultRoute.IPv6, } } - - opts.Public = flattenPublicInterface(li.Public) - opts.VPC = flattenVPCInterface(li.VPC) - opts.VLAN = flattenVLANInterface(li.VLAN) - - return + return opts } func flattenMetadata(m Metadata) *linodego.InstanceMetadataOptions { @@ -245,8 +239,11 @@ func (s *stepCreateLinode) Run(ctx context.Context, state multistep.StateBag) mu // When using custom disks, we skip waiting for running state here // because the instance won't boot until we create disks and configs if useCustomDisks { - // Wait for instance to be in offline state (resources allocated) - instance, err = s.client.WaitForInstanceStatus(ctx, instance.ID, linodego.InstanceOffline, int(c.StateTimeout.Seconds())) + // Wait for instance resources to be allocated before creating disks/configs. + waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout) + defer cancel() + + instance, err = s.client.WaitForInstanceStatus(waitCtx, instance.ID, linodego.InstanceOffline) if err != nil { return handleError("Failed to wait for Linode to be offline", err) } @@ -256,7 +253,10 @@ func (s *stepCreateLinode) Run(ctx context.Context, state multistep.StateBag) mu } // wait until instance is running - instance, err = s.client.WaitForInstanceStatus(ctx, instance.ID, linodego.InstanceRunning, int(c.StateTimeout.Seconds())) + waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout) + defer cancel() + + instance, err = s.client.WaitForInstanceStatus(waitCtx, instance.ID, linodego.InstanceRunning) if err != nil { return handleError("Failed to wait for Linode ready", err) } diff --git a/builder/linode/step_create_linode_test.go b/builder/linode/step_create_linode_test.go index f95a958a..32f65a32 100644 --- a/builder/linode/step_create_linode_test.go +++ b/builder/linode/step_create_linode_test.go @@ -3,7 +3,7 @@ package linode import ( "testing" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" ) func TestFlattenVPCInterface_IPv4AddressFields(t *testing.T) { @@ -33,11 +33,11 @@ func TestFlattenVPCInterface_IPv4AddressFields(t *testing.T) { if got.IPv4 == nil { t.Fatal("flattenVPCInterface().IPv4 returned nil") } - if got.IPv4.Addresses == nil || len(*got.IPv4.Addresses) != 1 { + if len(got.IPv4.Addresses) != 1 { t.Fatalf("flattenVPCInterface().IPv4.Addresses = %v, want one address", got.IPv4.Addresses) } - addr := (*got.IPv4.Addresses)[0] + addr := got.IPv4.Addresses[0] if addr.Address == nil || *addr.Address != "auto" { t.Fatalf("address = %v, want auto", addr.Address) } @@ -47,11 +47,11 @@ func TestFlattenVPCInterface_IPv4AddressFields(t *testing.T) { if addr.NAT1To1Address == nil || *addr.NAT1To1Address != "192.0.2.10" { t.Fatalf("nat_1_1_address = %v, want 192.0.2.10", addr.NAT1To1Address) } - if got.IPv4.Ranges == nil || len(*got.IPv4.Ranges) != 1 { + if len(got.IPv4.Ranges) != 1 { t.Fatalf("ranges = %v, want one range", got.IPv4.Ranges) } - if (*got.IPv4.Ranges)[0].Range != "10.0.0.0/28" { - t.Fatalf("range = %q, want 10.0.0.0/28", (*got.IPv4.Ranges)[0].Range) + if got.IPv4.Ranges[0].Range != "10.0.0.0/28" { + t.Fatalf("range = %q, want 10.0.0.0/28", got.IPv4.Ranges[0].Range) } } @@ -76,17 +76,17 @@ func TestFlattenVPCInterface_IPv6Fields(t *testing.T) { if got.IPv6 == nil { t.Fatal("flattenVPCInterface().IPv6 returned nil") } - if got.IPv6.SLAAC == nil || len(*got.IPv6.SLAAC) != 1 { + if len(got.IPv6.SLAAC) != 1 { t.Fatalf("slaac = %v, want one slaac range", got.IPv6.SLAAC) } - if (*got.IPv6.SLAAC)[0].Range != "2600:3c03:e000:123::/64" { - t.Fatalf("slaac range = %q, want 2600:3c03:e000:123::/64", (*got.IPv6.SLAAC)[0].Range) + if got.IPv6.SLAAC[0].Range != "2600:3c03:e000:123::/64" { + t.Fatalf("slaac range = %q, want 2600:3c03:e000:123::/64", got.IPv6.SLAAC[0].Range) } - if got.IPv6.Ranges == nil || len(*got.IPv6.Ranges) != 1 { + if len(got.IPv6.Ranges) != 1 { t.Fatalf("ranges = %v, want one ipv6 range", got.IPv6.Ranges) } - if (*got.IPv6.Ranges)[0].Range != "2600:3c03:e000:123:1::/64" { - t.Fatalf("range = %q, want 2600:3c03:e000:123:1::/64", (*got.IPv6.Ranges)[0].Range) + if got.IPv6.Ranges[0].Range != "2600:3c03:e000:123:1::/64" { + t.Fatalf("range = %q, want 2600:3c03:e000:123:1::/64", got.IPv6.Ranges[0].Range) } if got.IPv6.IsPublic == nil || !*got.IPv6.IsPublic { t.Fatalf("is_public = %v, want true", got.IPv6.IsPublic) @@ -153,17 +153,17 @@ func TestFlattenPublicInterface_AllFields(t *testing.T) { if got == nil || got.IPv4 == nil || got.IPv6 == nil { t.Fatalf("flattenPublicInterface() = %v, want non-nil ipv4 and ipv6", got) } - if got.IPv4.Addresses == nil || len(*got.IPv4.Addresses) != 1 { + if len(got.IPv4.Addresses) != 1 { t.Fatalf("ipv4 addresses = %v, want one address", got.IPv4.Addresses) } - addr := (*got.IPv4.Addresses)[0] + addr := got.IPv4.Addresses[0] if addr.Address == nil || *addr.Address != "auto" { t.Fatalf("ipv4 address = %v, want auto", addr.Address) } if addr.Primary == nil || !*addr.Primary { t.Fatalf("ipv4 primary = %v, want true", addr.Primary) } - if got.IPv6.Ranges == nil || len(*got.IPv6.Ranges) != 1 || (*got.IPv6.Ranges)[0].Range != "/64" { + if len(got.IPv6.Ranges) != 1 || got.IPv6.Ranges[0].Range != "/64" { t.Fatalf("ipv6 ranges = %v, want [/64]", got.IPv6.Ranges) } } @@ -201,10 +201,10 @@ func TestFlattenLinodeInterface_AllFields(t *testing.T) { if got.Public == nil { t.Fatalf("public = nil, want non-nil") } - if got.Public.IPv4 == nil || got.Public.IPv4.Addresses == nil || len(*got.Public.IPv4.Addresses) != 1 { + if got.Public.IPv4 == nil || len(got.Public.IPv4.Addresses) != 1 { t.Fatalf("public ipv4 addresses = %v, want one address", got.Public) } - if addr := (*got.Public.IPv4.Addresses)[0]; addr.Address == nil || *addr.Address != "auto" { + if addr := got.Public.IPv4.Addresses[0]; addr.Address == nil || *addr.Address != "auto" { t.Fatalf("public ipv4 address = %v, want auto", addr.Address) } if got.Public.IPv6 != nil { diff --git a/builder/linode/step_shutdown_linode.go b/builder/linode/step_shutdown_linode.go index a2b47f3a..bad33265 100644 --- a/builder/linode/step_shutdown_linode.go +++ b/builder/linode/step_shutdown_linode.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/packer-plugin-sdk/multistep" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/linode/packer-plugin-linode/helper" ) @@ -27,7 +27,10 @@ func (s *stepShutdownLinode) Run(ctx context.Context, state multistep.StateBag) return handleError("Error shutting down Linode", err) } - _, err := s.client.WaitForInstanceStatus(ctx, instance.ID, linodego.InstanceOffline, int(c.StateTimeout.Seconds())) + waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout) + defer cancel() + + _, err := s.client.WaitForInstanceStatus(waitCtx, instance.ID, linodego.InstanceOffline) if err != nil { return handleError("Error waiting for Linode offline", err) } diff --git a/datasource/image/data.go b/datasource/image/data.go index e66f2ae5..a63bed3f 100644 --- a/datasource/image/data.go +++ b/datasource/image/data.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/packer-plugin-sdk/hcl2helper" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" "github.com/hashicorp/packer-plugin-sdk/template/config" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/linode/packer-plugin-linode/helper" "github.com/zclconf/go-cty/cty" ) @@ -138,7 +138,10 @@ func (d *Datasource) Execute() (cty.Value, error) { return cty.NullVal(cty.EmptyObject), err } } else { - client = helper.NewLinodeClient(d.config.PersonalAccessToken) + client, err = helper.NewLinodeClient(d.config.PersonalAccessToken) + if err != nil { + return cty.NullVal(cty.EmptyObject), err + } } filters := linodego.Filter{} diff --git a/datasource/image/filter.go b/datasource/image/filter.go index 852a7395..edc3dae5 100644 --- a/datasource/image/filter.go +++ b/datasource/image/filter.go @@ -5,7 +5,7 @@ import ( "regexp" "sort" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" ) type ImageFilter func(linodego.Image) bool diff --git a/datasource/image/filter_test.go b/datasource/image/filter_test.go index bb929d15..1089fecc 100644 --- a/datasource/image/filter_test.go +++ b/datasource/image/filter_test.go @@ -3,7 +3,7 @@ package image import ( "testing" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" ) func TestImageDatasourceFilter_IDExactFilter(t *testing.T) { diff --git a/go.mod b/go.mod index 6b7676fa..16c18075 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.25.10 require ( github.com/hashicorp/hcl/v2 v2.24.0 github.com/hashicorp/packer-plugin-sdk v0.6.9 - github.com/linode/linodego v1.69.1 + github.com/linode/linodego/v2 v2.1.2 github.com/mitchellh/mapstructure v1.5.0 github.com/zclconf/go-cty v1.16.3 golang.org/x/crypto v0.52.0 @@ -60,7 +60,6 @@ require ( github.com/go-jose/go-jose/v4 v4.1.4 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-resty/resty/v2 v2.17.2 // indirect github.com/gofrs/flock v0.8.1 // indirect github.com/gofrs/uuid v4.4.0+incompatible // indirect github.com/google/go-querystring v1.2.0 // indirect @@ -132,7 +131,7 @@ require ( go.opentelemetry.io/otel/trace v1.43.0 // indirect golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect golang.org/x/mod v0.35.0 // indirect - golang.org/x/net v0.54.0 // indirect + golang.org/x/net v0.55.0 // indirect golang.org/x/sync v0.20.0 // indirect golang.org/x/sys v0.45.0 // indirect golang.org/x/term v0.43.0 // indirect diff --git a/go.sum b/go.sum index e71d7a6b..3e336d80 100644 --- a/go.sum +++ b/go.sum @@ -138,8 +138,6 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-resty/resty/v2 v2.17.2 h1:FQW5oHYcIlkCNrMD2lloGScxcHJ0gkjshV3qcQAyHQk= -github.com/go-resty/resty/v2 v2.17.2/go.mod h1:kCKZ3wWmwJaNc7S29BRtUhJwy7iqmn+2mLtQrOyQlVA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= @@ -287,8 +285,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/linode/linodego v1.69.1 h1:f45N2MHR/oece2/ktTTCYmrlfse4//k3NgwcF5zbGZ0= -github.com/linode/linodego v1.69.1/go.mod h1:Fha0NYsQSx5VZK1HQNJY/z/dIxxkFp+vb5veawbmAUw= +github.com/linode/linodego/v2 v2.1.2 h1:VpNzW97gkj5Ro6scw2HGqJEaAJcBYU8Al+YvS+ii3gc= +github.com/linode/linodego/v2 v2.1.2/go.mod h1:rsITrtsKFKBi+pEnznDbbF9ZGBou9S8UccCm1yHLbpI= github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 h1:2ZKn+w/BJeL43sCxI2jhPLRv73oVVOjEKZjKkflyqxg= github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786/go.mod h1:kCEbxUJlNDEBNbdQMkPSp6yaKcRXVI6f4ddk8Riv4bc= github.com/masterzen/winrm v0.0.0-20250927112105-5f8e6c707321 h1:AKIJL2PfBX2uie0Mn5pxtG1+zut3hAVMZbRfoXecFzI= @@ -459,8 +457,8 @@ golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.54.0 h1:2zJIZAxAHV/OHCDTCOHAYehQzLfSXuf/5SoL/Dv6w/w= -golang.org/x/net v0.54.0/go.mod h1:Sj4oj8jK6XmHpBZU/zWHw3BV3abl4Kvi+Ut7cQcY+cQ= +golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= +golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs= golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/helper/client.go b/helper/client.go index 3b1d11db..24e115df 100644 --- a/helper/client.go +++ b/helper/client.go @@ -8,7 +8,7 @@ import ( "os" "path/filepath" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/linode/packer-plugin-linode/version" "golang.org/x/oauth2" ) @@ -37,19 +37,22 @@ func AddRootCAToTransport(CAPath string, transport *http.Transport) error { return nil } -func linodeClientFromTransport(transport http.RoundTripper) *linodego.Client { +func linodeClientFromTransport(transport http.RoundTripper) (*linodego.Client, error) { oauth2Client := &http.Client{ Transport: transport, } - client := linodego.NewClient(oauth2Client) + client, err := linodego.NewClient(oauth2Client) + if err != nil { + return nil, fmt.Errorf("failed to initialize Linode client: %w", err) + } projectURL := "https://www.packer.io" userAgent := fmt.Sprintf("Packer/%s (+%s) linodego/%s", version.PluginVersion.FormattedVersion(), projectURL, linodego.Version) client.SetUserAgent(userAgent) - return &client + return &client, nil } func getDefaultTransportWithCA(CAPath string) (*http.Transport, error) { @@ -66,7 +69,7 @@ func getOauth2TransportWithToken(token string, baseTransport http.RoundTripper) return oauthTransport } -func NewLinodeClient(token string) *linodego.Client { +func NewLinodeClient(token string) (*linodego.Client, error) { oauthTransport := getOauth2TransportWithToken(token, nil) return linodeClientFromTransport(oauthTransport) } @@ -77,5 +80,5 @@ func NewLinodeClientWithCA(token, CAPath string) (*linodego.Client, error) { return nil, err } oauthTransport := getOauth2TransportWithToken(token, transport) - return linodeClientFromTransport(oauthTransport), nil + return linodeClientFromTransport(oauthTransport) }