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 cmdAccessExport struct {
|
|
|
|
ex ulext.External
|
|
|
|
|
|
|
|
name string
|
|
|
|
filename string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newCmdAccessExport(ex ulext.External) *cmdAccessExport {
|
|
|
|
return &cmdAccessExport{ex: ex}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdAccessExport) Setup(params clingy.Parameters) {
|
|
|
|
c.name = params.Arg("name", "Name of the access to export").(string)
|
|
|
|
c.filename = params.Arg("filename", "Name of the file to save to").(string)
|
|
|
|
}
|
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
func (c *cmdAccessExport) Execute(ctx context.Context) error {
|
2022-01-25 23:39:26 +00:00
|
|
|
if c.filename == "" {
|
|
|
|
return errs.New("Must specify a filename to write to.")
|
|
|
|
}
|
|
|
|
|
|
|
|
access, err := c.ex.OpenAccess(c.name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.ex.ExportAccess(ctx, access, c.filename)
|
|
|
|
}
|