-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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(core) implement entity tagging #4275
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
343925e
feat(db) add tags field to core entities
fffonion dbe2679
feat(db) add support for filtering and paginating by tag
fffonion 7ce073a
feat(api) add support for filtering by tags
fffonion 1071cf2
feat(tags) add the tags entity
fffonion 9f69772
tests(tags) add tests for tags and update entity tests with tags
fffonion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
local endpoints = require "kong.api.endpoints" | ||
|
||
local fmt = string.format | ||
local escape_uri = ngx.escape_uri | ||
|
||
|
||
return { | ||
["/tags/:tags"] = { | ||
GET = function(self, db, helpers, parent) | ||
local data, _, err_t, offset = | ||
endpoints.page_collection(self, db, db.tags.schema, "page_by_tag") | ||
|
||
if err_t then | ||
return endpoints.handle_error(err_t) | ||
end | ||
|
||
local next_page | ||
if offset then | ||
next_page = fmt("/tags/%s?offset=%s", self.params.tags, escape_uri(offset)) | ||
|
||
else | ||
next_page = ngx.null | ||
end | ||
|
||
return kong.response.exit(200, { | ||
data = data, | ||
offset = offset, | ||
next = next_page, | ||
}) | ||
end, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local Tags = {} | ||
|
||
function Tags:page_by_tag(tag, size, offset, options) | ||
local ok, err = self.schema:validate_field(self.schema.fields.tag, tag) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if not ok then | ||
local err_t = self.errors:invalid_unique('tag', err) | ||
return nil, tostring(err_t), err_t | ||
end | ||
|
||
local rows, err_t, offset = self.strategy:page_by_tag(tag, size or 100, offset, options) | ||
if err_t then | ||
return rows, tostring(err_t), err_t | ||
end | ||
return rows, nil, nil, offset | ||
end | ||
|
||
local function noop(self, ...) | ||
local err_t = self.errors:schema_violation({ tags = 'does not support insert/upsert/update/delete operations' }) | ||
return nil, tostring(err_t), err_t | ||
end | ||
|
||
Tags.insert = noop | ||
Tags.delete = noop | ||
Tags.update = noop | ||
Tags.upsert = noop | ||
|
||
return Tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ local CORE_ENTITIES = { | |
"targets", | ||
"plugins", | ||
"cluster_ca", | ||
"tags", | ||
} | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does the
options.tags
filter also work in generated methods for relationships, such asdb.targets:each_for_upstream({ id = U.id }, nil, { tags = T })
? (i.e. "give me all targets of upstream X that have tag T") — there needs to be a test in the suite answering this question :)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.
each_for_* will not support tags because it will not parse "?tags=" from Admin API, and uses a different pager
page_for_*
other than the tag-enabled functionpage
used by normal pagination. I'll add a unit test on each_for_upstream to ensure the functionality doesn't exist.