-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat: add owner/name filter to list clients #2637
Conversation
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.
Awesome, thank you for your contribution! This looks pretty good and I have some ideas how to improve it further :)
client/client.go
Outdated
@@ -200,6 +200,13 @@ type Client struct { | |||
Metadata sqlxx.JSONRawMessage `json:"metadata,omitempty" db:"metadata"` | |||
} | |||
|
|||
type ClientFilters struct { |
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 needs to be added to the swagger spec:
Line 90 in b597c88
type swaggerListClientsParameter struct { |
You can also probably re-use / re-purpose that struct as ClientFilter
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 added the name/owner params to that struct, is that all that needs done?
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.
Yes, that's all that's needed - I think this can be removed then!
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.
The ClientFilters struct is used internally to get passed to the client manager, so new filers could be easily added...
if filters.Name != "" { | ||
query.Where("client_name = ?", filters.Name) | ||
} | ||
if filters.Owner != "" { | ||
query.Where("owner = ?", filters.Owner) | ||
} |
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 probably means that we need to index these fields? Otherwise this will get very slow when you have lots of clients. Then again, if we just have like 1000 clients, it probably wouldn't matter too much (maybe 5ms with index, 200ms without). What do you think?
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 our use case, the index won't make much of a difference
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.
Ok, we can keep the filter omitted for now and add it later.
Codecov Report
@@ Coverage Diff @@
## master #2637 +/- ##
==========================================
+ Coverage 52.47% 52.54% +0.07%
==========================================
Files 234 234
Lines 13905 13924 +19
==========================================
+ Hits 7296 7317 +21
+ Misses 5986 5985 -1
+ Partials 623 622 -1
Continue to review full report at Codecov.
|
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.
Hey there, sorry for the slow review. Was quite a busy few days at Ory as we were working on the cloud platform. Next week I have much more time for reviews and merging things, which is also where I want to merge this PR!
if filters.Name != "" { | ||
query.Where("client_name = ?", filters.Name) | ||
} | ||
if filters.Owner != "" { | ||
query.Where("owner = ?", filters.Owner) | ||
} |
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.
Ok, we can keep the filter omitted for now and add it later.
client/client.go
Outdated
@@ -200,6 +200,13 @@ type Client struct { | |||
Metadata sqlxx.JSONRawMessage `json:"metadata,omitempty" db:"metadata"` | |||
} | |||
|
|||
type ClientFilters struct { |
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.
Yes, that's all that's needed - I think this can be removed then!
This is what I had in mind :) |
This adds client name and owner filters to the client list endpoint.
Related issue(s)
#1485
Checklist
contributing code guidelines.
vulnerability. If this pull request addresses a security. vulnerability, I
confirm that I got green light (please contact
security@ory.sh) from the maintainers to push
the changes.
works.
Further Comments
Still need to update documentation, looking for any initial feedback first