Skip to content

Commit 87a42a5

Browse files
authored
feat: support semantic type setting (#94)
* chore: use set for unordered collection * chore: update doc * fix: list all databases in the project * chore: update * fix: lint * chore: add databases for instance * chore: more error log * chore: update * chore: update * feat: database resource * fix: lint * feat: support semantic type setting * fix: lint * chore: update
1 parent 5522574 commit 87a42a5

File tree

20 files changed

+552
-27
lines changed

20 files changed

+552
-27
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.14
1+
1.0.15

api/setting.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const (
1212
SettingWorkspaceExternalApproval SettingName = "bb.workspace.approval.external"
1313
// SettingDataClassification is the setting name for data classification.
1414
SettingDataClassification SettingName = "bb.workspace.data-classification"
15+
// SettingSemanticTypes is the setting name for semantic types.
16+
SettingSemanticTypes SettingName = "bb.workspace.semantic-types"
1517
)
1618

1719
// RiskLevel is the approval risk level.

client/cel.go

-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"net/http"
77
"strings"
88

9-
"github.com/hashicorp/terraform-plugin-log/tflog"
10-
119
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
1210
"github.com/pkg/errors"
1311
v1alpha1 "google.golang.org/genproto/googleapis/api/expr/v1alpha1"
@@ -33,8 +31,6 @@ func (c *client) ParseExpression(ctx context.Context, expression string) (*v1alp
3331
return nil, err
3432
}
3533

36-
tflog.Debug(ctx, fmt.Sprintf("parse cel response:\n%v", string(body)))
37-
3834
var res v1pb.BatchParseResponse
3935
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
4036
return nil, err

docs/data-sources/setting.md

+68
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The setting data source.
2222
### Optional
2323

2424
- `classification` (Block List, Max: 1) Classification for data masking. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--classification))
25+
- `semantic_types` (Block Set) Semantic types for data masking. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--semantic_types))
2526
- `workspace_profile` (Block List, Max: 1) (see [below for nested schema](#nestedblock--workspace_profile))
2627

2728
### Read-Only
@@ -63,6 +64,73 @@ Optional:
6364

6465

6566

67+
<a id="nestedblock--semantic_types"></a>
68+
### Nested Schema for `semantic_types`
69+
70+
Optional:
71+
72+
- `algorithm` (Block List, Max: 1) The semantic type algorithm. Required. (see [below for nested schema](#nestedblock--semantic_types--algorithm))
73+
- `description` (String) The semantic type description. Optional.
74+
- `id` (String) The semantic type unique uuid.
75+
- `title` (String) The semantic type title. Required.
76+
77+
<a id="nestedblock--semantic_types--algorithm"></a>
78+
### Nested Schema for `semantic_types.algorithm`
79+
80+
Optional:
81+
82+
- `full_mask` (Block List, Max: 1) (see [below for nested schema](#nestedblock--semantic_types--algorithm--full_mask))
83+
- `inner_outer_mask` (Block List, Max: 1) (see [below for nested schema](#nestedblock--semantic_types--algorithm--inner_outer_mask))
84+
- `md5_mask` (Block List, Max: 1) (see [below for nested schema](#nestedblock--semantic_types--algorithm--md5_mask))
85+
- `range_mask` (Block List, Max: 1) (see [below for nested schema](#nestedblock--semantic_types--algorithm--range_mask))
86+
87+
<a id="nestedblock--semantic_types--algorithm--full_mask"></a>
88+
### Nested Schema for `semantic_types.algorithm.full_mask`
89+
90+
Optional:
91+
92+
- `substitution` (String) Substitution is the string used to replace the original value, the max length of the string is 16 bytes.
93+
94+
95+
<a id="nestedblock--semantic_types--algorithm--inner_outer_mask"></a>
96+
### Nested Schema for `semantic_types.algorithm.inner_outer_mask`
97+
98+
Optional:
99+
100+
- `prefix_len` (Number)
101+
- `substitution` (String)
102+
- `suffix_len` (Number)
103+
- `type` (String)
104+
105+
106+
<a id="nestedblock--semantic_types--algorithm--md5_mask"></a>
107+
### Nested Schema for `semantic_types.algorithm.md5_mask`
108+
109+
Optional:
110+
111+
- `salt` (String) Salt is the salt value to generate a different hash that with the word alone.
112+
113+
114+
<a id="nestedblock--semantic_types--algorithm--range_mask"></a>
115+
### Nested Schema for `semantic_types.algorithm.range_mask`
116+
117+
Optional:
118+
119+
- `slices` (Block List) (see [below for nested schema](#nestedblock--semantic_types--algorithm--range_mask--slices))
120+
121+
<a id="nestedblock--semantic_types--algorithm--range_mask--slices"></a>
122+
### Nested Schema for `semantic_types.algorithm.range_mask.slices`
123+
124+
Optional:
125+
126+
- `end` (Number) End is the stop index of the original value, should be less than the length of the original value.
127+
- `start` (Number) Start is the start index of the original value, start from 0 and should be less than stop.
128+
- `substitution` (String) Substitution is the string used to replace the OriginalValue[start:end).
129+
130+
131+
132+
133+
66134
<a id="nestedblock--workspace_profile"></a>
67135
### Nested Schema for `workspace_profile`
68136

docs/resources/setting.md

+68
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The setting resource.
2424
- `approval_flow` (Block List) Configure risk level and approval flow for different tasks. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--approval_flow))
2525
- `classification` (Block List, Max: 1) Classification for data masking. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--classification))
2626
- `external_approval_nodes` (Block List) Configure external nodes in the approval flow. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--external_approval_nodes))
27+
- `semantic_types` (Block Set) Semantic types for data masking. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--semantic_types))
2728
- `workspace_profile` (Block List, Max: 1) (see [below for nested schema](#nestedblock--workspace_profile))
2829

2930
### Read-Only
@@ -136,6 +137,73 @@ Required:
136137

137138

138139

140+
<a id="nestedblock--semantic_types"></a>
141+
### Nested Schema for `semantic_types`
142+
143+
Optional:
144+
145+
- `algorithm` (Block List, Max: 1) The semantic type algorithm. Required. (see [below for nested schema](#nestedblock--semantic_types--algorithm))
146+
- `description` (String) The semantic type description. Optional.
147+
- `id` (String) The semantic type unique uuid.
148+
- `title` (String) The semantic type title. Required.
149+
150+
<a id="nestedblock--semantic_types--algorithm"></a>
151+
### Nested Schema for `semantic_types.algorithm`
152+
153+
Optional:
154+
155+
- `full_mask` (Block List, Max: 1) (see [below for nested schema](#nestedblock--semantic_types--algorithm--full_mask))
156+
- `inner_outer_mask` (Block List, Max: 1) (see [below for nested schema](#nestedblock--semantic_types--algorithm--inner_outer_mask))
157+
- `md5_mask` (Block List, Max: 1) (see [below for nested schema](#nestedblock--semantic_types--algorithm--md5_mask))
158+
- `range_mask` (Block List, Max: 1) (see [below for nested schema](#nestedblock--semantic_types--algorithm--range_mask))
159+
160+
<a id="nestedblock--semantic_types--algorithm--full_mask"></a>
161+
### Nested Schema for `semantic_types.algorithm.full_mask`
162+
163+
Optional:
164+
165+
- `substitution` (String) Substitution is the string used to replace the original value, the max length of the string is 16 bytes.
166+
167+
168+
<a id="nestedblock--semantic_types--algorithm--inner_outer_mask"></a>
169+
### Nested Schema for `semantic_types.algorithm.inner_outer_mask`
170+
171+
Optional:
172+
173+
- `prefix_len` (Number)
174+
- `substitution` (String)
175+
- `suffix_len` (Number)
176+
- `type` (String)
177+
178+
179+
<a id="nestedblock--semantic_types--algorithm--md5_mask"></a>
180+
### Nested Schema for `semantic_types.algorithm.md5_mask`
181+
182+
Optional:
183+
184+
- `salt` (String) Salt is the salt value to generate a different hash that with the word alone.
185+
186+
187+
<a id="nestedblock--semantic_types--algorithm--range_mask"></a>
188+
### Nested Schema for `semantic_types.algorithm.range_mask`
189+
190+
Optional:
191+
192+
- `slices` (Block List) (see [below for nested schema](#nestedblock--semantic_types--algorithm--range_mask--slices))
193+
194+
<a id="nestedblock--semantic_types--algorithm--range_mask--slices"></a>
195+
### Nested Schema for `semantic_types.algorithm.range_mask.slices`
196+
197+
Optional:
198+
199+
- `end` (Number) End is the stop index of the original value, should be less than the length of the original value.
200+
- `start` (Number) Start is the start index of the original value, start from 0 and should be less than stop.
201+
- `substitution` (String) Substitution is the string used to replace the OriginalValue[start:end).
202+
203+
204+
205+
206+
139207
<a id="nestedblock--workspace_profile"></a>
140208
### Nested Schema for `workspace_profile`
141209

examples/environments/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "1.0.14"
5+
version = "1.0.15"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

examples/groups/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.14"
4+
version = "1.0.15"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}

examples/instances/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "1.0.14"
5+
version = "1.0.15"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

examples/policies/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.14"
4+
version = "1.0.15"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}

examples/projects/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "1.0.14"
5+
version = "1.0.15"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

examples/settings/main.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.14"
4+
version = "1.0.15"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}
@@ -33,6 +33,10 @@ data "bytebase_setting" "classification" {
3333
name = "bb.workspace.data-classification"
3434
}
3535

36+
data "bytebase_setting" "semantic_types" {
37+
name = "bb.workspace.semantic-types"
38+
}
39+
3640
output "approval_flow" {
3741
value = data.bytebase_setting.approval_flow
3842
}
@@ -48,3 +52,7 @@ output "workspace_profile" {
4852
output "classification" {
4953
value = data.bytebase_setting.classification
5054
}
55+
56+
output "semantic_types" {
57+
value = data.bytebase_setting.semantic_types
58+
}

examples/setup/data_masking.tf

+44
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,50 @@ resource "bytebase_setting" "classification" {
4040
}
4141
}
4242

43+
resource "bytebase_setting" "semantic_types" {
44+
name = "bb.workspace.semantic-types"
45+
46+
semantic_types {
47+
id = "bb.default"
48+
title = "Default"
49+
}
50+
51+
semantic_types {
52+
id = "bb.default-partial"
53+
title = "Default partial"
54+
}
55+
56+
semantic_types {
57+
id = "9c84e2a6-02e5-4031-89c5-13342b568f7b"
58+
title = "Full mask"
59+
algorithm {
60+
full_mask {
61+
substitution = "***"
62+
}
63+
}
64+
}
65+
66+
semantic_types {
67+
id = "bb14d0ae-5aff-4f65-9143-bced63f8b054"
68+
title = "Range mask"
69+
algorithm {
70+
range_mask {
71+
slices {
72+
start = 0
73+
end = 1
74+
substitution = "*"
75+
}
76+
77+
slices {
78+
start = 2
79+
end = 3
80+
substitution = "*"
81+
}
82+
}
83+
}
84+
}
85+
}
86+
4387
resource "bytebase_policy" "masking_exception_policy" {
4488
depends_on = [
4589
bytebase_project.sample_project,

examples/setup/database.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ resource "bytebase_database" "database" {
1515
name = "salary"
1616
columns {
1717
name = "amount"
18-
semantic_type = "default"
18+
semantic_type = "bb.default"
1919
}
2020
columns {
2121
name = "emp_no"
22-
semantic_type = "default-partial"
22+
semantic_type = "bb.default-partial"
2323
classification = "1-1"
2424
labels = {
2525
tenant = "example"

examples/setup/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.14"
4+
version = "1.0.15"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}

examples/setup/project.tf

-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ resource "bytebase_project" "sample_project" {
1111
title = "Sample project"
1212
key = "SAMM"
1313

14-
dynamic "databases" {
15-
for_each = bytebase_instance.prod.databases
16-
content {
17-
name = databases.value.name
18-
}
19-
}
20-
2114
members {
2215
member = format("user:%s", bytebase_user.workspace_dba.email)
2316
role = "roles/projectOwner"

examples/users/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.14"
4+
version = "1.0.15"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}

examples/vcs/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.14"
4+
version = "1.0.15"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}

0 commit comments

Comments
 (0)