-
Notifications
You must be signed in to change notification settings - Fork 137
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 functionality for users to retrieve template by Name as well as UUID #523
Conversation
Signed-off-by: William Belcher <[email protected]>
@tstromberg I had done something funky with my last PR for this and was unable to get the DCO signed off correctly. This PR is essentially the same as the last, just compressed into a single commit with DCO signed off. |
Signed-off-by: William Belcher <[email protected]>
@mmlb Just pushed a commit resolving your requested changes. The TemplateClient was an artefact remaining from the default workflow logic we had implemented locally. Sorry about that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with minor tweaks requested
// Parse arg[0] to see if it is a UUID | ||
if _, err := uuid.Parse(arg); err == nil { | ||
// UUID | ||
req = template.GetRequest{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since req
is already defined on line 32, this can be simplified to:
req.GetBy = &template.GetRequest_Id{Id: arg}
as well as the later else
statement.
if err != nil { | ||
continue | ||
for _, arg := range args { | ||
if _, err := uuid.Parse(arg); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability, handle the exceptional case first so that the rest of the flow can have minimal indentation: https://github.com/golang/go/wiki/CodeReviewComments#indent-error-flow
For instance, handle the err case that lets you search by name, and then call continue
rather than having an else statement:
if _, err := uuid.Parse(arg); err != nil {
// arg is invalid UUID, search for arg in `name` field of db
...
continue
}
// arg is a valid UUID, search for arg in `id` field of db
if opt.RetrieveByID == nil {
return errors.New("Get by ID is not implemented for this resource yet. Please have a look at the issue in GitHub or open a new one.")
}
Sorry I haven't gotten around to those changes yet @tstromberg , I've been super busy. Will get around to them this weekend. |
@Belchy06 - hey, just checking in to see if there is anything you would like help with here. I'm eager to see this PR be merged so that folks can use it :) |
Signed-off-by: William Belcher [email protected]
Description
This PR adds the ability for Tink to retrieve workflows by either UUID or by Name. If the value after
tink template get
is not a valid UUID, Tink will default to searching for the value in the Name field of the templates.This PR also adds a TemplateClient to the Tink client, allowing other services such as Boots to retrieve templates.
Why is this needed
This feature is required for the project I am working on but I am sure there are many other use cases I'm unaware of. Also, tinkerbell/smee#178
How Has This Been Tested?
This has been tested in the VM's based on the Local Setup with Vagrant tutorial, as well as in our personal deployment
How are existing users impacted? What migration steps/scripts do we need?
Checklist:
I have: