210 lines
5.9 KiB
Go
210 lines
5.9 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/influxdata/influx-cli/v2/api"
|
|
"github.com/influxdata/influx-cli/v2/clients/bucket"
|
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
func newBucketCmd() cli.Command {
|
|
return cli.Command{
|
|
Name: "bucket",
|
|
Usage: "Bucket management commands",
|
|
Before: middleware.NoArgs,
|
|
Subcommands: []cli.Command{
|
|
newBucketCreateCmd(),
|
|
newBucketDeleteCmd(),
|
|
newBucketListCmd(),
|
|
newBucketUpdateCmd(),
|
|
},
|
|
}
|
|
}
|
|
|
|
func newBucketCreateCmd() cli.Command {
|
|
params := bucket.BucketsCreateParams{
|
|
SchemaType: api.SCHEMATYPE_IMPLICIT,
|
|
}
|
|
return cli.Command{
|
|
Name: "create",
|
|
Usage: "Create bucket",
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Flags: append(
|
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
|
&cli.StringFlag{
|
|
Name: "name, n",
|
|
Usage: "New bucket name",
|
|
EnvVar: "INFLUX_BUCKET_NAME",
|
|
Destination: ¶ms.Name,
|
|
Required: true,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "description, d",
|
|
Usage: "Description of the bucket that will be created",
|
|
Destination: ¶ms.Description,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "retention, r",
|
|
Usage: "Duration bucket will retain data, or 0 for infinite",
|
|
Destination: ¶ms.Retention,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "shard-group-duration",
|
|
Usage: "Shard group duration used internally by the storage engine",
|
|
Destination: ¶ms.ShardGroupDuration,
|
|
},
|
|
&cli.GenericFlag{
|
|
Name: "schema-type",
|
|
Usage: "The schema type (implicit, explicit)",
|
|
Value: ¶ms.SchemaType,
|
|
},
|
|
),
|
|
Action: func(ctx *cli.Context) error {
|
|
if err := checkOrgFlags(¶ms.OrgParams); err != nil {
|
|
return err
|
|
}
|
|
api := getAPI(ctx)
|
|
client := bucket.Client{
|
|
CLI: getCLI(ctx),
|
|
BucketsApi: api.BucketsApi,
|
|
OrganizationsApi: api.OrganizationsApi,
|
|
}
|
|
return client.Create(getContext(ctx), ¶ms)
|
|
},
|
|
}
|
|
}
|
|
|
|
func newBucketDeleteCmd() cli.Command {
|
|
var params bucket.BucketsDeleteParams
|
|
return cli.Command{
|
|
Name: "delete",
|
|
Usage: "Delete bucket",
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Flags: append(
|
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
|
&cli.StringFlag{
|
|
Name: "id, i",
|
|
Usage: "The bucket ID, required if name isn't provided",
|
|
Destination: ¶ms.BucketID,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "name, n",
|
|
Usage: "The bucket name, org or org-id will be required by choosing this",
|
|
Destination: ¶ms.BucketName,
|
|
},
|
|
),
|
|
Action: func(ctx *cli.Context) error {
|
|
if err := checkOrgFlags(¶ms.OrgParams); err != nil {
|
|
return err
|
|
}
|
|
api := getAPI(ctx)
|
|
client := bucket.Client{
|
|
CLI: getCLI(ctx),
|
|
BucketsApi: api.BucketsApi,
|
|
OrganizationsApi: api.OrganizationsApi,
|
|
}
|
|
return client.Delete(getContext(ctx), ¶ms)
|
|
},
|
|
}
|
|
}
|
|
|
|
func newBucketListCmd() cli.Command {
|
|
var params bucket.BucketsListParams
|
|
return cli.Command{
|
|
Name: "list",
|
|
Usage: "List buckets",
|
|
Aliases: []string{"find", "ls"},
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Flags: append(
|
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
|
&cli.StringFlag{
|
|
Name: "id, i",
|
|
Usage: "The bucket ID, required if name isn't provided",
|
|
Destination: ¶ms.BucketID,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "name, n",
|
|
Usage: "The bucket name, org or org-id will be required by choosing this",
|
|
Destination: ¶ms.BucketName,
|
|
},
|
|
&cli.IntFlag{
|
|
Name: "limit",
|
|
Usage: "Total number of buckets to fetch from the server, or 0 to return all buckets",
|
|
Destination: ¶ms.Limit,
|
|
},
|
|
&cli.IntFlag{
|
|
Name: "offset",
|
|
Usage: "Number of buckets to skip over in the list",
|
|
Destination: ¶ms.Offset,
|
|
},
|
|
&cli.IntFlag{
|
|
Name: "page-size",
|
|
Usage: "Number of buckets to fetch per request to the server",
|
|
Value: 20,
|
|
Destination: ¶ms.PageSize,
|
|
},
|
|
),
|
|
Action: func(ctx *cli.Context) error {
|
|
if err := checkOrgFlags(¶ms.OrgParams); err != nil {
|
|
return err
|
|
}
|
|
api := getAPI(ctx)
|
|
client := bucket.Client{
|
|
CLI: getCLI(ctx),
|
|
BucketsApi: api.BucketsApi,
|
|
OrganizationsApi: api.OrganizationsApi,
|
|
}
|
|
return client.List(getContext(ctx), ¶ms)
|
|
},
|
|
}
|
|
}
|
|
|
|
func newBucketUpdateCmd() cli.Command {
|
|
var params bucket.BucketsUpdateParams
|
|
return cli.Command{
|
|
Name: "update",
|
|
Usage: "Update bucket",
|
|
Aliases: []string{"set"},
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Flags: append(
|
|
commonFlags(),
|
|
&cli.StringFlag{
|
|
Name: "name, n",
|
|
Usage: "New name to set on the bucket",
|
|
EnvVar: "INFLUX_BUCKET_NAME",
|
|
Destination: ¶ms.BucketName,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "id, i",
|
|
Usage: "The bucket ID",
|
|
Required: true,
|
|
Destination: ¶ms.BucketID,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "description, d",
|
|
Usage: "New description to set on the bucket",
|
|
Destination: ¶ms.Description,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "retention, r",
|
|
Usage: "New retention duration to set on the bucket, or 0 for infinite",
|
|
Destination: ¶ms.Retention,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "shard-group-duration",
|
|
Usage: "New shard group duration to set on the bucket, or 0 to have the server calculate a value",
|
|
Destination: ¶ms.ShardGroupDuration,
|
|
},
|
|
),
|
|
Action: func(ctx *cli.Context) error {
|
|
api := getAPI(ctx)
|
|
client := bucket.Client{
|
|
CLI: getCLI(ctx),
|
|
BucketsApi: api.BucketsApi,
|
|
OrganizationsApi: api.OrganizationsApi,
|
|
}
|
|
return client.Update(getContext(ctx), ¶ms)
|
|
},
|
|
}
|
|
}
|