2021-03-31 16:56:34 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2021-05-26 21:19:29 +01:00
|
|
|
import (
|
2021-06-25 17:51:05 +01:00
|
|
|
"fmt"
|
|
|
|
|
2021-05-26 21:19:29 +01:00
|
|
|
"github.com/zeebo/clingy"
|
|
|
|
|
|
|
|
"storj.io/storj/cmd/uplinkng/ulext"
|
|
|
|
)
|
2021-03-31 16:56:34 +01:00
|
|
|
|
|
|
|
type cmdAccessRevoke struct {
|
2021-05-26 21:19:29 +01:00
|
|
|
ex ulext.External
|
2021-06-25 17:51:05 +01:00
|
|
|
|
|
|
|
access string
|
|
|
|
revokee string
|
2021-05-26 21:19:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func newCmdAccessRevoke(ex ulext.External) *cmdAccessRevoke {
|
|
|
|
return &cmdAccessRevoke{ex: ex}
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 00:11:50 +01:00
|
|
|
func (c *cmdAccessRevoke) Setup(params clingy.Parameters) {
|
2021-06-25 17:51:05 +01:00
|
|
|
c.access = params.Flag("access", "Access name or value performing the revoke", "").(string)
|
|
|
|
c.revokee = params.Arg("revokee", "Access name or value revoke").(string)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdAccessRevoke) Execute(ctx clingy.Context) error {
|
2021-06-25 17:51:05 +01:00
|
|
|
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(ctx, "Revoked access %q\n", c.revokee)
|
|
|
|
|
2021-03-31 16:56:34 +01:00
|
|
|
return nil
|
|
|
|
}
|