yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/apsara/shell/ram_role.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 shell 16 17 import ( 18 "yunion.io/x/cloudmux/pkg/multicloud/apsara" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type ListRolesOptions struct { 24 Offset string 25 Limit int 26 } 27 shellutils.R(&ListRolesOptions{}, "cloud-role-list", "List ram roles", func(cli *apsara.SRegion, args *ListRolesOptions) error { 28 roles, err := cli.GetClient().ListRoles(args.Offset, args.Limit) 29 if err != nil { 30 return err 31 } 32 printList(roles.Roles.Role, 0, 0, 0, []string{}) 33 return nil 34 }) 35 36 type GetRoleOptions struct { 37 ROLENAME string 38 } 39 shellutils.R(&GetRoleOptions{}, "cloud-role-show", "Show ram role", func(cli *apsara.SRegion, args *GetRoleOptions) error { 40 role, err := cli.GetClient().GetRole(args.ROLENAME) 41 if err != nil { 42 return err 43 } 44 printObject(role) 45 return nil 46 }) 47 48 type RolePolicyOptions struct { 49 ROLENAME string 50 POLICYNAME string 51 POLICYTYPE string `choices:"Custom|System"` 52 } 53 54 shellutils.R(&RolePolicyOptions{}, "cloud-role-attach-policy", "Attach policy for role", func(cli *apsara.SRegion, args *RolePolicyOptions) error { 55 return cli.GetClient().AttachPolicy2Role(args.POLICYTYPE, args.POLICYNAME, args.ROLENAME) 56 }) 57 58 shellutils.R(&RolePolicyOptions{}, "cloud-role-detach-policy", "Detach policy from role", func(cli *apsara.SRegion, args *RolePolicyOptions) error { 59 return cli.GetClient().DetachPolicyFromRole(args.POLICYTYPE, args.POLICYNAME, args.ROLENAME) 60 }) 61 62 type RolePolicyListOptions struct { 63 ROLE string 64 } 65 66 shellutils.R(&RolePolicyListOptions{}, "cloud-role-policy-list", "List cloud role policies", func(cli *apsara.SRegion, args *RolePolicyListOptions) error { 67 policies, err := cli.GetClient().ListPoliciesForRole(args.ROLE) 68 if err != nil { 69 return err 70 } 71 printList(policies, 0, 0, 0, nil) 72 return nil 73 }) 74 75 type DeleteRoleOptions struct { 76 NAME string 77 } 78 shellutils.R(&DeleteRoleOptions{}, "cloud-role-delete", "Delete role", func(cli *apsara.SRegion, args *DeleteRoleOptions) error { 79 return cli.GetClient().DeleteRole(args.NAME) 80 }) 81 82 shellutils.R(&ListRolesOptions{}, "enable-image-import", "Enable image import privilege", func(cli *apsara.SRegion, args *ListRolesOptions) error { 83 return cli.GetClient().EnableImageImport() 84 }) 85 86 shellutils.R(&ListRolesOptions{}, "enable-image-export", "Enable image export privilege", func(cli *apsara.SRegion, args *ListRolesOptions) error { 87 return cli.GetClient().EnableImageExport() 88 }) 89 90 type CallerShowOptions struct { 91 } 92 93 shellutils.R(&CallerShowOptions{}, "caller-show", "Show caller info", func(cli *apsara.SRegion, args *CallerShowOptions) error { 94 caller, err := cli.GetClient().GetCallerIdentity() 95 if err != nil { 96 return err 97 } 98 printObject(caller) 99 return nil 100 }) 101 102 }