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 functionality for users to retrieve template by Name as well as UUID #523

Closed
wants to merge 5 commits into from

Conversation

Belchy06
Copy link
Contributor

@Belchy06 Belchy06 commented Aug 25, 2021

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:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@Belchy06
Copy link
Contributor Author

@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.

client/main.go Outdated Show resolved Hide resolved
protos/template/template.pb.go Outdated Show resolved Hide resolved
@Belchy06
Copy link
Contributor Author

@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.

@Belchy06 Belchy06 requested a review from mmlb August 26, 2021 02:21
Copy link
Contributor

@tstromberg tstromberg left a 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{
Copy link
Contributor

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 {
Copy link
Contributor

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.")
  }

@Belchy06
Copy link
Contributor Author

Belchy06 commented Sep 1, 2021

Sorry I haven't gotten around to those changes yet @tstromberg , I've been super busy. Will get around to them this weekend.

@tstromberg
Copy link
Contributor

@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 :)

@mmlb
Copy link
Contributor

mmlb commented Oct 19, 2021

Looks like this was originally #516 but mistakenly closed and then opened here which was also mistakenly close and continued in #541.

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