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
51 lines
1023 B
Go
51 lines
1023 B
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/zeebo/clingy"
|
|
|
|
"storj.io/storj/cmd/uplink/ulext"
|
|
)
|
|
|
|
type cmdAccessRevoke struct {
|
|
ex ulext.External
|
|
|
|
access string
|
|
revokee string
|
|
}
|
|
|
|
func newCmdAccessRevoke(ex ulext.External) *cmdAccessRevoke {
|
|
return &cmdAccessRevoke{ex: ex}
|
|
}
|
|
|
|
func (c *cmdAccessRevoke) Setup(params clingy.Parameters) {
|
|
c.access = params.Flag("access", "Access name or value performing the revoke", "").(string)
|
|
c.revokee = params.Arg("revokee", "Access name or value revoke").(string)
|
|
}
|
|
|
|
func (c *cmdAccessRevoke) Execute(ctx context.Context) error {
|
|
project, err := c.ex.OpenProject(ctx, c.access)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() { _ = project.Close() }()
|
|
|
|
access, err := c.ex.OpenAccess(c.revokee)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := project.RevokeAccess(ctx, access); err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Fprintf(clingy.Stdout(ctx), "Revoked access %q\n", c.revokee)
|
|
|
|
return nil
|
|
}
|