Skip to content

new: Add support for Parent/Child account switching#455

Merged
lgarber-akamai merged 24 commits intolinode:proj/parent-childfrom
lgarber-akamai:new/parent-child
Mar 6, 2024
Merged

new: Add support for Parent/Child account switching#455
lgarber-akamai merged 24 commits intolinode:proj/parent-childfrom
lgarber-akamai:new/parent-child

Conversation

@lgarber-akamai
Copy link
Contributor

@lgarber-akamai lgarber-akamai commented Feb 13, 2024

📝 Description

This change adds preemptive support for the Parent/Child Account Switching feature, including the following changes:

  • New endpoint methods:
    • client.ListChildAccounts(...)
    • client.GetChildAccount(...)
    • client.CreateChildAccountToken(...)
  • Updated structs:
    • linodego.User now contains a UserType field

In addition to the above changes, this change brings the linodego.Account struct up to parity with the current API response.

This change also makes the following testing/helper changes:

  • The test package now has a unit directory for storing mock tests
  • The test package now imports testify/require to make tests more concise

Depends on #458

✔️ How to Test

The following test steps assume you have pulled down this PR locally and are using the token and URL for a parent account in dev.

Unit Testing

make testunit

E2E Testing

make ARGS="-run TestUser" fixtures
make TEST_TAGS="parent_child" ARGS="-run TestAccount" fixtures

Manual Testing

  1. In a manual testing environment (e.g. dx-devenv), run the following script:
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/linode/linodego"
	"github.com/sanity-io/litter"
)

func main() {
	ctx := context.Background()

	client := linodego.NewClient(nil)
	client.SetToken(os.Getenv("LINODE_TOKEN"))

	childAccounts, err := client.ListChildAccounts(ctx, nil)
	if err != nil {
		log.Fatal(err)
	}

	childAccount, err := client.GetChildAccount(ctx, childAccounts[0].EUUID)
	if err != nil {
		log.Fatal(err)
	}

	token, err := client.CreateChildAccountToken(ctx, childAccount.EUUID)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Child Accounts:")
	litter.Dump(childAccounts)

	fmt.Println("\nChild Account:")
	litter.Dump(childAccount)

	fmt.Println("\nChild Account Token:")
	litter.Dump(token)
}
  1. Ensure the output looks similar to the following:
Child Accounts:
[]linodego.Account{
  linodego.Account{
    FirstName: "DX-Child",
    ...
  },
}

Child Account:
&linodego.Account{
  FirstName: "DX-Child",
  ...
}

Child Account Token:
&linodego.Token{
  ID: ...,
  Token: ...,
}

Add UserType enum

Add test case for user type

User fixtures

Add unit tests

Oops
@lgarber-akamai lgarber-akamai marked this pull request as ready for review February 13, 2024 21:53
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner February 13, 2024 21:53
@lgarber-akamai lgarber-akamai requested review from yec-akamai and zliang-akamai and removed request for a team February 13, 2024 21:53
Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing tests are passing 👍

@lgarber-akamai lgarber-akamai marked this pull request as draft February 27, 2024 16:20
@lgarber-akamai lgarber-akamai marked this pull request as ready for review February 27, 2024 17:44
@lgarber-akamai
Copy link
Contributor Author

Going to convert this back to a draft while I work to break some of the smaller changes into separate PRs

@lgarber-akamai lgarber-akamai marked this pull request as draft February 28, 2024 16:36
@lgarber-akamai lgarber-akamai marked this pull request as ready for review February 28, 2024 18:02
@zliang-akamai zliang-akamai requested review from a team, jriddle-linode, ykim-akamai and zliang-akamai and removed request for a team March 1, 2024 18:36
@zliang-akamai
Copy link
Member

TEST_TAGS wasn't added into the Makefile?
make TEST_TAGS="parent_child" ARGS="-run TestAccount" fixtures doesn't run any test case on my end..

Copy link
Member

@zliang-akamai zliang-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else tested and looks good!

@lgarber-akamai
Copy link
Contributor Author

@zliang-akamai Oops, looks like it was accidentally dropped when I was fixing some merge conflicts. I can fix it real quick 👍

Copy link
Member

@zliang-akamai zliang-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Change looks good to me.

Unit tests and user tests passed locally. I still don't have the 1pass vault set up for my account, so can't run through the parent/child integration tests on my end.

@lgarber-akamai lgarber-akamai merged commit 1a81a0d into linode:proj/parent-child Mar 6, 2024
@zliang-akamai zliang-akamai added the new-feature for new features in the changelog. label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature for new features in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants