2021-03-31 16:56:34 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-08-30 10:51:31 +01:00
|
|
|
"context"
|
2021-06-25 17:51:05 +01:00
|
|
|
"fmt"
|
|
|
|
|
2021-03-31 16:56:34 +01:00
|
|
|
"github.com/zeebo/clingy"
|
|
|
|
"github.com/zeebo/errs"
|
2021-05-26 21:19:29 +01:00
|
|
|
|
2022-01-06 19:55:46 +00:00
|
|
|
"storj.io/storj/cmd/uplink/ulext"
|
2021-03-31 16:56:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type cmdAccessUse struct {
|
2021-05-26 21:19:29 +01:00
|
|
|
ex ulext.External
|
|
|
|
|
2021-06-25 17:51:05 +01:00
|
|
|
access string
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
|
2021-05-26 21:19:29 +01:00
|
|
|
func newCmdAccessUse(ex ulext.External) *cmdAccessUse {
|
|
|
|
return &cmdAccessUse{ex: ex}
|
|
|
|
}
|
|
|
|
|
2021-05-25 00:11:50 +01:00
|
|
|
func (c *cmdAccessUse) Setup(params clingy.Parameters) {
|
2021-06-25 17:51:05 +01:00
|
|
|
c.access = params.Arg("access", "Access name to use").(string)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
func (c *cmdAccessUse) Execute(ctx context.Context) error {
|
2021-05-26 21:19:29 +01:00
|
|
|
_, accesses, err := c.ex.GetAccessInfo(true)
|
2021-03-31 16:56:34 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-25 17:51:05 +01:00
|
|
|
if _, ok := accesses[c.access]; !ok {
|
|
|
|
return errs.New("unknown access: %q", c.access)
|
|
|
|
}
|
|
|
|
if err := c.ex.SaveAccessInfo(c.access, accesses); err != nil {
|
|
|
|
return err
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
2021-06-25 17:51:05 +01:00
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
fmt.Fprintf(clingy.Stdout(ctx), "Switched default access to %q\n", c.access)
|
2021-06-25 17:51:05 +01:00
|
|
|
|
|
|
|
return nil
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|