forked from mdklein/candid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-group.go
68 lines (57 loc) · 1.53 KB
/
remove-group.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
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package admincmd
import (
"github.com/juju/cmd"
"golang.org/x/net/context"
"gopkg.in/CanonicalLtd/candidclient.v1/params"
"gopkg.in/errgo.v1"
)
type removeGroupCommand struct {
userCommand
groups []string
}
func newRemoveGroupCommand(cc *candidCommand) cmd.Command {
c := &removeGroupCommand{}
c.candidCommand = cc
return c
}
var removeGroupDoc = `
The remove-group command removes the specified user from the specified
group, or groups.
To remove the group-1 and group-2 groups from the user bob:
candid remove-group -u bob group-1 group-2
To remove the example-1 and example-2 groups from the user with the
email removeress bob@example.com:
candid remove-group -e bob@example.com group-1 group-2
`
func (c *removeGroupCommand) Info() *cmd.Info {
return &cmd.Info{
Name: "remove-group",
Args: "[group...]",
Purpose: "remove a user from groups",
Doc: removeGroupDoc,
}
}
func (c *removeGroupCommand) Init(args []string) error {
c.groups = args
return errgo.Mask(c.userCommand.Init(nil))
}
func (c *removeGroupCommand) Run(ctxt *cmd.Context) error {
defer c.Close(ctxt)
username, err := c.lookupUser(ctxt)
if err != nil {
return errgo.Mask(err)
}
client, err := c.Client(ctxt)
if err != nil {
return errgo.Mask(err)
}
err = client.ModifyUserGroups(context.Background(), ¶ms.ModifyUserGroupsRequest{
Username: username,
Groups: params.ModifyGroups{
Remove: c.groups,
},
})
return errgo.Mask(err)
}