-
Notifications
You must be signed in to change notification settings - Fork 402
/
cmd_access_revoke.go
50 lines (37 loc) · 1023 Bytes
/
cmd_access_revoke.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
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"fmt"
"github.com/zeebo/clingy"
"storj.io/storj/cmd/uplink/ulext"
)
type cmdAccessRevoke struct {
ex ulext.External
access string
revokee string
}
func newCmdAccessRevoke(ex ulext.External) *cmdAccessRevoke {
return &cmdAccessRevoke{ex: ex}
}
func (c *cmdAccessRevoke) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value performing the revoke", "").(string)
c.revokee = params.Arg("revokee", "Access name or value revoke").(string)
}
func (c *cmdAccessRevoke) Execute(ctx context.Context) error {
project, err := c.ex.OpenProject(ctx, c.access)
if err != nil {
return err
}
defer func() { _ = project.Close() }()
access, err := c.ex.OpenAccess(c.revokee)
if err != nil {
return err
}
if err := project.RevokeAccess(ctx, access); err != nil {
return err
}
fmt.Fprintf(clingy.Stdout(ctx), "Revoked access %q\n", c.revokee)
return nil
}