fix: aliyun tag list api

This commit is contained in:
Qu Xuan
2021-03-10 20:31:39 +08:00
parent 756e1c1b26
commit 4d9f007727
2 changed files with 13 additions and 11 deletions
+4 -2
View File
@@ -170,8 +170,10 @@ func (self *SRegion) GetInstances(zoneId string, ids []string, offset int, limit
}
type SAliyunTag struct {
TagKey string
TagValue string
ResourceId string
ResourceType string
TagKey string
TagValue string
}
func (self *SInstance) GetSecurityGroupIds() ([]string, error) {
+9 -9
View File
@@ -49,25 +49,25 @@ func (self *SRegion) ListTags(serviceType string, resourceType string, resourceI
params["RegionId"] = self.RegionId
params["ResourceType"] = resourceType
params["ResourceId.1"] = resourceId
params["PageSize"] = "50"
var page int = 1
nextToken := ""
for {
params["PageNumber"] = fmt.Sprintf("%d", page)
resp, err := self.tagRequest(serviceType, "DescribeTags", params)
if len(nextToken) > 0 {
params["NextToken"] = nextToken
}
resp, err := self.tagRequest(serviceType, "ListTagResources", params)
if err != nil {
return nil, errors.Wrapf(err, "%s DescribeTags %s", serviceType, params)
return nil, errors.Wrapf(err, "%s ListTagResources %s", serviceType, params)
}
part := []SAliyunTag{}
err = resp.Unmarshal(&part, "Tags", "Tag")
err = resp.Unmarshal(&part, "TagResources", "TagResource")
if err != nil {
return nil, errors.Wrapf(err, "resp.Unmarshal")
}
tags = append(tags, part...)
total, _ := resp.Int("TotalCount")
if len(tags) >= int(total) {
nextToken, _ = resp.GetString("NextToken")
if len(nextToken) == 0 {
break
}
page++
}
return tags, nil
}