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

Token Management Add/Remove/List/Update #1611

Merged
merged 26 commits into from Apr 17, 2024

Conversation

aliotta
Copy link
Contributor

@aliotta aliotta commented Mar 28, 2024

Description

Adds the ability to Add/Remove/List/Update the following

  • org api tokens in workspaces
  • org api tokens in deployments
  • workspace api tokens in deployments

🎟 Issue(s)

Related #19973

🧪 Functional Testing

  • tested all 12 new commands to verify they were working as expected against dev using various combinations of optional flags passed in. Including passing in a name param instead of an id, passing in an id, not passsing in an id and having the user select the token from a list. Passing and not passing in a role flag. tested the checks preventing a user from modifying the wrong type of token with a given cmd e.g. you cannot pass in a deployment api token id to an update org token cmd.

📸 Screenshots

Screenshot 2024-04-16 at 10 46 43 AM Screenshot 2024-04-16 at 10 50 03 AM Screenshot 2024-04-16 at 11 20 40 AM

📋 Checklist

  • Rebased from the main (or release if patching) branch (before testing)
  • Ran make test before taking out of draft
  • Ran make lint before taking out of draft
  • Added/updated applicable tests
  • Tested against Astro-API (if necessary).
  • Tested against Houston-API and Astronomer (if necessary).
  • Communicated to/tagged owners of respective clients potentially impacted by these changes.
  • Updated any related documentation

Copy link

codecov bot commented Apr 8, 2024

Codecov Report

Attention: Patch coverage is 89.25400% with 121 lines in your changes are missing coverage. Please review.

Project coverage is 86.77%. Comparing base (a9f4c7c) to head (124c82a).
Report is 9 commits behind head on main.

Files Patch % Lines
cloud/workspace-token/workspace_token.go 82.90% 44 Missing and 29 partials ⚠️
cloud/deployment/deployment_token.go 90.11% 13 Missing and 13 partials ⚠️
cmd/cloud/deployment.go 91.30% 8 Missing and 8 partials ⚠️
cloud/organization/organization_token.go 94.18% 3 Missing and 2 partials ⚠️
cloud/team/team.go 97.22% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1611      +/-   ##
==========================================
+ Coverage   86.59%   86.77%   +0.18%     
==========================================
  Files         114      114              
  Lines       16080    16661     +581     
==========================================
+ Hits        13924    14458     +534     
- Misses       1293     1315      +22     
- Partials      863      888      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aliotta aliotta changed the title DRAFT wip Token Management Add/Remove Apr 9, 2024
@aliotta aliotta marked this pull request as ready for review April 9, 2024 15:33
@@ -1,16 +1,20 @@
package workspace
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to move this into a seperate file to prevent a cyclic import (caused by our auth package importing workspace and the new workspace token code importing organization)

@aliotta aliotta changed the title Token Management Add/Remove Token Management Add/Remove/List/Update Apr 9, 2024
req.Header.Add("x-astro-client-identifier", "cli")
req.Header.Add("x-astro-client-version", version.CurrVersion)
req.Header.Add("x-client-os-identifier", os+"-"+arch)
req.Header.Add("User-Agent", fmt.Sprintf("astro-cli/%s", version.CurrVersion))

Choose a reason for hiding this comment

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

Should we add a request header for the API version as well? We do want to get to v1 so tracking API versions in the client could help with this effort. @vandyliu @fredzhy what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

API version is already handled on core API side so we don't need that info from the clients

@@ -10,10 +10,14 @@ import (
"time"

astrocore "github.com/astronomer/astro-cli/astro-client-core"
astrocoreiam "github.com/astronomer/astro-cli/astro-client-iam-core"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
astrocoreiam "github.com/astronomer/astro-cli/astro-client-iam-core"
astroiamcore "github.com/astronomer/astro-cli/astro-client-iam-core"

Just so we stay consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done for all files

@@ -10,10 +10,14 @@ import (
"time"

astrocore "github.com/astronomer/astro-cli/astro-client-core"
astrocoreiam "github.com/astronomer/astro-cli/astro-client-iam-core"
"github.com/astronomer/astro-cli/cloud/organization"
workspace2 "github.com/astronomer/astro-cli/cloud/workspace-token"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this? workspace2 sounds confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done for all files

Comment on lines 425 to 426
if tokenTypes != nil { // verify the user has passed in an id that matches the operations expected token type
if len(*tokenTypes) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if tokenTypes != nil { // verify the user has passed in an id that matches the operations expected token type
if len(*tokenTypes) > 0 {
if tokenTypes != nil && len(*tokenTypes) > 0 { // verify the user has passed in an id that matches the operations expected token type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done for all files

@@ -112,28 +121,20 @@ func CreateToken(name, description, role, deployment string, expiration int, cle
}

// Update a deployment token
func UpdateToken(id, name, newName, description, role, deployment string, out io.Writer, client astrocore.CoreClient) error {
func UpdateToken(id, name, newName, description, role, deployment string, out io.Writer, client astrocore.CoreClient, iamClient astrocoreiam.CoreClient) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func UpdateToken(id, name, newName, description, role, deployment string, out io.Writer, client astrocore.CoreClient, iamClient astrocoreiam.CoreClient) error {
func UpdateToken(id, name, newName, description, role, deploymentID string, out io.Writer, client astrocore.CoreClient, iamClient astrocoreiam.CoreClient) error {

Copy link
Contributor

Choose a reason for hiding this comment

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

Same for all other functions too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done for all files

return nil
}

func UpsertWorkspaceTokenDeploymentRole(id, name, role, workspace, deployment, operation string, out io.Writer, client astrocore.CoreClient, iamClient astrocoreiam.CoreClient) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func UpsertWorkspaceTokenDeploymentRole(id, name, role, workspace, deployment, operation string, out io.Writer, client astrocore.CoreClient, iamClient astrocoreiam.CoreClient) error {
func UpsertWorkspaceTokenDeploymentRole(id, name, role, workspaceID, deploymentID, operation string, out io.Writer, client astrocore.CoreClient, iamClient astrocoreiam.CoreClient) error {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done for all files

if roles[i].Role == role {
return errWorkspaceTokenInDeployment
} else {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The continue is needed as line 614 would assign the old deployment role to the token instead of the role the user is assigning.

Comment on lines 604 to 605
if roles[i].EntityId == deployment {
if roles[i].Role == role {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if roles[i].EntityId == deployment {
if roles[i].Role == role {
if roles[i].EntityId == deployment && roles[i].Role == role {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The continue is needed

apiTokenDeploymentRoles := []astrocore.ApiTokenDeploymentRoleRequest{apiTokenDeploymentRole}
roles := *token.Roles
for i := range roles {
if roles[i].EntityId == deployment {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments as above function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The continue is needed

Short: "Update a Deployment or Organaization API token",
Long: "Update a Deployment or Organaization API token that has a role in an Astro Deployment\n$astro workspace token update [TOKEN_ID] --name [new token name] --role [Possible values are DEPLOYMENT_ADMIN or a custom role name].",
Short: "Update a Deployment API token",
Long: "Update a Deployment API token that has a role in an Astro Deployment\n$astro workspace token update [TOKEN_ID] --name [new token name] --role [Possible values are DEPLOYMENT_ADMIN or a custom role name].",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Long: "Update a Deployment API token that has a role in an Astro Deployment\n$astro workspace token update [TOKEN_ID] --name [new token name] --role [Possible values are DEPLOYMENT_ADMIN or a custom role name].",
Long: "Update a Deployment API token that has a role in an Astro Deployment\n$astro deployment token update [TOKEN_ID] --name [new token name] --role [Possible values are DEPLOYMENT_ADMIN or a custom role name].",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good eyes

@kushalmalani
Copy link
Contributor

A bunch of the comments are applicable in other files too, so if you addressing them, please scan through all the files in this PR for similar changes.

Since this PR is adding a lot of new commands, it would be helpful if you can post screenshots of them working against dev for more confidence

Copy link
Contributor

@kushalmalani kushalmalani left a comment

Choose a reason for hiding this comment

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

Thanks for addressing comments. Looks good

@aliotta aliotta merged commit 0383381 into main Apr 17, 2024
4 of 5 checks passed
@aliotta aliotta deleted the addOrgAndWorkspaceTokenToDeployment branch April 17, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants