-
Notifications
You must be signed in to change notification settings - Fork 138
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
Support fetching templates by name #349
Conversation
7acfae7
to
2efcae7
Compare
Codecov Report
@@ Coverage Diff @@
## master #349 +/- ##
==========================================
+ Coverage 23.79% 24.74% +0.95%
==========================================
Files 14 14
Lines 1244 1277 +33
==========================================
+ Hits 296 316 +20
- Misses 928 940 +12
- Partials 20 21 +1
Continue to review full report at Codecov.
|
I opened up #351 to fix the whitespace issue and avoid it in the future by making sure CI catches. |
Do we want somehow to formalize and make this filtering available for other resources? I am just trying to avoid an unfriendly proliferation of different filters that probably sounds useful short term but won't make usability nice in long term |
@gianarb Can you elaborate? Are you suggesting we should also provide the option to filter by any attribute of a resource? |
@kdeng3849 yeah something like that. I am wondering if we should build this feature in a way that will allow us to get filtering done for all the resources across fields in a consistent way. Without building something ad hoc for one case. I think having the filtering done one by one will make the UX inconsistent and not great |
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.
We need a rebase, @mmlb 's fault :P
oh that merged already? :toot: |
25ae6d9
to
8d15c9a
Compare
8d15c9a
to
7d790bc
Compare
grpc-server/template_test.go
Outdated
want struct { | ||
expectedError bool | ||
} |
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.
can we make this something like:
want struct { | |
expectedError bool | |
} | |
err bool |
instead? No need to define a struct for just one type and its easier to use too.
Yeah I think maybe something like ...
rpc GetTemplate(GetRequest) returns (WorkflowTemplate)
...
message GetRequest {
oneof get_oneof {
string id = 1;
string name = 2;
}
} we can leave the other oneof options for later if necessary. I think I'd rather see a pattern we can agree on that is extensible to avoid GetBy... for each proto type. Does this line up with what you're thinking @gianarb ? |
7d790bc
to
5dac292
Compare
Yeah I think it sounds good @mmlb |
@mmlb & @gianarb this PR is blocking Central Eng (or @mattcburns ) from moving forward on a commitment integration deadline. While @mmlb comments I think is worthy... I believe this can be served in another ticket. Resulting in unblocking Matt Burns for this deadline. |
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.
I am having some difficulties visualizing the grpc API right now but I don't want to hold more on this :)
cmd/tink-cli/cmd/template/delete.go
Outdated
grID := &template.GetRequest_Id{Id: arg} | ||
req := template.GetRequest{GetBy: grID} |
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.
Can we do it like this instead please:
req := template.GetRequest{
GetBy: &template.GetRequest_Id{
Id: arg,
},
}
No need to introduce a variable that we have to remember to ignore (grID) :D
db/db.go
Outdated
@@ -35,7 +36,7 @@ type hardware interface { | |||
|
|||
type template interface { | |||
CreateTemplate(ctx context.Context, name string, data string, id uuid.UUID) error | |||
GetTemplate(ctx context.Context, id string) (string, string, error) | |||
GetTemplate(ctx context.Context, attributes map[string]string) (string, string, error) |
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.
I think a struct will be better to use here.
protos/template/template.proto
Outdated
@@ -51,4 +51,9 @@ message CreateResponse { | |||
|
|||
message GetRequest { | |||
string id = 1; | |||
string name = 2; |
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.
this is in the wrong commit :D
cmd/tink-cli/cmd/template/list.go
Outdated
@@ -43,7 +43,7 @@ var listCmd = &cobra.Command{ | |||
} | |||
|
|||
func listTemplates(cmd *cobra.Command, t table.Writer) { | |||
list, err := client.TemplateClient.ListTemplates(context.Background(), &template.FilterRequest{Filter: "%"}) | |||
list, err := client.TemplateClient.ListTemplates(context.Background(), &template.FilterRequest{Filter: "*"}) |
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.
this commit should be squashed into the previous one
@@ -2,6 +2,7 @@ package grpcserver | |||
|
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.
Please update the commit message to something like
Add tests for Get filtering
@@ -270,15 +270,18 @@ func (s *server) ShowWorkflowEvents(req *workflow.GetRequest, stream workflow.Wo | |||
return 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.
I think adding createYaml to the commit message would help when looking through git history:
createYaml: use more descriptive argument names
Rename temp and tempData to templateID and templateData for better clarity.
@@ -36,7 +36,7 @@ type hardware interface { | |||
|
|||
type template interface { |
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.
agree with this, but should just be squashed in the commit that does it :D
protos/template/template.proto
Outdated
message FilterRequest { | ||
string filter = 1; | ||
} |
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.
I think it'd be great to have FilterRequest
look like GetRequest
so that we have one way to do filtering. This would also help to convey what field the filter is taking place on.
message FilterRequest {
one_of filter_types {
string name = 1;
}
}
0fc74b6
to
f69a0d0
Compare
Signed-off-by: Kelly Deng <[email protected]>
f69a0d0
to
3f8c387
Compare
Signed-off-by: Kelly Deng <[email protected]>
Signed-off-by: Kelly Deng <[email protected]>
Signed-off-by: Kelly Deng <[email protected]>
Signed-off-by: Kelly Deng <[email protected]>
3f8c387
to
775cdf7
Compare
## Description Fetching a template by name now also returns the associated ID. ## Why is this needed A recent PR #349 added the functionality of fetching a template by name. The returned template is expected to include the ID, name, and template data. However, currently, it would only return the name and the template data. The returned ID is just an empty string. ## How Has This Been Tested? Manually ## How are existing users impacted? What migration steps/scripts do we need? ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [x] added unit or e2e tests - [ ] provided instructions on how to upgrade
Description
Adds the ability to query templates by name.
The
ListTemplates
method has been changed to accept aFilterRequest
instead of justEmpty
.The
FilterRequest
has a fieldfilter
that accepts a string used to match the names of templates. A wildcard*
can be used to match a sequence of zero or more characters.Passing an empty
FilterRequest
will return all templates.Why is this needed
A user might have the following templates:
hello-world
,ubuntu-01
,ubuntu-02
,ubuntu-03
,goodbye-world
and wants to list only the linux templates. Before, they would only be able to either list all of the templates, or only one (and only if they already know the id).With this PR, they can just call
ListTemplates
with theFilterRequest
's filter field toubuntu-*
and it will return onlyubuntu-01
,ubuntu-02
, andubuntu-03
.Fixes: #352 / ENG-9455
How Has This Been Tested?
How are existing users impacted? What migration steps/scripts do we need?
Users using an older version of the tink-cli may experience errors. Best solution is to update the tink-server, tink-cli, and tink-worker to use the images built from this PR
Checklist:
I have: