Merge pull request #14026 from ioito/automated-cherry-pick-of-#14025-upstream-release-3.9

Automated cherry pick of #14025: fix(region): apsara resource groups
This commit is contained in:
Zexi Li
2022-04-15 11:35:16 +08:00
committed by GitHub
2 changed files with 28 additions and 14 deletions

View File

@@ -301,10 +301,13 @@ func (self *SApsaraClient) getDefaultClient(regionId string) (*sdk.Client, error
}
ret := struct {
AsapiErrorCode string `json:"asapiErrorCode"`
Code int
Code string
}{}
obj.Unmarshal(&ret)
if ret.Code == 403 || strings.Contains(ret.AsapiErrorCode, "NoPermission") {
if ret.Code == "403" ||
strings.Contains(ret.AsapiErrorCode, "NoPermission") ||
utils.HasPrefix(ret.Code, "Forbidden") ||
utils.HasPrefix(ret.Code, "NoPermission") {
self.cpcfg.UpdatePermission(service, action)
}
}

View File

@@ -50,6 +50,26 @@ type SOrganization struct {
UUID string
}
type ResourceGroupList []SResourceGroupList
func (rgs ResourceGroupList) ToProjects(tags []string) []SProject {
ret := []SProject{}
for _, rg := range rgs {
name := rg.ResourceGroupName
if strings.HasPrefix(name, "ResourceSet(") {
name = strings.TrimPrefix(name, "ResourceSet(")
name = strings.TrimSuffix(name, ")")
}
proj := SProject{
Id: rg.Id,
Name: name,
Tags: tags,
}
ret = append(ret, proj)
}
return ret
}
type SOrganizationTree struct {
Active bool
Alias string
@@ -58,7 +78,7 @@ type SOrganizationTree struct {
ParentId string
MultiCCloudStatus string
Children []SOrganizationTree
ResourceGroupList []SResourceGroupList
ResourceGroupList ResourceGroupList
SupportRegions string
UUID string
}
@@ -68,18 +88,9 @@ func (self *SOrganizationTree) GetProject(tags []string) []SProject {
if self.Name != "root" {
tags = append(tags, self.Name)
}
ret = append(ret, self.ResourceGroupList.ToProjects(tags)...)
if len(self.Children) == 0 {
for _, resGrp := range self.ResourceGroupList {
if strings.HasPrefix(resGrp.ResourceGroupName, "ResourceSet(") {
continue
}
proj := SProject{
Id: resGrp.Id,
Name: resGrp.ResourceGroupName,
Tags: tags,
}
ret = append(ret, proj)
}
return ret
}
for _, child := range self.Children {
ret = append(ret, child.GetProject(tags)...)