yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/roles.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package huawei 16 17 import ( 18 "yunion.io/x/jsonutils" 19 "yunion.io/x/pkg/errors" 20 21 "yunion.io/x/cloudmux/pkg/cloudprovider" 22 ) 23 24 type SRole struct { 25 DomainId string 26 Flag string 27 DescriptionCn string 28 Catelog string 29 Description string 30 Id string 31 DisplayName string 32 Type string 33 UpdatedTime string 34 CreatedTime string 35 Links SLink 36 Policy jsonutils.JSONDict 37 } 38 39 func (role *SRole) GetName() string { 40 return role.DisplayName 41 } 42 43 func (role *SRole) GetDescription() string { 44 return role.DescriptionCn 45 } 46 47 func (role *SRole) GetPolicyType() string { 48 return "System" 49 } 50 51 func (role *SRole) GetGlobalId() string { 52 return role.Id 53 } 54 55 func (role *SRole) UpdateDocument(document *jsonutils.JSONDict) error { 56 return cloudprovider.ErrNotImplemented 57 } 58 59 func (role *SRole) GetDocument() (*jsonutils.JSONDict, error) { 60 return &role.Policy, nil 61 } 62 63 func (role *SRole) Delete() error { 64 return cloudprovider.ErrNotImplemented 65 } 66 67 func (self *SHuaweiClient) GetISystemCloudpolicies() ([]cloudprovider.ICloudpolicy, error) { 68 roles, err := self.GetRoles("", "") 69 if err != nil { 70 return nil, errors.Wrap(err, "GetRoles") 71 } 72 ret := []cloudprovider.ICloudpolicy{} 73 for i := range roles { 74 ret = append(ret, &roles[i]) 75 } 76 return ret, nil 77 } 78 79 func (self *SHuaweiClient) GetRoles(domainId, name string) ([]SRole, error) { 80 params := map[string]string{} 81 if len(domainId) > 0 { 82 params["domain_id"] = self.ownerId 83 } 84 if len(name) > 0 { 85 params["name"] = name 86 } 87 88 client, err := self.newGeneralAPIClient() 89 if err != nil { 90 return nil, errors.Wrap(err, "newGeneralAPIClient") 91 } 92 93 roles := []SRole{} 94 err = doListAllWithNextLink(client.Roles.List, params, &roles) 95 if err != nil { 96 return nil, errors.Wrap(err, "doListAllWithOffset") 97 } 98 return roles, nil 99 }