Skip to content

Commit 42b65da

Browse files
authored
chore: support title and reason (#133)
1 parent 09b536c commit 42b65da

File tree

7 files changed

+32
-2
lines changed

7 files changed

+32
-2
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.8.2
1+
3.8.3

docs/data-sources/policy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Required:
6969
- `id` (String) The unique rule id
7070
- `semantic_type` (String) The semantic type id
7171

72+
Optional:
73+
74+
- `title` (String) The title for the rule
75+
7276

7377

7478
<a id="nestedblock--masking_exception_policy"></a>
@@ -91,6 +95,7 @@ Optional:
9195

9296
- `column` (String)
9397
- `expire_timestamp` (String) The expiration timestamp in YYYY-MM-DDThh:mm:ss.000Z format
98+
- `reason` (String) The reason for the masking exemption
9499
- `schema` (String)
95100
- `table` (String)
96101

docs/data-sources/policy_list.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Read-Only:
5151
- `condition` (String)
5252
- `id` (String)
5353
- `semantic_type` (String)
54+
- `title` (String)
5455

5556

5657

@@ -71,6 +72,7 @@ Read-Only:
7172
- `database` (String)
7273
- `expire_timestamp` (String)
7374
- `member` (String)
75+
- `reason` (String)
7476
- `schema` (String)
7577
- `table` (String)
7678

docs/resources/policy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Required:
6969
- `id` (String) The unique rule id
7070
- `semantic_type` (String) The semantic type id
7171

72+
Optional:
73+
74+
- `title` (String) The title for the rule
75+
7276

7377

7478
<a id="nestedblock--masking_exception_policy"></a>
@@ -91,6 +95,7 @@ Optional:
9195

9296
- `column` (String)
9397
- `expire_timestamp` (String) The expiration timestamp in YYYY-MM-DDThh:mm:ss.000Z format
98+
- `reason` (String) The reason for the masking exemption
9499
- `schema` (String)
95100
- `table` (String)
96101

examples/setup/data_masking.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ resource "bytebase_policy" "masking_exception_policy" {
115115
column = "amount"
116116
member = "user:[email protected]"
117117
action = "EXPORT"
118+
reason = "Grant access to ed for export"
118119
}
119120
exceptions {
120121
database = "instances/test-sample-instance/databases/employee"
@@ -142,11 +143,13 @@ resource "bytebase_policy" "global_masking_policy" {
142143
condition = "environment_id in [\"test\"]"
143144
id = "69df1d15-abe5-4bc9-be38-f2a4bef3f7e0"
144145
semantic_type = "bb.default-partial"
146+
title = "Partial masking for test environment"
145147
}
146148
rules {
147149
condition = "instance_id in [\"prod-sample-instance\"]"
148150
id = "90adb734-0808-4c9f-b281-1f76f7a1a29a"
149151
semantic_type = "bb.default"
152+
title = "Default masking for prod instance"
150153
}
151154
}
152155
}

provider/data_source_policy.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ func getMaskingExceptionPolicySchema(computed bool) *schema.Schema {
130130
v1pb.MaskingExceptionPolicy_MaskingException_EXPORT.String(),
131131
}, false),
132132
},
133+
"reason": {
134+
Type: schema.TypeString,
135+
Optional: true,
136+
Description: "The reason for the masking exemption",
137+
},
133138
"expire_timestamp": {
134139
Type: schema.TypeString,
135140
Computed: computed,
@@ -169,6 +174,11 @@ func getGlobalMaskingPolicySchema(computed bool) *schema.Schema {
169174
ValidateFunc: validation.StringIsNotEmpty,
170175
Description: "The unique rule id",
171176
},
177+
"title": {
178+
Type: schema.TypeString,
179+
Optional: true,
180+
Description: "The title for the rule",
181+
},
172182
"semantic_type": {
173183
Type: schema.TypeString,
174184
Required: true,
@@ -404,6 +414,7 @@ func flattenGlobalMaskingPolicy(p *v1pb.MaskingRulePolicy) ([]interface{}, error
404414
raw["id"] = rule.Id
405415
raw["semantic_type"] = rule.SemanticType
406416
raw["condition"] = rule.Condition.Expression
417+
raw["title"] = rule.Condition.Title
407418

408419
ruleList = append(ruleList, raw)
409420
}
@@ -424,6 +435,7 @@ func flattenMaskingExceptionPolicy(p *v1pb.MaskingExceptionPolicy) ([]interface{
424435
if exception.Condition == nil || exception.Condition.Expression == "" {
425436
return nil, errors.Errorf("invalid exception policy condition")
426437
}
438+
raw["reason"] = exception.Condition.Description
427439

428440
expressions := strings.Split(exception.Condition.Expression, " && ")
429441
instanceID := ""

provider/resource_policy.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,12 @@ func convertToMaskingRulePolicy(d *schema.ResourceData) (*v1pb.MaskingRulePolicy
312312

313313
for _, rule := range ruleList {
314314
rawRule := rule.(map[string]interface{})
315+
title := rawRule["title"].(string)
315316
policy.Rules = append(policy.Rules, &v1pb.MaskingRulePolicy_MaskingRule{
316317
Id: rawRule["id"].(string),
317318
SemanticType: rawRule["semantic_type"].(string),
318319
Condition: &expr.Expr{
320+
Title: title,
319321
Expression: rawRule["condition"].(string),
320322
},
321323
})
@@ -380,7 +382,8 @@ func convertToMaskingExceptionPolicy(d *schema.ResourceData) (*v1pb.MaskingExcep
380382
v1pb.MaskingExceptionPolicy_MaskingException_Action_value[rawException["action"].(string)],
381383
),
382384
Condition: &expr.Expr{
383-
Expression: strings.Join(expressions, " && "),
385+
Description: rawException["reason"].(string),
386+
Expression: strings.Join(expressions, " && "),
384387
},
385388
})
386389
}

0 commit comments

Comments
 (0)