From 0022e5828f2dcdeff6a0df52c5802c04ec0c4619 Mon Sep 17 00:00:00 2001 From: Anandhu <141626925+amanoj-do@users.noreply.github.com> Date: Thu, 12 Dec 2024 01:45:52 +0530 Subject: [PATCH] refactor: move assign/unassign actions to reserved-ipv6 command (#1630) * vendor: update godo dependency to v1.131.1 * refactor: move assign/unassign actions to reserved-ipv6 command * test: add assign and unassign commands to reserved IPv6 tests --- commands/command_config.go | 74 +++++++-------- commands/commands_test.go | 75 +++++++-------- commands/doit.go | 1 - commands/reserved_ipv6_actions.go | 93 ------------------- commands/reserved_ipv6_actions_test.go | 48 ---------- commands/reserved_ipv6s.go | 55 +++++++++++ commands/reserved_ipv6s_test.go | 24 ++++- do/mocks/ReservedIPv6ActionsService.go | 70 -------------- do/mocks/ReservedIPv6sService.go | 30 ++++++ do/reserved_ipv6_actions.go | 58 ------------ do/reserved_ipv6s.go | 21 +++++ go.mod | 2 +- go.sum | 4 +- integration/reserved_ipv6_actions_test.go | 4 +- .../github.com/digitalocean/godo/CHANGELOG.md | 3 + vendor/github.com/digitalocean/godo/godo.go | 2 +- vendor/modules.txt | 2 +- 17 files changed, 211 insertions(+), 355 deletions(-) delete mode 100644 commands/reserved_ipv6_actions.go delete mode 100644 commands/reserved_ipv6_actions_test.go delete mode 100644 do/mocks/ReservedIPv6ActionsService.go delete mode 100644 do/reserved_ipv6_actions.go diff --git a/commands/command_config.go b/commands/command_config.go index 665b73f27..c0e6bfdc9 100644 --- a/commands/command_config.go +++ b/commands/command_config.go @@ -38,43 +38,42 @@ type CmdConfig struct { componentBuilderFactory builder.ComponentBuilderFactory // services - Keys func() do.KeysService - Sizes func() do.SizesService - Regions func() do.RegionsService - Images func() do.ImagesService - ImageActions func() do.ImageActionsService - LoadBalancers func() do.LoadBalancersService - ReservedIPs func() do.ReservedIPsService - ReservedIPv6s func() do.ReservedIPv6sService - ReservedIPv6Actions func() do.ReservedIPv6ActionsService - ReservedIPActions func() do.ReservedIPActionsService - Droplets func() do.DropletsService - DropletActions func() do.DropletActionsService - DropletAutoscale func() do.DropletAutoscaleService - Domains func() do.DomainsService - Actions func() do.ActionsService - Account func() do.AccountService - Balance func() do.BalanceService - BillingHistory func() do.BillingHistoryService - Invoices func() do.InvoicesService - Tags func() do.TagsService - UptimeChecks func() do.UptimeChecksService - Volumes func() do.VolumesService - VolumeActions func() do.VolumeActionsService - Snapshots func() do.SnapshotsService - Certificates func() do.CertificatesService - Firewalls func() do.FirewallsService - CDNs func() do.CDNsService - Projects func() do.ProjectsService - Kubernetes func() do.KubernetesService - Databases func() do.DatabasesService - Registry func() do.RegistryService - VPCs func() do.VPCsService - OneClicks func() do.OneClickService - Apps func() do.AppsService - Monitoring func() do.MonitoringService - Serverless func() do.ServerlessService - OAuth func() do.OAuthService + Keys func() do.KeysService + Sizes func() do.SizesService + Regions func() do.RegionsService + Images func() do.ImagesService + ImageActions func() do.ImageActionsService + LoadBalancers func() do.LoadBalancersService + ReservedIPs func() do.ReservedIPsService + ReservedIPActions func() do.ReservedIPActionsService + ReservedIPv6s func() do.ReservedIPv6sService + Droplets func() do.DropletsService + DropletActions func() do.DropletActionsService + DropletAutoscale func() do.DropletAutoscaleService + Domains func() do.DomainsService + Actions func() do.ActionsService + Account func() do.AccountService + Balance func() do.BalanceService + BillingHistory func() do.BillingHistoryService + Invoices func() do.InvoicesService + Tags func() do.TagsService + UptimeChecks func() do.UptimeChecksService + Volumes func() do.VolumesService + VolumeActions func() do.VolumeActionsService + Snapshots func() do.SnapshotsService + Certificates func() do.CertificatesService + Firewalls func() do.FirewallsService + CDNs func() do.CDNsService + Projects func() do.ProjectsService + Kubernetes func() do.KubernetesService + Databases func() do.DatabasesService + Registry func() do.RegistryService + VPCs func() do.VPCsService + OneClicks func() do.OneClickService + Apps func() do.AppsService + Monitoring func() do.MonitoringService + Serverless func() do.ServerlessService + OAuth func() do.OAuthService } // NewCmdConfig creates an instance of a CmdConfig. @@ -101,7 +100,6 @@ func NewCmdConfig(ns string, dc doctl.Config, out io.Writer, args []string, init c.ReservedIPs = func() do.ReservedIPsService { return do.NewReservedIPsService(godoClient) } c.ReservedIPActions = func() do.ReservedIPActionsService { return do.NewReservedIPActionsService(godoClient) } c.ReservedIPv6s = func() do.ReservedIPv6sService { return do.NewReservedIPv6sService(godoClient) } - c.ReservedIPv6Actions = func() do.ReservedIPv6ActionsService { return do.NewReservedIPv6ActionsService(godoClient) } c.Droplets = func() do.DropletsService { return do.NewDropletsService(godoClient) } c.DropletActions = func() do.DropletActionsService { return do.NewDropletActionsService(godoClient) } c.DropletAutoscale = func() do.DropletAutoscaleService { return do.NewDropletAutoscaleService(godoClient) } diff --git a/commands/commands_test.go b/commands/commands_test.go index b5a6b35cc..160f65a0c 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -230,7 +230,6 @@ type tcMocks struct { reservedIPs *domocks.MockReservedIPsService reservedIPActions *domocks.MockReservedIPActionsService reservedIPv6s *domocks.MockReservedIPv6sService - reservedIPv6Actions *domocks.MockReservedIPv6ActionsService domains *domocks.MockDomainsService uptimeChecks *domocks.MockUptimeChecksService volumes *domocks.MockVolumesService @@ -276,7 +275,6 @@ func withTestClient(t *testing.T, tFn testFn) { reservedIPs: domocks.NewMockReservedIPsService(ctrl), reservedIPActions: domocks.NewMockReservedIPActionsService(ctrl), reservedIPv6s: domocks.NewMockReservedIPv6sService(ctrl), - reservedIPv6Actions: domocks.NewMockReservedIPv6ActionsService(ctrl), droplets: domocks.NewMockDropletsService(ctrl), dropletActions: domocks.NewMockDropletActionsService(ctrl), dropletAutoscale: domocks.NewMockDropletAutoscaleService(ctrl), @@ -326,43 +324,42 @@ func withTestClient(t *testing.T, tFn testFn) { componentBuilderFactory: tm.appBuilderFactory, - Keys: func() do.KeysService { return tm.keys }, - Sizes: func() do.SizesService { return tm.sizes }, - Regions: func() do.RegionsService { return tm.regions }, - Images: func() do.ImagesService { return tm.images }, - ImageActions: func() do.ImageActionsService { return tm.imageActions }, - ReservedIPs: func() do.ReservedIPsService { return tm.reservedIPs }, - ReservedIPActions: func() do.ReservedIPActionsService { return tm.reservedIPActions }, - ReservedIPv6s: func() do.ReservedIPv6sService { return tm.reservedIPv6s }, - ReservedIPv6Actions: func() do.ReservedIPv6ActionsService { return tm.reservedIPv6Actions }, - Droplets: func() do.DropletsService { return tm.droplets }, - DropletActions: func() do.DropletActionsService { return tm.dropletActions }, - DropletAutoscale: func() do.DropletAutoscaleService { return tm.dropletAutoscale }, - Domains: func() do.DomainsService { return tm.domains }, - Actions: func() do.ActionsService { return tm.actions }, - Account: func() do.AccountService { return tm.account }, - Balance: func() do.BalanceService { return tm.balance }, - BillingHistory: func() do.BillingHistoryService { return tm.billingHistory }, - Invoices: func() do.InvoicesService { return tm.invoices }, - Tags: func() do.TagsService { return tm.tags }, - UptimeChecks: func() do.UptimeChecksService { return tm.uptimeChecks }, - Volumes: func() do.VolumesService { return tm.volumes }, - VolumeActions: func() do.VolumeActionsService { return tm.volumeActions }, - Snapshots: func() do.SnapshotsService { return tm.snapshots }, - Certificates: func() do.CertificatesService { return tm.certificates }, - LoadBalancers: func() do.LoadBalancersService { return tm.loadBalancers }, - Firewalls: func() do.FirewallsService { return tm.firewalls }, - CDNs: func() do.CDNsService { return tm.cdns }, - Projects: func() do.ProjectsService { return tm.projects }, - Kubernetes: func() do.KubernetesService { return tm.kubernetes }, - Databases: func() do.DatabasesService { return tm.databases }, - Registry: func() do.RegistryService { return tm.registry }, - VPCs: func() do.VPCsService { return tm.vpcs }, - OneClicks: func() do.OneClickService { return tm.oneClick }, - Apps: func() do.AppsService { return tm.apps }, - Monitoring: func() do.MonitoringService { return tm.monitoring }, - Serverless: func() do.ServerlessService { return tm.serverless }, - OAuth: func() do.OAuthService { return tm.oauth }, + Keys: func() do.KeysService { return tm.keys }, + Sizes: func() do.SizesService { return tm.sizes }, + Regions: func() do.RegionsService { return tm.regions }, + Images: func() do.ImagesService { return tm.images }, + ImageActions: func() do.ImageActionsService { return tm.imageActions }, + ReservedIPs: func() do.ReservedIPsService { return tm.reservedIPs }, + ReservedIPActions: func() do.ReservedIPActionsService { return tm.reservedIPActions }, + ReservedIPv6s: func() do.ReservedIPv6sService { return tm.reservedIPv6s }, + Droplets: func() do.DropletsService { return tm.droplets }, + DropletActions: func() do.DropletActionsService { return tm.dropletActions }, + DropletAutoscale: func() do.DropletAutoscaleService { return tm.dropletAutoscale }, + Domains: func() do.DomainsService { return tm.domains }, + Actions: func() do.ActionsService { return tm.actions }, + Account: func() do.AccountService { return tm.account }, + Balance: func() do.BalanceService { return tm.balance }, + BillingHistory: func() do.BillingHistoryService { return tm.billingHistory }, + Invoices: func() do.InvoicesService { return tm.invoices }, + Tags: func() do.TagsService { return tm.tags }, + UptimeChecks: func() do.UptimeChecksService { return tm.uptimeChecks }, + Volumes: func() do.VolumesService { return tm.volumes }, + VolumeActions: func() do.VolumeActionsService { return tm.volumeActions }, + Snapshots: func() do.SnapshotsService { return tm.snapshots }, + Certificates: func() do.CertificatesService { return tm.certificates }, + LoadBalancers: func() do.LoadBalancersService { return tm.loadBalancers }, + Firewalls: func() do.FirewallsService { return tm.firewalls }, + CDNs: func() do.CDNsService { return tm.cdns }, + Projects: func() do.ProjectsService { return tm.projects }, + Kubernetes: func() do.KubernetesService { return tm.kubernetes }, + Databases: func() do.DatabasesService { return tm.databases }, + Registry: func() do.RegistryService { return tm.registry }, + VPCs: func() do.VPCsService { return tm.vpcs }, + OneClicks: func() do.OneClickService { return tm.oneClick }, + Apps: func() do.AppsService { return tm.apps }, + Monitoring: func() do.MonitoringService { return tm.monitoring }, + Serverless: func() do.ServerlessService { return tm.serverless }, + OAuth: func() do.OAuthService { return tm.oauth }, } tFn(config, tm) diff --git a/commands/doit.go b/commands/doit.go index 56b09c3fb..8b3b44af7 100644 --- a/commands/doit.go +++ b/commands/doit.go @@ -212,7 +212,6 @@ func computeCmd() *Command { cmd.AddCommand(ReservedIP()) cmd.AddCommand(ReservedIPAction()) cmd.AddCommand(ReservedIPv6()) - cmd.AddCommand(ReservedIPv6Action()) cmd.AddCommand(Images()) cmd.AddCommand(ImageAction()) cmd.AddCommand(LoadBalancer()) diff --git a/commands/reserved_ipv6_actions.go b/commands/reserved_ipv6_actions.go deleted file mode 100644 index 476ba829c..000000000 --- a/commands/reserved_ipv6_actions.go +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright 2024 The Doctl Authors All rights reserved. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package commands - -import ( - "fmt" - "strconv" - - "github.com/digitalocean/doctl" - "github.com/digitalocean/doctl/commands/displayers" - "github.com/digitalocean/doctl/do" - "github.com/spf13/cobra" -) - -// ReservedIPv6Action creates the reserved IPv6 action command. -func ReservedIPv6Action() *Command { - cmd := &Command{ - Command: &cobra.Command{ - Use: "reserved-ipv6-action", - Short: "Display commands to associate reserved IPv6 addresses with Droplets", - Long: "Reserved IP actions are commands that are used to manage DigitalOcean reserved IPv6 addresses.", - Aliases: []string{"reserved-ipv6-actions"}, - Hidden: true, - }, - } - - cmdReservedIPv6ActionsAssign := CmdBuilder(cmd, RunReservedIPv6ActionsAssign, - "assign ", "Assign a reserved IPv6 address to a Droplet", "Assigns a reserved IPv6 address to the specified Droplet.", Writer, - displayerType(&displayers.Action{})) - cmdReservedIPv6ActionsAssign.Example = `The following example assigns the reserved IPv6 address ` + "`" + `5a11:a:b0a7` + "`" + ` to a Droplet with the ID ` + "`" + `386734086` + "`" + `: doctl compute reserved-ipv6-action assign 5a11:a:b0a7 386734086` - - cmdReservedIPv6ActionsUnassign := CmdBuilder(cmd, RunReservedIPv6ActionsUnassign, - "unassign ", "Unassign a reserved IPv6 address from a Droplet", `Unassigns a reserved IPv6 address from a Droplet.`, Writer, - displayerType(&displayers.Action{})) - cmdReservedIPv6ActionsUnassign.Example = `The following example unassigns the reserved IPv6 address ` + "`" + `5a11:a:b0a7` + "`" + ` from a resource: doctl compute reserved-ipv6-action unassign 5a11:a:b0a7` - - return cmd -} - -// RunReservedIPv6ActionsAssign assigns a reserved IP to a droplet. -func RunReservedIPv6ActionsAssign(c *CmdConfig) error { - if len(c.Args) != 2 { - return doctl.NewMissingArgsErr(c.NS) - } - - ip := c.Args[0] - - fia := c.ReservedIPv6Actions() - - dropletID, err := strconv.Atoi(c.Args[1]) - if err != nil { - return err - } - - a, err := fia.Assign(ip, dropletID) - if err != nil { - checkErr(fmt.Errorf("could not assign IP to droplet: %v", err)) - } - - item := &displayers.Action{Actions: do.Actions{*a}} - return c.Display(item) -} - -// RunReservedIPActionsUnassign unassigns a reserved IP to a droplet. -func RunReservedIPv6ActionsUnassign(c *CmdConfig) error { - err := ensureOneArg(c) - if err != nil { - return err - } - - ip := c.Args[0] - - fia := c.ReservedIPv6Actions() - - a, err := fia.Unassign(ip) - if err != nil { - checkErr(fmt.Errorf("could not unassign IP to droplet: %v", err)) - } - - item := &displayers.Action{Actions: do.Actions{*a}} - return c.Display(item) -} diff --git a/commands/reserved_ipv6_actions_test.go b/commands/reserved_ipv6_actions_test.go deleted file mode 100644 index f4da3902b..000000000 --- a/commands/reserved_ipv6_actions_test.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2024 The Doctl Authors All rights reserved. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package commands - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestReservedIPv6ActionCommand(t *testing.T) { - cmd := ReservedIPv6Action() - assert.NotNil(t, cmd) - assertCommandNames(t, cmd, "assign", "unassign") -} - -func TestReservedIPv6ActionsAssign(t *testing.T) { - withTestClient(t, func(config *CmdConfig, tm *tcMocks) { - tm.reservedIPv6Actions.EXPECT().Assign("5a11:a:b0a7", 2).Return(&testAction, nil) - - config.Args = append(config.Args, "5a11:a:b0a7", "2") - - err := RunReservedIPv6ActionsAssign(config) - assert.NoError(t, err) - }) -} - -func TestReservedIPv6ActionsUnassign(t *testing.T) { - withTestClient(t, func(config *CmdConfig, tm *tcMocks) { - tm.reservedIPv6Actions.EXPECT().Unassign("5a11:a:b0a7").Return(&testAction, nil) - - config.Args = append(config.Args, "5a11:a:b0a7") - - err := RunReservedIPv6ActionsUnassign(config) - assert.NoError(t, err) - }) -} diff --git a/commands/reserved_ipv6s.go b/commands/reserved_ipv6s.go index 22f0a7468..1bf620d5d 100644 --- a/commands/reserved_ipv6s.go +++ b/commands/reserved_ipv6s.go @@ -16,6 +16,7 @@ package commands import ( "errors" "fmt" + "strconv" "github.com/digitalocean/doctl" "github.com/digitalocean/doctl/commands/displayers" @@ -56,6 +57,16 @@ Reserved IPv6 addresses can be held in the region they were created in on your a AddStringFlag(cmdReservedIPv6List, doctl.ArgRegionSlug, "", "", "Retrieves a list of reserved IPv6 addresses in the specified region") cmdReservedIPv6List.Example = `The following example lists all reserved IPv6 addresses in the ` + "`" + `nyc1` + "`" + ` region: doctl compute reserved-ipv6 list --region nyc1` + cmdReservedIPv6ActionsAssign := CmdBuilder(cmd, RunReservedIPv6sAssign, + "assign ", "Assign a reserved IPv6 address to a Droplet", "Assigns a reserved IPv6 address to the specified Droplet.", Writer, + displayerType(&displayers.Action{})) + cmdReservedIPv6ActionsAssign.Example = `The following example assigns the reserved IPv6 address ` + "`" + `5a11:a:b0a7` + "`" + ` to a Droplet with the ID ` + "`" + `386734086` + "`" + `: doctl compute reserved-ipv6 assign 5a11:a:b0a7 386734086` + + cmdReservedIPv6ActionsUnassign := CmdBuilder(cmd, RunReservedIPv6sUnassign, + "unassign ", "Unassign a reserved IPv6 address from a Droplet", `Unassigns a reserved IPv6 address from a Droplet.`, Writer, + displayerType(&displayers.Action{})) + cmdReservedIPv6ActionsUnassign.Example = `The following example unassigns the reserved IPv6 address ` + "`" + `5a11:a:b0a7` + "`" + ` from a resource: doctl compute reserved-ipv6 unassign 5a11:a:b0a7` + return cmd } @@ -159,3 +170,47 @@ func RunReservedIPv6List(c *CmdConfig) error { item := rips return c.Display(item) } + +// RunReservedIPv6sAssign assigns a reserved IP to a droplet. +func RunReservedIPv6sAssign(c *CmdConfig) error { + if len(c.Args) != 2 { + return doctl.NewMissingArgsErr(c.NS) + } + + ip := c.Args[0] + + fia := c.ReservedIPv6s() + + dropletID, err := strconv.Atoi(c.Args[1]) + if err != nil { + return err + } + + a, err := fia.Assign(ip, dropletID) + if err != nil { + checkErr(fmt.Errorf("could not assign IP to droplet: %v", err)) + } + + item := &displayers.Action{Actions: do.Actions{*a}} + return c.Display(item) +} + +// RunReservedIPv6sUnassign unassigns a reserved IP to a droplet. +func RunReservedIPv6sUnassign(c *CmdConfig) error { + err := ensureOneArg(c) + if err != nil { + return err + } + + ip := c.Args[0] + + fia := c.ReservedIPv6s() + + a, err := fia.Unassign(ip) + if err != nil { + checkErr(fmt.Errorf("could not unassign IP to droplet: %v", err)) + } + + item := &displayers.Action{Actions: do.Actions{*a}} + return c.Display(item) +} diff --git a/commands/reserved_ipv6s_test.go b/commands/reserved_ipv6s_test.go index ecb3b7579..aa35bfd57 100644 --- a/commands/reserved_ipv6s_test.go +++ b/commands/reserved_ipv6s_test.go @@ -24,7 +24,7 @@ import ( func TestReservedIPv6Commands(t *testing.T) { cmd := ReservedIPv6() assert.NotNil(t, cmd) - assertCommandNames(t, cmd, "create", "delete", "get", "list") + assertCommandNames(t, cmd, "create", "delete", "get", "list", "assign", "unassign") } func TestReservedIPv6sList(t *testing.T) { @@ -75,3 +75,25 @@ func TestReservedIPv6sDelete(t *testing.T) { RunReservedIPv6Delete(config) }) } + +func TestReservedIPv6ActionsAssign(t *testing.T) { + withTestClient(t, func(config *CmdConfig, tm *tcMocks) { + tm.reservedIPv6s.EXPECT().Assign("5a11:a:b0a7", 2).Return(&testAction, nil) + + config.Args = append(config.Args, "5a11:a:b0a7", "2") + + err := RunReservedIPv6sAssign(config) + assert.NoError(t, err) + }) +} + +func TestReservedIPv6ActionsUnassign(t *testing.T) { + withTestClient(t, func(config *CmdConfig, tm *tcMocks) { + tm.reservedIPv6s.EXPECT().Unassign("5a11:a:b0a7").Return(&testAction, nil) + + config.Args = append(config.Args, "5a11:a:b0a7") + + err := RunReservedIPv6sUnassign(config) + assert.NoError(t, err) + }) +} diff --git a/do/mocks/ReservedIPv6ActionsService.go b/do/mocks/ReservedIPv6ActionsService.go deleted file mode 100644 index 5a3197997..000000000 --- a/do/mocks/ReservedIPv6ActionsService.go +++ /dev/null @@ -1,70 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: reserved_ipv6_actions.go -// -// Generated by this command: -// -// mockgen -source reserved_ipv6_actions.go -package=mocks ReservedIPv6ActionsService -// - -// Package mocks is a generated GoMock package. -package mocks - -import ( - reflect "reflect" - - do "github.com/digitalocean/doctl/do" - gomock "go.uber.org/mock/gomock" -) - -// MockReservedIPv6ActionsService is a mock of ReservedIPv6ActionsService interface. -type MockReservedIPv6ActionsService struct { - ctrl *gomock.Controller - recorder *MockReservedIPv6ActionsServiceMockRecorder -} - -// MockReservedIPv6ActionsServiceMockRecorder is the mock recorder for MockReservedIPv6ActionsService. -type MockReservedIPv6ActionsServiceMockRecorder struct { - mock *MockReservedIPv6ActionsService -} - -// NewMockReservedIPv6ActionsService creates a new mock instance. -func NewMockReservedIPv6ActionsService(ctrl *gomock.Controller) *MockReservedIPv6ActionsService { - mock := &MockReservedIPv6ActionsService{ctrl: ctrl} - mock.recorder = &MockReservedIPv6ActionsServiceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockReservedIPv6ActionsService) EXPECT() *MockReservedIPv6ActionsServiceMockRecorder { - return m.recorder -} - -// Assign mocks base method. -func (m *MockReservedIPv6ActionsService) Assign(ip string, dropletID int) (*do.Action, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Assign", ip, dropletID) - ret0, _ := ret[0].(*do.Action) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Assign indicates an expected call of Assign. -func (mr *MockReservedIPv6ActionsServiceMockRecorder) Assign(ip, dropletID any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Assign", reflect.TypeOf((*MockReservedIPv6ActionsService)(nil).Assign), ip, dropletID) -} - -// Unassign mocks base method. -func (m *MockReservedIPv6ActionsService) Unassign(ip string) (*do.Action, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Unassign", ip) - ret0, _ := ret[0].(*do.Action) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Unassign indicates an expected call of Unassign. -func (mr *MockReservedIPv6ActionsServiceMockRecorder) Unassign(ip any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unassign", reflect.TypeOf((*MockReservedIPv6ActionsService)(nil).Unassign), ip) -} diff --git a/do/mocks/ReservedIPv6sService.go b/do/mocks/ReservedIPv6sService.go index f109fbab3..d85fb193a 100644 --- a/do/mocks/ReservedIPv6sService.go +++ b/do/mocks/ReservedIPv6sService.go @@ -40,6 +40,21 @@ func (m *MockReservedIPv6sService) EXPECT() *MockReservedIPv6sServiceMockRecorde return m.recorder } +// Assign mocks base method. +func (m *MockReservedIPv6sService) Assign(ip string, dropletID int) (*do.Action, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Assign", ip, dropletID) + ret0, _ := ret[0].(*do.Action) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Assign indicates an expected call of Assign. +func (mr *MockReservedIPv6sServiceMockRecorder) Assign(ip, dropletID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Assign", reflect.TypeOf((*MockReservedIPv6sService)(nil).Assign), ip, dropletID) +} + // Create mocks base method. func (m *MockReservedIPv6sService) Create(ficr *godo.ReservedIPV6CreateRequest) (*do.ReservedIPv6, error) { m.ctrl.T.Helper() @@ -98,3 +113,18 @@ func (mr *MockReservedIPv6sServiceMockRecorder) List() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockReservedIPv6sService)(nil).List)) } + +// Unassign mocks base method. +func (m *MockReservedIPv6sService) Unassign(ip string) (*do.Action, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Unassign", ip) + ret0, _ := ret[0].(*do.Action) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Unassign indicates an expected call of Unassign. +func (mr *MockReservedIPv6sServiceMockRecorder) Unassign(ip any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unassign", reflect.TypeOf((*MockReservedIPv6sService)(nil).Unassign), ip) +} diff --git a/do/reserved_ipv6_actions.go b/do/reserved_ipv6_actions.go deleted file mode 100644 index 229f553f2..000000000 --- a/do/reserved_ipv6_actions.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright 2024 The Doctl Authors All rights reserved. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package do - -import ( - "context" - - "github.com/digitalocean/godo" -) - -// ReservedIPv6ActionsService is an interface for interacting with -// DigitalOcean's reserved IPv6 action api. -type ReservedIPv6ActionsService interface { - Assign(ip string, dropletID int) (*Action, error) - Unassign(ip string) (*Action, error) -} - -type reservedIPv6ActionsService struct { - client *godo.Client -} - -var _ ReservedIPv6ActionsService = &reservedIPv6ActionsService{} - -// NewReservedIPv6ActionsService builds a ReservedIPv6ActionsService instance. -func NewReservedIPv6ActionsService(godoClient *godo.Client) ReservedIPv6ActionsService { - return &reservedIPv6ActionsService{ - client: godoClient, - } -} - -func (fia *reservedIPv6ActionsService) Assign(ip string, dropletID int) (*Action, error) { - a, _, err := fia.client.ReservedIPV6Actions.Assign(context.TODO(), ip, dropletID) - if err != nil { - return nil, err - } - - return &Action{Action: a}, nil -} - -func (fia *reservedIPv6ActionsService) Unassign(ip string) (*Action, error) { - a, _, err := fia.client.ReservedIPV6Actions.Unassign(context.TODO(), ip) - if err != nil { - return nil, err - } - - return &Action{Action: a}, nil -} diff --git a/do/reserved_ipv6s.go b/do/reserved_ipv6s.go index e367772ad..b81596da8 100644 --- a/do/reserved_ipv6s.go +++ b/do/reserved_ipv6s.go @@ -33,6 +33,9 @@ type ReservedIPv6sService interface { Get(ip string) (*ReservedIPv6, error) Create(ficr *godo.ReservedIPV6CreateRequest) (*ReservedIPv6, error) Delete(ip string) error + + Assign(ip string, dropletID int) (*Action, error) + Unassign(ip string) (*Action, error) } type reservedIPv6sService struct { @@ -99,3 +102,21 @@ func (fis *reservedIPv6sService) Delete(ip string) error { _, err := fis.client.ReservedIPV6s.Delete(context.TODO(), ip) return err } + +func (fia *reservedIPv6sService) Assign(ip string, dropletID int) (*Action, error) { + a, _, err := fia.client.ReservedIPV6Actions.Assign(context.TODO(), ip, dropletID) + if err != nil { + return nil, err + } + + return &Action{Action: a}, nil +} + +func (fia *reservedIPv6sService) Unassign(ip string) (*Action, error) { + a, _, err := fia.client.ReservedIPV6Actions.Unassign(context.TODO(), ip) + if err != nil { + return nil, err + } + + return &Action{Action: a}, nil +} diff --git a/go.mod b/go.mod index 76d71a50a..0de693c53 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 require ( github.com/blang/semver v3.5.1+incompatible github.com/creack/pty v1.1.21 - github.com/digitalocean/godo v1.131.1-0.20241127211050-a97e39731918 + github.com/digitalocean/godo v1.131.1 github.com/docker/cli v24.0.5+incompatible github.com/docker/docker v25.0.6+incompatible github.com/docker/docker-credential-helpers v0.7.0 // indirect diff --git a/go.sum b/go.sum index 06b15ea13..45f5e393f 100644 --- a/go.sum +++ b/go.sum @@ -91,8 +91,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/digitalocean/godo v1.131.1-0.20241127211050-a97e39731918 h1:7xOw7i5AFH1n5vIMMH7HtR87jdxV8XnLKOBafNbVetM= -github.com/digitalocean/godo v1.131.1-0.20241127211050-a97e39731918/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc= +github.com/digitalocean/godo v1.131.1 h1:2QsRwjNukKgOQbflMxOsTDoC05o5UKBpqQMFKXegYKE= +github.com/digitalocean/godo v1.131.1/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/docker/cli v24.0.5+incompatible h1:WeBimjvS0eKdH4Ygx+ihVq1Q++xg36M/rMi4aXAvodc= diff --git a/integration/reserved_ipv6_actions_test.go b/integration/reserved_ipv6_actions_test.go index 62825a3a9..c742a5dca 100644 --- a/integration/reserved_ipv6_actions_test.go +++ b/integration/reserved_ipv6_actions_test.go @@ -82,7 +82,7 @@ var _ = suite("compute/reserved-ipv6-action/assign", func(t *testing.T, when spe "-t", "some-magic-token", "-u", server.URL, "compute", - "reserved-ipv6-action", + "reserved-ipv6", alias, "fd53:616d:6d60::1071:5001", "1212", @@ -104,7 +104,7 @@ var _ = suite("compute/reserved-ipv6-action/assign", func(t *testing.T, when spe "-t", "some-magic-token", "-u", server.URL, "compute", - "reserved-ipv6-action", + "reserved-ipv6", alias, "fd53:616d:6d60::1071:5001", ) diff --git a/vendor/github.com/digitalocean/godo/CHANGELOG.md b/vendor/github.com/digitalocean/godo/CHANGELOG.md index 3fb2a160c..8b177989d 100644 --- a/vendor/github.com/digitalocean/godo/CHANGELOG.md +++ b/vendor/github.com/digitalocean/godo/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## [v1.131.1] - 2024-12-10 +- #762 - @imaskm - Updated list ipv6 response + ## [v1.131.0] - 2024-11-25 - #760 - @jvasilevsky - LBAAS: add ipv6 field to loadbalancer model diff --git a/vendor/github.com/digitalocean/godo/godo.go b/vendor/github.com/digitalocean/godo/godo.go index 62498fc44..94d31631a 100644 --- a/vendor/github.com/digitalocean/godo/godo.go +++ b/vendor/github.com/digitalocean/godo/godo.go @@ -21,7 +21,7 @@ import ( ) const ( - libraryVersion = "1.131.0" + libraryVersion = "1.131.1" defaultBaseURL = "https://api.digitalocean.com/" userAgent = "godo/" + libraryVersion mediaType = "application/json" diff --git a/vendor/modules.txt b/vendor/modules.txt index 8d1c12c55..db1c338c1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -61,7 +61,7 @@ github.com/creack/pty # github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc ## explicit github.com/davecgh/go-spew/spew -# github.com/digitalocean/godo v1.131.1-0.20241127211050-a97e39731918 +# github.com/digitalocean/godo v1.131.1 ## explicit; go 1.22 github.com/digitalocean/godo github.com/digitalocean/godo/metrics