2021-03-31 16:56:34 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeebo/clingy"
|
2021-06-22 23:41:22 +01:00
|
|
|
"github.com/zeebo/errs"
|
2021-05-26 21:19:29 +01:00
|
|
|
|
|
|
|
"storj.io/storj/cmd/uplinkng/ulext"
|
2021-03-31 16:56:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type cmdAccessCreate struct {
|
2021-05-26 21:19:29 +01:00
|
|
|
ex ulext.External
|
2021-06-22 23:41:22 +01:00
|
|
|
am accessMaker
|
2021-03-31 16:56:34 +01:00
|
|
|
|
|
|
|
token string
|
|
|
|
passphrase string
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:19:29 +01:00
|
|
|
func newCmdAccessCreate(ex ulext.External) *cmdAccessCreate {
|
|
|
|
return &cmdAccessCreate{ex: ex}
|
|
|
|
}
|
|
|
|
|
2021-05-25 00:11:50 +01:00
|
|
|
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)
|
2021-03-31 16:56:34 +01:00
|
|
|
|
2021-06-22 23:41:22 +01:00
|
|
|
params.Break()
|
|
|
|
c.am.Setup(params, c.ex, false)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 23:41:22 +01:00
|
|
|
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 == "" {
|
|
|
|
// TODO: secret prompt
|
|
|
|
c.passphrase, err = c.ex.PromptInput(ctx, "Passphrase:")
|
|
|
|
if err != nil {
|
|
|
|
return errs.Wrap(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
access, err := c.ex.RequestAccess(ctx, c.token, c.passphrase)
|
|
|
|
if err != nil {
|
|
|
|
return errs.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.am.Execute(ctx, access)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|