Skip to content

Add the user id to the get create and delete keypair#2146

Closed
randomswdev wants to merge 3 commits intogophercloud:masterfrom
randomswdev:keypair-add-userid
Closed

Add the user id to the get create and delete keypair#2146
randomswdev wants to merge 3 commits intogophercloud:masterfrom
randomswdev:keypair-add-userid

Conversation

@randomswdev
Copy link
Copy Markdown
Contributor

@randomswdev randomswdev commented Apr 25, 2021

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 25, 2021

Coverage Status

Coverage increased (+0.008%) to 79.924% when pulling 9815af9 on randomswdev:keypair-add-userid into 05c2cc8 on gophercloud:master.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Apr 25, 2021

Build failed.

@randomswdev
Copy link
Copy Markdown
Contributor Author

I think the build failure is not related to my ciode, but is more of an environmental issue. Can someone help me fixing it?

@jtopjian
Copy link
Copy Markdown
Contributor

@randomswdev Thanks for submitting this. I encourage you to read our contributor tutorial, specifically Step 3, to gather all of the information needed for this PR.

The way this is being implemented is a pretty large breaking change. Normally I don't mind merging patches that cause breaking changes, key pairs are a core resource of openstack and this PR would require a lot of downstream code to be rewritten. Additionally, since this feature was added in a microversion, it's technically not part of the base API calls.

Adding UserID to CreateOpts is fine to do, as long as the guidelines here are followed.

For the Get and Delete functions, I suggest creating new functions for Get and Delete that specifically pass the userID field. Perhaps GetWithUserID and DeleteWithUserID.

Please let me know if you have any questions.

@randomswdev
Copy link
Copy Markdown
Contributor Author

@jtopjian thanks for the comments.

Adding UserID to CreateOpts is fine to do, as long as the guidelines here are followed.

The UserID field is flagged as omitempty, so should be ok based on the guidelines.

For the Get and Delete functions, I suggest creating new functions for Get and Delete that specifically pass the userID field. Perhaps GetWithUserID and DeleteWithUserID.

I added the GetWithUserID and DeleteWithUserID functions, and reverted the changes to the interface of Get and Delete, that are now backward compatible.

Let me know if other changes are needed. I'm monuitoring the openlab/check status: if it fails again, is there anything I can do to fix it?

@jtopjian
Copy link
Copy Markdown
Contributor

@randomswdev Thanks!

The OpenLab error might be temporary. If it fails again, you can retrigger it by adding a comment with the single word "recheck".

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Apr 26, 2021

Build failed.

@jtopjian
Copy link
Copy Markdown
Contributor

recheck

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Apr 27, 2021

Build failed.

@jtopjian
Copy link
Copy Markdown
Contributor

@randomswdev The OpenLab error is ignorable - you aren't modifying any of the existing acceptance tests, so it's a problem with OpenLab itself.

Let me know if you're done working on this and if it's ready to be merged.

@randomswdev
Copy link
Copy Markdown
Contributor Author

Let me know if you're done working on this and if it's ready to be merged.

@jtopjian sorry for the delay in answering. Yes, I'm done with hte implementation, so if it is ok for you I think it can be merged.

@randomswdev
Copy link
Copy Markdown
Contributor Author

recheck

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jun 9, 2021

Build failed.

@randomswdev randomswdev force-pushed the keypair-add-userid branch from e0e4bc4 to 9815af9 Compare June 9, 2021 14:10
@randomswdev
Copy link
Copy Markdown
Contributor Author

Just rebased on the latest master.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jun 9, 2021

Build failed.

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

@randomswdev Thanks again for working on this. I've left some comments - please let me know if you have any questions or need any help.

// Get returns public data about a previously uploaded KeyPair.
func Get(client *gophercloud.ServiceClient, name string) (r GetResult) {
resp, err := client.Get(getURL(client, name), &r.Body, nil)
r = GetWithUserID(client, name, "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Get should not be coupled to the new GetWithUserID. They need to be two separate functions that can work unrelated.

// Delete requests the deletion of a previous stored KeyPair from the server.
func Delete(client *gophercloud.ServiceClient, name string) (r DeleteResult) {
resp, err := client.Delete(deleteURL(client, name), nil)
r = DeleteWithUserID(client, name, "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar here, Delete should not call DeleteWithUserID.


// GetWithUserID returns public data about a previously uploaded KeyPair, owned by a specific userID.
// If the userID is an empty string, it searches the KeyPairs of the current user.
func GetWithUserID(client *gophercloud.ServiceClient, name string, userID string) (r GetResult) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of passing in userID in the function parameters, create a GetOpts struct that contains a UserID field. See here for an example: https://github.com/gophercloud/gophercloud/blob/master/openstack/compute/v2/extensions/limits/requests.go

The reason this is done is because the user ID is a query parameter of the URL and not part of the URL itself.


// DeleteWithUserID requests the deletion of a previous stored KeyPair from the server, owned by a specific userID.
// If the userID is an empty string, it deletes the KeyPair of the calling user.
func DeleteWithUserID(client *gophercloud.ServiceClient, name string, userID string) (r DeleteResult) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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


func getURL(c *gophercloud.ServiceClient, name string) string {
return c.ServiceURL(resourcePath, name)
func getURL(c *gophercloud.ServiceClient, name string, userID string) string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By using a GetOpts struct, you should be able to revert getURL back to the original code and just append the query params.


func deleteURL(c *gophercloud.ServiceClient, name string) string {
return getURL(c, name)
func deleteURL(c *gophercloud.ServiceClient, name string, userID string) string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar here: by using DeleteOpts, you should be able to revert this.

@jtopjian
Copy link
Copy Markdown
Contributor

jtopjian commented Jul 2, 2021

@randomswdev Thank you for your work on this. This work was amended to #2186 and merged.

@jtopjian jtopjian closed this Jul 2, 2021
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.

3 participants