-
Notifications
You must be signed in to change notification settings - Fork 28
/
iam_user.go
143 lines (122 loc) · 4.58 KB
/
iam_user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// 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 shell
import (
"yunion.io/x/cloudmux/pkg/multicloud/aws"
"yunion.io/x/onecloud/pkg/util/shellutils"
)
func init() {
type ClouduserListOptions struct {
Offset string
Limit int
PathPrefix string
}
shellutils.R(&ClouduserListOptions{}, "cloud-user-list", "List cloudusers", func(cli *aws.SRegion, args *ClouduserListOptions) error {
users, err := cli.GetClient().ListUsers(args.Offset, args.Limit, args.PathPrefix)
if err != nil {
return err
}
printList(users.Users, 0, 0, 0, nil)
return nil
})
type ClouduserCreateOptions struct {
NAME string
Path string
}
shellutils.R(&ClouduserCreateOptions{}, "cloud-user-create", "Create clouduser", func(cli *aws.SRegion, args *ClouduserCreateOptions) error {
user, err := cli.GetClient().CreateUser(args.Path, args.NAME)
if err != nil {
return err
}
printObject(user)
return nil
})
type ClouduserOptions struct {
NAME string
}
shellutils.R(&ClouduserOptions{}, "cloud-user-show", "Show clouduser details", func(cli *aws.SRegion, args *ClouduserOptions) error {
user, err := cli.GetClient().GetUser(args.NAME)
if err != nil {
return err
}
printObject(user)
return nil
})
shellutils.R(&ClouduserOptions{}, "cloud-user-loginprofile", "Show clouduser loginprofile", func(cli *aws.SRegion, args *ClouduserOptions) error {
profile, err := cli.GetClient().GetLoginProfile(args.NAME)
if err != nil {
return err
}
printObject(profile)
return nil
})
shellutils.R(&ClouduserOptions{}, "cloud-user-loginprofile-delete", "Delete clouduser loginprofile", func(cli *aws.SRegion, args *ClouduserOptions) error {
return cli.GetClient().DeleteLoginProfile(args.NAME)
})
shellutils.R(&ClouduserOptions{}, "cloud-user-delete", "Delete clouduser", func(cli *aws.SRegion, args *ClouduserOptions) error {
return cli.GetClient().DeleteUser(args.NAME)
})
type ClouduserLoginProfileCreateOptions struct {
NAME string
PASSWORD string
}
shellutils.R(&ClouduserLoginProfileCreateOptions{}, "cloud-user-loginprofile-create", "Create clouduser loginprofile", func(cli *aws.SRegion, args *ClouduserLoginProfileCreateOptions) error {
profile, err := cli.GetClient().CreateLoginProfile(args.NAME, args.PASSWORD)
if err != nil {
return err
}
printObject(profile)
return nil
})
shellutils.R(&ClouduserLoginProfileCreateOptions{}, "cloud-user-reset-password", "Reset clouduser password", func(cli *aws.SRegion, args *ClouduserLoginProfileCreateOptions) error {
return cli.GetClient().ResetUserPassword(args.NAME, args.PASSWORD)
})
type ClouduserPolicyListOptions struct {
NAME string
Offset string
Limit int
}
shellutils.R(&ClouduserPolicyListOptions{}, "cloud-user-policy-list", "List clouduser policies", func(cli *aws.SRegion, args *ClouduserPolicyListOptions) error {
policies, err := cli.GetClient().ListUserPolicies(args.NAME, args.Offset, args.Limit)
if err != nil {
return err
}
printObject(policies)
return nil
})
type ClouduserAttachedPolicyListOptions struct {
NAME string
Offset string
Limit int
PathPrefix string
}
shellutils.R(&ClouduserAttachedPolicyListOptions{}, "cloud-user-attached-policy-list", "List clouduser attached policies", func(cli *aws.SRegion, args *ClouduserAttachedPolicyListOptions) error {
policies, err := cli.GetClient().ListAttachedUserPolicies(args.NAME, args.Offset, args.Limit, args.PathPrefix)
if err != nil {
return err
}
printList(policies.AttachedPolicies, 0, 0, 0, nil)
return nil
})
type ClouduserPolicyOptions struct {
NAME string
POLICY_ARN string
}
shellutils.R(&ClouduserPolicyOptions{}, "cloud-user-attach-policy", "Attach policy for clouduser", func(cli *aws.SRegion, args *ClouduserPolicyOptions) error {
return cli.GetClient().AttachUserPolicy(args.NAME, args.POLICY_ARN)
})
shellutils.R(&ClouduserPolicyOptions{}, "cloud-user-detach-policy", "Detach policy from clouduser", func(cli *aws.SRegion, args *ClouduserPolicyOptions) error {
return cli.GetClient().DetachUserPolicy(args.NAME, args.POLICY_ARN)
})
}