2021-03-31 16:56:34 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-08-30 10:51:31 +01:00
|
|
|
"context"
|
|
|
|
|
2021-03-31 16:56:34 +01:00
|
|
|
"github.com/zeebo/clingy"
|
2021-05-05 22:53:08 +01:00
|
|
|
"github.com/zeebo/errs"
|
2021-05-26 21:19:29 +01:00
|
|
|
|
2022-01-06 19:55:46 +00:00
|
|
|
"storj.io/storj/cmd/uplink/ulext"
|
|
|
|
"storj.io/storj/cmd/uplink/ulloc"
|
2021-03-31 16:56:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type cmdMb struct {
|
2021-05-26 21:19:29 +01:00
|
|
|
ex ulext.External
|
|
|
|
|
|
|
|
access string
|
2021-03-31 16:56:34 +01:00
|
|
|
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:19:29 +01:00
|
|
|
func newCmdMb(ex ulext.External) *cmdMb {
|
|
|
|
return &cmdMb{ex: ex}
|
|
|
|
}
|
|
|
|
|
2021-05-25 00:11:50 +01:00
|
|
|
func (c *cmdMb) Setup(params clingy.Parameters) {
|
2021-06-25 17:51:05 +01:00
|
|
|
c.access = params.Flag("access", "Access name or value to use", "").(string)
|
2021-03-31 16:56:34 +01:00
|
|
|
|
2021-08-31 17:58:01 +01:00
|
|
|
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)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
|
2022-08-30 10:51:31 +01:00
|
|
|
func (c *cmdMb) Execute(ctx context.Context) error {
|
2021-05-26 21:19:29 +01:00
|
|
|
project, err := c.ex.OpenProject(ctx, c.access)
|
2021-05-05 22:53:08 +01:00
|
|
|
if err != nil {
|
|
|
|
return errs.Wrap(err)
|
|
|
|
}
|
|
|
|
defer func() { _ = project.Close() }()
|
|
|
|
|
|
|
|
_, err = project.CreateBucket(ctx, c.name)
|
|
|
|
return err
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|