Skip to content

Commit afe5d0b

Browse files
Merge branch 'main' into TPT-2873_firewall_rules-instance_firewalls
2 parents fe6772e + 87439ea commit afe5d0b

File tree

95 files changed

+28430
-15208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+28430
-15208
lines changed

account_child.go

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type ChildAccount = Account
1414
type ChildAccountToken = Token
1515

1616
// ListChildAccounts lists child accounts under the current account.
17+
// NOTE: Parent/Child related features may not be generally available.
1718
func (c *Client) ListChildAccounts(ctx context.Context, opts *ListOptions) ([]ChildAccount, error) {
1819
return getPaginatedResults[ChildAccount](
1920
ctx,
@@ -24,6 +25,7 @@ func (c *Client) ListChildAccounts(ctx context.Context, opts *ListOptions) ([]Ch
2425
}
2526

2627
// GetChildAccount gets a single child accounts under the current account.
28+
// NOTE: Parent/Child related features may not be generally available.
2729
func (c *Client) GetChildAccount(ctx context.Context, euuid string) (*ChildAccount, error) {
2830
return doGETRequest[ChildAccount](
2931
ctx,
@@ -35,6 +37,7 @@ func (c *Client) GetChildAccount(ctx context.Context, euuid string) (*ChildAccou
3537
// CreateChildAccountToken creates a short-lived token that can be used to
3638
// access the Linode API under a child account.
3739
// The attributes of this token are not currently configurable.
40+
// NOTE: Parent/Child related features may not be generally available.
3841
func (c *Client) CreateChildAccountToken(ctx context.Context, euuid string) (*ChildAccountToken, error) {
3942
return doPOSTRequest[ChildAccountToken, any](
4043
ctx,

account_users.go

+12-53
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ package linodego
33
import (
44
"context"
55
"encoding/json"
6-
"fmt"
7-
"net/url"
86
"time"
97

10-
"github.com/go-resty/resty/v2"
118
"github.com/linode/linodego/internal/parseabletime"
129
)
1310

@@ -82,91 +79,53 @@ func (i User) GetUpdateOptions() (o UserUpdateOptions) {
8279
return
8380
}
8481

85-
// UsersPagedResponse represents a paginated User API response
86-
type UsersPagedResponse struct {
87-
*PageOptions
88-
Data []User `json:"data"`
89-
}
90-
91-
// endpoint gets the endpoint URL for User
92-
func (UsersPagedResponse) endpoint(_ ...any) string {
93-
return "account/users"
94-
}
95-
96-
func (resp *UsersPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
97-
res, err := coupleAPIErrors(r.SetResult(UsersPagedResponse{}).Get(e))
98-
if err != nil {
99-
return 0, 0, err
100-
}
101-
castedRes := res.Result().(*UsersPagedResponse)
102-
resp.Data = append(resp.Data, castedRes.Data...)
103-
return castedRes.Pages, castedRes.Results, nil
104-
}
105-
10682
// ListUsers lists Users on the account
10783
func (c *Client) ListUsers(ctx context.Context, opts *ListOptions) ([]User, error) {
108-
response := UsersPagedResponse{}
109-
err := c.listHelper(ctx, &response, opts)
84+
response, err := getPaginatedResults[User](ctx, c, "account/users", opts)
11085
if err != nil {
11186
return nil, err
11287
}
11388

114-
return response.Data, nil
89+
return response, nil
11590
}
11691

11792
// GetUser gets the user with the provided ID
11893
func (c *Client) GetUser(ctx context.Context, userID string) (*User, error) {
119-
userID = url.PathEscape(userID)
120-
e := fmt.Sprintf("account/users/%s", userID)
121-
req := c.R(ctx).SetResult(&User{})
122-
r, err := coupleAPIErrors(req.Get(e))
94+
e := formatAPIPath("account/users/%s", userID)
95+
response, err := doGETRequest[User](ctx, c, e)
12396
if err != nil {
12497
return nil, err
12598
}
12699

127-
return r.Result().(*User), nil
100+
return response, nil
128101
}
129102

130103
// CreateUser creates a User. The email address must be confirmed before the
131104
// User account can be accessed.
132105
func (c *Client) CreateUser(ctx context.Context, opts UserCreateOptions) (*User, error) {
133-
body, err := json.Marshal(opts)
134-
if err != nil {
135-
return nil, err
136-
}
137-
138106
e := "account/users"
139-
req := c.R(ctx).SetResult(&User{}).SetBody(string(body))
140-
r, err := coupleAPIErrors(req.Post(e))
107+
response, err := doPOSTRequest[User](ctx, c, e, opts)
141108
if err != nil {
142109
return nil, err
143110
}
144111

145-
return r.Result().(*User), nil
112+
return response, nil
146113
}
147114

148115
// UpdateUser updates the User with the specified id
149116
func (c *Client) UpdateUser(ctx context.Context, userID string, opts UserUpdateOptions) (*User, error) {
150-
body, err := json.Marshal(opts)
151-
if err != nil {
152-
return nil, err
153-
}
154-
155-
userID = url.PathEscape(userID)
156-
e := fmt.Sprintf("account/users/%s", userID)
157-
req := c.R(ctx).SetResult(&User{}).SetBody(string(body))
158-
r, err := coupleAPIErrors(req.Put(e))
117+
e := formatAPIPath("account/users/%s", userID)
118+
response, err := doPUTRequest[User](ctx, c, e, opts)
159119
if err != nil {
160120
return nil, err
161121
}
162122

163-
return r.Result().(*User), nil
123+
return response, nil
164124
}
165125

166126
// DeleteUser deletes the User with the specified id
167127
func (c *Client) DeleteUser(ctx context.Context, userID string) error {
168-
userID = url.PathEscape(userID)
169-
e := fmt.Sprintf("account/users/%s", userID)
170-
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
128+
e := formatAPIPath("account/users/%s", userID)
129+
err := doDELETERequest(ctx, c, e)
171130
return err
172131
}

betas.go

+6-32
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ package linodego
33
import (
44
"context"
55
"encoding/json"
6-
"fmt"
7-
"net/url"
86
"time"
97

10-
"github.com/go-resty/resty/v2"
118
"github.com/linode/linodego/internal/parseabletime"
129
)
1310

@@ -32,17 +29,6 @@ type BetaProgram struct {
3229
MoreInfo string `json:"more_info"`
3330
}
3431

35-
// BetasPagedResponse represents a paginated Beta Programs API response
36-
type BetasPagedResponse struct {
37-
*PageOptions
38-
Data []BetaProgram `json:"data"`
39-
}
40-
41-
// endpoint gets the endpoint URL for BetaProgram
42-
func (BetasPagedResponse) endpoint(_ ...any) string {
43-
return "/betas"
44-
}
45-
4632
// UnmarshalJSON implements the json.Unmarshaler interface
4733
func (beta *BetaProgram) UnmarshalJSON(b []byte) error {
4834
type Mask BetaProgram
@@ -65,35 +51,23 @@ func (beta *BetaProgram) UnmarshalJSON(b []byte) error {
6551
return nil
6652
}
6753

68-
func (resp *BetasPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
69-
res, err := coupleAPIErrors(r.SetResult(BetasPagedResponse{}).Get(e))
70-
if err != nil {
71-
return 0, 0, err
72-
}
73-
castedRes := res.Result().(*BetasPagedResponse)
74-
resp.Data = append(resp.Data, castedRes.Data...)
75-
return castedRes.Pages, castedRes.Results, nil
76-
}
77-
7854
// ListBetaPrograms lists active beta programs
7955
func (c *Client) ListBetaPrograms(ctx context.Context, opts *ListOptions) ([]BetaProgram, error) {
80-
response := BetasPagedResponse{}
81-
err := c.listHelper(ctx, &response, opts)
56+
response, err := getPaginatedResults[BetaProgram](ctx, c, "/betas", opts)
8257
if err != nil {
8358
return nil, err
8459
}
85-
return response.Data, nil
60+
61+
return response, nil
8662
}
8763

8864
// GetBetaProgram gets the beta program's detail with the ID
8965
func (c *Client) GetBetaProgram(ctx context.Context, betaID string) (*BetaProgram, error) {
90-
req := c.R(ctx).SetResult(&BetaProgram{})
91-
betaID = url.PathEscape(betaID)
92-
b := fmt.Sprintf("betas/%s", betaID)
93-
r, err := coupleAPIErrors(req.Get(b))
66+
e := formatAPIPath("betas/%s", betaID)
67+
response, err := doGETRequest[BetaProgram](ctx, c, e)
9468
if err != nil {
9569
return nil, err
9670
}
9771

98-
return r.Result().(*BetaProgram), nil
72+
return response, nil
9973
}

0 commit comments

Comments
 (0)