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()
|
2021-06-25 17:51:05 +01:00
|
|
|
c.am.Setup(params, c.ex, amSaveDefaultTrue)
|
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 == "" {
|
2021-08-02 17:54:30 +01:00
|
|
|
c.passphrase, err = c.ex.PromptSecret(ctx, "Passphrase:")
|
2021-06-22 23:41:22 +01:00
|
|
|
if err != nil {
|
|
|
|
return errs.Wrap(err)
|
|
|
|
}
|
2021-08-02 17:54:30 +01:00
|
|
|
if c.passphrase == "" {
|
|
|
|
return errs.New("Encryption passphrase must be non-empty")
|
|
|
|
}
|
2021-06-22 23:41:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|