yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/shell/cam_user.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/qcloud" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type ClouduserListOptions struct { 24 } 25 shellutils.R(&ClouduserListOptions{}, "cloud-user-list", "List cloudusers", func(cli *qcloud.SRegion, args *ClouduserListOptions) error { 26 users, err := cli.GetClient().ListUsers() 27 if err != nil { 28 return err 29 } 30 printList(users, 0, 0, 0, nil) 31 return nil 32 }) 33 34 type ClouduserOptions struct { 35 USER string 36 } 37 shellutils.R(&ClouduserOptions{}, "cloud-user-delete", "Delete clouduser", func(cli *qcloud.SRegion, args *ClouduserOptions) error { 38 return cli.GetClient().DeleteUser(args.USER) 39 }) 40 41 shellutils.R(&ClouduserOptions{}, "cloud-user-show", "Show clouduser", func(cli *qcloud.SRegion, args *ClouduserOptions) error { 42 user, err := cli.GetClient().GetUser(args.USER) 43 if err != nil { 44 return err 45 } 46 printObject(user) 47 return nil 48 }) 49 50 type ClouduserCreateOptions struct { 51 NAME string 52 Password string 53 Desc string 54 ConsoleLogin bool 55 } 56 57 shellutils.R(&ClouduserCreateOptions{}, "cloud-user-create", "Create clouduser", func(cli *qcloud.SRegion, args *ClouduserCreateOptions) error { 58 user, err := cli.GetClient().AddUser(args.NAME, args.Password, args.Desc, args.ConsoleLogin) 59 if err != nil { 60 return err 61 } 62 printObject(user) 63 return nil 64 }) 65 66 type ClouduserPolicyOptions struct { 67 UIN string 68 POLICY_ID string 69 } 70 71 shellutils.R(&ClouduserPolicyOptions{}, "cloud-user-attach-policy", "Attach policy for clouduser", func(cli *qcloud.SRegion, args *ClouduserPolicyOptions) error { 72 return cli.GetClient().AttachUserPolicy(args.UIN, args.POLICY_ID) 73 }) 74 75 shellutils.R(&ClouduserPolicyOptions{}, "cloud-user-detach-policy", "Detach policy from clouduser", func(cli *qcloud.SRegion, args *ClouduserPolicyOptions) error { 76 return cli.GetClient().DetachUserPolicy(args.UIN, args.POLICY_ID) 77 }) 78 79 type ClouduserPolicyListOptions struct { 80 UIN string 81 Offset int 82 Limit int 83 } 84 85 shellutils.R(&ClouduserPolicyListOptions{}, "cloud-user-policy-list", "List policy from clouduser", func(cli *qcloud.SRegion, args *ClouduserPolicyListOptions) error { 86 policies, _, err := cli.GetClient().ListAttachedUserPolicies(args.UIN, args.Offset, args.Limit) 87 if err != nil { 88 return err 89 } 90 printList(policies, 0, 0, 0, nil) 91 return nil 92 }) 93 94 type ClouduserGroupListOptions struct { 95 UIN int 96 Offset int 97 Limit int 98 } 99 100 shellutils.R(&ClouduserGroupListOptions{}, "cloud-user-group-list", "List clouduser groups", func(cli *qcloud.SRegion, args *ClouduserGroupListOptions) error { 101 groups, _, err := cli.GetClient().ListGroupsForUser(args.UIN, args.Offset, args.Limit) 102 if err != nil { 103 return err 104 } 105 printList(groups, 0, 0, 0, nil) 106 return nil 107 }) 108 109 type CollaboratorList struct { 110 Offset int 111 Limit int 112 } 113 114 shellutils.R(&CollaboratorList{}, "collaborator-list", "List collaborator", func(cli *qcloud.SRegion, args *CollaboratorList) error { 115 collaborators, _, err := cli.GetClient().ListCollaborators(args.Offset, args.Limit) 116 if err != nil { 117 return err 118 } 119 printList(collaborators, 0, 0, 0, nil) 120 return nil 121 }) 122 123 }