storj/cmd/uplinkng/cmd_mb.go
Michał Niewrzał 5b66136312 cmd/uplinkng: fix mb command
Make bucket command was using full location
specified in command line instead only bucket name.

As an addition change contains basic integration tests
with storj-sim.

Change-Id: Ie3b5283468b7fbde0b1333f01dc4fc2a2952e1a1
2021-09-29 15:22:03 +00:00

49 lines
1.0 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"
"storj.io/storj/cmd/uplinkng/ulloc"
)
type cmdMb struct {
ex ulext.External
access string
name string
}
func newCmdMb(ex ulext.External) *cmdMb {
return &cmdMb{ex: ex}
}
func (c *cmdMb) Setup(params clingy.Parameters) {
c.access = params.Flag("access", "Access name or value to use", "").(string)
c.name = params.Arg("name", "Bucket name (sj://BUCKET)", clingy.Transform(ulloc.Parse),
clingy.Transform(func(location ulloc.Location) (string, error) {
if bucket, key, ok := location.RemoteParts(); key == "" && ok {
return bucket, nil
}
return "", errs.New("invalid bucket name")
}),
).(string)
}
func (c *cmdMb) Execute(ctx clingy.Context) error {
project, err := c.ex.OpenProject(ctx, c.access)
if err != nil {
return errs.Wrap(err)
}
defer func() { _ = project.Close() }()
_, err = project.CreateBucket(ctx, c.name)
return err
}