Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proto validations #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ out/
/app/build/
output/

.common-protos

app/src/main/resources/application-local.yaml
32 changes: 0 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
.PHONY: clean-common-protos

common_protos := ${CURDIR}/.common-protos

grpc_version := 1.50.0
protobuf_version := 3.21.9
google_common_protos_version := 2.10.0
git_branch := $(shell git rev-parse --abbrev-ref HEAD)

# google/protobuf dependencies (predefined Protos for e.g. Timestamp, Duration, etc)
${common_protos}/protobuf-java.jar:
curl "https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/${protobuf_version}/protobuf-java-${protobuf_version}.jar" --create-dirs -o "${common_protos}/protobuf-java.jar"

# google/api dependencies (Common Google Protos, such as field_behavior)
${common_protos}/proto-google-common-protos.jar:
curl "https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-common-protos/${google_common_protos_version}/proto-google-common-protos-${google_common_protos_version}.jar" --create-dirs -o "${common_protos}/proto-google-common-protos.jar"

${common_protos}: ${common_protos}/proto-google-common-protos.jar ${common_protos}/protobuf-java.jar ${common_protos}/validate/validate.proto

clean-common-protos:
rm -rf ${common_protos}

${common_protos}/google/protobuf: ${common_protos}/protobuf-java.jar
unzip -d ${common_protos} $< "google/**/*.proto"

${common_protos}/google/api: ${common_protos}/proto-google-common-protos.jar
unzip -d ${common_protos} $< "google/**/*.proto"

${common_protos}/validate/validate.proto:
curl "https://raw.githubusercontent.com/bufbuild/protoc-gen-validate/v0.9.1/validate/validate.proto" --create-dirs -o "${common_protos}/validate/validate.proto"

# To ensure that we use the same Google Common Protobuf files in all languages, we extract them from the jar
default-google-dependencies: ${common_protos}/google/protobuf ${common_protos}/google/api
protoc-gen-validate-dependency: ${common_protos}/validate/validate.proto

intellij: ${common_protos}
./protos/setup-ide-protobuf-plugins.sh

buf-publish-current-branch:
[[ "$$OSTYPE" == "darwin"* ]] && SED=gsed || SED=sed && \
commit_hash=$$(cd protos && buf push --branch "${git_branch}") && \
Expand Down
3 changes: 3 additions & 0 deletions protos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1. Install the `Buf for Protocol Buffers` and the bundled `gRPC` plugins for Intellij.
2. Configure your buf path in the plugin settings (e.g. `$ which buf`)
3. Update buf with `buf mod update`
8 changes: 4 additions & 4 deletions protos/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
version: v1
deps:
- remote: buf.build
owner: envoyproxy
repository: protoc-gen-validate
commit: eac44469a7af47e7839a7f1f3d7ac004
digest: shake256:0feabcde01b6b11e3c75a5e3f807968d5995626546f39c37e5d4205892b3a59cced0ed83b35a2eb9e6dddd3309660ad46b737c9dcd224b425de0a6654ce04417
owner: bufbuild
repository: protovalidate
commit: 0de7443d03cf41228f8a9790b12b417e
digest: shake256:3c0676a73cef06439c107cb9560627354815adbc254976f807d645de7e2c1bf19d0438d5d56d5bc92465377e0d9315951e986fc6ced2871e450534b2b8c953b0
- remote: buf.build
owner: googleapis
repository: googleapis
Expand Down
5 changes: 2 additions & 3 deletions protos/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
version: v1
name: buf.build/getstrm/daps
name: buf.build/getstrm/pace
deps:
- buf.build/googleapis/googleapis
# FIXME once an official repo is available for bufbuild/protoc-gen-validate, we should change to that
- buf.build/envoyproxy/protoc-gen-validate
- buf.build/bufbuild/protovalidate
breaking:
use:
- FILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package getstrm.api.data_policies.v1alpha;

import "getstrm/api/data_policies/v1alpha/entities_v1alpha.proto";
import "google/api/annotations.proto";
import "buf/validate/validate.proto";

option java_package = "com.getstrm.api.data_policies.v1alpha";
option java_multiple_files = true;
Expand Down Expand Up @@ -124,7 +125,7 @@ message ListProcessingPlatformGroupsResponse {

message GetProcessingPlatformBarePolicyRequest {
DataPolicy.ProcessingPlatform platform = 1;
string table = 2;
string table = 2 [(buf.validate.field) = {string: {min_len: 1}, ignore_empty: false}];
}

message GetProcessingPlatformBarePolicyResponse {
Expand All @@ -133,7 +134,7 @@ message GetProcessingPlatformBarePolicyResponse {


message GetDataPolicyRequest {
string id = 1;
string id = 1 [(buf.validate.field).string.uuid = true];
}

message GetDataPolicyResponse {
Expand Down
37 changes: 19 additions & 18 deletions protos/getstrm/api/data_policies/v1alpha/entities_v1alpha.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ syntax = "proto3";

package getstrm.api.data_policies.v1alpha;

import "buf/validate/validate.proto";
import "google/protobuf/timestamp.proto";

message DataPolicy {
string id = 1;
string id = 1 [(buf.validate.field).string.uuid = true];
Info info = 2;
Source source = 3;
ProcessingPlatform platform = 4;
repeated RuleSet rule_sets = 5;

message Info {
string title = 1;
string description = 2;
string version = 3;
string organization_id = 4;
string title = 1 [(buf.validate.field).string.min_len = 3];
string description = 2 [(buf.validate.field).ignore_empty = true];
string version = 3 [(buf.validate.field).string.pattern = "^\\d+\\.\\d+\\.\\d+$"];
string organization_id = 4 [(buf.validate.field) = {string: {uuid: true}, ignore_empty: true}];
google.protobuf.Timestamp create_time = 5;
google.protobuf.Timestamp update_time = 6;
}
Expand All @@ -30,7 +31,7 @@ message DataPolicy {
// Last condition in the list must have 0 principals, as this acts as the default / else condition.
repeated Condition conditions = 3;
message Condition {
repeated string principals = 1;
repeated string principals = 1 [(buf.validate.field).repeated = { items: { string: {min_len: 1} }, min_items: 0 }];
string condition = 2;
}
}
Expand All @@ -40,7 +41,7 @@ message DataPolicy {
// Last condition in the list must have 0 principals, as this acts as the default / else condition.
repeated Transform transforms = 2;
message Transform {
repeated string principals = 1;
repeated string principals = 1 [(buf.validate.field).repeated = { items: { string: {min_len: 1} } }];
oneof transform {
RegexReplace regex = 2;
bool identity = 3;
Expand Down Expand Up @@ -70,7 +71,7 @@ message DataPolicy {

message ProcessingPlatform {
PlatformType platform_type = 1;
string id = 2;
string id = 2 [(buf.validate.field).string.min_len = 1];
enum PlatformType {
PLATFORM_TYPE_UNSPECIFIED = 0;
DATABRICKS = 1;
Expand All @@ -81,7 +82,7 @@ message DataPolicy {

message Target {
TargetType type = 1;
string fullname = 2;
string fullname = 2 [(buf.validate.field).string.min_len = 1];
enum TargetType {
TARGET_TYPE_UNSPECIFIED = 0;
DYNAMIC_VIEW = 1;
Expand All @@ -90,7 +91,7 @@ message DataPolicy {

message Source {
// The ref is an identifier for the source, unique at the source platform level.
string ref = 1;
string ref = 1 [(buf.validate.field).string.min_len = 3];
Type type = 2;
// Note: we are currently not using the string-based spec after all. Using the Attributes instead improves
// testability and should make it easier for the frontend to render the policy. Otherwise the frontend
Expand All @@ -113,7 +114,7 @@ message DataPolicy {

message Attribute {
// Instead of using "nodes", nesting can be expressed by specifying multiple path components. This is similar to BigQuery.
repeated string path_components = 1;
repeated string path_components = 1 [(buf.validate.field).repeated = { items: { string: {min_len: 1} } }];
// This is the "native" type, originating from the source platform.
string type = 2;
bool required = 3;
Expand All @@ -123,7 +124,7 @@ message DataPolicy {


message DataCatalog {
string id = 1;
string id = 1 [(buf.validate.field) = {ignore_empty: false, string: {min_len: 1}}];
Type type = 2;
repeated DataBase databases = 3;
enum Type {
Expand All @@ -134,23 +135,23 @@ message DataCatalog {
}

message DataBase {
string id = 1;
string id = 1 [(buf.validate.field) = {ignore_empty: false, string: {min_len: 1}}];
string type = 2;
string display_name = 3;
string display_name = 3 [(buf.validate.field) = {ignore_empty: false, string: {min_len: 1}}];
DataCatalog catalog = 4;
repeated Schema schemas = 5;
}

message Schema {
string id = 1;
string name = 2;
string id = 1 [(buf.validate.field) = {ignore_empty: false, string: {min_len: 1}}];
string name = 2 [(buf.validate.field) = {ignore_empty: false, string: {min_len: 1}}];
DataBase database = 3;
repeated Table tables = 4;
}

message Table {
string id = 1;
string name = 2;
string id = 1 [(buf.validate.field) = {ignore_empty: false, string: {min_len: 1}}];
string name = 2 [(buf.validate.field) = {ignore_empty: false, string: {min_len: 1}}];
Schema schema = 3;
}
}
81 changes: 0 additions & 81 deletions protos/setup-ide-protobuf-plugins.sh

This file was deleted.

Loading