mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix(region): project mapping key match at end of list (#19380)
This commit is contained in:
@@ -55,8 +55,30 @@ type ProjectMappingRuleInfo struct {
|
||||
Domain string `json:"domain"`
|
||||
}
|
||||
|
||||
func (rule ProjectMappingRuleInfo) IsWide() bool {
|
||||
for _, tag := range rule.Tags {
|
||||
if len(tag.Value) == 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type MappingRules []ProjectMappingRuleInfo
|
||||
|
||||
func (rules MappingRules) Rules() MappingRules {
|
||||
normal := []ProjectMappingRuleInfo{}
|
||||
wide := []ProjectMappingRuleInfo{}
|
||||
for _, rule := range rules {
|
||||
if rule.IsWide() {
|
||||
wide = append(wide, rule)
|
||||
} else {
|
||||
normal = append(normal, rule)
|
||||
}
|
||||
}
|
||||
return append(normal, wide...)
|
||||
}
|
||||
|
||||
func (rule *ProjectMappingRuleInfo) Validate() error {
|
||||
if len(rule.Tags) == 0 {
|
||||
return httperrors.NewInputParameterError("missing tags")
|
||||
@@ -159,6 +181,7 @@ type ProjectMappingDetails struct {
|
||||
type ProjectMappingCreateInput struct {
|
||||
apis.EnabledStatusInfrasResourceBaseCreateInput
|
||||
|
||||
// 根据标签key匹配的规则会默认排到列表最后
|
||||
Rules MappingRules
|
||||
}
|
||||
|
||||
@@ -173,6 +196,7 @@ type ProjectMappingResourceInfo struct {
|
||||
type ProjectMappingUpdateInput struct {
|
||||
apis.EnabledStatusInfrasResourceBaseUpdateInput
|
||||
|
||||
// 根据标签key匹配的规则会默认排到列表最后
|
||||
Rules MappingRules
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ func (manager *SProjectMappingManager) ValidateCreateData(
|
||||
input.Rules[i].Project = tenant.Name
|
||||
}
|
||||
}
|
||||
input.Rules = input.Rules.Rules()
|
||||
input.SetEnabled()
|
||||
input.Status = api.PROJECT_MAPPING_STATUS_AVAILABLE
|
||||
input.EnabledStatusInfrasResourceBaseCreateInput, err = manager.SEnabledStatusInfrasResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.EnabledStatusInfrasResourceBaseCreateInput)
|
||||
@@ -249,6 +250,7 @@ func (self *SProjectMapping) ValidateUpdateData(ctx context.Context, userCred mc
|
||||
input.Rules[i].Project = tenant.Name
|
||||
}
|
||||
}
|
||||
input.Rules = input.Rules.Rules()
|
||||
input.EnabledStatusInfrasResourceBaseUpdateInput, err = self.SEnabledStatusInfrasResourceBase.ValidateUpdateData(ctx, userCred, query, input.EnabledStatusInfrasResourceBaseUpdateInput)
|
||||
return input, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user