Skip to content

Commit de32ba0

Browse files
Added missing options for POST and PUT methods (#700)
1 parent f90dabb commit de32ba0

20 files changed

+141
-83
lines changed

account_child.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (c *Client) GetChildAccount(ctx context.Context, euuid string) (*ChildAccou
3939
// The attributes of this token are not currently configurable.
4040
// NOTE: Parent/Child related features may not be generally available.
4141
func (c *Client) CreateChildAccountToken(ctx context.Context, euuid string) (*ChildAccountToken, error) {
42-
return doPOSTRequest[ChildAccountToken, any](
42+
return doPOSTRequestNoRequestBody[ChildAccountToken](
4343
ctx,
4444
c,
4545
formatAPIPath("account/child-accounts/%s/token", euuid),

account_invoices.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ type InvoiceItem struct {
3939
Total float32 `json:"total"`
4040
}
4141

42-
// ListInvoices gets a paginated list of Invoices against the Account
43-
func (c *Client) ListInvoices(ctx context.Context, opts *ListOptions) ([]Invoice, error) {
44-
return getPaginatedResults[Invoice](ctx, c, "account/invoices", opts)
45-
}
46-
4742
// UnmarshalJSON implements the json.Unmarshaler interface
4843
func (i *Invoice) UnmarshalJSON(b []byte) error {
4944
type Mask Invoice
@@ -86,6 +81,11 @@ func (i *InvoiceItem) UnmarshalJSON(b []byte) error {
8681
return nil
8782
}
8883

84+
// ListInvoices gets a paginated list of Invoices against the Account
85+
func (c *Client) ListInvoices(ctx context.Context, opts *ListOptions) ([]Invoice, error) {
86+
return getPaginatedResults[Invoice](ctx, c, "account/invoices", opts)
87+
}
88+
8989
// GetInvoice gets a single Invoice matching the provided ID
9090
func (c *Client) GetInvoice(ctx context.Context, invoiceID int) (*Invoice, error) {
9191
e := formatAPIPath("account/invoices/%d", invoiceID)

account_logins.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ type Login struct {
1717
Status string `json:"status"`
1818
}
1919

20-
func (c *Client) ListLogins(ctx context.Context, opts *ListOptions) ([]Login, error) {
21-
return getPaginatedResults[Login](ctx, c, "account/logins", opts)
22-
}
23-
2420
// UnmarshalJSON implements the json.Unmarshaler interface
2521
func (i *Login) UnmarshalJSON(b []byte) error {
2622
type Mask Login
@@ -41,6 +37,10 @@ func (i *Login) UnmarshalJSON(b []byte) error {
4137
return nil
4238
}
4339

40+
func (c *Client) ListLogins(ctx context.Context, opts *ListOptions) ([]Login, error) {
41+
return getPaginatedResults[Login](ctx, c, "account/logins", opts)
42+
}
43+
4444
func (c *Client) GetLogin(ctx context.Context, loginID int) (*Login, error) {
4545
e := formatAPIPath("account/logins/%d", loginID)
4646
return doGETRequest[Login](ctx, c, e)

account_notifications.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ const (
5656
NotificationMaintenance NotificationType = "maintenance"
5757
)
5858

59-
// ListNotifications gets a collection of Notification objects representing important,
60-
// often time-sensitive items related to the Account. An account cannot interact directly with
61-
// Notifications, and a Notification will disappear when the circumstances causing it
62-
// have been resolved. For example, if the account has an important Ticket open, a response
63-
// to the Ticket will dismiss the Notification.
64-
func (c *Client) ListNotifications(ctx context.Context, opts *ListOptions) ([]Notification, error) {
65-
return getPaginatedResults[Notification](ctx, c, "account/notifications", opts)
66-
}
67-
6859
// UnmarshalJSON implements the json.Unmarshaler interface
6960
func (i *Notification) UnmarshalJSON(b []byte) error {
7061
type Mask Notification
@@ -86,3 +77,12 @@ func (i *Notification) UnmarshalJSON(b []byte) error {
8677

8778
return nil
8879
}
80+
81+
// ListNotifications gets a collection of Notification objects representing important,
82+
// often time-sensitive items related to the Account. An account cannot interact directly with
83+
// Notifications, and a Notification will disappear when the circumstances causing it
84+
// have been resolved. For example, if the account has an important Ticket open, a response
85+
// to the Ticket will dismiss the Notification.
86+
func (c *Client) ListNotifications(ctx context.Context, opts *ListOptions) ([]Notification, error) {
87+
return getPaginatedResults[Notification](ctx, c, "account/notifications", opts)
88+
}

account_oauth_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ func (c *Client) DeleteOAuthClient(ctx context.Context, clientID string) error {
111111
// ResetOAuthClientSecret resets the OAuth Client secret for a client with a specified id
112112
func (c *Client) ResetOAuthClientSecret(ctx context.Context, clientID string) (*OAuthClient, error) {
113113
e := formatAPIPath("account/oauth-clients/%s/reset-secret", clientID)
114-
return doPOSTRequest[OAuthClient, any](ctx, c, e)
114+
return doPOSTRequestNoRequestBody[OAuthClient](ctx, c, e)
115115
}

instance_disks.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ type InstanceDiskUpdateOptions struct {
6565
Label string `json:"label"`
6666
}
6767

68-
type InstanceDiskCloneOptions struct{}
68+
// InstanceDiskResizeOptions are InstanceDisk settings that can be used in resizes
69+
type InstanceDiskResizeOptions struct {
70+
Size int `json:"size"`
71+
}
6972

70-
// ListInstanceDisks lists InstanceDisks
71-
func (c *Client) ListInstanceDisks(ctx context.Context, linodeID int, opts *ListOptions) ([]InstanceDisk, error) {
72-
return getPaginatedResults[InstanceDisk](ctx, c, formatAPIPath("linode/instances/%d/disks", linodeID), opts)
73+
// InstanceDiskPasswordResetOptions are InstanceDisk settings that can be used in password resets
74+
type InstanceDiskPasswordResetOptions struct {
75+
Password string `json:"password"`
7376
}
7477

7578
// UnmarshalJSON implements the json.Unmarshaler interface
@@ -94,6 +97,11 @@ func (i *InstanceDisk) UnmarshalJSON(b []byte) error {
9497
return nil
9598
}
9699

100+
// ListInstanceDisks lists InstanceDisks
101+
func (c *Client) ListInstanceDisks(ctx context.Context, linodeID int, opts *ListOptions) ([]InstanceDisk, error) {
102+
return getPaginatedResults[InstanceDisk](ctx, c, formatAPIPath("linode/instances/%d/disks", linodeID), opts)
103+
}
104+
97105
// GetInstanceDisk gets the template with the provided ID
98106
func (c *Client) GetInstanceDisk(ctx context.Context, linodeID int, diskID int) (*InstanceDisk, error) {
99107
e := formatAPIPath("linode/instances/%d/disks/%d", linodeID, diskID)
@@ -118,21 +126,13 @@ func (c *Client) RenameInstanceDisk(ctx context.Context, linodeID int, diskID in
118126
}
119127

120128
// ResizeInstanceDisk resizes the size of the Instance disk
121-
func (c *Client) ResizeInstanceDisk(ctx context.Context, linodeID int, diskID int, size int) error {
122-
opts := map[string]any{
123-
"size": size,
124-
}
125-
129+
func (c *Client) ResizeInstanceDisk(ctx context.Context, linodeID int, diskID int, opts InstanceDiskResizeOptions) error {
126130
e := formatAPIPath("linode/instances/%d/disks/%d/resize", linodeID, diskID)
127131
return doPOSTRequestNoResponseBody(ctx, c, e, opts)
128132
}
129133

130134
// PasswordResetInstanceDisk resets the "root" account password on the Instance disk
131-
func (c *Client) PasswordResetInstanceDisk(ctx context.Context, linodeID int, diskID int, password string) error {
132-
opts := map[string]any{
133-
"password": password,
134-
}
135-
135+
func (c *Client) PasswordResetInstanceDisk(ctx context.Context, linodeID int, diskID int, opts InstanceDiskPasswordResetOptions) error {
136136
e := formatAPIPath("linode/instances/%d/disks/%d/password", linodeID, diskID)
137137
return doPOSTRequestNoResponseBody(ctx, c, e, opts)
138138
}
@@ -144,7 +144,7 @@ func (c *Client) DeleteInstanceDisk(ctx context.Context, linodeID int, diskID in
144144
}
145145

146146
// CloneInstanceDisk clones the given InstanceDisk for the given Instance
147-
func (c *Client) CloneInstanceDisk(ctx context.Context, linodeID, diskID int, opts InstanceDiskCloneOptions) (*InstanceDisk, error) {
147+
func (c *Client) CloneInstanceDisk(ctx context.Context, linodeID, diskID int) (*InstanceDisk, error) {
148148
e := formatAPIPath("linode/instances/%d/disks/%d/clone", linodeID, diskID)
149-
return doPOSTRequest[InstanceDisk](ctx, c, e, opts)
149+
return doPOSTRequestNoRequestBody[InstanceDisk](ctx, c, e)
150150
}

instance_ips.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ type InstanceReserveIPOptions struct {
8585
Address string `json:"address"`
8686
}
8787

88+
type InstanceIPAddOptions struct {
89+
Type string `json:"type"`
90+
Public bool `json:"public"`
91+
}
92+
8893
// InstanceIPType constants start with IPType and include Linode Instance IP Types
8994
type InstanceIPType string
9095

@@ -109,14 +114,10 @@ func (c *Client) GetInstanceIPAddress(ctx context.Context, linodeID int, ipaddre
109114
}
110115

111116
// AddInstanceIPAddress adds a public or private IP to a Linode instance
112-
func (c *Client) AddInstanceIPAddress(ctx context.Context, linodeID int, public bool) (*InstanceIP, error) {
113-
instanceipRequest := struct {
114-
Type string `json:"type"`
115-
Public bool `json:"public"`
116-
}{"ipv4", public}
117-
117+
func (c *Client) AddInstanceIPAddress(ctx context.Context, linodeID int, opts InstanceIPAddOptions) (*InstanceIP, error) {
118+
opts.Type = "ipv4"
118119
e := formatAPIPath("linode/instances/%d/ips", linodeID)
119-
return doPOSTRequest[InstanceIP](ctx, c, e, instanceipRequest)
120+
return doPOSTRequest[InstanceIP](ctx, c, e, opts)
120121
}
121122

122123
// UpdateInstanceIPAddress updates the IPAddress with the specified instance id and IP address

instance_snapshots.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ type RestoreInstanceOptions struct {
2626
Overwrite bool `json:"overwrite"`
2727
}
2828

29+
type InstanceSnapshotCreateOptions struct {
30+
Label string `json:"label"`
31+
}
32+
2933
// InstanceSnapshot represents a linode backup snapshot
3034
type InstanceSnapshot struct {
3135
ID int `json:"id"`
@@ -92,9 +96,7 @@ func (c *Client) GetInstanceSnapshot(ctx context.Context, linodeID int, snapshot
9296
}
9397

9498
// CreateInstanceSnapshot Creates or Replaces the snapshot Backup of a Linode. If a previous snapshot exists for this Linode, it will be deleted.
95-
func (c *Client) CreateInstanceSnapshot(ctx context.Context, linodeID int, label string) (*InstanceSnapshot, error) {
96-
opts := map[string]string{"label": label}
97-
99+
func (c *Client) CreateInstanceSnapshot(ctx context.Context, linodeID int, opts InstanceSnapshotCreateOptions) (*InstanceSnapshot, error) {
98100
e := formatAPIPath("linode/instances/%d/backups", linodeID)
99101
return doPOSTRequest[InstanceSnapshot](ctx, c, e, opts)
100102
}

instances.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ type InstanceResizeOptions struct {
277277
AllowAutoDiskResize *bool `json:"allow_auto_disk_resize,omitempty"`
278278
}
279279

280+
type InstanceBootOptions struct {
281+
ConfigID int `json:"config_id"`
282+
}
283+
284+
type InstanceRebootOptions struct {
285+
ConfigID int `json:"config_id"`
286+
}
287+
280288
// InstanceMigrateOptions is an options struct used when migrating an instance
281289
type InstanceMigrateOptions struct {
282290
Type *InstanceMigrationType `json:"type,omitempty"`
@@ -333,15 +341,17 @@ func (c *Client) DeleteInstance(ctx context.Context, linodeID int) error {
333341

334342
// BootInstance will boot a Linode instance
335343
// A configID of 0 will cause Linode to choose the last/best config
336-
func (c *Client) BootInstance(ctx context.Context, linodeID int, configID int) error {
337-
opts := make(map[string]int)
344+
func (c *Client) BootInstance(ctx context.Context, linodeID int, opts InstanceBootOptions) error {
345+
var payload InstanceBootOptions
338346

339-
if configID != 0 {
340-
opts = map[string]int{"config_id": configID}
347+
if opts.ConfigID != 0 {
348+
payload = opts // Use the struct when ConfigID is set
349+
} else {
350+
payload = InstanceBootOptions{} // Send an empty JSON object when ConfigID is 0
341351
}
342352

343353
e := formatAPIPath("linode/instances/%d/boot", linodeID)
344-
return doPOSTRequestNoResponseBody(ctx, c, e, opts)
354+
return doPOSTRequestNoResponseBody(ctx, c, e, payload)
345355
}
346356

347357
// CloneInstance clone an existing Instances Disks and Configuration profiles to another Linode Instance
@@ -358,15 +368,17 @@ func (c *Client) ResetInstancePassword(ctx context.Context, linodeID int, opts I
358368

359369
// RebootInstance reboots a Linode instance
360370
// A configID of 0 will cause Linode to choose the last/best config
361-
func (c *Client) RebootInstance(ctx context.Context, linodeID int, configID int) error {
362-
opts := make(map[string]int)
371+
func (c *Client) RebootInstance(ctx context.Context, linodeID int, opts InstanceRebootOptions) error {
372+
var payload InstanceRebootOptions
363373

364-
if configID != 0 {
365-
opts = map[string]int{"config_id": configID}
374+
if opts.ConfigID != 0 {
375+
payload = opts // Use the struct when ConfigID is set
376+
} else {
377+
payload = InstanceRebootOptions{} // Send an empty JSON object when ConfigID is 0
366378
}
367379

368380
e := formatAPIPath("linode/instances/%d/reboot", linodeID)
369-
return doPOSTRequestNoResponseBody(ctx, c, e, opts)
381+
return doPOSTRequestNoResponseBody(ctx, c, e, payload)
370382
}
371383

372384
// InstanceRebuildOptions is a struct representing the options to send to the rebuild linode endpoint

request_helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ func doPOSTRequestNoResponseBody[T any](
159159
return err
160160
}
161161

162+
// doPOSTRequestNoRequestBody runs a POST request using the given client and API endpoint.
163+
// It does not expect a request body but does expect a response from the endpoint.
164+
func doPOSTRequestNoRequestBody[T any](
165+
ctx context.Context,
166+
client *Client,
167+
endpoint string,
168+
) (*T, error) {
169+
return doPOSTRequest[T, any](ctx, client, endpoint)
170+
}
171+
162172
// doPOSTRequestNoRequestResponseBody runs a POST request where no request body is needed and no response body
163173
// is expected from the endpoints.
164174
func doPOSTRequestNoRequestResponseBody(

0 commit comments

Comments
 (0)