59b8422318
this makes the distinction between an "access name" and an "access value" and talks about which is expected for commands. most are "access name or value". Change-Id: I43c0043a17d37e89ab5f87388ae9e890a8b59958
45 lines
879 B
Go
45 lines
879 B
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/zeebo/clingy"
|
|
"github.com/zeebo/errs"
|
|
|
|
"storj.io/storj/cmd/uplinkng/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 clingy.Context) error {
|
|
_, accesses, err := c.ex.GetAccessInfo(true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
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
|
|
}
|
|
|
|
fmt.Fprintf(ctx, "Switched default access to access %q\n", c.access)
|
|
|
|
return nil
|
|
}
|