2022-01-25 23:39:26 +00:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeebo/clingy"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2022-01-06 19:55:46 +00:00
|
|
|
"storj.io/storj/cmd/uplink/ulext"
|
2022-01-25 23:39:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 clingy.Context) (err error) {
|
|
|
|
if c.name == "" {
|
|
|
|
return errs.New("Must specify a name to import the access as.")
|
|
|
|
}
|
|
|
|
|
2022-04-26 15:50:52 +01:00
|
|
|
access, err := parseAccessDataOrPossiblyFile(c.access)
|
2022-01-25 23:39:26 +00:00
|
|
|
if err != nil {
|
2022-04-26 15:50:52 +01:00
|
|
|
return errs.Wrap(err)
|
2022-01-25 23:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = c.am.Execute(ctx, c.name, access)
|
|
|
|
return err
|
|
|
|
}
|