Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

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 zliang-akamai and yec-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 👍

account_child.go Outdated Show resolved Hide resolved
account.go Outdated Show resolved Hide resolved
@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

@zliang-akamai zliang-akamai requested review from zliang-akamai, a team, jriddle-linode and ykim-1 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
3 checks passed
@zliang-akamai zliang-akamai added the new-feature for new features in the changelog. label Jun 3, 2024
renovate bot added a commit to anza-labs/lke-operator that referenced this pull request Jun 6, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [github.com/linode/linodego](https://github.com/linode/linodego) |
`v1.34.0` -> `v1.35.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2flinode%2flinodego/v1.35.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2flinode%2flinodego/v1.35.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2flinode%2flinodego/v1.34.0/v1.35.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2flinode%2flinodego/v1.34.0/v1.35.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>linode/linodego (github.com/linode/linodego)</summary>

###
[`v1.35.0`](https://github.com/linode/linodego/releases/tag/v1.35.0)

[Compare
Source](https://github.com/linode/linodego/compare/v1.34.0...v1.35.0)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

##### 🚀 New Features

- Add support for Parent/Child account switching by
[@&#8203;lgarber-akamai](https://github.com/lgarber-akamai) and
[@&#8203;jriddle-linode](https://github.com/jriddle-linode) in
[linode/linodego#455
and
[linode/linodego#513

##### 📖 Documentation

- Format code example in README by
[@&#8203;zliang-akamai](https://github.com/zliang-akamai) in
[linode/linodego#510

**Full Changelog**:
linode/linodego@v1.34.0...v1.35.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/anza-labs/lke-operator).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zODguMSIsInVwZGF0ZWRJblZlciI6IjM3LjM4OC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJhcmVhL2RlcGVuZGVuY3kiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

None yet

3 participants