mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-30 18:23:35 +08:00
fix(cloudid): huawei group role attach and detach
This commit is contained in:
@@ -17,6 +17,9 @@ package modules
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huawei/client/auth"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huawei/client/responses"
|
||||
)
|
||||
@@ -50,6 +53,24 @@ func (manager *SGroupManager) ListRoles(domainId string, groupId string) (*respo
|
||||
return manager.ListInContextWithSpec(nil, fmt.Sprintf("%s/roles", groupId), nil, "roles")
|
||||
}
|
||||
|
||||
func (manager *SGroupManager) DeleteProjectRole(projectId, groupId, roleId string) error {
|
||||
if len(projectId) == 0 {
|
||||
return fmt.Errorf("missing projectId")
|
||||
}
|
||||
if len(groupId) == 0 {
|
||||
return fmt.Errorf("missing groupId")
|
||||
}
|
||||
if len(roleId) == 0 {
|
||||
return fmt.Errorf("missing roleId")
|
||||
}
|
||||
manager.SetVersion(fmt.Sprintf("v3/projects/%s", projectId))
|
||||
_, err := manager.DeleteInContextWithSpec(nil, groupId, fmt.Sprintf("roles/%s", roleId), nil, nil, "")
|
||||
if err != nil && errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (manager *SGroupManager) DeleteRole(domainId string, groupId, roleId string) error {
|
||||
if len(domainId) == 0 {
|
||||
return fmt.Errorf("missing domainId")
|
||||
@@ -62,6 +83,24 @@ func (manager *SGroupManager) DeleteRole(domainId string, groupId, roleId string
|
||||
}
|
||||
manager.SetVersion(fmt.Sprintf("v3/domains/%s", domainId))
|
||||
_, err := manager.DeleteInContextWithSpec(nil, groupId, fmt.Sprintf("roles/%s", roleId), nil, nil, "")
|
||||
if err != nil && errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (manager *SGroupManager) AddProjectRole(projectId string, groupId, roleId string) error {
|
||||
if len(projectId) == 0 {
|
||||
return fmt.Errorf("missing projectId")
|
||||
}
|
||||
if len(groupId) == 0 {
|
||||
return fmt.Errorf("missing groupId")
|
||||
}
|
||||
if len(roleId) == 0 {
|
||||
return fmt.Errorf("missing roleId")
|
||||
}
|
||||
manager.SetVersion(fmt.Sprintf("v3/projects/%s", projectId))
|
||||
_, err := manager.UpdateInContextWithSpec(nil, groupId, fmt.Sprintf("roles/%s", roleId), nil, "")
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +257,21 @@ func (self *SHuaweiClient) DetachGroupRole(groupId, roleId string) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "newGeneralAPIClient")
|
||||
}
|
||||
return client.Groups.DeleteRole(self.ownerId, groupId, roleId)
|
||||
err = client.Groups.DeleteRole(self.ownerId, groupId, roleId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "DeleteRole")
|
||||
}
|
||||
projects, err := self.GetProjects()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetProjects")
|
||||
}
|
||||
for _, project := range projects {
|
||||
err = client.Groups.DeleteProjectRole(project.ID, groupId, roleId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "DeleteProjectRole")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) AttachGroupRole(groupId, roleId string) error {
|
||||
@@ -265,5 +279,19 @@ func (self *SHuaweiClient) AttachGroupRole(groupId, roleId string) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "newGeneralAPIClient")
|
||||
}
|
||||
return client.Groups.AddRole(self.ownerId, groupId, roleId)
|
||||
err = client.Groups.AddRole(self.ownerId, groupId, roleId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "AddRole")
|
||||
}
|
||||
projects, err := self.GetProjects()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetProjects")
|
||||
}
|
||||
for _, project := range projects {
|
||||
err = client.Groups.AddProjectRole(project.ID, groupId, roleId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "AddProjectRole")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -68,6 +68,19 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type GroupRoleOptions struct {
|
||||
GROUP_ID string
|
||||
ROLE_ID string
|
||||
}
|
||||
|
||||
shellutils.R(&GroupRoleOptions{}, "cloud-group-detach-policy", "Detach group role", func(cli *huawei.SRegion, args *GroupRoleOptions) error {
|
||||
return cli.GetClient().DetachGroupRole(args.GROUP_ID, args.ROLE_ID)
|
||||
})
|
||||
|
||||
shellutils.R(&GroupRoleOptions{}, "cloud-group-attach-policy", "Detach group role", func(cli *huawei.SRegion, args *GroupRoleOptions) error {
|
||||
return cli.GetClient().AttachGroupRole(args.GROUP_ID, args.ROLE_ID)
|
||||
})
|
||||
|
||||
type GroupUserListOptions struct {
|
||||
GROUP_ID string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user