2021-03-31 16:56:34 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
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
|
|
|
|
|
|
|
"storj.io/storj/cmd/uplinkng/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
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdAccessUse) Execute(ctx clingy.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
|
|
|
|
|
|
|
fmt.Fprintf(ctx, "Switched default access to access %q\n", c.access)
|
|
|
|
|
|
|
|
return nil
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|