Skip to content

Commit 68ae38d

Browse files
committed
chore: update risk level
1 parent 4e839fc commit 68ae38d

File tree

10 files changed

+35
-39
lines changed

10 files changed

+35
-39
lines changed

docs/data-sources/policy.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,10 @@ Optional:
9797
<a id="nestedblock--query_data_policy"></a>
9898
### Nested Schema for `query_data_policy`
9999

100-
Required:
100+
Optional:
101101

102102
- `disable_copy_data` (Boolean) Disable copying data in the SQL editor
103103
- `disable_export` (Boolean) Disable export data in the SQL editor
104-
105-
Optional:
106-
107104
- `maximum_result_rows` (Number) The return rows limit. If the value <= 0, will be treated as no limit. The default value is -1.
108105
- `maximum_result_size` (Number) The size limit in bytes. The default value is 100MB, we will use the default value if the limit <= 0.
109106
- `timeout_in_seconds` (Number) The maximum time allowed for a query to run in SQL Editor. No limit when the value <= 0

docs/resources/policy.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,10 @@ Optional:
9797
<a id="nestedblock--query_data_policy"></a>
9898
### Nested Schema for `query_data_policy`
9999

100-
Required:
100+
Optional:
101101

102102
- `disable_copy_data` (Boolean) Disable copying data in the SQL editor
103103
- `disable_export` (Boolean) Disable export data in the SQL editor
104-
105-
Optional:
106-
107104
- `maximum_result_rows` (Number) The return rows limit. If the value <= 0, will be treated as no limit. The default value is -1.
108105
- `maximum_result_size` (Number) The size limit in bytes. The default value is 100MB, we will use the default value if the limit <= 0.
109106
- `timeout_in_seconds` (Number) The maximum time allowed for a query to run in SQL Editor. No limit when the value <= 0

docs/resources/risk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The risk resource. Require ENTERPRISE subscription. Check the docs https://www.b
1818
### Required
1919

2020
- `condition` (String) The risk condition. Check the proto message https://github.com/bytebase/bytebase/blob/main/proto/v1/v1/risk_service.proto#L210 for details.
21-
- `level` (Number) The risk level, should be 300, 200 or 100. Higher number means higher level.
21+
- `level` (String) The risk level. Check https://github.com/bytebase/bytebase/blob/fd87c6bfe8a0d4883f25eb480a3b05ed3c2e1727/proto/v1/v1/common.proto#L93 for details
2222
- `source` (String) The risk source. Check https://github.com/bytebase/bytebase/blob/main/proto/v1/v1/risk_service.proto#L138 for details
2323
- `title` (String) The risk title.
2424

examples/setup/risk.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "bytebase_risk" "risk" {
22
title = "Risk for prod environment"
33
source = "DML"
4-
level = 300
4+
level = "HIGH"
55
active = true
66
condition = "resource.environment_id == \"prod\" && statement.affected_rows >= 100"
77
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.24.4
55
toolchain go1.24.5
66

77
require (
8-
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.19.1-20251010010834-1aa0c6de76e4.1
9-
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.10-20251010010834-1aa0c6de76e4.1
8+
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.19.1-20251010051414-0534aa930702.1
9+
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.10-20251010051414-0534aa930702.1
1010
connectrpc.com/connect v1.19.1
1111
github.com/hashicorp/go-cty v1.5.0
1212
github.com/hashicorp/terraform-plugin-docs v0.13.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.19.1-20251010010834-1aa0c6de76e4.1 h1:WNQflXc5jqg/LZikcsJxwVFfJMB0i1O7olWXgBZ/DVM=
2-
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.19.1-20251010010834-1aa0c6de76e4.1/go.mod h1:EhBo6m8asi2++hICIxqtAJdmw8SGYXdxZxPpytC1xUw=
3-
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.10-20251010010834-1aa0c6de76e4.1 h1:LKV7Q1GToSWI0IFvWxfw5Ul8AyiR8ItAzq1cKbEGP8U=
4-
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.10-20251010010834-1aa0c6de76e4.1/go.mod h1:hCjM3DsxzHQGb3QEnCNYrln9ZgB16AZLOVfRJZRKC0E=
1+
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.19.1-20251010051414-0534aa930702.1 h1:T4v2vd8e4RkC6ccfOdsvmDZ7YnW2YyAT6OFMdwcPgOA=
2+
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.19.1-20251010051414-0534aa930702.1/go.mod h1:A57O99YuSmuL9rUI39AMITcbFfJc6Ikv48Qb6Y2EgCw=
3+
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.10-20251010051414-0534aa930702.1 h1:5bZgEFfHz4kUG6fkHH9wmBG3dxyaA5rKpaprSP0csTo=
4+
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.10-20251010051414-0534aa930702.1/go.mod h1:hCjM3DsxzHQGb3QEnCNYrln9ZgB16AZLOVfRJZRKC0E=
55
connectrpc.com/connect v1.19.1 h1:R5M57z05+90EfEvCY1b7hBxDVOUl45PrtXtAV2fOC14=
66
connectrpc.com/connect v1.19.1/go.mod h1:tN20fjdGlewnSFeZxLKb0xwIZ6ozc3OQs2hTXy4du9w=
77
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=

provider/internal/mock_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func (c *mockClient) UpdateDatabase(ctx context.Context, patch *v1pb.Database, u
418418
}
419419

420420
// BatchUpdateDatabases batch updates databases.
421-
func (c *mockClient) BatchUpdateDatabases(ctx context.Context, request *v1pb.BatchUpdateDatabasesRequest) (*v1pb.BatchUpdateDatabasesResponse, error) {
421+
func (c *mockClient) BatchUpdateDatabases(_ context.Context, request *v1pb.BatchUpdateDatabasesRequest) (*v1pb.BatchUpdateDatabasesResponse, error) {
422422
mu.Lock()
423423
defer mu.Unlock()
424424
for _, req := range request.Requests {

provider/resource_risk.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ func resourceRisk() *schema.Resource {
5151
Description: "The risk source. Check https://github.com/bytebase/bytebase/blob/main/proto/v1/v1/risk_service.proto#L138 for details",
5252
},
5353
"level": {
54-
Type: schema.TypeInt,
54+
Type: schema.TypeString,
5555
Required: true,
56-
ValidateFunc: validation.IntInSlice([]int{
57-
300, 200, 100,
58-
}),
59-
Description: "The risk level, should be 300, 200 or 100. Higher number means higher level.",
56+
ValidateFunc: validation.StringInSlice([]string{
57+
v1pb.RiskLevel_HIGH.String(),
58+
v1pb.RiskLevel_MODERATE.String(),
59+
v1pb.RiskLevel_LOW.String(),
60+
}, false),
61+
Description: "The risk level. Check https://github.com/bytebase/bytebase/blob/fd87c6bfe8a0d4883f25eb480a3b05ed3c2e1727/proto/v1/v1/common.proto#L93 for details",
6062
},
6163
"active": {
6264
Type: schema.TypeBool,
@@ -102,7 +104,7 @@ func setRisk(d *schema.ResourceData, risk *v1pb.Risk) diag.Diagnostics {
102104
if err := d.Set("source", risk.Source.String()); err != nil {
103105
return diag.Errorf("cannot set source for risk: %s", err.Error())
104106
}
105-
if err := d.Set("level", int(risk.Level)); err != nil {
107+
if err := d.Set("level", risk.Level.String()); err != nil {
106108
return diag.Errorf("cannot set level for risk: %s", err.Error())
107109
}
108110
if err := d.Set("active", risk.Active); err != nil {
@@ -121,7 +123,7 @@ func resourceRiskCreate(ctx context.Context, d *schema.ResourceData, m interface
121123
created, err := c.CreateRisk(ctx, &v1pb.Risk{
122124
Title: d.Get("title").(string),
123125
Active: d.Get("active").(bool),
124-
Level: int32(d.Get("level").(int)),
126+
Level: v1pb.RiskLevel(v1pb.RiskLevel_value[d.Get("level").(string)]),
125127
Source: v1pb.Risk_Source(v1pb.Risk_Source_value[d.Get("source").(string)]),
126128
Condition: &expr.Expr{
127129
Expression: d.Get("condition").(string),
@@ -156,7 +158,7 @@ func resourceRiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
156158
}
157159
if d.HasChange("level") {
158160
updateMasks = append(updateMasks, "level")
159-
existedRisk.Level = int32(d.Get("level").(int))
161+
existedRisk.Level = v1pb.RiskLevel(v1pb.RiskLevel_value[d.Get("level").(string)])
160162
}
161163
if d.HasChange("source") {
162164
updateMasks = append(updateMasks, "source")

provider/resource_risk_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func TestAccRisk(t *testing.T) {
2222
title := "Test Risk"
2323
titleUpdated := "Updated Test Risk"
2424
source := v1pb.Risk_DDL.String()
25-
level := 300
26-
levelUpdated := 200
25+
level := v1pb.RiskLevel_HIGH.String()
26+
levelUpdated := v1pb.RiskLevel_MODERATE.String()
2727

2828
resource.Test(t, resource.TestCase{
2929
PreCheck: func() {
@@ -39,7 +39,7 @@ func TestAccRisk(t *testing.T) {
3939
internal.TestCheckResourceExists(resourceName),
4040
resource.TestCheckResourceAttr(resourceName, "title", title),
4141
resource.TestCheckResourceAttr(resourceName, "source", source),
42-
resource.TestCheckResourceAttr(resourceName, "level", fmt.Sprintf("%d", level)),
42+
resource.TestCheckResourceAttr(resourceName, "level", level),
4343
resource.TestCheckResourceAttr(resourceName, "active", "true"),
4444
resource.TestCheckResourceAttrSet(resourceName, "name"),
4545
),
@@ -51,7 +51,7 @@ func TestAccRisk(t *testing.T) {
5151
internal.TestCheckResourceExists(resourceName),
5252
resource.TestCheckResourceAttr(resourceName, "title", titleUpdated),
5353
resource.TestCheckResourceAttr(resourceName, "source", source),
54-
resource.TestCheckResourceAttr(resourceName, "level", fmt.Sprintf("%d", levelUpdated)),
54+
resource.TestCheckResourceAttr(resourceName, "level", levelUpdated),
5555
resource.TestCheckResourceAttr(resourceName, "active", "false"),
5656
),
5757
},
@@ -62,7 +62,7 @@ func TestAccRisk(t *testing.T) {
6262
internal.TestCheckResourceExists(resourceName),
6363
resource.TestCheckResourceAttr(resourceName, "title", titleUpdated),
6464
resource.TestCheckResourceAttr(resourceName, "source", v1pb.Risk_DML.String()),
65-
resource.TestCheckResourceAttr(resourceName, "level", fmt.Sprintf("%d", level)),
65+
resource.TestCheckResourceAttr(resourceName, "level", level),
6666
resource.TestCheckResourceAttr(resourceName, "active", "true"),
6767
),
6868
},
@@ -92,7 +92,7 @@ func TestAccRisk_AllSources(t *testing.T) {
9292
CheckDestroy: testAccCheckRiskDestroy,
9393
Steps: []resource.TestStep{
9494
{
95-
Config: testAccCheckRiskResource(identifier, fmt.Sprintf("Test Risk %s", source), source, 300, true),
95+
Config: testAccCheckRiskResource(identifier, fmt.Sprintf("Test Risk %s", source), source, v1pb.RiskLevel_HIGH.String(), true),
9696
Check: resource.ComposeTestCheckFunc(
9797
internal.TestCheckResourceExists(resourceName),
9898
resource.TestCheckResourceAttr(resourceName, "source", source),
@@ -120,7 +120,7 @@ func TestAccRisk_InvalidInput(t *testing.T) {
120120
resource "bytebase_risk" "%s" {
121121
title = ""
122122
source = "%s"
123-
level = 300
123+
level = "HIGH"
124124
active = true
125125
condition = "{\"expressions\":[{\"title\":\"High risk database\",\"expression\":\"resource.database == 'production'\"}]}"
126126
}
@@ -133,7 +133,7 @@ resource "bytebase_risk" "%s" {
133133
resource "bytebase_risk" "%s" {
134134
title = "Test Risk"
135135
source = "INVALID_SOURCE"
136-
level = 300
136+
level = "HIGH"
137137
active = true
138138
condition = "{\"expressions\":[{\"title\":\"High risk database\",\"expression\":\"resource.database == 'production'\"}]}"
139139
}
@@ -146,7 +146,7 @@ resource "bytebase_risk" "%s" {
146146
resource "bytebase_risk" "%s" {
147147
title = "Test Risk"
148148
source = "%s"
149-
level = 150
149+
level = "RISK_LEVEL_UNSPECIFIED"
150150
active = true
151151
condition = "{\"expressions\":[{\"title\":\"High risk database\",\"expression\":\"resource.database == 'production'\"}]}"
152152
}
@@ -157,7 +157,7 @@ resource "bytebase_risk" "%s" {
157157
})
158158
}
159159

160-
func testAccCheckRiskResource(identifier, title, source string, level int, active bool) string {
160+
func testAccCheckRiskResource(identifier, title, source string, level string, active bool) string {
161161
// Different conditions based on source type
162162
condition := ""
163163
switch source {
@@ -209,7 +209,7 @@ func testAccCheckRiskResource(identifier, title, source string, level int, activ
209209
resource "bytebase_risk" "%s" {
210210
title = "%s"
211211
source = "%s"
212-
level = %d
212+
level = "%s"
213213
active = %t
214214
condition = jsonencode(%s)
215215
}

tutorials/4-2-risk.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
resource "bytebase_risk" "dml_moderate" {
22
title = "DML Moderate Risk"
33
source = "DML"
4-
level = 200
4+
level = "MODERATE"
55
active = true
66
condition = "resource.environment_id == \"prod\" && statement.affected_rows >= 100"
77
}
88

99
resource "bytebase_risk" "ddl_high" {
1010
title = "DDL High Risk"
1111
source = "DDL"
12-
level = 300
12+
level = "HIGH"
1313
active = true
1414
condition = "resource.environment_id == \"prod\""
15-
}
15+
}

0 commit comments

Comments
 (0)