diff --git a/VERSION b/VERSION index 00e897b..dcd32c1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.8.2 \ No newline at end of file +3.8.3 \ No newline at end of file diff --git a/docs/data-sources/policy.md b/docs/data-sources/policy.md index 53f79e5..36a894f 100644 --- a/docs/data-sources/policy.md +++ b/docs/data-sources/policy.md @@ -69,6 +69,10 @@ Required: - `id` (String) The unique rule id - `semantic_type` (String) The semantic type id +Optional: + +- `title` (String) The title for the rule + @@ -91,6 +95,7 @@ Optional: - `column` (String) - `expire_timestamp` (String) The expiration timestamp in YYYY-MM-DDThh:mm:ss.000Z format +- `reason` (String) The reason for the masking exemption - `schema` (String) - `table` (String) diff --git a/docs/data-sources/policy_list.md b/docs/data-sources/policy_list.md index 442a110..f66e19e 100644 --- a/docs/data-sources/policy_list.md +++ b/docs/data-sources/policy_list.md @@ -51,6 +51,7 @@ Read-Only: - `condition` (String) - `id` (String) - `semantic_type` (String) +- `title` (String) @@ -71,6 +72,7 @@ Read-Only: - `database` (String) - `expire_timestamp` (String) - `member` (String) +- `reason` (String) - `schema` (String) - `table` (String) diff --git a/docs/resources/policy.md b/docs/resources/policy.md index d57c986..394b698 100644 --- a/docs/resources/policy.md +++ b/docs/resources/policy.md @@ -69,6 +69,10 @@ Required: - `id` (String) The unique rule id - `semantic_type` (String) The semantic type id +Optional: + +- `title` (String) The title for the rule + @@ -91,6 +95,7 @@ Optional: - `column` (String) - `expire_timestamp` (String) The expiration timestamp in YYYY-MM-DDThh:mm:ss.000Z format +- `reason` (String) The reason for the masking exemption - `schema` (String) - `table` (String) diff --git a/examples/setup/data_masking.tf b/examples/setup/data_masking.tf index 0a47099..416ed4b 100644 --- a/examples/setup/data_masking.tf +++ b/examples/setup/data_masking.tf @@ -115,6 +115,7 @@ resource "bytebase_policy" "masking_exception_policy" { column = "amount" member = "user:ed@bytebase.com" action = "EXPORT" + reason = "Grant access to ed for export" } exceptions { database = "instances/test-sample-instance/databases/employee" @@ -142,11 +143,13 @@ resource "bytebase_policy" "global_masking_policy" { condition = "environment_id in [\"test\"]" id = "69df1d15-abe5-4bc9-be38-f2a4bef3f7e0" semantic_type = "bb.default-partial" + title = "Partial masking for test environment" } rules { condition = "instance_id in [\"prod-sample-instance\"]" id = "90adb734-0808-4c9f-b281-1f76f7a1a29a" semantic_type = "bb.default" + title = "Default masking for prod instance" } } } diff --git a/provider/data_source_policy.go b/provider/data_source_policy.go index 254635c..af4b58d 100644 --- a/provider/data_source_policy.go +++ b/provider/data_source_policy.go @@ -130,6 +130,11 @@ func getMaskingExceptionPolicySchema(computed bool) *schema.Schema { v1pb.MaskingExceptionPolicy_MaskingException_EXPORT.String(), }, false), }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "The reason for the masking exemption", + }, "expire_timestamp": { Type: schema.TypeString, Computed: computed, @@ -169,6 +174,11 @@ func getGlobalMaskingPolicySchema(computed bool) *schema.Schema { ValidateFunc: validation.StringIsNotEmpty, Description: "The unique rule id", }, + "title": { + Type: schema.TypeString, + Optional: true, + Description: "The title for the rule", + }, "semantic_type": { Type: schema.TypeString, Required: true, @@ -404,6 +414,7 @@ func flattenGlobalMaskingPolicy(p *v1pb.MaskingRulePolicy) ([]interface{}, error raw["id"] = rule.Id raw["semantic_type"] = rule.SemanticType raw["condition"] = rule.Condition.Expression + raw["title"] = rule.Condition.Title ruleList = append(ruleList, raw) } @@ -424,6 +435,7 @@ func flattenMaskingExceptionPolicy(p *v1pb.MaskingExceptionPolicy) ([]interface{ if exception.Condition == nil || exception.Condition.Expression == "" { return nil, errors.Errorf("invalid exception policy condition") } + raw["reason"] = exception.Condition.Description expressions := strings.Split(exception.Condition.Expression, " && ") instanceID := "" diff --git a/provider/resource_policy.go b/provider/resource_policy.go index 559cd1f..6cd4ab4 100644 --- a/provider/resource_policy.go +++ b/provider/resource_policy.go @@ -312,10 +312,12 @@ func convertToMaskingRulePolicy(d *schema.ResourceData) (*v1pb.MaskingRulePolicy for _, rule := range ruleList { rawRule := rule.(map[string]interface{}) + title := rawRule["title"].(string) policy.Rules = append(policy.Rules, &v1pb.MaskingRulePolicy_MaskingRule{ Id: rawRule["id"].(string), SemanticType: rawRule["semantic_type"].(string), Condition: &expr.Expr{ + Title: title, Expression: rawRule["condition"].(string), }, }) @@ -380,7 +382,8 @@ func convertToMaskingExceptionPolicy(d *schema.ResourceData) (*v1pb.MaskingExcep v1pb.MaskingExceptionPolicy_MaskingException_Action_value[rawException["action"].(string)], ), Condition: &expr.Expr{ - Expression: strings.Join(expressions, " && "), + Description: rawException["reason"].(string), + Expression: strings.Join(expressions, " && "), }, }) }