ea1408f7a8
As a reminder: latest clingy removed the requirement of having custom context (which made the usage of context.WithValue harder) and uses simple context instead. Clingy saves the stdin/stdout/stderr to the context (earlier to separated context type) to make it available for unit testing. Change-Id: I8896574f4670721de43a577cd4b35952e3b5d00e
52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/zeebo/clingy"
|
|
"github.com/zeebo/errs"
|
|
|
|
"storj.io/storj/cmd/uplink/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 context.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(clingy.Stdout(ctx), "Removed access %q from %q\n", c.access, c.ex.AccessInfoFile())
|
|
|
|
return nil
|
|
}
|