mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix(region): add account info for sec rules (#22575)
This commit is contained in:
@@ -291,6 +291,16 @@ type SecgroupDetails struct {
|
||||
type SecurityGroupResourceInfo struct {
|
||||
// 安全组名称
|
||||
Secgroup string `json:"secgroup"`
|
||||
|
||||
// VPC归属区域ID
|
||||
CloudregionId string `json:"cloudregion_id"`
|
||||
|
||||
CloudregionResourceInfo
|
||||
|
||||
// VPC归属云订阅ID
|
||||
ManagerId string `json:"manager_id"`
|
||||
|
||||
ManagedResourceInfo
|
||||
}
|
||||
|
||||
type GuestsecgroupListInput struct {
|
||||
|
||||
@@ -36,7 +36,10 @@ type SSecurityGroupResourceBase struct {
|
||||
SecgroupId string `width:"36" charset:"ascii" nullable:"false" create:"required" index:"true" list:"user" json:"secgroup_id"`
|
||||
}
|
||||
|
||||
type SSecurityGroupResourceBaseManager struct{}
|
||||
type SSecurityGroupResourceBaseManager struct {
|
||||
SCloudregionResourceBaseManager
|
||||
SManagedResourceBaseManager
|
||||
}
|
||||
|
||||
func ValidateSecurityGroupResourceInput(ctx context.Context, userCred mcclient.TokenCredential, query api.SecgroupResourceInput) (*SSecurityGroup, api.SecgroupResourceInput, error) {
|
||||
secgrpObj, err := SecurityGroupManager.FetchByIdOrName(ctx, userCred, query.SecgroupId)
|
||||
@@ -78,16 +81,34 @@ func (manager *SSecurityGroupResourceBaseManager) FetchCustomizeColumns(
|
||||
}
|
||||
secgrpIds[i] = base.SecgroupId
|
||||
}
|
||||
secgrpNames, err := db.FetchIdNameMap2(SecurityGroupManager, secgrpIds)
|
||||
|
||||
groups := make(map[string]SSecurityGroup)
|
||||
err := db.FetchStandaloneObjectsByIds(SecurityGroupManager, secgrpIds, groups)
|
||||
if err != nil {
|
||||
log.Errorf("FetchIdNameMap2 fail %s", err)
|
||||
return rows
|
||||
log.Errorf("FetchStandaloneObjectsByIds fail %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
regionList := make([]interface{}, len(rows))
|
||||
managerList := make([]interface{}, len(rows))
|
||||
for i := range rows {
|
||||
if name, ok := secgrpNames[secgrpIds[i]]; ok {
|
||||
rows[i].Secgroup = name
|
||||
rows[i] = api.SecurityGroupResourceInfo{}
|
||||
if group, ok := groups[secgrpIds[i]]; ok {
|
||||
rows[i].Secgroup = group.Name
|
||||
rows[i].CloudregionId = group.CloudregionId
|
||||
rows[i].ManagerId = group.ManagerId
|
||||
}
|
||||
regionList[i] = &SCloudregionResourceBase{rows[i].CloudregionId}
|
||||
managerList[i] = &SManagedResourceBase{rows[i].ManagerId}
|
||||
}
|
||||
|
||||
regionRows := manager.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, regionList, fields, isList)
|
||||
managerRows := manager.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, managerList, fields, isList)
|
||||
for i := range rows {
|
||||
rows[i].CloudregionResourceInfo = regionRows[i]
|
||||
rows[i].ManagedResourceInfo = managerRows[i]
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user