diff --git a/pkg/multicloud/qcloud/cam_collaborator.go b/pkg/multicloud/qcloud/cam_collaborator.go new file mode 100644 index 0000000000..92109351e7 --- /dev/null +++ b/pkg/multicloud/qcloud/cam_collaborator.go @@ -0,0 +1,42 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package qcloud + +import ( + "fmt" + + "yunion.io/x/pkg/errors" +) + +func (self *SQcloudClient) ListCollaborators(offset, limit int) ([]SUser, int, error) { + if limit < 1 || limit > 50 { + limit = 50 + } + params := map[string]string{ + "Offset": fmt.Sprintf("%d", offset), + "Limit": fmt.Sprintf("%d", limit), + } + resp, err := self.camRequest("ListCollaborators", params) + if err != nil { + return nil, 0, errors.Wrapf(err, "ListCollaborators") + } + result := []SUser{} + err = resp.Unmarshal(&result, "Data") + if err != nil { + return nil, 0, errors.Wrapf(err, "resp.Unmarshal") + } + total, _ := resp.Float("totalNum") + return result, int(total), nil +} diff --git a/pkg/multicloud/qcloud/cam_user.go b/pkg/multicloud/qcloud/cam_user.go index 2addfc0f38..13f520705d 100644 --- a/pkg/multicloud/qcloud/cam_user.go +++ b/pkg/multicloud/qcloud/cam_user.go @@ -191,11 +191,27 @@ func (self *SQcloudClient) GetICloudusers() ([]cloudprovider.IClouduser, error) if err != nil { return nil, errors.Wrap(err, "ListUsers") } + ret := []cloudprovider.IClouduser{} for i := range users { users[i].client = self ret = append(ret, &users[i]) } + collaborators := []SUser{} + for { + part, total, err := self.ListCollaborators(len(collaborators), 50) + if err != nil { + return nil, errors.Wrapf(err, "ListCollaborators") + } + collaborators = append(collaborators, part...) + if len(collaborators) >= total { + break + } + } + for i := range collaborators { + collaborators[i].client = self + ret = append(ret, &collaborators[i]) + } return ret, nil } diff --git a/pkg/multicloud/qcloud/shell/cam_user.go b/pkg/multicloud/qcloud/shell/cam_user.go index cad8bba7c3..e62af9d531 100644 --- a/pkg/multicloud/qcloud/shell/cam_user.go +++ b/pkg/multicloud/qcloud/shell/cam_user.go @@ -106,4 +106,18 @@ func init() { return nil }) + type CollaboratorList struct { + Offset int + Limit int + } + + shellutils.R(&CollaboratorList{}, "collaborator-list", "List collaborator", func(cli *qcloud.SRegion, args *CollaboratorList) error { + collaborators, _, err := cli.GetClient().ListCollaborators(args.Offset, args.Limit) + if err != nil { + return err + } + printList(collaborators, 0, 0, 0, nil) + return nil + }) + }