storj/cmd/uplinkng/cmd_access_remove.go
Jeff Wendling b7ca2289e0 cmd/uplinkng: improvements to prepare for doc update
* improve setup wizard
* added access grant file support
* improved consistency across commands
* a couple bug fixes
* added access import and export

Change-Id: I30ad9d4771f15430904a503a4d465bc40be471b5
2022-01-31 17:37:54 +00:00

51 lines
1.0 KiB
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 cmdAccessRemove struct {
ex ulext.External
access string
}
func newCmdAccessRemove(ex ulext.External) *cmdAccessRemove {
return &cmdAccessRemove{ex: ex}
}
func (c *cmdAccessRemove) Setup(params clingy.Parameters) {
c.access = params.Arg("name", "Access name to delete").(string)
}
func (c *cmdAccessRemove) Execute(ctx clingy.Context) error {
defaultName, accesses, err := c.ex.GetAccessInfo(true)
if err != nil {
return err
}
if c.access == defaultName {
return errs.New("cannot delete current access")
}
if _, ok := accesses[c.access]; !ok {
return errs.New("unknown access: %q", c.access)
}
delete(accesses, c.access)
if err := c.ex.SaveAccessInfo(defaultName, accesses); err != nil {
return err
}
fmt.Fprintf(ctx, "Removed access %q from %q\n", c.access, c.ex.AccessInfoFile())
return nil
}