-
Notifications
You must be signed in to change notification settings - Fork 386
/
cmd_access_use.go
46 lines (34 loc) · 975 Bytes
/
cmd_access_use.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
// 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 cmdAccessUse struct {
ex ulext.External
access string
}
func newCmdAccessUse(ex ulext.External) *cmdAccessUse {
return &cmdAccessUse{ex: ex}
}
func (c *cmdAccessUse) Setup(params clingy.Parameters) {
c.access = params.Arg("access", "Access name to use").(string)
}
func (c *cmdAccessUse) Execute(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
_, accesses, err := c.ex.GetAccessInfo(true)
if err != nil {
return err
}
if _, ok := accesses[c.access]; !ok {
return fmt.Errorf("ERROR: access %q does not exist. Use 'uplink access list' to see existing accesses", c.access)
}
if err := c.ex.SaveAccessInfo(c.access, accesses); err != nil {
return err
}
fmt.Fprintf(clingy.Stdout(ctx), "Switched default access to %q\n", c.access)
return nil
}