Przeglądaj źródła

fix: Create/Update 透传 operatorUserName 以满足白泽校验

mbsd systemConfig 写接口要求 operatorUserName;SDK 增加第三参数并在为空时回退 userId。

Co-authored-by: Cursor <cursoragent@cursor.com>
郭铭泽 3 dni temu
rodzic
commit
f47b397934
2 zmienionych plików z 43 dodań i 33 usunięć
  1. 1 1
      README.md
  2. 42 32
      client.go

+ 1 - 1
README.md

@@ -47,7 +47,7 @@ err := mbsdsdk.Update(mbsdsdk.ConfigInfo{
     ID: info.ID, ConfigKey: info.ConfigKey, ConfigValue: newValue,
     ValueType: info.ValueType, ConfigGroup: info.ConfigGroup,
     Service: info.Service, Description: info.Description,
-}, userID)
+}, userID, operatorUserName)
 ```
 
 ## 版本发布(Gogs)

+ 42 - 32
client.go

@@ -59,24 +59,26 @@ type infoResponse struct {
 }
 
 type updateRequest struct {
-	ID           string `json:"id"`
-	ConfigKey    string `json:"configKey"`
-	ConfigValue  string `json:"configValue"`
-	ValueType    string `json:"valueType"`
-	ConfigGroup  string `json:"configGroup"`
-	Service      string `json:"service"`
-	Description  string `json:"description"`
-	UpdateUserID string `json:"updateUserId"`
+	ID               string `json:"id"`
+	ConfigKey        string `json:"configKey"`
+	ConfigValue      string `json:"configValue"`
+	ValueType        string `json:"valueType"`
+	ConfigGroup      string `json:"configGroup"`
+	Service          string `json:"service"`
+	Description      string `json:"description"`
+	UpdateUserID     string `json:"updateUserId"`
+	OperatorUserName string `json:"operatorUserName"`
 }
 
 type createRequest struct {
-	ConfigKey    string `json:"configKey"`
-	ConfigValue  string `json:"configValue"`
-	ValueType    string `json:"valueType"`
-	ConfigGroup  string `json:"configGroup"`
-	Service      string `json:"service"`
-	Description  string `json:"description"`
-	CreateUserID string `json:"createUserId"`
+	ConfigKey        string `json:"configKey"`
+	ConfigValue      string `json:"configValue"`
+	ValueType        string `json:"valueType"`
+	ConfigGroup      string `json:"configGroup"`
+	Service          string `json:"service"`
+	Description      string `json:"description"`
+	CreateUserID     string `json:"createUserId"`
+	OperatorUserName string `json:"operatorUserName"`
 }
 
 var (
@@ -300,23 +302,27 @@ func GetBool(key string, defaultValue bool) bool {
 }
 
 // Update 更新已有配置项(需带 ID)。
-func Update(info ConfigInfo, updateUserID string) error {
+func Update(info ConfigInfo, updateUserID, operatorUserName string) error {
 	if invokeAPI == nil {
 		return errors.New("mbsdsdk not initialized")
 	}
 	if info.ID == "" {
 		return errors.New("config id is required")
 	}
+	if operatorUserName == "" {
+		operatorUserName = updateUserID
+	}
 
 	body, err := json.Marshal(&updateRequest{
-		ID:           info.ID,
-		ConfigKey:    info.ConfigKey,
-		ConfigValue:  info.ConfigValue,
-		ValueType:    info.ValueType,
-		ConfigGroup:  info.ConfigGroup,
-		Service:      info.Service,
-		Description:  info.Description,
-		UpdateUserID: updateUserID,
+		ID:               info.ID,
+		ConfigKey:        info.ConfigKey,
+		ConfigValue:      info.ConfigValue,
+		ValueType:        info.ValueType,
+		ConfigGroup:      info.ConfigGroup,
+		Service:          info.Service,
+		Description:      info.Description,
+		UpdateUserID:     updateUserID,
+		OperatorUserName: operatorUserName,
 	})
 	if err != nil {
 		return err
@@ -345,19 +351,23 @@ func Update(info ConfigInfo, updateUserID string) error {
 }
 
 // Create 新建配置项。
-func Create(info ConfigInfo, createUserID string) error {
+func Create(info ConfigInfo, createUserID, operatorUserName string) error {
 	if invokeAPI == nil {
 		return errors.New("mbsdsdk not initialized")
 	}
+	if operatorUserName == "" {
+		operatorUserName = createUserID
+	}
 
 	body, err := json.Marshal(&createRequest{
-		ConfigKey:    info.ConfigKey,
-		ConfigValue:  info.ConfigValue,
-		ValueType:    info.ValueType,
-		ConfigGroup:  info.ConfigGroup,
-		Service:      info.Service,
-		Description:  info.Description,
-		CreateUserID: createUserID,
+		ConfigKey:        info.ConfigKey,
+		ConfigValue:      info.ConfigValue,
+		ValueType:        info.ValueType,
+		ConfigGroup:      info.ConfigGroup,
+		Service:          info.Service,
+		Description:      info.Description,
+		CreateUserID:     createUserID,
+		OperatorUserName: operatorUserName,
 	})
 	if err != nil {
 		return err