Skip to content
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
50 changes: 42 additions & 8 deletions network_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@ import (
"context"
)

// IPAddressUpdateOptions fields are those accepted by UpdateToken
type IPAddressUpdateOptions struct {
// IPAddressUpdateOptionsV2 fields are those accepted by UpdateIPAddress.
// NOTE: An IP's RDNS can be reset to default using the following pattern:
//
// IPAddressUpdateOptionsV2{
// RDNS: linodego.Pointer[*string](nil),
// }
type IPAddressUpdateOptionsV2 struct {
// The reverse DNS assigned to this address. For public IPv4 addresses, this will be set to a default value provided by Linode if set to nil.
Reserved *bool `json:"reserved,omitempty"`
RDNS *string `json:"rdns,omitempty"`
Reserved *bool `json:"reserved,omitempty"`
RDNS **string `json:"rdns,omitempty"`
}

// IPAddressUpdateOptions fields are those accepted by UpdateIPAddress.
// Deprecated: Please use IPAddressUpdateOptionsV2 for all new implementations.
type IPAddressUpdateOptions struct {
RDNS *string `json:"rdns"`
}

// LinodeIPAssignment stores an assignment between an IP address and a Linode instance.
Expand Down Expand Up @@ -44,13 +55,24 @@ type ListIPAddressesQuery struct {
SkipIPv6RDNS bool `query:"skip_ipv6_rdns"`
}

// GetUpdateOptions converts a IPAddress to IPAddressUpdateOptions for use in UpdateIPAddress
// GetUpdateOptionsV2 converts a IPAddress to IPAddressUpdateOptionsV2 for use in UpdateIPAddressV2.
func (i InstanceIP) GetUpdateOptionsV2() IPAddressUpdateOptionsV2 {
rdns := copyString(&i.RDNS)

return IPAddressUpdateOptionsV2{
RDNS: &rdns,
Reserved: copyBool(&i.Reserved),
}
}

// GetUpdateOptions converts a IPAddress to IPAddressUpdateOptions for use in UpdateIPAddress.
// Deprecated: Please use GetUpdateOptionsV2 for all new implementations.
func (i InstanceIP) GetUpdateOptions() (o IPAddressUpdateOptions) {
o.RDNS = copyString(&i.RDNS)
return
}

// ListIPAddresses lists IPAddresses
// ListIPAddresses lists IPAddresses.
func (c *Client) ListIPAddresses(ctx context.Context, opts *ListOptions) ([]InstanceIP, error) {
response, err := getPaginatedResults[InstanceIP](ctx, c, "networking/ips", opts)
if err != nil {
Expand All @@ -60,7 +82,7 @@ func (c *Client) ListIPAddresses(ctx context.Context, opts *ListOptions) ([]Inst
return response, nil
}

// GetIPAddress gets the IPAddress with the provided IP
// GetIPAddress gets the IPAddress with the provided IP.
func (c *Client) GetIPAddress(ctx context.Context, id string) (*InstanceIP, error) {
e := formatAPIPath("networking/ips/%s", id)
response, err := doGETRequest[InstanceIP](ctx, c, e)
Expand All @@ -71,7 +93,19 @@ func (c *Client) GetIPAddress(ctx context.Context, id string) (*InstanceIP, erro
return response, nil
}

// UpdateIPAddress updates the IPAddress with the specified id
// UpdateIPAddressV2 updates the IP address with the specified address.
func (c *Client) UpdateIPAddressV2(ctx context.Context, address string, opts IPAddressUpdateOptionsV2) (*InstanceIP, error) {
e := formatAPIPath("networking/ips/%s", address)
response, err := doPUTRequest[InstanceIP](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
}

// UpdateIPAddress updates the IP address with the specified id.
// Deprecated: Please use UpdateIPAddressV2 for all new implementation.
func (c *Client) UpdateIPAddress(ctx context.Context, id string, opts IPAddressUpdateOptions) (*InstanceIP, error) {
e := formatAPIPath("networking/ips/%s", id)
response, err := doPUTRequest[InstanceIP](ctx, c, e, opts)
Expand Down
3 changes: 2 additions & 1 deletion test/integration/account_oauth_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package integration

import (
"context"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"

"github.com/linode/linodego"
. "github.com/linode/linodego"
)
Expand Down
1 change: 0 additions & 1 deletion test/integration/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func setupDomain(t *testing.T, fixturesYaml string) (*linodego.Client, *linodego

func TestDomain_Clone_smoke(t *testing.T) {
client, domainToClone, teardown, err := setupDomain(t, "fixtures/TestDomain_Clone")

if err != nil {
t.Errorf("Error creating domain: %v", err)
}
Expand Down
496 changes: 229 additions & 267 deletions test/integration/fixtures/TestIPAddress_GetFound.yaml

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions test/integration/fixtures/TestIPAddress_GetMissing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ interactions:
- HEAD, GET, OPTIONS, POST, PUT, DELETE
Access-Control-Allow-Origin:
- '*'
Akamai-Internal-Account:
- '*'
Cache-Control:
- max-age=0, no-cache, no-store
Connection:
Expand All @@ -31,7 +33,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Mon, 08 Jul 2024 13:31:44 GMT
- Wed, 11 Dec 2024 19:17:27 GMT
Pragma:
- no-cache
Vary:
Expand All @@ -43,7 +45,7 @@ interactions:
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "400"
- "1600"
status: 404 Not Found
code: 404
duration: ""
Loading
Loading