Skip to content

Commit

Permalink
feat: Add bucket schema management commands
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcarnie committed Apr 29, 2021
1 parent 01dd763 commit 72ffab2
Show file tree
Hide file tree
Showing 19 changed files with 2,054 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/influx/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func newBucketCreateCmd() *cli.Command {
EnvVars: []string{"INFLUX_ORG"},
Destination: &params.OrgName,
},
&cli.StringFlag{
Name: "schema-type",
Usage: "The schema type (implicit, explicit)",
DefaultText: "implicit",
Destination: &params.SchemaType,
},
),
Action: func(ctx *cli.Context) error {
clients := getBucketsClient(ctx)
Expand Down
1 change: 1 addition & 0 deletions cmd/influx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ var app = cli.App{
newSetupCmd(),
newWriteCmd(),
newBucketCmd(),
newMeasurementSchemaCmd(),
},
}

Expand Down
74 changes: 74 additions & 0 deletions cmd/influx/measurement_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"github.com/influxdata/influx-cli/v2/internal/cmd/measurement_schema"
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
"github.com/urfave/cli/v2"
)

func withMSClient() cli.BeforeFunc {
return middleware.WithBeforeFns(
withCli(),
withApi(),
func(ctx *cli.Context) error {
c := getCLI(ctx)
client := getAPI(ctx)
ctx.App.Metadata["measurement_schema"] = measurement_schema.Client{
OrgApi: client.OrganizationsApi,
BucketApi: client.BucketsApi,
BucketSchemasApi: client.BucketSchemasApi,
CLI: c,
}
return nil
})
}

func getMSClient(ctx *cli.Context) measurement_schema.Client {
i, ok := ctx.App.Metadata["measurement_schema"].(measurement_schema.Client)
if !ok {
panic("missing measurement schema client")
}
return i
}

func newMeasurementSchemaCmd() *cli.Command {
return &cli.Command{
Name: "bucket-schema",
Usage: "Bucket schema management commands",
Subcommands: []*cli.Command{
newMeasurementSchemaCreateCmd(),
newMeasurementSchemaListCmd(),
},
}
}

func newMeasurementSchemaCreateCmd() *cli.Command {
var params measurement_schema.CreateParams
return &cli.Command{
Name: "create",
Usage: "Create a measurement schema for a bucket",
Before: withMSClient(),
Flags: append(
commonFlags,
params.Flags()...),
Action: func(ctx *cli.Context) error {
return getMSClient(ctx).Create(ctx.Context, params)
},
}
}

func newMeasurementSchemaListCmd() *cli.Command {
var params measurement_schema.ListParams
return &cli.Command{
Name: "list",
Usage: "List schemas for a bucket",
Before: withMSClient(),
Flags: append(
commonFlags,
params.Flags()...,
),
Action: func(ctx *cli.Context) error {
return getMSClient(ctx).List(ctx.Context, params)
},
}
}
6 changes: 4 additions & 2 deletions etc/generate-openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ declare -r ETC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
declare -r ROOT_DIR="$(dirname ${ETC_DIR})"

declare -r GENERATOR_DOCKER_IMG=openapitools/openapi-generator-cli:v5.1.0
declare -r OPENAPI_COMMIT=e41d5e327a67e472a46cd6edfe673496e1b066dd
declare -r OPENAPI_COMMIT=sgc/issues/9672

# Download our target API spec.
# NOTE: openapi-generator supports HTTP references to API docs, but using that feature
# causes the host of the URL to be injected into the base paths of generated code.
curl -o ${ROOT_DIR}/internal/api/cli.yml https://raw.githubusercontent.com/influxdata/openapi/${OPENAPI_COMMIT}/contracts/cli.yml
# curl -o ${ROOT_DIR}/internal/api/cli.yml https://raw.githubusercontent.com/influxdata/openapi/${OPENAPI_COMMIT}/contracts/cli.yml

cp -c ~/projects/go/influxdata/openapi/contracts/cli.yml ${ROOT_DIR}/internal/api/cli.yml

# Run the generator - This produces many more files than we want to track in git.
docker run --rm -it -u "$(id -u):$(id -g)" \
Expand Down
Loading

0 comments on commit 72ffab2

Please sign in to comment.