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
47 lines
977 B
Go
47 lines
977 B
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zeebo/clingy"
|
|
"github.com/zeebo/errs"
|
|
|
|
"storj.io/storj/cmd/uplink/ulext"
|
|
)
|
|
|
|
type cmdAccessImport struct {
|
|
ex ulext.External
|
|
am accessMaker
|
|
|
|
name string
|
|
access string
|
|
}
|
|
|
|
func newCmdAccessImport(ex ulext.External) *cmdAccessImport {
|
|
return &cmdAccessImport{ex: ex}
|
|
}
|
|
|
|
func (c *cmdAccessImport) Setup(params clingy.Parameters) {
|
|
c.am.Setup(params, c.ex)
|
|
|
|
c.name = params.Arg("name", "Name to save the access as").(string)
|
|
c.access = params.Arg("access|filename", "Serialized access value or file path to save").(string)
|
|
}
|
|
|
|
func (c *cmdAccessImport) Execute(ctx context.Context) (err error) {
|
|
if c.name == "" {
|
|
return errs.New("Must specify a name to import the access as.")
|
|
}
|
|
|
|
access, err := parseAccessDataOrPossiblyFile(c.access)
|
|
if err != nil {
|
|
return errs.Wrap(err)
|
|
}
|
|
|
|
_, err = c.am.Execute(ctx, c.name, access)
|
|
return err
|
|
}
|