The search WSAPI accepts JSON conditions - #31
Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This commit adds a
jsonCondquery parameter toGET /cyclops/sets/{setName}as a safe alternative tocond. The client sends the condition's structure as JSON rather than CCMS command language. mod-cyclops validates it and generates the condition itself, so a value can never be read as syntax.condis unchanged and still works for now — the two are mutually exclusive, and supplying neither remains an unconditional retrieval. At some point, once ui-cyclops is updated to usejsonCond, the security-hole that iscondwill go away.The
jsonCondparameter is simply URL-encoded JSON. The format is documented inramls/cond-schema.json, with a motivating example inramls/examples/cond.json. It represents a tree of clauses with an explicit type discriminator: and/or junctions, not, term (field + abstract relation + value), and filter references. Relations are abstract names (contains,ge,isNull), never CCMS operators, so the backend owns the whole mapping.The JSON-condition decoder and CCMS-condition encoder live in
cyclops/cond.go.DecodeCondbuilds the tree checking only shape;RenderCondchecks it against an optional condition schema (currently vacuous) and emits a CCMS condition, quoting values using the existingsqlString/intval/identhelpers. Trees that are too deep, have too many nodes, or contain too-long list values are rejected.The existing search handler
handleRetrieveaccepts either form of condition.requestCondresolves the two parameters and returns HTTP error 400 if both are supplied or a JSON condition is malformed.Tests: there is a 37-file corpus of JSON conditions under
ramls/condtest/with its ownMakefile, and it's wired intoramls/Makefile. There are also Go tests covering the corpus, the limits, operator injection, the permissive-schema behaviour, and the handler end to end.