Add the user id to the get create and delete keypair#2146
Add the user id to the get create and delete keypair#2146randomswdev wants to merge 3 commits intogophercloud:masterfrom
Conversation
|
Build failed.
|
|
I think the build failure is not related to my ciode, but is more of an environmental issue. Can someone help me fixing it? |
|
@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 For the Please let me know if you have any questions. |
|
@jtopjian thanks for the comments.
The UserID field is flagged as omitempty, so should be ok based on the guidelines.
I added the 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? |
5294dc7 to
e0e4bc4
Compare
|
@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". |
|
Build failed.
|
|
recheck |
|
Build failed.
|
|
@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. |
@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. |
|
recheck |
|
Build failed.
|
e0e4bc4 to
9815af9
Compare
|
Just rebased on the latest master. |
|
Build failed.
|
jtopjian
left a comment
There was a problem hiding this comment.
@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, "") |
There was a problem hiding this comment.
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, "") |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Similar here: there needs to be a DeleteOpts struct created: https://github.com/gophercloud/gophercloud/blob/master/openstack/blockstorage/v3/qos/requests.go#L67-L100
|
|
||
| func getURL(c *gophercloud.ServiceClient, name string) string { | ||
| return c.ServiceURL(resourcePath, name) | ||
| func getURL(c *gophercloud.ServiceClient, name string, userID string) string { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Similar here: by using DeleteOpts, you should be able to revert this.
|
@randomswdev Thank you for your work on this. This work was amended to #2186 and merged. |
For #2145
The capability to create of get the keypair of another user is documented in the Nova Rest API reference:
https://docs.openstack.org/api-ref/compute/?expanded=list-keypairs-detail,show-keypair-details-detail,create-or-import-keypair-detail#create-or-import-keypair
This pull request adds the capability to create or get the keypairs also for another user.