Skip to content

Commit 04e6d0b

Browse files
author
Aliaksei Burau
authored
Default validation (#13)
* Add validation to invalid field * add gentool patch for protoc-gen-atlas-query-validate * update examples * small improvments * latest updates * Fix gramma
1 parent d8257fe commit 04e6d0b

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.10.0 AS builder
2+
3+
LABEL stage=server-intermediate
4+
5+
WORKDIR /go/src/github.com/infobloxopen/protoc-gen-atlas-query-validate
6+
COPY . .
7+
RUN CGO_ENABLED=0 GOOS=linux go build -o /out/usr/bin/protoc-gen-atlas-query-validate main.go
8+
9+
FROM infoblox/atlas-gentool:latest AS runner
10+
11+
COPY --from=builder /out/usr/bin/protoc-gen-atlas-query-validate /usr/bin/protoc-gen-atlas-query-validate
12+
COPY --from=builder /go/src/github.com/infobloxopen/protoc-gen-atlas-query-validate/options/*.proto /go/src/github.com/infobloxopen/protoc-gen-atlas-query-validate/options/
13+
14+
WORKDIR /go/src

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ test: example
2222

2323
.PHONY: vendor
2424
vendor:
25-
dep ensure -vendor-only
25+
dep ensure -vendor-only
26+
27+
.PHONY: gentool
28+
gentool:
29+
docker build -t infoblox/atlas-gentool:test-query .
30+
docker image prune -f --filter label=stage=server-intermediate

example/example.pb.atlas.query.validate.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

options/validate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func ValidateFiltering(f *query.Filtering, messageInfo map[string]FilteringOptio
2929
if !ok {
3030
return fmt.Errorf("Unknown field: %s", fieldTag)
3131
}
32+
if fieldInfo.ValueType == QueryValidate_DEFAULT {
33+
return fmt.Errorf("Filtering is not supported for field %s", fieldTag)
34+
}
3235

3336
tp := ""
3437

@@ -57,8 +60,8 @@ func ValidateFiltering(f *query.Filtering, messageInfo map[string]FilteringOptio
5760
}
5861
nc := &query.Filtering_NumberArrayCondition{x}
5962
tp = query.NumberArrayCondition_Type_name[int32(nc.NumberArrayCondition.Type)]
60-
6163
default:
64+
6265
return nil
6366
}
6467
for _, val := range fieldInfo.Deny {

plugin/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ func (p *QueryValidatePlugin) getFilteringData(msg *generator.Descriptor) []fiel
228228
valueType := opts.GetValueType()
229229
if valueType == options.QueryValidate_DEFAULT {
230230
if field.IsRepeated() {
231+
data = append(data, fieldValidate{fieldName, options.FilteringOption{ValueType: options.QueryValidate_DEFAULT, Deny: []options.QueryValidate_FilterOperator{options.QueryValidate_ALL}}})
231232
continue
232233
}
234+
233235
valueType = p.getValueType(field)
234236
if valueType == options.QueryValidate_DEFAULT {
235237
if field.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE && opts.GetEnableNestedFields() {
@@ -238,7 +240,9 @@ func (p *QueryValidatePlugin) getFilteringData(msg *generator.Descriptor) []fiel
238240
for _, v := range nestedDeny {
239241
data = append(data, fieldValidate{fieldName + "." + v.fieldName, v.option})
240242
}
243+
continue
241244
}
245+
data = append(data, fieldValidate{fieldName, options.FilteringOption{ValueType: options.QueryValidate_DEFAULT, Deny: []options.QueryValidate_FilterOperator{options.QueryValidate_ALL}}})
242246
continue
243247
}
244248

0 commit comments

Comments
 (0)