fix: map-fixed fallback builds JSON from DataDescriptor sub-param defaults

This commit is contained in:
“Naeel”
2026-07-19 09:34:26 +04:00
parent 35792091bd
commit 0a027c2ebf
8 changed files with 56 additions and 16 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ terraform {
required_providers {
nubes = {
source = "registry.kube5s.ru/nubes-test/nubes"
version = "5.1.5"
version = "5.1.6"
}
}
}
+7 -1
View File
@@ -1,5 +1,5 @@
resource "nubes_postgres" "npg" {
resource_name = "pgtst01"
resource_name = "pgtst02"
startup_configuration = {
resource_realm = var.realm
@@ -46,6 +46,12 @@ resource "nubes_postgres" "npg" {
operation_timeout = "11m"
adopt_existing_on_create = true
# mtls_configuration = {
# type = "off"
# duration_c_a = 175200
# duration_server = 87600
# }
}
+4
View File
@@ -122,6 +122,10 @@ Each operation has a kind:
в пользовательском `.tf`, подставлять zero-value по `dataType`:
- `integer``"0"`, `boolean``"false"`, `map-fixed``"{}"`, `array``"[]"`, `string``""`
- Это предотвращает NullPointerException на стороне API при добавлении новых полей.
- **map-fixed default из DataDescriptor** (`buildMapFixedDefault`): если API возвращает
`dataDescriptor` для `map-fixed`-параметра, а значение отсутствует или равно `"{}"`,
строится JSON из дефолтов sub-параметров (`{"type":"off","durationCA":"175200",...}`).
Это гарантирует что API получит все обязательные sub-поля с их значениями по умолчанию.
- **modify всегда через WithDefaults** (`RunInstanceOperationUniversalWithDefaults`):
modify-операции запрашивают `cfsParams` у API и отправляют все параметры,
включая новые, с дефолтами из API.
+1 -1
View File
@@ -4,7 +4,7 @@ TOKEN_FILE="secrets/dev.token"
# Release versions
# Version
VERSION="3.1.4"
VERSION="3.1.5"
# Registry/S3 settings
REGISTRY_HOST="registry.kube5s.ru"
+1 -1
View File
@@ -4,7 +4,7 @@ TOKEN_FILE="secrets/prod.token"
# Release versions
# Version
VERSION="2.1.3"
VERSION="2.1.4"
# Registry/S3 settings
REGISTRY_HOST="registry.kube5s.ru"
+1 -1
View File
@@ -3,7 +3,7 @@ NUBES_API_ENDPOINT="https://lk-api-gateway-test.ngcloud.ru/api/v1/svc"
TOKEN_FILE="secrets/test.token"
# Version
VERSION="5.1.6"
VERSION="5.1.7"
# Docs generation — ONLY from docs_gen/<stand>/ (never from docs/)
DOCS_GEN_DIR="provider/docs_gen/test"
+41 -11
View File
@@ -162,17 +162,25 @@ type universalOperation struct {
CfsParams []universalCfsParam `json:"cfsParams"`
}
type universalSubParam struct {
DefaultValue string `json:"defaultValue"`
DataType string `json:"dataType"`
SvcOperationCfsSubparam string `json:"svcOperationCfsSubparam"`
IsRequired bool `json:"isRequired"`
}
type universalCfsParam struct {
SvcOperationCfsParamId int `json:"svcOperationCfsParamId"`
ParamValue *string `json:"paramValue"`
DefaultValue *string `json:"defaultValue"`
IsRequired bool `json:"isRequired"`
DataType string `json:"dataType"`
Name string `json:"name"`
Code string `json:"code"`
Label string `json:"label"`
SvcOperationCfsParam string `json:"svcOperationCfsParam"`
RefSvcId *int `json:"refSvcId"`
SvcOperationCfsParamId int `json:"svcOperationCfsParamId"`
ParamValue *string `json:"paramValue"`
DefaultValue *string `json:"defaultValue"`
IsRequired bool `json:"isRequired"`
DataType string `json:"dataType"`
Name string `json:"name"`
Code string `json:"code"`
Label string `json:"label"`
SvcOperationCfsParam string `json:"svcOperationCfsParam"`
RefSvcId *int `json:"refSvcId"`
DataDescriptor map[string]universalSubParam `json:"dataDescriptor"`
}
// CreateGenericInstanceUniversalV6 implements the universal flow:
@@ -311,6 +319,19 @@ func (c *UniversalClient) CreateGenericInstanceUniversalV6(ctx context.Context,
return instanceUid, nil
}
// buildMapFixedDefault строит JSON-объект из дефолтов sub-параметров map-fixed.
func buildMapFixedDefault(param universalCfsParam) string {
result := make(map[string]string, len(param.DataDescriptor))
for key, sub := range param.DataDescriptor {
result[key] = sub.DefaultValue
}
b, err := json.Marshal(result)
if err != nil {
return "{}"
}
return string(b)
}
func normalizeUniversalValueV6(val string, param universalCfsParam) string {
trimmed := strings.TrimSpace(val)
if strings.EqualFold(trimmed, "null") {
@@ -319,11 +340,20 @@ func normalizeUniversalValueV6(val string, param universalCfsParam) string {
if trimmed == "\"\"" {
trimmed = ""
}
// map-fixed с DataDescriptor: если значение пустое или "{}" — строим JSON из дефолтов sub-params.
dataType := strings.ToLower(param.DataType)
if (dataType == "map-fixed" || strings.HasPrefix(dataType, "map")) && len(param.DataDescriptor) > 0 {
if trimmed == "" || trimmed == "{}" {
return buildMapFixedDefault(param)
}
return trimmed
}
if trimmed != "" {
return trimmed
}
dataType := strings.ToLower(param.DataType)
nameHint := strings.ToLower(param.Name + " " + param.Code + " " + param.Label + " " + param.SvcOperationCfsParam)
if strings.Contains(dataType, "array") || strings.Contains(nameHint, "array") || strings.Contains(nameHint, "list") {