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"
|
|
|
|
"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
|
|
|
"storj.io/uplink"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cmdAccessSave struct {
|
2021-05-26 21:19:29 +01:00
|
|
|
ex ulext.External
|
2021-06-22 23:41:22 +01:00
|
|
|
am accessMaker
|
2021-05-26 21:19:29 +01:00
|
|
|
|
2021-03-31 16:56:34 +01:00
|
|
|
access string
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:19:29 +01:00
|
|
|
func newCmdAccessSave(ex ulext.External) *cmdAccessSave {
|
|
|
|
return &cmdAccessSave{ex: ex}
|
|
|
|
}
|
|
|
|
|
2021-05-25 00:11:50 +01:00
|
|
|
func (c *cmdAccessSave) Setup(params clingy.Parameters) {
|
2021-06-25 17:51:05 +01:00
|
|
|
c.access = params.Flag("access", "Serialized access value to save (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, amSaveForced)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 23:41:22 +01:00
|
|
|
func (c *cmdAccessSave) Execute(ctx clingy.Context) (err error) {
|
2021-03-31 16:56:34 +01:00
|
|
|
if c.access == "" {
|
2021-05-26 21:19:29 +01:00
|
|
|
c.access, err = c.ex.PromptInput(ctx, "Access:")
|
2021-05-12 17:41:05 +01:00
|
|
|
if err != nil {
|
2021-05-26 21:19:29 +01:00
|
|
|
return errs.Wrap(err)
|
2021-05-12 17:41:05 +01:00
|
|
|
}
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
2021-05-26 21:19:29 +01:00
|
|
|
|
2021-06-22 23:41:22 +01:00
|
|
|
access, err := uplink.ParseAccess(c.access)
|
|
|
|
if err != nil {
|
2021-03-31 16:56:34 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-06-22 23:41:22 +01:00
|
|
|
return c.am.Execute(ctx, access)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|