Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11.3
3.11.4
29 changes: 0 additions & 29 deletions api/setting.go

This file was deleted.

2 changes: 1 addition & 1 deletion examples/database/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/database_group/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/environments/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/groups/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/iamPolicy/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/policies/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/risk/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/roles/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/settings/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/setup/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/sql_review/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/users/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
27 changes: 7 additions & 20 deletions provider/data_source_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ func getWorkspaceApprovalSetting(computed bool) *schema.Schema {
Computed: computed,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(api.RiskLevelDefault),
string(api.RiskLevelLow),
string(api.RiskLevelModerate),
string(api.RiskLevelHigh),
v1pb.RiskLevel_LOW.String(),
v1pb.RiskLevel_MODERATE.String(),
v1pb.RiskLevel_HIGH.String(),
v1pb.RiskLevel_RISK_LEVEL_UNSPECIFIED.String(),
}, false),
},
},
Expand Down Expand Up @@ -677,23 +677,10 @@ func parseApprovalExpression(callExpr *v1alpha1.Expr_Call) ([]map[string]interfa
}

argName := argExpr.Args[0].GetIdentExpr().Name
constExpr := argExpr.Args[1].GetConstExpr()
switch argName {
case "source":
resp[argName] = argExpr.Args[1].GetConstExpr().GetStringValue()
case "level":
levelNumber := argExpr.Args[1].GetConstExpr().GetInt64Value()
switch int(levelNumber) {
case api.RiskLevelDefault.Int():
resp[argName] = api.RiskLevelDefault
case api.RiskLevelLow.Int():
resp[argName] = api.RiskLevelLow
case api.RiskLevelModerate.Int():
resp[argName] = api.RiskLevelModerate
case api.RiskLevelHigh.Int():
resp[argName] = api.RiskLevelHigh
default:
return nil, errors.Errorf("unknown risk level: %v", levelNumber)
}
case "source", "level":
resp[argName] = constExpr.GetStringValue()
default:
return nil, errors.Errorf("unsupport arg: %v", argName)
}
Expand Down
33 changes: 19 additions & 14 deletions provider/internal/mock_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"slices"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -641,6 +640,12 @@ func (*mockClient) ParseExpression(_ context.Context, expression string) (*v1alp
}

func parseCondition(condition string, baseID int64) *v1alpha1.Expr {
// Trim outer parentheses and whitespace first
condition = strings.TrimSpace(condition)
condition = strings.TrimPrefix(condition, "(")
condition = strings.TrimSuffix(condition, ")")
condition = strings.TrimSpace(condition)

// Parse AND conditions (&&)
parts := strings.Split(condition, " && ")
if len(parts) != 2 {
Expand All @@ -656,22 +661,22 @@ func parseCondition(condition string, baseID int64) *v1alpha1.Expr {
}

var sourceValue string
var levelValue int64
var levelValue string

for _, part := range parts {
part = strings.TrimSpace(part)
if strings.HasPrefix(part, "source ==") {
// Extract source value
sourceValue = strings.Trim(strings.TrimPrefix(part, "source =="), ` "`)
// Extract source value: remove 'source == ' and surrounding quotes
val := strings.TrimPrefix(part, "source ==")
val = strings.TrimSpace(val)
val = strings.Trim(val, `"`)
sourceValue = val
} else if strings.HasPrefix(part, "level ==") {
// Extract level value
levelStr := strings.TrimSpace(strings.TrimPrefix(part, "level =="))
var err error
levelValue, err = strconv.ParseInt(levelStr, 10, 64)
if err != nil {
// Default to 0 if parsing fails
levelValue = 0
}
// Extract level value as string: remove 'level == ' and surrounding quotes
val := strings.TrimPrefix(part, "level ==")
val = strings.TrimSpace(val)
val = strings.Trim(val, `"`)
levelValue = val
}
}

Expand Down Expand Up @@ -727,8 +732,8 @@ func parseCondition(condition string, baseID int64) *v1alpha1.Expr {
Id: baseID + 6,
ExprKind: &v1alpha1.Expr_ConstExpr{
ConstExpr: &v1alpha1.Constant{
ConstantKind: &v1alpha1.Constant_Int64Value{
Int64Value: levelValue,
ConstantKind: &v1alpha1.Constant_StringValue{
StringValue: levelValue,
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions provider/resource_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ func convertToV1ApprovalSetting(d *schema.ResourceData) (*v1pb.WorkspaceApproval
buildCondition := []string{}
for _, condition := range conditionList {
rawCondition := condition.(map[string]interface{})
rawLevel := rawCondition["level"].(string)
buildCondition = append(buildCondition, fmt.Sprintf(`source == "%s" && level == %d`, rawCondition["source"].(string), api.RiskLevel(rawLevel).Int()))
buildCondition = append(buildCondition, fmt.Sprintf(`(source == "%s" && level == "%s")`, rawCondition["source"].(string), rawCondition["level"].(string)))
}
expression := strings.Join(buildCondition, " || ")

Expand Down
2 changes: 1 addition & 1 deletion tutorials/0-provider.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "3.11.3"
version = "3.11.4"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down