diff --git a/VERSION b/VERSION index fc89ddd..2b6882d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.11.3 \ No newline at end of file +3.11.4 \ No newline at end of file diff --git a/api/setting.go b/api/setting.go deleted file mode 100644 index f3a4a25..0000000 --- a/api/setting.go +++ /dev/null @@ -1,29 +0,0 @@ -package api - -// RiskLevel is the approval risk level. -type RiskLevel string - -const ( - // RiskLevelDefault is the default risk level, the level number should be 0. - RiskLevelDefault RiskLevel = "DEFAULT" - // RiskLevelLow is the low risk level, the level number should be 100. - RiskLevelLow RiskLevel = "LOW" - // RiskLevelModerate is the moderate risk level, the level number should be 200. - RiskLevelModerate RiskLevel = "MODERATE" - // RiskLevelHigh is the high risk level, the level number should be 300. - RiskLevelHigh RiskLevel = "HIGH" -) - -// Int returns the int value for risk. -func (r RiskLevel) Int() int { - switch r { - case RiskLevelLow: - return 100 - case RiskLevelModerate: - return 200 - case RiskLevelHigh: - return 300 - default: - return 0 - } -} diff --git a/examples/database/main.tf b/examples/database/main.tf index a67a134..ddb7bc1 100644 --- a/examples/database/main.tf +++ b/examples/database/main.tf @@ -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" } diff --git a/examples/database_group/main.tf b/examples/database_group/main.tf index d45d511..9cde338 100644 --- a/examples/database_group/main.tf +++ b/examples/database_group/main.tf @@ -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" } diff --git a/examples/environments/main.tf b/examples/environments/main.tf index 7cdfacd..5a8cd4d 100644 --- a/examples/environments/main.tf +++ b/examples/environments/main.tf @@ -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" } diff --git a/examples/groups/main.tf b/examples/groups/main.tf index a61bd5f..8a7c045 100644 --- a/examples/groups/main.tf +++ b/examples/groups/main.tf @@ -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" } diff --git a/examples/iamPolicy/main.tf b/examples/iamPolicy/main.tf index a80b284..a7604b2 100644 --- a/examples/iamPolicy/main.tf +++ b/examples/iamPolicy/main.tf @@ -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" } diff --git a/examples/instances/main.tf b/examples/instances/main.tf index 7fb7f80..213cd2b 100644 --- a/examples/instances/main.tf +++ b/examples/instances/main.tf @@ -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" } diff --git a/examples/policies/main.tf b/examples/policies/main.tf index 2a66504..82193d4 100644 --- a/examples/policies/main.tf +++ b/examples/policies/main.tf @@ -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" } diff --git a/examples/projects/main.tf b/examples/projects/main.tf index 63ae1f4..9eda580 100644 --- a/examples/projects/main.tf +++ b/examples/projects/main.tf @@ -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" } diff --git a/examples/risk/main.tf b/examples/risk/main.tf index ea46263..7e4b452 100644 --- a/examples/risk/main.tf +++ b/examples/risk/main.tf @@ -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" } diff --git a/examples/roles/main.tf b/examples/roles/main.tf index 5192c4c..763dcf5 100644 --- a/examples/roles/main.tf +++ b/examples/roles/main.tf @@ -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" } diff --git a/examples/settings/main.tf b/examples/settings/main.tf index 45fe8e3..c8870b7 100644 --- a/examples/settings/main.tf +++ b/examples/settings/main.tf @@ -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" } diff --git a/examples/setup/main.tf b/examples/setup/main.tf index 3c22594..5500168 100644 --- a/examples/setup/main.tf +++ b/examples/setup/main.tf @@ -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" } diff --git a/examples/sql_review/main.tf b/examples/sql_review/main.tf index 867bd2e..c1a4923 100644 --- a/examples/sql_review/main.tf +++ b/examples/sql_review/main.tf @@ -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" } diff --git a/examples/users/main.tf b/examples/users/main.tf index eec67b8..312e81a 100644 --- a/examples/users/main.tf +++ b/examples/users/main.tf @@ -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" } diff --git a/provider/data_source_setting.go b/provider/data_source_setting.go index e770bb5..52e9716 100644 --- a/provider/data_source_setting.go +++ b/provider/data_source_setting.go @@ -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), }, }, @@ -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) } diff --git a/provider/internal/mock_client.go b/provider/internal/mock_client.go index 449a4ee..27a6ccf 100644 --- a/provider/internal/mock_client.go +++ b/provider/internal/mock_client.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "slices" - "strconv" "strings" "sync" @@ -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 { @@ -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 } } @@ -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, }, }, }, diff --git a/provider/resource_setting.go b/provider/resource_setting.go index ddeb96b..e014c85 100644 --- a/provider/resource_setting.go +++ b/provider/resource_setting.go @@ -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, " || ") diff --git a/tutorials/0-provider.tf b/tutorials/0-provider.tf index 7d553be..a14ba99 100644 --- a/tutorials/0-provider.tf +++ b/tutorials/0-provider.tf @@ -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" }