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

Add dep api token crud #1564

Merged
merged 23 commits into from Feb 29, 2024
Merged

Add dep api token crud #1564

merged 23 commits into from Feb 29, 2024

Conversation

aliotta
Copy link
Contributor

@aliotta aliotta commented Feb 22, 2024

Description

Describe the purpose of this pull request.

Adds the ability to manage deployment api tokens including Creation, Removal, Updating the apiToken role, and Listing.

🎟 Issue(s)

Related #18928

🧪 Functional Testing

List the functional testing steps to confirm this feature or fix.

Use the cli to create, update, remove and delete deployment api tokens passing in the flags that are required and testing both passing in and not passing in the optional flags

📸 Screenshots

Screenshot 2024-02-26 at 3 57 02 PM

📋 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

@aliotta aliotta marked this pull request as ready for review February 26, 2024 20:43
Copy link

codecov bot commented Feb 26, 2024

Codecov Report

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

Project coverage is 86.51%. Comparing base (81b3793) to head (e648de4).
Report is 4 commits behind head on main.

Files Patch % Lines
cloud/apitoken/apitoken.go 90.44% 8 Missing and 7 partials ⚠️
cmd/cloud/deployment.go 95.78% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1564      +/-   ##
==========================================
+ Coverage   86.41%   86.51%   +0.09%     
==========================================
  Files         113      114       +1     
  Lines       15668    15918     +250     
==========================================
+ Hits        13540    13771     +231     
- Misses       1280     1290      +10     
- Partials      848      857       +9     

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

}
err = astrocore.NormalizeAPIError(resp.HTTPResponse, resp.Body)
if err != nil {
fmt.Println("error in NormalizeAPIError")
Copy link
Contributor

Choose a reason for hiding this comment

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

@sunkickr @kushalmalani
do we normally have this here and if so do we want to keep doing it like this?
I'm wondering since it would be meaningless for the user to see, but I guess it would be useful for us if we need to debug

Copy link
Contributor

Choose a reason for hiding this comment

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

I think most API calls have this but I have never seen it actually come up

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah would be useful for debugging. Can we improve that error message though? it looks like a debugging log

Copy link
Contributor Author

@aliotta aliotta Feb 29, 2024

Choose a reason for hiding this comment

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

tbh it seems unecessary to me as the method that calls it prints out a prettier error message

e.g.

shrividyahegde@Hegde ~ % astro deployment user update --deployment-id clt6yb6vm001r01nmwzffhbs9
Enter a user Deployment role or custom role name to update user: sample

error in NormalizeAPIError
Error: Invalid request: Role sample does not exist
shrividyahegde@Hegde ~ %

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 removed them

}

if apiTokenID == "" {
// Get all org apiTokens. Setting limit to 1000 for now
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
// Get all org apiTokens. Setting limit to 1000 for now
// Get all deployment apiTokens. Setting limit to 1000 for now

@vandyliu
Copy link
Contributor

@shri-astro @sreenusuuda
Just a heads up for more QA that will need to be done for adding deployment tokens to CLI

@sunkickr
Copy link
Contributor

Why do we call it remove instead of delete? The api token is being deleted correct? Remove makes it sound like the token is being removed from the deployment but still exists

@aliotta
Copy link
Contributor Author

aliotta commented Feb 28, 2024

Why do we call it remove instead of delete? The api token is being deleted correct? Remove makes it sound like the token is being removed from the deployment but still exists

Good call. That verbiage was a holdover from remove user/team from deployment (where I was riffing from) but does not fit here. I will update to delete.

@aliotta
Copy link
Contributor Author

aliotta commented Feb 29, 2024

Why do we call it remove instead of delete? The api token is being deleted correct? Remove makes it sound like the token is being removed from the deployment but still exists

done

@aliotta aliotta merged commit 72d98da into main Feb 29, 2024
4 of 5 checks passed
@aliotta aliotta deleted the addDepApiTokenCrud branch February 29, 2024 22:00
return createDeploymentAPIToken(cmd, nil, out)
},
}
cmd.Flags().StringVarP(&apiTokenRole, "role", "r", "", "The role for the "+
Copy link
Contributor

Choose a reason for hiding this comment

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

Should DEPLOYMENT_ADMIN be default role?

DynamicPadding: true,
Header: []string{"NAME", "DESCRIPTION", "ID", "DEPLOYMENT ROLE", "CREATE DATE", "UPDATE DATE"},
}
apiTokens, err := GetDeploymentAPITokens(client, deployment, apiTokenPagnationLimit)
Copy link
Contributor

Choose a reason for hiding this comment

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

if there are no api tokens, we should display an error message, rather than an empty table with only headers

Name: name,
Description: &description,
}
resp, err := client.CreateDeploymentApiTokenWithResponse(httpContext.Background(), ctx.Organization, deployment, mutateAPITokenInput)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should save the api token from response to ASTRO_API_TOKEN variable. Right now, the token gets created, but user cannot use the token value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will get a pr up for your comments

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 think instead of setting it we really want to print it to screen so they can use it where they want to.

Copy link
Contributor

Choose a reason for hiding this comment

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

worried about the token leaking in ci cd logs...

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