forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for missing Account-related endpoints (linode#598)
* Added support for missing account endpoints * Addressed PR comments * Fix lint
- Loading branch information
1 parent
551a48a
commit b6c358f
Showing
14 changed files
with
492 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package linodego | ||
|
||
import "context" | ||
|
||
// AccountAgreements represents the agreements and their acceptance status for an Account | ||
type AccountAgreements struct { | ||
EUModel bool `json:"eu_model"` | ||
MasterServiceAgreement bool `json:"master_service_agreement"` | ||
PrivacyPolicy bool `json:"privacy_policy"` | ||
} | ||
|
||
// AccountAgreementsUpdateOptions fields are those accepted by UpdateAccountAgreements | ||
type AccountAgreementsUpdateOptions struct { | ||
EUModel bool `json:"eu_model,omitempty"` | ||
MasterServiceAgreement bool `json:"master_service_agreement,omitempty"` | ||
PrivacyPolicy bool `json:"privacy_policy,omitempty"` | ||
} | ||
|
||
// GetUpdateOptions converts an AccountAgreements to AccountAgreementsUpdateOptions for use in UpdateAccountAgreements | ||
func (i AccountAgreements) GetUpdateOptions() (o AccountAgreementsUpdateOptions) { | ||
o.EUModel = i.EUModel | ||
o.MasterServiceAgreement = i.MasterServiceAgreement | ||
o.PrivacyPolicy = i.PrivacyPolicy | ||
|
||
return | ||
} | ||
|
||
// GetAccountAgreements gets all agreements and their acceptance status for the Account. | ||
func (c *Client) GetAccountAgreements(ctx context.Context) (*AccountAgreements, error) { | ||
return doGETRequest[AccountAgreements](ctx, c, "account/agreements") | ||
} | ||
|
||
// AcknowledgeAccountAgreements acknowledges account agreements for the Account | ||
func (c *Client) AcknowledgeAccountAgreements(ctx context.Context, opts AccountAgreementsUpdateOptions) error { | ||
_, err := doPOSTRequest[AccountAgreements](ctx, c, "account/agreements", opts) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package linodego | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"time" | ||
|
||
"github.com/linode/linodego/internal/parseabletime" | ||
) | ||
|
||
// AccountMaintenance represents a Maintenance object for any entity a user has permissions to view | ||
type AccountMaintenance struct { | ||
Entity *Entity `json:"entity"` | ||
Reason string `json:"reason"` | ||
Status string `json:"status"` | ||
Type string `json:"type"` | ||
When *time.Time `json:"when"` | ||
} | ||
|
||
// The entity being affected by maintenance | ||
type Entity struct { | ||
ID int `json:"id"` | ||
Label string `json:"label"` | ||
Type string `json:"type"` | ||
URL string `json:"url"` | ||
} | ||
|
||
// UnmarshalJSON implements the json.Unmarshaler interface | ||
func (accountMaintenance *AccountMaintenance) UnmarshalJSON(b []byte) error { | ||
type Mask AccountMaintenance | ||
|
||
p := struct { | ||
*Mask | ||
When *parseabletime.ParseableTime `json:"when"` | ||
}{ | ||
Mask: (*Mask)(accountMaintenance), | ||
} | ||
|
||
if err := json.Unmarshal(b, &p); err != nil { | ||
return err | ||
} | ||
|
||
accountMaintenance.When = (*time.Time)(p.When) | ||
|
||
return nil | ||
} | ||
|
||
// ListMaintenances lists Account Maintenance objects for any entity a user has permissions to view | ||
func (c *Client) ListMaintenances(ctx context.Context, opts *ListOptions) ([]AccountMaintenance, error) { | ||
return getPaginatedResults[AccountMaintenance](ctx, c, "account/maintenance", opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestAccountAgreements_Get(t *testing.T) { | ||
client, fixtureTeardown := createTestClient(t, "fixtures/TestAccountAgreements_List") | ||
defer fixtureTeardown() | ||
|
||
_, err := client.GetAccountAgreements(context.Background()) | ||
if err != nil { | ||
t.Errorf("Error getting agreements, expected struct, got error %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/linode/linodego" | ||
) | ||
|
||
func TestAccountMaintenances_List(t *testing.T) { | ||
client, fixtureTeardown := createTestClient(t, "fixtures/TestAccountMaintenances_List") | ||
defer fixtureTeardown() | ||
|
||
listOpts := linodego.NewListOptions(0, "") | ||
_, err := client.ListMaintenances(context.Background(), listOpts) | ||
if err != nil { | ||
t.Errorf("Error listing maintenances, expected array, got error %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: "" | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- linodego/dev https://github.com/linode/linodego | ||
url: https://api.linode.com/v4beta/account/agreements | ||
method: GET | ||
response: | ||
body: '{"privacy_policy": true, "eu_model": false, "master_service_agreement": | ||
false}' | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- "true" | ||
Access-Control-Allow-Headers: | ||
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter | ||
Access-Control-Allow-Methods: | ||
- HEAD, GET, OPTIONS, POST, PUT, DELETE | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Access-Control-Expose-Headers: | ||
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status | ||
Akamai-Internal-Account: | ||
- '*' | ||
Cache-Control: | ||
- max-age=0, no-cache, no-store | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "78" | ||
Content-Security-Policy: | ||
- default-src 'none' | ||
Content-Type: | ||
- application/json | ||
Expires: | ||
- Wed, 30 Oct 2024 14:07:33 GMT | ||
Pragma: | ||
- no-cache | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Authorization, X-Filter | ||
- Authorization, X-Filter | ||
X-Accepted-Oauth-Scopes: | ||
- account:read_only | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
- DENY | ||
X-Oauth-Scopes: | ||
- '*' | ||
X-Ratelimit-Limit: | ||
- "800" | ||
X-Xss-Protection: | ||
- 1; mode=block | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
65 changes: 65 additions & 0 deletions
65
test/integration/fixtures/TestAccountMaintenances_List.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: "" | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- linodego/dev https://github.com/linode/linodego | ||
url: https://api.linode.com/v4beta/account/maintenance?page=1 | ||
method: GET | ||
response: | ||
body: '{"data": [], "page": 1, "pages": 1, "results": 0}' | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- "true" | ||
Access-Control-Allow-Headers: | ||
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter | ||
Access-Control-Allow-Methods: | ||
- HEAD, GET, OPTIONS, POST, PUT, DELETE | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Access-Control-Expose-Headers: | ||
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status | ||
Akamai-Internal-Account: | ||
- '*' | ||
Cache-Control: | ||
- max-age=0, no-cache, no-store | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "49" | ||
Content-Security-Policy: | ||
- default-src 'none' | ||
Content-Type: | ||
- application/json | ||
Expires: | ||
- Wed, 30 Oct 2024 14:06:55 GMT | ||
Pragma: | ||
- no-cache | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Authorization, X-Filter | ||
- Authorization, X-Filter | ||
X-Accepted-Oauth-Scopes: | ||
- '*' | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
- DENY | ||
X-Oauth-Scopes: | ||
- unknown | ||
X-Ratelimit-Limit: | ||
- "800" | ||
X-Xss-Protection: | ||
- 1; mode=block | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package unit | ||
|
||
import ( | ||
"context" | ||
"github.com/jarcoal/httpmock" | ||
"github.com/linode/linodego" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestAccountAgreements_Get(t *testing.T) { | ||
fixtureData, err := fixtures.GetFixture("account_agreements_get") | ||
assert.NoError(t, err) | ||
|
||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
base.MockGet("account/agreements", fixtureData) | ||
|
||
agreements, err := base.Client.GetAccountAgreements(context.Background()) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, true, agreements.EUModel) | ||
assert.Equal(t, true, agreements.PrivacyPolicy) | ||
assert.Equal(t, true, agreements.MasterServiceAgreement) | ||
} | ||
|
||
func TestAccountAgreements_Acknowledge(t *testing.T) { | ||
client := createMockClient(t) | ||
|
||
requestData := linodego.AccountAgreementsUpdateOptions{ | ||
EUModel: true, | ||
MasterServiceAgreement: true, | ||
PrivacyPolicy: true, | ||
} | ||
|
||
httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "account/agreements"), | ||
mockRequestBodyValidate(t, requestData, nil)) | ||
|
||
if err := client.AcknowledgeAccountAgreements(context.Background(), requestData); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
Oops, something went wrong.