Skip to content

Commit

Permalink
👻 Relation renamed. (#466)
Browse files Browse the repository at this point in the history
The `Relation` validation was originally added to support:
```
tag=(A,B,C)
```
Where tag = A **and** B **and** C which is implemented as an SQL
INTERSECT.
However, it seems the `Labels` use cases are implemented as JSON query.
This PR attempts to provide a more intuitive name.

Replaces:
```
{Field: "Labels", Kind: qf.STRING, Relation: true}, 
```
With
```
{Field: "Labels", Kind: qf.STRING, And: true}, 
```

---------

Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel authored Aug 7, 2023
1 parent c0393ef commit d58e413
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
30 changes: 15 additions & 15 deletions api/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (h AnalysisHandler) AppDeps(ctx *gin.Context) {
{Field: "version", Kind: qf.STRING},
{Field: "sha", Kind: qf.STRING},
{Field: "indirect", Kind: qf.STRING},
{Field: "labels", Kind: qf.STRING, Relation: true},
{Field: "labels", Kind: qf.STRING, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down Expand Up @@ -488,7 +488,7 @@ func (h AnalysisHandler) AppIssues(ctx *gin.Context) {
{Field: "name", Kind: qf.STRING},
{Field: "category", Kind: qf.STRING},
{Field: "effort", Kind: qf.LITERAL},
{Field: "labels", Kind: qf.STRING, Relation: true},
{Field: "labels", Kind: qf.STRING, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down Expand Up @@ -566,10 +566,10 @@ func (h AnalysisHandler) Issues(ctx *gin.Context) {
{Field: "name", Kind: qf.STRING},
{Field: "category", Kind: qf.STRING},
{Field: "effort", Kind: qf.LITERAL},
{Field: "labels", Kind: qf.STRING, Relation: true},
{Field: "labels", Kind: qf.STRING, And: true},
{Field: "application.id", Kind: qf.LITERAL},
{Field: "application.name", Kind: qf.STRING},
{Field: "tag.id", Kind: qf.LITERAL, Relation: true},
{Field: "tag.id", Kind: qf.LITERAL, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down Expand Up @@ -751,13 +751,13 @@ func (h AnalysisHandler) RuleReports(ctx *gin.Context) {
{Field: "rule", Kind: qf.STRING},
{Field: "category", Kind: qf.STRING},
{Field: "effort", Kind: qf.LITERAL},
{Field: "labels", Kind: qf.STRING, Relation: true},
{Field: "labels", Kind: qf.STRING, And: true},
{Field: "applications", Kind: qf.LITERAL},
{Field: "application.id", Kind: qf.STRING},
{Field: "application.name", Kind: qf.STRING},
{Field: "businessService.id", Kind: qf.LITERAL},
{Field: "businessService.name", Kind: qf.STRING},
{Field: "tag.id", Kind: qf.LITERAL, Relation: true},
{Field: "tag.id", Kind: qf.LITERAL, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down Expand Up @@ -880,7 +880,7 @@ func (h AnalysisHandler) AppIssueReports(ctx *gin.Context) {
{Field: "rule", Kind: qf.STRING},
{Field: "category", Kind: qf.STRING},
{Field: "effort", Kind: qf.LITERAL},
{Field: "labels", Kind: qf.STRING, Relation: true},
{Field: "labels", Kind: qf.STRING, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down Expand Up @@ -1029,12 +1029,12 @@ func (h AnalysisHandler) IssueAppReports(ctx *gin.Context) {
{Field: "issue.rule", Kind: qf.STRING},
{Field: "issue.category", Kind: qf.STRING},
{Field: "issue.effort", Kind: qf.LITERAL},
{Field: "issue.labels", Kind: qf.STRING, Relation: true},
{Field: "issue.labels", Kind: qf.STRING, And: true},
{Field: "application.id", Kind: qf.LITERAL},
{Field: "application.name", Kind: qf.STRING},
{Field: "businessService.id", Kind: qf.LITERAL},
{Field: "businessService.name", Kind: qf.STRING},
{Field: "tag.id", Kind: qf.LITERAL, Relation: true},
{Field: "tag.id", Kind: qf.LITERAL, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down Expand Up @@ -1246,10 +1246,10 @@ func (h AnalysisHandler) Deps(ctx *gin.Context) {
{Field: "version", Kind: qf.STRING},
{Field: "sha", Kind: qf.STRING},
{Field: "indirect", Kind: qf.STRING},
{Field: "labels", Kind: qf.STRING, Relation: true},
{Field: "labels", Kind: qf.STRING, And: true},
{Field: "application.id", Kind: qf.LITERAL},
{Field: "application.name", Kind: qf.STRING},
{Field: "tag.id", Kind: qf.LITERAL, Relation: true},
{Field: "tag.id", Kind: qf.LITERAL, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down Expand Up @@ -1337,13 +1337,13 @@ func (h AnalysisHandler) DepReports(ctx *gin.Context) {
{Field: "version", Kind: qf.STRING},
{Field: "sha", Kind: qf.STRING},
{Field: "indirect", Kind: qf.STRING},
{Field: "labels", Kind: qf.STRING, Relation: true},
{Field: "labels", Kind: qf.STRING, And: true},
{Field: "applications", Kind: qf.LITERAL},
{Field: "application.id", Kind: qf.LITERAL},
{Field: "application.name", Kind: qf.STRING},
{Field: "businessService.id", Kind: qf.LITERAL},
{Field: "businessService.name", Kind: qf.STRING},
{Field: "tag.id", Kind: qf.LITERAL, Relation: true},
{Field: "tag.id", Kind: qf.LITERAL, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down Expand Up @@ -1482,12 +1482,12 @@ func (h AnalysisHandler) DepAppReports(ctx *gin.Context) {
{Field: "dep.version", Kind: qf.LITERAL},
{Field: "dep.sha", Kind: qf.LITERAL},
{Field: "dep.indirect", Kind: qf.LITERAL},
{Field: "dep.labels", Kind: qf.STRING, Relation: true},
{Field: "dep.labels", Kind: qf.STRING, And: true},
{Field: "application.id", Kind: qf.LITERAL},
{Field: "application.name", Kind: qf.STRING},
{Field: "businessService.id", Kind: qf.LITERAL},
{Field: "businessService.name", Kind: qf.STRING},
{Field: "tag.id", Kind: qf.LITERAL, Relation: true},
{Field: "tag.id", Kind: qf.LITERAL, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down
8 changes: 4 additions & 4 deletions api/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ func (f *Field) operator() (s string) {
//
// Assert -
type Assert struct {
Field string
Kind byte
Relation bool
Field string
Kind byte
And bool
}

//
Expand All @@ -372,7 +372,7 @@ func (r *Assert) assert(p *Predicate) (err error) {
return
}
}
if !r.Relation {
if !r.And {
if (&Field{*p}).Value.Operator(AND) {
err = Errorf("(,,) cannot be used with '%s'.", name)
return
Expand Down
3 changes: 2 additions & 1 deletion api/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (h RuleSetHandler) Get(ctx *gin.Context) {
// @summary List all bindings.
// @description List all bindings.
// @description filters:
// @description - name
// @description - labels
// @tags rulesets
// @produce json
Expand All @@ -79,7 +80,7 @@ func (h RuleSetHandler) List(ctx *gin.Context) {
filter, err := qf.New(ctx,
[]qf.Assert{
{Field: "name", Kind: qf.STRING},
{Field: "labels", Kind: qf.STRING},
{Field: "labels", Kind: qf.STRING, And: true},
})
if err != nil {
_ = ctx.Error(err)
Expand Down

0 comments on commit d58e413

Please sign in to comment.