Skip to content

Commit

Permalink
Refactoring (#8)
Browse files Browse the repository at this point in the history
* Remove redundant test

* Major refactoring

* Resolve volatility of generated code

* Fix Identifier name
  • Loading branch information
Daniil Kukharau authored Sep 21, 2018
1 parent 69c0123 commit d9d2dfd
Show file tree
Hide file tree
Showing 18 changed files with 448 additions and 675 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ script:
- make vendor
- make install
# NOTE: We will be able to run protoc commands from Travis once
# protoc-gen-atlas-query-perm is added to the atlas gentool. For now, we can just run
# protoc-gen-atlas-query-validate is added to the atlas gentool. For now, we can just run
# tests to ensure that everything works as expected.
- go test -v ./...
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ default: options install
options:
protoc -I. -I$(SRCPATH) -I./vendor \
--gogo_out="Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor:$(SRCPATH)" \
options/collection_permissions.proto
options/query_validate.proto

.PHONY: install
install:
go install

.PHONY: perm-test
perm-test: ./example/* ./test/*
test: ./example/*
echo ${SRCPATH}
protoc -I. -I${SRCPATH} -I./vendor -I./vendor/github.com/grpc-ecosystem/grpc-gateway --atlas-query-perm_out=. example/example.proto
protoc -I. -I${SRCPATH} -I./vendor -I./vendor/github.com/grpc-ecosystem/grpc-gateway --atlas-query-validate_out=. example/example.proto
go test ./...

.PHONY: vendor
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# protoc-gen-atlas-query-perm
# protoc-gen-atlas-query-validate
59 changes: 0 additions & 59 deletions example/example.pb.atlas.query.perm.go

This file was deleted.

38 changes: 38 additions & 0 deletions example/example.pb.atlas.query.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions example/example.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ syntax = "proto3";
package example;

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

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

message CustomType {
}

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

Expand Down
10 changes: 6 additions & 4 deletions example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/infobloxopen/atlas-app-toolkit/query"
"github.com/infobloxopen/protoc-gen-atlas-query-validate/options"
)

func TestFilteringPermissionsValidation(t *testing.T) {
Expand All @@ -12,15 +13,16 @@ func TestFilteringPermissionsValidation(t *testing.T) {
Err bool
}{
{`first_name~"Sam"`, false},
{`first_name=="Sam"`, false},
{`weight==1`, false},
{`comment=="comment1"`, false},
{`speciality~"spec"`, false},
{`last_name=="Smith"`, false},
{`last_name~"Smith"`, false},
{`id=="some_id"`, true},
{`first_name=="Sam"`, true},
{`first_name<"Sam"`, true},
{`weight<=1`, true},
{`first_name=="Jan"`, true},
{`first_name<"Jan"`, true},
{`speciality=="spec"`, true},
{`unknown_field=="unk"`, true},
{`id=="some_id"`, true},
Expand All @@ -38,7 +40,7 @@ func TestFilteringPermissionsValidation(t *testing.T) {
if err != nil {
t.Fatalf("Invalid filtering data '%s'", test.Query)
}
err = ExampleValidateQuery(f, nil, "/example.TestService/List")
err = options.ValidateFiltering(f, ExampleMessagesRequireQueryValidation["User"])
if err != nil {
if test.Err == false {
t.Errorf("Unexpected error for %s query: %s", test.Query, err)
Expand Down Expand Up @@ -74,7 +76,7 @@ func TestSortingPermissionsValidation(t *testing.T) {
if err != nil {
t.Fatalf("Invalid sorting data '%s'", test.Query)
}
err = ExampleValidateQuery(nil, s, "/example.TestService/List")
err = options.ValidateSorting(s, ExampleMessagesRequireQueryValidation["User"])
if err != nil {
if test.Err == false {
t.Errorf("Unexpected error for %s query: %s", test.Query, err)
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"github.com/gogo/protobuf/vanity/command"
"github.com/infobloxopen/protoc-gen-atlas-query-perm/plugin"
"github.com/infobloxopen/protoc-gen-atlas-query-validate/plugin"
)

func main() {
plugin := &plugin.PermPlugin{}
response := command.GeneratePlugin(command.Read(), plugin, ".pb.atlas.query.perm.go")
plugin := &plugin.QueryValidatePlugin{}
response := command.GeneratePlugin(command.Read(), plugin, ".pb.atlas.query.validate.go")
plugin.CleanFiles(response)
command.Write(response)
}
Loading

0 comments on commit d9d2dfd

Please sign in to comment.