Skip to content

Commit d9d2dfd

Browse files
author
Daniil Kukharau
authored
Refactoring (#8)
* Remove redundant test * Major refactoring * Resolve volatility of generated code * Fix Identifier name
1 parent 69c0123 commit d9d2dfd

18 files changed

+448
-675
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ script:
1616
- make vendor
1717
- make install
1818
# NOTE: We will be able to run protoc commands from Travis once
19-
# protoc-gen-atlas-query-perm is added to the atlas gentool. For now, we can just run
19+
# protoc-gen-atlas-query-validate is added to the atlas gentool. For now, we can just run
2020
# tests to ensure that everything works as expected.
2121
- go test -v ./...

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ default: options install
88
options:
99
protoc -I. -I$(SRCPATH) -I./vendor \
1010
--gogo_out="Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor:$(SRCPATH)" \
11-
options/collection_permissions.proto
11+
options/query_validate.proto
1212

1313
.PHONY: install
1414
install:
1515
go install
1616

17-
.PHONY: perm-test
18-
perm-test: ./example/* ./test/*
17+
test: ./example/*
1918
echo ${SRCPATH}
20-
protoc -I. -I${SRCPATH} -I./vendor -I./vendor/github.com/grpc-ecosystem/grpc-gateway --atlas-query-perm_out=. example/example.proto
19+
protoc -I. -I${SRCPATH} -I./vendor -I./vendor/github.com/grpc-ecosystem/grpc-gateway --atlas-query-validate_out=. example/example.proto
2120
go test ./...
2221

2322
.PHONY: vendor

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# protoc-gen-atlas-query-perm
1+
# protoc-gen-atlas-query-validate

example/example.pb.atlas.query.perm.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

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

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

example/example.proto

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@ syntax = "proto3";
33
package example;
44

55
import "google/protobuf/wrappers.proto";
6-
import "github.com/infobloxopen/protoc-gen-atlas-query-perm/options/collection_permissions.proto";
6+
import "github.com/infobloxopen/protoc-gen-atlas-query-validate/options/query_validate.proto";
77
import "github.com/infobloxopen/atlas-app-toolkit/query/collection_operators.proto";
88

99
message User {
10-
string first_name = 1 [(atlas.query.permissions).filters.allow = "MATCH"];
11-
float weight = 2 [(atlas.query.permissions).filters.deny = "LE"];
12-
bool on_vacation = 3 [(atlas.query.permissions).disable_sorting = true];
13-
string speciality = 4 [(atlas.query.permissions) = {filters: {allow: "MATCH"}, disable_sorting: true}];
10+
string first_name = 1 [(atlas.query.validate) = {allow: MATCH, allow: EQ}];
11+
float weight = 2 [(atlas.query.validate).deny = LE];
12+
bool on_vacation = 3 [(atlas.query.validate).disable_sorting = true];
13+
string speciality = 4 [(atlas.query.validate) = {allow: MATCH, disable_sorting: true}];
1414
string comment = 5;
1515
google.protobuf.StringValue last_name = 6;
16-
string id = 7 [(atlas.query.permissions) = {filters: {deny: "ALL"}}];
16+
string id = 7 [(atlas.query.validate).deny = ALL];
1717
repeated string array = 8;
1818
CustomType custom_type = 9;
19-
CustomType custom_type_string = 10 [(atlas.query.permissions) = {filter_type: STRING}];
20-
Address home_address = 11 [(atlas.query.permissions) = {enable_nested_fields: true}];
19+
CustomType custom_type_string = 10 [(atlas.query.validate) = {filter_type: STRING}];
20+
Address home_address = 11 [(atlas.query.validate) = {enable_nested_fields: true}];
2121
Address work_address = 12;
2222
}
2323

2424
message CustomType {
2525
}
2626

2727
message Address {
28-
string city = 1 [(atlas.query.permissions) = {filters: {allow: "EQ"}, disable_sorting: true}];
28+
string city = 1 [(atlas.query.validate) = {allow: EQ, disable_sorting: true}];
2929
string country = 2;
3030
}
3131

example/example_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"github.com/infobloxopen/atlas-app-toolkit/query"
7+
"github.com/infobloxopen/protoc-gen-atlas-query-validate/options"
78
)
89

910
func TestFilteringPermissionsValidation(t *testing.T) {
@@ -12,15 +13,16 @@ func TestFilteringPermissionsValidation(t *testing.T) {
1213
Err bool
1314
}{
1415
{`first_name~"Sam"`, false},
16+
{`first_name=="Sam"`, false},
1517
{`weight==1`, false},
1618
{`comment=="comment1"`, false},
1719
{`speciality~"spec"`, false},
1820
{`last_name=="Smith"`, false},
1921
{`last_name~"Smith"`, false},
2022
{`id=="some_id"`, true},
21-
{`first_name=="Sam"`, true},
23+
{`first_name<"Sam"`, true},
2224
{`weight<=1`, true},
23-
{`first_name=="Jan"`, true},
25+
{`first_name<"Jan"`, true},
2426
{`speciality=="spec"`, true},
2527
{`unknown_field=="unk"`, true},
2628
{`id=="some_id"`, true},
@@ -38,7 +40,7 @@ func TestFilteringPermissionsValidation(t *testing.T) {
3840
if err != nil {
3941
t.Fatalf("Invalid filtering data '%s'", test.Query)
4042
}
41-
err = ExampleValidateQuery(f, nil, "/example.TestService/List")
43+
err = options.ValidateFiltering(f, ExampleMessagesRequireQueryValidation["User"])
4244
if err != nil {
4345
if test.Err == false {
4446
t.Errorf("Unexpected error for %s query: %s", test.Query, err)
@@ -74,7 +76,7 @@ func TestSortingPermissionsValidation(t *testing.T) {
7476
if err != nil {
7577
t.Fatalf("Invalid sorting data '%s'", test.Query)
7678
}
77-
err = ExampleValidateQuery(nil, s, "/example.TestService/List")
79+
err = options.ValidateSorting(s, ExampleMessagesRequireQueryValidation["User"])
7880
if err != nil {
7981
if test.Err == false {
8082
t.Errorf("Unexpected error for %s query: %s", test.Query, err)

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package main
22

33
import (
44
"github.com/gogo/protobuf/vanity/command"
5-
"github.com/infobloxopen/protoc-gen-atlas-query-perm/plugin"
5+
"github.com/infobloxopen/protoc-gen-atlas-query-validate/plugin"
66
)
77

88
func main() {
9-
plugin := &plugin.PermPlugin{}
10-
response := command.GeneratePlugin(command.Read(), plugin, ".pb.atlas.query.perm.go")
9+
plugin := &plugin.QueryValidatePlugin{}
10+
response := command.GeneratePlugin(command.Read(), plugin, ".pb.atlas.query.validate.go")
1111
plugin.CleanFiles(response)
1212
command.Write(response)
1313
}

0 commit comments

Comments
 (0)