2022-01-25 23:39:26 +00: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
|
|
|
"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)
|
|
|
|
}
|
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
func (c *cmdAccessImport) Execute(ctx context.Context) (err error) {
|
2022-01-25 23:39:26 +00:00
|
|
|
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
|
|
|
|
}
|