-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Add support for Parent/Child account switching (#455)
* Implement new endpoints Add UserType enum Add test case for user type User fixtures Add unit tests Oops * gofumpt * Address feedback * Consume new helpers * test * Add unit directory; move mock tests * Add integration test * Use variadic * oops * add test note * oops * Use testify in unit tests * Make account tests opt-in * Update README * oops * oops * drop opt in tests * Drop optInTest * Add User.LastLogin * SDF * Support test tags in makefile
- Loading branch information
1 parent
377f746
commit 1a81a0d
Showing
28 changed files
with
1,017 additions
and
394 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
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 linodego | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// ChildAccount represents an account under the current account. | ||
// NOTE: This is an alias to prevent any future breaking changes. | ||
type ChildAccount = Account | ||
|
||
// ChildAccountToken represents a short-lived token created using | ||
// the CreateChildAccountToken(...) function. | ||
// NOTE: This is an alias to prevent any future breaking changes. | ||
type ChildAccountToken = Token | ||
|
||
// ListChildAccounts lists child accounts under the current account. | ||
func (c *Client) ListChildAccounts(ctx context.Context, opts *ListOptions) ([]ChildAccount, error) { | ||
return getPaginatedResults[ChildAccount]( | ||
ctx, | ||
c, | ||
"account/child-accounts", | ||
opts, | ||
) | ||
} | ||
|
||
// GetChildAccount gets a single child accounts under the current account. | ||
func (c *Client) GetChildAccount(ctx context.Context, euuid string) (*ChildAccount, error) { | ||
return doGETRequest[ChildAccount]( | ||
ctx, | ||
c, | ||
formatAPIPath("account/child-accounts/%s", euuid), | ||
) | ||
} | ||
|
||
// CreateChildAccountToken creates a short-lived token that can be used to | ||
// access the Linode API under a child account. | ||
// The attributes of this token are not currently configurable. | ||
func (c *Client) CreateChildAccountToken(ctx context.Context, euuid string) (*ChildAccountToken, error) { | ||
return doPOSTRequest[ChildAccountToken, any]( | ||
ctx, | ||
c, | ||
formatAPIPath("account/child-accounts/%s/token", euuid), | ||
) | ||
} |
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
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
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,40 @@ | ||
//go:build parent_child | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// NOTE: These fixtures are expected to be run under a parent account. | ||
func TestAccountChild_basic(t *testing.T) { | ||
client, teardown := createTestClient(t, "fixtures/TestAccountChild_basic") | ||
defer teardown() | ||
|
||
childAccounts, err := client.ListChildAccounts(context.Background(), nil) | ||
require.NoError(t, err) | ||
require.Greater( | ||
t, | ||
len(childAccounts), | ||
0, | ||
"number of child accounts should be > 0", | ||
) | ||
|
||
childAccount, err := client.GetChildAccount(context.Background(), childAccounts[0].EUUID) | ||
require.NoError(t, err) | ||
require.True( | ||
t, | ||
reflect.DeepEqual(*childAccount, childAccounts[0]), | ||
"child accounts should be equal", | ||
cmp.Diff(*childAccount, childAccounts[0]), | ||
) | ||
|
||
token, err := client.CreateChildAccountToken(context.Background(), childAccount.EUUID) | ||
require.NoError(t, err) | ||
require.Greater(t, len(token.Token), 0) | ||
} |
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
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
Oops, something went wrong.