mirror of
https://github.com/drone/drone-cli.git
synced 2024-11-23 01:11:57 +01:00
add commands to block, update users
This commit is contained in:
parent
0dc2f87702
commit
844f92083a
2
Gopkg.lock
generated
2
Gopkg.lock
generated
@ -79,7 +79,7 @@
|
||||
"plugin/registry",
|
||||
"plugin/secret"
|
||||
]
|
||||
revision = "1b7bf64213564df83337d6ef7271fed757261c3a"
|
||||
revision = "1354e27647f2efee29b63dcd9cc561fafb4c51c1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
@ -10,6 +10,8 @@ var Command = cli.Command{
|
||||
userListCmd,
|
||||
userInfoCmd,
|
||||
userAddCmd,
|
||||
userUpdateCmd,
|
||||
userRemoveCmd,
|
||||
userBlockCmd,
|
||||
},
|
||||
}
|
||||
|
37
drone/user/user_block.go
Normal file
37
drone/user/user_block.go
Normal file
@ -0,0 +1,37 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
|
||||
"github.com/drone/drone-cli/drone/internal"
|
||||
"github.com/drone/drone-go/drone"
|
||||
)
|
||||
|
||||
var userBlockCmd = cli.Command{
|
||||
Name: "block",
|
||||
Usage: "block a user",
|
||||
ArgsUsage: "<username>",
|
||||
Action: userBlock,
|
||||
}
|
||||
|
||||
func userBlock(c *cli.Context) error {
|
||||
login := c.Args().First()
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
active := false
|
||||
opts := &drone.UserPatch{
|
||||
Active: &active,
|
||||
}
|
||||
_, err = client.UserUpdate(login, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Successfully blocked user %s\n", login)
|
||||
return nil
|
||||
}
|
@ -51,5 +51,6 @@ func userInfo(c *cli.Context) error {
|
||||
var tmplUserInfo = `User: {{ .Login }}
|
||||
Email: {{ .Email }}
|
||||
Admin: {{ .Admin }}
|
||||
Active: {{ .Active }}
|
||||
Machine: {{ .Machine }}
|
||||
`
|
||||
|
51
drone/user/user_update.go
Normal file
51
drone/user/user_update.go
Normal file
@ -0,0 +1,51 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
|
||||
"github.com/drone/drone-cli/drone/internal"
|
||||
"github.com/drone/drone-go/drone"
|
||||
)
|
||||
|
||||
var userUpdateCmd = cli.Command{
|
||||
Name: "update",
|
||||
Usage: "update a user",
|
||||
ArgsUsage: "<username>",
|
||||
Action: userUpdate,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "active",
|
||||
Usage: "user is active",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "admin",
|
||||
Usage: "user is an admin",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func userUpdate(c *cli.Context) error {
|
||||
login := c.Args().First()
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts := &drone.UserPatch{}
|
||||
if c.IsSet("active") {
|
||||
v := c.Bool("active")
|
||||
opts.Active = &v
|
||||
}
|
||||
if c.IsSet("admin") {
|
||||
v := c.Bool("admin")
|
||||
opts.Admin = &v
|
||||
}
|
||||
if _, err := client.UserUpdate(login, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Successfully updated user %s\n", login)
|
||||
return nil
|
||||
}
|
4
vendor/github.com/drone/drone-go/drone/client.go
generated
vendored
4
vendor/github.com/drone/drone-go/drone/client.go
generated
vendored
@ -134,9 +134,9 @@ func (c *client) UserCreate(in *User) (*User, error) {
|
||||
}
|
||||
|
||||
// UserUpdate updates a user account.
|
||||
func (c *client) UserUpdate(in *User) (*User, error) {
|
||||
func (c *client) UserUpdate(login string, in *UserPatch) (*User, error) {
|
||||
out := new(User)
|
||||
uri := fmt.Sprintf(pathUser, c.addr, in.Login)
|
||||
uri := fmt.Sprintf(pathUser, c.addr, login)
|
||||
err := c.patch(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
2
vendor/github.com/drone/drone-go/drone/interface.go
generated
vendored
2
vendor/github.com/drone/drone-go/drone/interface.go
generated
vendored
@ -44,7 +44,7 @@ type Client interface {
|
||||
UserCreate(user *User) (*User, error)
|
||||
|
||||
// UserUpdate updates a user account.
|
||||
UserUpdate(user *User) (*User, error)
|
||||
UserUpdate(login string, user *UserPatch) (*User, error)
|
||||
|
||||
// UserDelete deletes a user account.
|
||||
UserDelete(login string) error
|
||||
|
7
vendor/github.com/drone/drone-go/drone/types.go
generated
vendored
7
vendor/github.com/drone/drone-go/drone/types.go
generated
vendored
@ -31,6 +31,13 @@ type (
|
||||
LastLogin int64 `json:"last_login"`
|
||||
}
|
||||
|
||||
// UserPatch defines a user patch request.
|
||||
UserPatch struct {
|
||||
Active *bool `json:"active,omitempty"`
|
||||
Admin *bool `json:"admin,omitempty"`
|
||||
Machine *bool `json:"machine,omitempty"`
|
||||
}
|
||||
|
||||
// Repo represents a repository.
|
||||
Repo struct {
|
||||
ID int64 `json:"id"`
|
||||
|
Loading…
Reference in New Issue
Block a user