2021-06-22 23:41:22 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-08-30 10:51:31 +01:00
|
|
|
"context"
|
2022-01-25 23:39:26 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-06-22 23:41:22 +01:00
|
|
|
"github.com/zeebo/clingy"
|
2022-01-25 23:39:26 +00:00
|
|
|
"github.com/zeebo/errs"
|
2021-06-22 23:41:22 +01:00
|
|
|
|
2022-01-06 19:55:46 +00:00
|
|
|
"storj.io/storj/cmd/uplink/ulext"
|
2021-06-22 23:41:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type cmdAccessRestrict struct {
|
|
|
|
ex ulext.External
|
|
|
|
am accessMaker
|
|
|
|
|
2022-01-25 23:39:26 +00:00
|
|
|
access string
|
|
|
|
importAs string
|
|
|
|
exportTo string
|
2021-06-22 23:41:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func newCmdAccessRestrict(ex ulext.External) *cmdAccessRestrict {
|
|
|
|
return &cmdAccessRestrict{ex: ex}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdAccessRestrict) Setup(params clingy.Parameters) {
|
2021-06-25 17:51:05 +01:00
|
|
|
c.access = params.Flag("access", "Access name or value to restrict", "").(string)
|
2022-01-25 23:39:26 +00:00
|
|
|
c.importAs = params.Flag("import-as", "Import the access as this name", "").(string)
|
|
|
|
c.exportTo = params.Flag("export-to", "Export the access to this file path", "").(string)
|
2021-06-22 23:41:22 +01:00
|
|
|
|
|
|
|
params.Break()
|
2022-01-25 23:39:26 +00:00
|
|
|
c.am.Setup(params, c.ex)
|
|
|
|
params.Break()
|
|
|
|
c.am.perms.Setup(params, true)
|
2021-06-22 23:41:22 +01:00
|
|
|
}
|
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
func (c *cmdAccessRestrict) Execute(ctx context.Context) error {
|
2021-06-22 23:41:22 +01:00
|
|
|
access, err := c.ex.OpenAccess(c.access)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-25 23:39:26 +00:00
|
|
|
access, err = c.am.Execute(ctx, c.importAs, access)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.exportTo != "" {
|
|
|
|
return c.ex.ExportAccess(ctx, access, c.exportTo)
|
|
|
|
}
|
|
|
|
|
|
|
|
serialized, err := access.Serialize()
|
|
|
|
if err != nil {
|
|
|
|
return errs.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
fmt.Fprintln(clingy.Stdout(ctx), serialized)
|
2022-01-25 23:39:26 +00:00
|
|
|
return nil
|
2021-06-22 23:41:22 +01:00
|
|
|
}
|