Skip to content

Commit

Permalink
Merge pull request #3 from BoltApp/updateReadme
Browse files Browse the repository at this point in the history
Updated Readme. Added description and examples of using PolicyTags
  • Loading branch information
Harsh-Git-Hub authored Feb 10, 2022
2 parents a6c440c + 09f8691 commit 269b0c6
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,105 @@ The message `foo.Baz` is ignored because it doesn't have option `gen_bq_schema.b
`protoc --bq-schema_out=. --bq-schema_opt=single-message single_message.proto` will generate a file named `foo/single_message.schema`.
The message `foo.Baz` is also ignored because it is not the first message in the file.


### Support for PolicyTags
`protoc-gen-bq-schema` now supports [policyTags](https://cloud.google.com/bigquery/docs/column-level-security-intro).
You can define a `Policy Tag` for a field in `.proto` file.

### Example with Policy Tags
Suppose that you have the following `test_table.proto`
```
syntax = "proto3";
package foo;
import "bq_table.proto";
import "bq_field.proto";
message TestTable{
option (gen_bq_schema.bigquery_opts).table_name = "test_table";
int32 a = 1 [
(gen_bq_schema.bigquery) = {
require: true
policy_tags : "private"
}
];
string b = 2 [(gen_bq_schema.bigquery).policy_tags="public"];
message Nested {
int32 a = 1 [(gen_bq_schema.bigquery) = {
require: true
policy_tags : "private"
}
];
string b = 2;
}
repeated Nested nested = 3 [(gen_bq_schema.bigquery).require = true];
message EmptyMessage {}
repeated EmptyMessage hasMessage = 4;
}
```
`protoc --bq-schema_out=. test_table.proto` will generate a file named `foo/test_table.schema`.
The field `hasMessage` is ignored because the message `EmptyMessage` is empty.

It will generate the following `JSON` schema
```
[
{
"name": "a",
"type": "INTEGER",
"mode": "REQUIRED",
"policyTags": {
"names": [
"private"
]
}
},
{
"name": "b",
"type": "STRING",
"mode": "NULLABLE",
"policyTags": {
"names": [
"public
]
}
},
{
"name": "nested",
"type": "RECORD",
"mode": "REQUIRED",
"fields": [
{
"name": "a",
"type": "INTEGER",
"mode": "REQUIRED",
"policyTags": {
"names": [
"private"
]
}
},
{
"name": "b",
"type": "STRING",
"mode": "NULLABLE"
}
]
}
]
```

The policy tag name provided in `test_table.proto` file is taken as it is. According to [Google Docs](https://cloud.google.com/bigquery/docs/column-level-security-intro),
the policy tag string should be of the following format

`projects/project-id/locations/location/taxonomies/taxonomy-id/policyTags/policytag-id`


## License

protoc-gen-bq-schema is licensed under the Apache License version 2.0.
Expand Down

0 comments on commit 269b0c6

Please sign in to comment.