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

Refactor #45

Merged
merged 3 commits into from
Nov 4, 2020
Merged

Refactor #45

merged 3 commits into from
Nov 4, 2020

Conversation

tri-adam
Copy link
Member

@tri-adam tri-adam commented Aug 6, 2020

Use functional arguments for NewClient. Modify (*Client).NewRequest to accept a context and a relative URL reference. Add (*Client).Do method. Add HTTPError type to represent unsuccessful HTTP responses, utilizing Go 1.13 error wrapping. Improve documentation around errors. Improve testing.

Return version string directly from (*Client).GetVersion.

Accept all 2xx HTTP status codes as successful.

@tri-adam tri-adam force-pushed the refactor branch 4 times, most recently from 9fb38d6 to aecd579 Compare August 7, 2020 17:22
client/client.go Outdated
}

const defaultBaseURL = "https://keys.sylabs.io/"
// Client describes the client details.
type Client struct {
Copy link

Choose a reason for hiding this comment

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

@tri-adam Would it be possible to also pass a callback function in order to grab the body content response or copy the content to retrieve if after the request ? In case of success it could be helpful to display content to give some hint. As for error by example in pkg/sypgp/sypgp.go there is an hardcoded hint to guide users about authentication, as this is something specific to an endpoint the keyserver could provide this hint instead via the JSON error response with a hint field maybe ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @cclerget, apologies for the slow response!

I'm making the assumption you're referring solely to (*Client).PKSLookup(), as that's the relevant API for the specific part of the code you reference in the sypgp package.

I'm not sure there is much use to have an alternative way to get a copy of the body when the request was successful, since it is already returned in its entirety in this case.

When the request is unsuccessful, it will return a (*github.com/sylabs/scs-key-client/client).HTTPError, which a caller could then use errors.As() and (*HTTPError).Code() to obtain the HTTP status code. Since the HKP draft specification really doesn't define error/hint formats, this is likely a good level for Singularity to do its logic at in terms of whether authentication is necessary.

The use case you describe about providing hints was actually the inspiration for the github.com/sylabs/json-resp package. Since all Sylabs HKP servers use that format, this module will also return a wrapped jsonresp.Error when the response contains that format, making it possible to return more detailed help to the user via the Message field.

But, back to your question... if the ask is to handle some other type of error format, I would suggest that exposing the response body via a Body() method on the (*github.com/sylabs/scs-key-client/client).HTTPError would be the idiomatic way to do so. The caller could then implement any sort of custom logic they choose to mine any clues from the content of the response.

Let me know what you think, and thanks for taking the time to provide feedback!

Copy link

Choose a reason for hiding this comment

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

Hi @tri-adam , I'm referring to PKSAdd as there is key server like Hagrid https://keys.openpgp.org/about/api by example which are providing some hint as a result of a push because it does additional verification regarding the key being uploaded and it would be nice to return the response message on CLI then a user could proceed with verification by following instructions returned by the server without being misguided by a message like : your key has been successfully pushed. So just returning nil from PKSAdd as a success can't cover those cases.
That's not really related to error as this is pretty much covered and can be done from singularity at this level

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that makes sense, thanks for the clarification. I've opened #47 to track that. I think it's best kept separate from this refactoring, given the scope of this is already quite large.

@tri-adam tri-adam force-pushed the refactor branch 2 times, most recently from 782136c to 4f85e90 Compare November 3, 2020 19:32
@tri-adam tri-adam marked this pull request as ready for review November 3, 2020 20:37
Copy link
Member

@dtrudg dtrudg left a comment

Choose a reason for hiding this comment

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

LGTM me and pairs with singularity via apptainer/singularity#5689 ok. 👍

@tri-adam tri-adam merged commit a4cef10 into sylabs:master Nov 4, 2020
@tri-adam tri-adam deleted the refactor branch November 4, 2020 21:33
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

3 participants