Skip to content

Commit cbcb8d9

Browse files
authored
feat: enhance Meta structure in handlePatchInstance to include Peer and Tags validation
1 parent 1d41d2d commit cbcb8d9

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

internal/master.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,10 @@ func (m *Master) handlePatchInstance(w http.ResponseWriter, r *http.Request, id
11391139
Alias string `json:"alias,omitempty"`
11401140
Action string `json:"action,omitempty"`
11411141
Restart *bool `json:"restart,omitempty"`
1142-
Meta *Meta `json:"meta,omitempty"`
1142+
Meta *struct {
1143+
Peer *Peer `json:"peer,omitempty"`
1144+
Tags map[string]string `json:"tags,omitempty"`
1145+
} `json:"meta,omitempty"`
11431146
}
11441147
if err := json.NewDecoder(r.Body).Decode(&reqData); err == nil {
11451148
if id == apiKeyID {
@@ -1218,19 +1221,24 @@ func (m *Master) handlePatchInstance(w http.ResponseWriter, r *http.Request, id
12181221

12191222
// 更新元数据
12201223
if reqData.Meta != nil {
1221-
if len(reqData.Meta.Peer.SID) > maxValueLen {
1222-
httpError(w, fmt.Sprintf("Meta peer.sid exceeds maximum length %d", maxValueLen), http.StatusBadRequest)
1223-
return
1224-
}
1225-
if len(reqData.Meta.Peer.Type) > maxValueLen {
1226-
httpError(w, fmt.Sprintf("Meta peer.type exceeds maximum length %d", maxValueLen), http.StatusBadRequest)
1227-
return
1228-
}
1229-
if len(reqData.Meta.Peer.Alias) > maxValueLen {
1230-
httpError(w, fmt.Sprintf("Meta peer.alias exceeds maximum length %d", maxValueLen), http.StatusBadRequest)
1231-
return
1224+
// 验证并更新 Peer 信息
1225+
if reqData.Meta.Peer != nil {
1226+
if len(reqData.Meta.Peer.SID) > maxValueLen {
1227+
httpError(w, fmt.Sprintf("Meta peer.sid exceeds maximum length %d", maxValueLen), http.StatusBadRequest)
1228+
return
1229+
}
1230+
if len(reqData.Meta.Peer.Type) > maxValueLen {
1231+
httpError(w, fmt.Sprintf("Meta peer.type exceeds maximum length %d", maxValueLen), http.StatusBadRequest)
1232+
return
1233+
}
1234+
if len(reqData.Meta.Peer.Alias) > maxValueLen {
1235+
httpError(w, fmt.Sprintf("Meta peer.alias exceeds maximum length %d", maxValueLen), http.StatusBadRequest)
1236+
return
1237+
}
1238+
instance.Meta.Peer = *reqData.Meta.Peer
12321239
}
12331240

1241+
// 验证并更新 Tags 信息
12341242
if reqData.Meta.Tags != nil {
12351243
// 检查键值对的唯一性和长度
12361244
seen := make(map[string]bool)
@@ -1249,9 +1257,9 @@ func (m *Master) handlePatchInstance(w http.ResponseWriter, r *http.Request, id
12491257
}
12501258
seen[key] = true
12511259
}
1260+
instance.Meta.Tags = reqData.Meta.Tags
12521261
}
12531262

1254-
instance.Meta = *reqData.Meta
12551263
m.instances.Store(id, instance)
12561264
go m.saveState()
12571265
m.logger.Info("Meta updated [%v]", instance.ID)

0 commit comments

Comments
 (0)