7eaa7490a1
Change-Id: I1b407b59559281c2242b55ebcf835d465db38e1d
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"github.com/zeebo/clingy"
|
|
"github.com/zeebo/errs"
|
|
|
|
"storj.io/storj/cmd/uplinkng/ulext"
|
|
)
|
|
|
|
type cmdAccessCreate struct {
|
|
ex ulext.External
|
|
am accessMaker
|
|
|
|
token string
|
|
passphrase string
|
|
}
|
|
|
|
func newCmdAccessCreate(ex ulext.External) *cmdAccessCreate {
|
|
return &cmdAccessCreate{ex: ex}
|
|
}
|
|
|
|
func (c *cmdAccessCreate) Setup(params clingy.Parameters) {
|
|
c.token = params.Flag("token", "Setup token from satellite UI (prompted if unspecified)", "").(string)
|
|
c.passphrase = params.Flag("passphrase", "Passphrase used for encryption (prompted if unspecified)", "").(string)
|
|
|
|
params.Break()
|
|
c.am.Setup(params, c.ex, amSaveDefaultTrue)
|
|
}
|
|
|
|
func (c *cmdAccessCreate) Execute(ctx clingy.Context) (err error) {
|
|
if c.token == "" {
|
|
c.token, err = c.ex.PromptInput(ctx, "Setup token:")
|
|
if err != nil {
|
|
return errs.Wrap(err)
|
|
}
|
|
}
|
|
|
|
if c.passphrase == "" {
|
|
c.passphrase, err = c.ex.PromptSecret(ctx, "Passphrase:")
|
|
if err != nil {
|
|
return errs.Wrap(err)
|
|
}
|
|
if c.passphrase == "" {
|
|
return errs.New("Encryption passphrase must be non-empty")
|
|
}
|
|
}
|
|
|
|
access, err := c.ex.RequestAccess(ctx, c.token, c.passphrase)
|
|
if err != nil {
|
|
return errs.Wrap(err)
|
|
}
|
|
|
|
return c.am.Execute(ctx, access)
|
|
}
|