feat: port influx setup from influxdb (#35)

This commit is contained in:
Daniel Moran 2021-04-22 09:46:15 -04:00 committed by GitHub
parent 079f707c21
commit 68ad797ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 6669 additions and 121 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/influxdata/influx-cli/v2/internal"
"github.com/influxdata/influx-cli/v2/internal/api"
"github.com/influxdata/influx-cli/v2/internal/config"
"github.com/influxdata/influx-cli/v2/internal/stdio"
"github.com/urfave/cli/v2"
)
@ -23,32 +24,52 @@ var (
)
var (
tokenFlag = "token"
hostFlag = "host"
skipVerifyFlag = "skip-verify"
traceIdFlag = "trace-debug-id"
configPathFlag = "config-path"
configNameFlag = "active-config"
httpDebugFlag = "http-debug"
tokenFlag = "token"
hostFlag = "host"
skipVerifyFlag = "skip-verify"
traceIdFlag = "trace-debug-id"
configPathFlag = "configs-path"
configNameFlag = "active-config"
httpDebugFlag = "http-debug"
printJsonFlag = "json"
hideHeadersFlag = "hide-headers"
)
// loadConfig reads CLI configs from disk, returning the config with the
// name specified over the CLI (or default if no name was given).
func loadConfig(ctx *cli.Context) (config.Config, error) {
configs := config.GetConfigsOrDefault(ctx.String(configPathFlag))
configName := ctx.String(configNameFlag)
if configName != "" {
if err := configs.Switch(configName); err != nil {
return config.Config{}, err
// newCli builds a CLI core that reads from stdin, writes to stdout/stderr, manages a local config store,
// and optionally tracks a trace ID specified over the CLI.
func newCli(ctx *cli.Context) (*internal.CLI, error) {
configPath := ctx.String(configPathFlag)
var err error
if configPath == "" {
configPath, err = config.DefaultPath()
if err != nil {
return nil, err
}
}
return configs.Active(), nil
configSvc := config.NewLocalConfigService(configPath)
var activeConfig config.Config
if ctx.IsSet(configNameFlag) {
if activeConfig, err = configSvc.SwitchActive(ctx.String(configNameFlag)); err != nil {
return nil, err
}
} else if activeConfig, err = configSvc.Active(); err != nil {
return nil, err
}
return &internal.CLI{
StdIO: stdio.TerminalStdio,
TraceId: ctx.String(traceIdFlag),
PrintAsJSON: ctx.Bool(printJsonFlag),
HideTableHeaders: ctx.Bool(hideHeadersFlag),
ActiveConfig: activeConfig,
ConfigService: configSvc,
}, nil
}
// newApiClient returns an API client configured to communicate with a remote InfluxDB instance over HTTP.
// Client parameters are pulled from the CLI context.
func newApiClient(ctx *cli.Context, injectToken bool) (*api.APIClient, error) {
cfg, err := loadConfig(ctx)
func newApiClient(ctx *cli.Context, cli *internal.CLI, injectToken bool) (*api.APIClient, error) {
cfg, err := cli.ConfigService.Active()
if err != nil {
return nil, err
}
@ -80,17 +101,6 @@ func newApiClient(ctx *cli.Context, injectToken bool) (*api.APIClient, error) {
return api.NewAPIClient(apiConfig), nil
}
// newCli builds a CLI core that reads from stdin, writes to stdout/stderr, and
// optionally tracks a trace ID specified over the CLI.
func newCli(ctx *cli.Context) *internal.CLI {
return &internal.CLI{
Stdin: ctx.App.Reader,
Stdout: ctx.App.Writer,
Stderr: ctx.App.ErrWriter,
TraceId: ctx.String(traceIdFlag),
}
}
func main() {
if len(date) == 0 {
date = time.Now().UTC().Format(time.RFC3339)
@ -104,13 +114,9 @@ func main() {
// to be specified after _all_ command names were given.
//
// We replicate the pattern from the old CLI so existing scripts and docs stay valid.
commonFlags := []cli.Flag{
&cli.StringFlag{
Name: tokenFlag,
Usage: "Authentication token",
Aliases: []string{"t"},
EnvVars: []string{"INFLUX_TOKEN"},
},
// Some commands (i.e. `setup` use custom help-text for the token flag).
commonFlagsNoToken := []cli.Flag{
&cli.StringFlag{
Name: hostFlag,
Usage: "HTTP address of InfluxDB",
@ -120,7 +126,7 @@ func main() {
Name: skipVerifyFlag,
Usage: "Skip TLS certificate chain and host name verification",
},
&cli.StringFlag{
&cli.PathFlag{
Name: configPathFlag,
Usage: "Path to the influx CLI configurations",
EnvVars: []string{"INFLUX_CLI_CONFIGS_PATH"},
@ -142,6 +148,14 @@ func main() {
},
}
// Most commands use this form of the token flag.
//commonFlags := append(commonFlagsNoToken, &cli.StringFlag{
// Name: tokenFlag,
// Usage: "Authentication token",
// Aliases: []string{"t"},
// EnvVars: []string{"INFLUX_TOKEN"},
//})
app := cli.App{
Name: "influx",
Usage: "Influx Client",
@ -158,20 +172,104 @@ func main() {
{
Name: "ping",
Usage: "Check the InfluxDB /health endpoint",
Flags: commonFlags,
Flags: commonFlagsNoToken,
Action: func(ctx *cli.Context) error {
client, err := newApiClient(ctx, false)
cli, err := newCli(ctx)
if err != nil {
return err
}
return newCli(ctx).Ping(ctx.Context, client.HealthApi)
client, err := newApiClient(ctx, cli, false)
if err != nil {
return err
}
return cli.Ping(ctx.Context, client.HealthApi)
},
},
{
Name: "setup",
Usage: "Setup instance with initial user, org, bucket",
Flags: append(
commonFlagsNoToken,
&cli.StringFlag{
Name: "username",
Usage: "Name of initial user to create",
Aliases: []string{"u"},
},
&cli.StringFlag{
Name: "password",
Usage: "Password to set on initial user",
Aliases: []string{"p"},
},
&cli.StringFlag{
Name: tokenFlag,
Usage: "Auth token to set on the initial user",
Aliases: []string{"t"},
EnvVars: []string{"INFLUX_TOKEN"},
DefaultText: "auto-generated",
},
&cli.StringFlag{
Name: "org",
Usage: "Name of initial organization to create",
Aliases: []string{"o"},
},
&cli.StringFlag{
Name: "bucket",
Usage: "Name of initial bucket to create",
Aliases: []string{"b"},
},
&cli.StringFlag{
Name: "retention",
Usage: "Duration initial bucket will retain data, or 0 for infinite",
Aliases: []string{"r"},
DefaultText: "infinite",
},
&cli.BoolFlag{
Name: "force",
Usage: "Skip confirmation prompt",
Aliases: []string{"f"},
},
&cli.StringFlag{
Name: "name",
Usage: "Name to set on CLI config generated for the InfluxDB instance, required if other configs exist",
Aliases: []string{"n"},
},
&cli.BoolFlag{
Name: printJsonFlag,
Usage: "Output data as JSON",
EnvVars: []string{"INFLUX_OUTPUT_JSON"},
},
&cli.BoolFlag{
Name: hideHeadersFlag,
Usage: "Hide the table headers in output data",
EnvVars: []string{"INFLUX_HIDE_HEADERS"},
},
),
Action: func(ctx *cli.Context) error {
cli, err := newCli(ctx)
if err != nil {
return err
}
client, err := newApiClient(ctx, cli, false)
if err != nil {
return err
}
return cli.Setup(ctx.Context, client.SetupApi, &internal.SetupParams{
Username: ctx.String("username"),
Password: ctx.String("password"),
AuthToken: ctx.String(tokenFlag),
Org: ctx.String("org"),
Bucket: ctx.String("bucket"),
Retention: ctx.String("retention"),
Force: ctx.Bool("force"),
ConfigName: ctx.String("name"),
})
},
},
},
}
if err := app.Run(os.Args); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error: %v", err)
_, _ = fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}

1
go.mod
View File

@ -3,6 +3,7 @@ module github.com/influxdata/influx-cli/v2
go 1.16
require (
github.com/AlecAivazis/survey/v2 v2.2.9
github.com/BurntSushi/toml v0.3.1
github.com/daixiang0/gci v0.2.8
github.com/kr/pretty v0.1.0 // indirect

25
go.sum
View File

@ -1,17 +1,34 @@
github.com/AlecAivazis/survey/v2 v2.2.9 h1:LWvJtUswz/W9/zVVXELrmlvdwWcKE60ZAw0FWV9vssk=
github.com/AlecAivazis/survey/v2 v2.2.9/go.mod h1:9DYvHgXtiXm6nCn+jXnOXLKbH+Yo9u8fAS/SduGdoPk=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/daixiang0/gci v0.2.8 h1:1mrIGMBQsBu0P7j7m1M8Lb+ZeZxsZL+jyGX4YoMJJpg=
github.com/daixiang0/gci v0.2.8/go.mod h1:+4dZ7TISfSmqfAGv59ePaHfNzgGtIkHAhhdKggP1JAc=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ=
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
@ -19,13 +36,16 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
@ -35,11 +55,14 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=

View File

@ -34,6 +34,54 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/setup:
get:
operationId: GetSetup
tags:
- Setup
summary: 'Check if database has default user, org, bucket'
description: 'Returns `true` if no default user, organization, or bucket has been created.'
parameters:
- $ref: '#/components/parameters/TraceSpan'
responses:
'200':
description: allowed true or false
content:
application/json:
schema:
type: object
properties:
allowed:
description: True means that the influxdb instance has NOT had initial setup; false means that the database has been setup.
type: boolean
post:
operationId: PostSetup
tags:
- Setup
summary: 'Set up initial user, org and bucket'
description: 'Post an onboarding request to set up initial user, org and bucket.'
parameters:
- $ref: '#/components/parameters/TraceSpan'
requestBody:
description: Source to create
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/OnboardingRequest'
responses:
'201':
description: 'Created default user, bucket, org'
content:
application/json:
schema:
$ref: '#/components/schemas/OnboardingResponse'
default:
description: Unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
parameters:
TraceSpan:
@ -110,3 +158,362 @@ components:
enum:
- pass
- fail
OnboardingRequest:
type: object
properties:
username:
type: string
password:
type: string
org:
type: string
bucket:
type: string
retentionPeriodSeconds:
type: integer
format: int64
retentionPeriodHrs:
type: integer
deprecated: true
description: |
Retention period *in nanoseconds* for the new bucket. This key's name has been misleading since OSS 2.0 GA, please transition to use `retentionPeriodSeconds`
token:
type: string
description: |
Authentication token to set on the initial user. If not specified, the server will generate a token.
required:
- username
- org
- bucket
OnboardingResponse:
type: object
properties:
user:
$ref: '#/components/schemas/UserResponse'
org:
$ref: '#/components/schemas/Organization'
bucket:
$ref: '#/components/schemas/Bucket'
auth:
$ref: '#/components/schemas/Authorization'
UserResponse:
properties:
id:
readOnly: true
type: string
oauthID:
type: string
name:
type: string
status:
description: If inactive the user is inactive.
default: active
type: string
enum:
- active
- inactive
links:
type: object
readOnly: true
example:
self: /api/v2/users/1
properties:
self:
type: string
format: uri
required:
- name
Link:
type: string
format: uri
readOnly: true
description: URI of resource.
Organization:
properties:
links:
type: object
readOnly: true
example:
self: /api/v2/orgs/1
members: /api/v2/orgs/1/members
owners: /api/v2/orgs/1/owners
labels: /api/v2/orgs/1/labels
secrets: /api/v2/orgs/1/secrets
buckets: /api/v2/buckets?org=myorg
tasks: /api/v2/tasks?org=myorg
dashboards: /api/v2/dashboards?org=myorg
properties:
self:
$ref: '#/components/schemas/Link'
members:
$ref: '#/components/schemas/Link'
owners:
$ref: '#/components/schemas/Link'
labels:
$ref: '#/components/schemas/Link'
secrets:
$ref: '#/components/schemas/Link'
buckets:
$ref: '#/components/schemas/Link'
tasks:
$ref: '#/components/schemas/Link'
dashboards:
$ref: '#/components/schemas/Link'
id:
readOnly: true
type: string
name:
type: string
description:
type: string
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
status:
description: If inactive the organization is inactive.
default: active
type: string
enum:
- active
- inactive
required:
- name
Bucket:
properties:
links:
type: object
readOnly: true
example:
labels: /api/v2/buckets/1/labels
members: /api/v2/buckets/1/members
org: /api/v2/orgs/2
owners: /api/v2/buckets/1/owners
self: /api/v2/buckets/1
write: /api/v2/write?org=2&bucket=1
properties:
labels:
description: URL to retrieve labels for this bucket
$ref: '#/components/schemas/Link'
members:
description: URL to retrieve members that can read this bucket
$ref: '#/components/schemas/Link'
org:
description: URL to retrieve parent organization for this bucket
$ref: '#/components/schemas/Link'
owners:
description: URL to retrieve owners that can read and write to this bucket.
$ref: '#/components/schemas/Link'
self:
description: URL for this bucket
$ref: '#/components/schemas/Link'
write:
description: URL to write line protocol for this bucket
$ref: '#/components/schemas/Link'
id:
readOnly: true
type: string
type:
readOnly: true
type: string
default: user
enum:
- user
- system
name:
type: string
description:
type: string
orgID:
type: string
rp:
type: string
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
retentionRules:
$ref: '#/components/schemas/RetentionRules'
labels:
$ref: '#/components/schemas/Labels'
required:
- name
- retentionRules
RetentionRules:
type: array
description: Rules to expire or retain data. No rules means data never expires.
items:
$ref: '#/components/schemas/RetentionRule'
RetentionRule:
type: object
properties:
type:
type: string
default: expire
enum:
- expire
everySeconds:
type: integer
format: int64
description: Duration in seconds for how long data will be kept in the database. 0 means infinite.
example: 86400
minimum: 0
shardGroupDurationSeconds:
type: integer
format: int64
description: Shard duration measured in seconds.
required:
- type
- everySeconds
Labels:
type: array
items:
$ref: '#/components/schemas/Label'
Label:
type: object
properties:
id:
readOnly: true
type: string
orgID:
readOnly: true
type: string
name:
type: string
properties:
type: object
additionalProperties:
type: string
description: Key/Value pairs associated with this label. Keys can be removed by sending an update with an empty value.
example:
color: ffb3b3
description: this is a description
Authorization:
required:
- orgID
- permissions
allOf:
- $ref: '#/components/schemas/AuthorizationUpdateRequest'
- type: object
properties:
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
orgID:
type: string
description: ID of org that authorization is scoped to.
permissions:
type: array
minItems: 1
description: List of permissions for an auth. An auth must have at least one Permission.
items:
$ref: '#/components/schemas/Permission'
id:
readOnly: true
type: string
token:
readOnly: true
type: string
description: Passed via the Authorization Header and Token Authentication type.
userID:
readOnly: true
type: string
description: ID of user that created and owns the token.
user:
readOnly: true
type: string
description: Name of user that created and owns the token.
org:
readOnly: true
type: string
description: Name of the org token is scoped to.
links:
type: object
readOnly: true
example:
self: /api/v2/authorizations/1
user: /api/v2/users/12
properties:
self:
readOnly: true
$ref: '#/components/schemas/Link'
user:
readOnly: true
$ref: '#/components/schemas/Link'
AuthorizationUpdateRequest:
properties:
status:
description: If inactive the token is inactive and requests using the token will be rejected.
default: active
type: string
enum:
- active
- inactive
description:
type: string
description: A description of the token.
Permission:
required:
- action
- resource
properties:
action:
type: string
enum:
- read
- write
resource:
type: object
required:
- type
properties:
type:
type: string
enum:
- authorizations
- buckets
- dashboards
- orgs
- sources
- tasks
- telegrafs
- users
- variables
- scrapers
- secrets
- labels
- views
- documents
- notificationRules
- notificationEndpoints
- checks
- dbrp
id:
type: string
nullable: true
description: If ID is set that is a permission for a specific resource. if it is not set it is a permission for all resources of that resource type.
name:
type: string
nullable: true
description: Optional name of the resource if the resource has a name field.
orgID:
type: string
nullable: true
description: If orgID is set that is a permission for all resources owned my that org. if it is not set it is a permission for all resources of that resource type.
org:
type: string
nullable: true
description: Optional name of the organization of the organization with orgID.

307
internal/api/api_setup.go Normal file
View File

@ -0,0 +1,307 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"bytes"
_context "context"
_ioutil "io/ioutil"
_nethttp "net/http"
_neturl "net/url"
)
// Linger please
var (
_ _context.Context
)
type SetupApi interface {
/*
* GetSetup Check if database has default user, org, bucket
* Returns `true` if no default user, organization, or bucket has been created.
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @return ApiGetSetupRequest
*/
GetSetup(ctx _context.Context) ApiGetSetupRequest
/*
* GetSetupExecute executes the request
* @return InlineResponse200
*/
GetSetupExecute(r ApiGetSetupRequest) (InlineResponse200, *_nethttp.Response, error)
/*
* PostSetup Set up initial user, org and bucket
* Post an onboarding request to set up initial user, org and bucket.
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @return ApiPostSetupRequest
*/
PostSetup(ctx _context.Context) ApiPostSetupRequest
/*
* PostSetupExecute executes the request
* @return OnboardingResponse
*/
PostSetupExecute(r ApiPostSetupRequest) (OnboardingResponse, *_nethttp.Response, error)
}
// SetupApiService SetupApi service
type SetupApiService service
type ApiGetSetupRequest struct {
ctx _context.Context
ApiService SetupApi
zapTraceSpan *string
}
func (r ApiGetSetupRequest) ZapTraceSpan(zapTraceSpan string) ApiGetSetupRequest {
r.zapTraceSpan = &zapTraceSpan
return r
}
func (r ApiGetSetupRequest) GetZapTraceSpan() *string {
return r.zapTraceSpan
}
func (r ApiGetSetupRequest) Execute() (InlineResponse200, *_nethttp.Response, error) {
return r.ApiService.GetSetupExecute(r)
}
/*
* GetSetup Check if database has default user, org, bucket
* Returns `true` if no default user, organization, or bucket has been created.
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @return ApiGetSetupRequest
*/
func (a *SetupApiService) GetSetup(ctx _context.Context) ApiGetSetupRequest {
return ApiGetSetupRequest{
ApiService: a,
ctx: ctx,
}
}
/*
* Execute executes the request
* @return InlineResponse200
*/
func (a *SetupApiService) GetSetupExecute(r ApiGetSetupRequest) (InlineResponse200, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodGet
localVarPostBody interface{}
localVarFormFileName string
localVarFileName string
localVarFileBytes []byte
localVarReturnValue InlineResponse200
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SetupApiService.GetSetup")
if err != nil {
return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/setup"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.zapTraceSpan != nil {
localVarHeaderParams["Zap-Trace-Span"] = parameterToString(*r.zapTraceSpan, "")
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = _ioutil.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ApiPostSetupRequest struct {
ctx _context.Context
ApiService SetupApi
onboardingRequest *OnboardingRequest
zapTraceSpan *string
}
func (r ApiPostSetupRequest) OnboardingRequest(onboardingRequest OnboardingRequest) ApiPostSetupRequest {
r.onboardingRequest = &onboardingRequest
return r
}
func (r ApiPostSetupRequest) GetOnboardingRequest() *OnboardingRequest {
return r.onboardingRequest
}
func (r ApiPostSetupRequest) ZapTraceSpan(zapTraceSpan string) ApiPostSetupRequest {
r.zapTraceSpan = &zapTraceSpan
return r
}
func (r ApiPostSetupRequest) GetZapTraceSpan() *string {
return r.zapTraceSpan
}
func (r ApiPostSetupRequest) Execute() (OnboardingResponse, *_nethttp.Response, error) {
return r.ApiService.PostSetupExecute(r)
}
/*
* PostSetup Set up initial user, org and bucket
* Post an onboarding request to set up initial user, org and bucket.
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @return ApiPostSetupRequest
*/
func (a *SetupApiService) PostSetup(ctx _context.Context) ApiPostSetupRequest {
return ApiPostSetupRequest{
ApiService: a,
ctx: ctx,
}
}
/*
* Execute executes the request
* @return OnboardingResponse
*/
func (a *SetupApiService) PostSetupExecute(r ApiPostSetupRequest) (OnboardingResponse, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodPost
localVarPostBody interface{}
localVarFormFileName string
localVarFileName string
localVarFileBytes []byte
localVarReturnValue OnboardingResponse
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SetupApiService.PostSetup")
if err != nil {
return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/setup"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
if r.onboardingRequest == nil {
return localVarReturnValue, nil, reportError("onboardingRequest is required and must be specified")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{"application/json"}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if r.zapTraceSpan != nil {
localVarHeaderParams["Zap-Trace-Span"] = parameterToString(*r.zapTraceSpan, "")
}
// body params
localVarPostBody = r.onboardingRequest
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = _ioutil.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
var v Error
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}

View File

@ -47,6 +47,8 @@ type APIClient struct {
// API Services
HealthApi HealthApi
SetupApi SetupApi
}
type service struct {
@ -66,6 +68,7 @@ func NewAPIClient(cfg *Configuration) *APIClient {
// API Services
c.HealthApi = (*HealthApiService)(&c.common)
c.SetupApi = (*SetupApiService)(&c.common)
return c
}

View File

@ -0,0 +1,508 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
"time"
)
// Authorization struct for Authorization
type Authorization struct {
// If inactive the token is inactive and requests using the token will be rejected.
Status *string `json:"status,omitempty"`
// A description of the token.
Description *string `json:"description,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
// ID of org that authorization is scoped to.
OrgID string `json:"orgID"`
// List of permissions for an auth. An auth must have at least one Permission.
Permissions []Permission `json:"permissions"`
Id *string `json:"id,omitempty"`
// Passed via the Authorization Header and Token Authentication type.
Token *string `json:"token,omitempty"`
// ID of user that created and owns the token.
UserID *string `json:"userID,omitempty"`
// Name of user that created and owns the token.
User *string `json:"user,omitempty"`
// Name of the org token is scoped to.
Org *string `json:"org,omitempty"`
Links *AuthorizationAllOfLinks `json:"links,omitempty"`
}
// NewAuthorization instantiates a new Authorization object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewAuthorization(orgID string, permissions []Permission) *Authorization {
this := Authorization{}
var status string = "active"
this.Status = &status
this.OrgID = orgID
this.Permissions = permissions
return &this
}
// NewAuthorizationWithDefaults instantiates a new Authorization object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewAuthorizationWithDefaults() *Authorization {
this := Authorization{}
var status string = "active"
this.Status = &status
return &this
}
// GetStatus returns the Status field value if set, zero value otherwise.
func (o *Authorization) GetStatus() string {
if o == nil || o.Status == nil {
var ret string
return ret
}
return *o.Status
}
// GetStatusOk returns a tuple with the Status field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetStatusOk() (*string, bool) {
if o == nil || o.Status == nil {
return nil, false
}
return o.Status, true
}
// HasStatus returns a boolean if a field has been set.
func (o *Authorization) HasStatus() bool {
if o != nil && o.Status != nil {
return true
}
return false
}
// SetStatus gets a reference to the given string and assigns it to the Status field.
func (o *Authorization) SetStatus(v string) {
o.Status = &v
}
// GetDescription returns the Description field value if set, zero value otherwise.
func (o *Authorization) GetDescription() string {
if o == nil || o.Description == nil {
var ret string
return ret
}
return *o.Description
}
// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetDescriptionOk() (*string, bool) {
if o == nil || o.Description == nil {
return nil, false
}
return o.Description, true
}
// HasDescription returns a boolean if a field has been set.
func (o *Authorization) HasDescription() bool {
if o != nil && o.Description != nil {
return true
}
return false
}
// SetDescription gets a reference to the given string and assigns it to the Description field.
func (o *Authorization) SetDescription(v string) {
o.Description = &v
}
// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise.
func (o *Authorization) GetCreatedAt() time.Time {
if o == nil || o.CreatedAt == nil {
var ret time.Time
return ret
}
return *o.CreatedAt
}
// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetCreatedAtOk() (*time.Time, bool) {
if o == nil || o.CreatedAt == nil {
return nil, false
}
return o.CreatedAt, true
}
// HasCreatedAt returns a boolean if a field has been set.
func (o *Authorization) HasCreatedAt() bool {
if o != nil && o.CreatedAt != nil {
return true
}
return false
}
// SetCreatedAt gets a reference to the given time.Time and assigns it to the CreatedAt field.
func (o *Authorization) SetCreatedAt(v time.Time) {
o.CreatedAt = &v
}
// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise.
func (o *Authorization) GetUpdatedAt() time.Time {
if o == nil || o.UpdatedAt == nil {
var ret time.Time
return ret
}
return *o.UpdatedAt
}
// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetUpdatedAtOk() (*time.Time, bool) {
if o == nil || o.UpdatedAt == nil {
return nil, false
}
return o.UpdatedAt, true
}
// HasUpdatedAt returns a boolean if a field has been set.
func (o *Authorization) HasUpdatedAt() bool {
if o != nil && o.UpdatedAt != nil {
return true
}
return false
}
// SetUpdatedAt gets a reference to the given time.Time and assigns it to the UpdatedAt field.
func (o *Authorization) SetUpdatedAt(v time.Time) {
o.UpdatedAt = &v
}
// GetOrgID returns the OrgID field value
func (o *Authorization) GetOrgID() string {
if o == nil {
var ret string
return ret
}
return o.OrgID
}
// GetOrgIDOk returns a tuple with the OrgID field value
// and a boolean to check if the value has been set.
func (o *Authorization) GetOrgIDOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.OrgID, true
}
// SetOrgID sets field value
func (o *Authorization) SetOrgID(v string) {
o.OrgID = v
}
// GetPermissions returns the Permissions field value
func (o *Authorization) GetPermissions() []Permission {
if o == nil {
var ret []Permission
return ret
}
return o.Permissions
}
// GetPermissionsOk returns a tuple with the Permissions field value
// and a boolean to check if the value has been set.
func (o *Authorization) GetPermissionsOk() (*[]Permission, bool) {
if o == nil {
return nil, false
}
return &o.Permissions, true
}
// SetPermissions sets field value
func (o *Authorization) SetPermissions(v []Permission) {
o.Permissions = v
}
// GetId returns the Id field value if set, zero value otherwise.
func (o *Authorization) GetId() string {
if o == nil || o.Id == nil {
var ret string
return ret
}
return *o.Id
}
// GetIdOk returns a tuple with the Id field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetIdOk() (*string, bool) {
if o == nil || o.Id == nil {
return nil, false
}
return o.Id, true
}
// HasId returns a boolean if a field has been set.
func (o *Authorization) HasId() bool {
if o != nil && o.Id != nil {
return true
}
return false
}
// SetId gets a reference to the given string and assigns it to the Id field.
func (o *Authorization) SetId(v string) {
o.Id = &v
}
// GetToken returns the Token field value if set, zero value otherwise.
func (o *Authorization) GetToken() string {
if o == nil || o.Token == nil {
var ret string
return ret
}
return *o.Token
}
// GetTokenOk returns a tuple with the Token field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetTokenOk() (*string, bool) {
if o == nil || o.Token == nil {
return nil, false
}
return o.Token, true
}
// HasToken returns a boolean if a field has been set.
func (o *Authorization) HasToken() bool {
if o != nil && o.Token != nil {
return true
}
return false
}
// SetToken gets a reference to the given string and assigns it to the Token field.
func (o *Authorization) SetToken(v string) {
o.Token = &v
}
// GetUserID returns the UserID field value if set, zero value otherwise.
func (o *Authorization) GetUserID() string {
if o == nil || o.UserID == nil {
var ret string
return ret
}
return *o.UserID
}
// GetUserIDOk returns a tuple with the UserID field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetUserIDOk() (*string, bool) {
if o == nil || o.UserID == nil {
return nil, false
}
return o.UserID, true
}
// HasUserID returns a boolean if a field has been set.
func (o *Authorization) HasUserID() bool {
if o != nil && o.UserID != nil {
return true
}
return false
}
// SetUserID gets a reference to the given string and assigns it to the UserID field.
func (o *Authorization) SetUserID(v string) {
o.UserID = &v
}
// GetUser returns the User field value if set, zero value otherwise.
func (o *Authorization) GetUser() string {
if o == nil || o.User == nil {
var ret string
return ret
}
return *o.User
}
// GetUserOk returns a tuple with the User field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetUserOk() (*string, bool) {
if o == nil || o.User == nil {
return nil, false
}
return o.User, true
}
// HasUser returns a boolean if a field has been set.
func (o *Authorization) HasUser() bool {
if o != nil && o.User != nil {
return true
}
return false
}
// SetUser gets a reference to the given string and assigns it to the User field.
func (o *Authorization) SetUser(v string) {
o.User = &v
}
// GetOrg returns the Org field value if set, zero value otherwise.
func (o *Authorization) GetOrg() string {
if o == nil || o.Org == nil {
var ret string
return ret
}
return *o.Org
}
// GetOrgOk returns a tuple with the Org field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetOrgOk() (*string, bool) {
if o == nil || o.Org == nil {
return nil, false
}
return o.Org, true
}
// HasOrg returns a boolean if a field has been set.
func (o *Authorization) HasOrg() bool {
if o != nil && o.Org != nil {
return true
}
return false
}
// SetOrg gets a reference to the given string and assigns it to the Org field.
func (o *Authorization) SetOrg(v string) {
o.Org = &v
}
// GetLinks returns the Links field value if set, zero value otherwise.
func (o *Authorization) GetLinks() AuthorizationAllOfLinks {
if o == nil || o.Links == nil {
var ret AuthorizationAllOfLinks
return ret
}
return *o.Links
}
// GetLinksOk returns a tuple with the Links field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Authorization) GetLinksOk() (*AuthorizationAllOfLinks, bool) {
if o == nil || o.Links == nil {
return nil, false
}
return o.Links, true
}
// HasLinks returns a boolean if a field has been set.
func (o *Authorization) HasLinks() bool {
if o != nil && o.Links != nil {
return true
}
return false
}
// SetLinks gets a reference to the given AuthorizationAllOfLinks and assigns it to the Links field.
func (o *Authorization) SetLinks(v AuthorizationAllOfLinks) {
o.Links = &v
}
func (o Authorization) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Status != nil {
toSerialize["status"] = o.Status
}
if o.Description != nil {
toSerialize["description"] = o.Description
}
if o.CreatedAt != nil {
toSerialize["createdAt"] = o.CreatedAt
}
if o.UpdatedAt != nil {
toSerialize["updatedAt"] = o.UpdatedAt
}
if true {
toSerialize["orgID"] = o.OrgID
}
if true {
toSerialize["permissions"] = o.Permissions
}
if o.Id != nil {
toSerialize["id"] = o.Id
}
if o.Token != nil {
toSerialize["token"] = o.Token
}
if o.UserID != nil {
toSerialize["userID"] = o.UserID
}
if o.User != nil {
toSerialize["user"] = o.User
}
if o.Org != nil {
toSerialize["org"] = o.Org
}
if o.Links != nil {
toSerialize["links"] = o.Links
}
return json.Marshal(toSerialize)
}
type NullableAuthorization struct {
value *Authorization
isSet bool
}
func (v NullableAuthorization) Get() *Authorization {
return v.value
}
func (v *NullableAuthorization) Set(val *Authorization) {
v.value = val
v.isSet = true
}
func (v NullableAuthorization) IsSet() bool {
return v.isSet
}
func (v *NullableAuthorization) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableAuthorization(val *Authorization) *NullableAuthorization {
return &NullableAuthorization{value: val, isSet: true}
}
func (v NullableAuthorization) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableAuthorization) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,444 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
"time"
)
// AuthorizationAllOf struct for AuthorizationAllOf
type AuthorizationAllOf struct {
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
// ID of org that authorization is scoped to.
OrgID *string `json:"orgID,omitempty"`
// List of permissions for an auth. An auth must have at least one Permission.
Permissions *[]Permission `json:"permissions,omitempty"`
Id *string `json:"id,omitempty"`
// Passed via the Authorization Header and Token Authentication type.
Token *string `json:"token,omitempty"`
// ID of user that created and owns the token.
UserID *string `json:"userID,omitempty"`
// Name of user that created and owns the token.
User *string `json:"user,omitempty"`
// Name of the org token is scoped to.
Org *string `json:"org,omitempty"`
Links *AuthorizationAllOfLinks `json:"links,omitempty"`
}
// NewAuthorizationAllOf instantiates a new AuthorizationAllOf object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewAuthorizationAllOf() *AuthorizationAllOf {
this := AuthorizationAllOf{}
return &this
}
// NewAuthorizationAllOfWithDefaults instantiates a new AuthorizationAllOf object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewAuthorizationAllOfWithDefaults() *AuthorizationAllOf {
this := AuthorizationAllOf{}
return &this
}
// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetCreatedAt() time.Time {
if o == nil || o.CreatedAt == nil {
var ret time.Time
return ret
}
return *o.CreatedAt
}
// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetCreatedAtOk() (*time.Time, bool) {
if o == nil || o.CreatedAt == nil {
return nil, false
}
return o.CreatedAt, true
}
// HasCreatedAt returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasCreatedAt() bool {
if o != nil && o.CreatedAt != nil {
return true
}
return false
}
// SetCreatedAt gets a reference to the given time.Time and assigns it to the CreatedAt field.
func (o *AuthorizationAllOf) SetCreatedAt(v time.Time) {
o.CreatedAt = &v
}
// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetUpdatedAt() time.Time {
if o == nil || o.UpdatedAt == nil {
var ret time.Time
return ret
}
return *o.UpdatedAt
}
// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetUpdatedAtOk() (*time.Time, bool) {
if o == nil || o.UpdatedAt == nil {
return nil, false
}
return o.UpdatedAt, true
}
// HasUpdatedAt returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasUpdatedAt() bool {
if o != nil && o.UpdatedAt != nil {
return true
}
return false
}
// SetUpdatedAt gets a reference to the given time.Time and assigns it to the UpdatedAt field.
func (o *AuthorizationAllOf) SetUpdatedAt(v time.Time) {
o.UpdatedAt = &v
}
// GetOrgID returns the OrgID field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetOrgID() string {
if o == nil || o.OrgID == nil {
var ret string
return ret
}
return *o.OrgID
}
// GetOrgIDOk returns a tuple with the OrgID field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetOrgIDOk() (*string, bool) {
if o == nil || o.OrgID == nil {
return nil, false
}
return o.OrgID, true
}
// HasOrgID returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasOrgID() bool {
if o != nil && o.OrgID != nil {
return true
}
return false
}
// SetOrgID gets a reference to the given string and assigns it to the OrgID field.
func (o *AuthorizationAllOf) SetOrgID(v string) {
o.OrgID = &v
}
// GetPermissions returns the Permissions field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetPermissions() []Permission {
if o == nil || o.Permissions == nil {
var ret []Permission
return ret
}
return *o.Permissions
}
// GetPermissionsOk returns a tuple with the Permissions field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetPermissionsOk() (*[]Permission, bool) {
if o == nil || o.Permissions == nil {
return nil, false
}
return o.Permissions, true
}
// HasPermissions returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasPermissions() bool {
if o != nil && o.Permissions != nil {
return true
}
return false
}
// SetPermissions gets a reference to the given []Permission and assigns it to the Permissions field.
func (o *AuthorizationAllOf) SetPermissions(v []Permission) {
o.Permissions = &v
}
// GetId returns the Id field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetId() string {
if o == nil || o.Id == nil {
var ret string
return ret
}
return *o.Id
}
// GetIdOk returns a tuple with the Id field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetIdOk() (*string, bool) {
if o == nil || o.Id == nil {
return nil, false
}
return o.Id, true
}
// HasId returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasId() bool {
if o != nil && o.Id != nil {
return true
}
return false
}
// SetId gets a reference to the given string and assigns it to the Id field.
func (o *AuthorizationAllOf) SetId(v string) {
o.Id = &v
}
// GetToken returns the Token field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetToken() string {
if o == nil || o.Token == nil {
var ret string
return ret
}
return *o.Token
}
// GetTokenOk returns a tuple with the Token field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetTokenOk() (*string, bool) {
if o == nil || o.Token == nil {
return nil, false
}
return o.Token, true
}
// HasToken returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasToken() bool {
if o != nil && o.Token != nil {
return true
}
return false
}
// SetToken gets a reference to the given string and assigns it to the Token field.
func (o *AuthorizationAllOf) SetToken(v string) {
o.Token = &v
}
// GetUserID returns the UserID field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetUserID() string {
if o == nil || o.UserID == nil {
var ret string
return ret
}
return *o.UserID
}
// GetUserIDOk returns a tuple with the UserID field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetUserIDOk() (*string, bool) {
if o == nil || o.UserID == nil {
return nil, false
}
return o.UserID, true
}
// HasUserID returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasUserID() bool {
if o != nil && o.UserID != nil {
return true
}
return false
}
// SetUserID gets a reference to the given string and assigns it to the UserID field.
func (o *AuthorizationAllOf) SetUserID(v string) {
o.UserID = &v
}
// GetUser returns the User field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetUser() string {
if o == nil || o.User == nil {
var ret string
return ret
}
return *o.User
}
// GetUserOk returns a tuple with the User field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetUserOk() (*string, bool) {
if o == nil || o.User == nil {
return nil, false
}
return o.User, true
}
// HasUser returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasUser() bool {
if o != nil && o.User != nil {
return true
}
return false
}
// SetUser gets a reference to the given string and assigns it to the User field.
func (o *AuthorizationAllOf) SetUser(v string) {
o.User = &v
}
// GetOrg returns the Org field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetOrg() string {
if o == nil || o.Org == nil {
var ret string
return ret
}
return *o.Org
}
// GetOrgOk returns a tuple with the Org field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetOrgOk() (*string, bool) {
if o == nil || o.Org == nil {
return nil, false
}
return o.Org, true
}
// HasOrg returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasOrg() bool {
if o != nil && o.Org != nil {
return true
}
return false
}
// SetOrg gets a reference to the given string and assigns it to the Org field.
func (o *AuthorizationAllOf) SetOrg(v string) {
o.Org = &v
}
// GetLinks returns the Links field value if set, zero value otherwise.
func (o *AuthorizationAllOf) GetLinks() AuthorizationAllOfLinks {
if o == nil || o.Links == nil {
var ret AuthorizationAllOfLinks
return ret
}
return *o.Links
}
// GetLinksOk returns a tuple with the Links field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOf) GetLinksOk() (*AuthorizationAllOfLinks, bool) {
if o == nil || o.Links == nil {
return nil, false
}
return o.Links, true
}
// HasLinks returns a boolean if a field has been set.
func (o *AuthorizationAllOf) HasLinks() bool {
if o != nil && o.Links != nil {
return true
}
return false
}
// SetLinks gets a reference to the given AuthorizationAllOfLinks and assigns it to the Links field.
func (o *AuthorizationAllOf) SetLinks(v AuthorizationAllOfLinks) {
o.Links = &v
}
func (o AuthorizationAllOf) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.CreatedAt != nil {
toSerialize["createdAt"] = o.CreatedAt
}
if o.UpdatedAt != nil {
toSerialize["updatedAt"] = o.UpdatedAt
}
if o.OrgID != nil {
toSerialize["orgID"] = o.OrgID
}
if o.Permissions != nil {
toSerialize["permissions"] = o.Permissions
}
if o.Id != nil {
toSerialize["id"] = o.Id
}
if o.Token != nil {
toSerialize["token"] = o.Token
}
if o.UserID != nil {
toSerialize["userID"] = o.UserID
}
if o.User != nil {
toSerialize["user"] = o.User
}
if o.Org != nil {
toSerialize["org"] = o.Org
}
if o.Links != nil {
toSerialize["links"] = o.Links
}
return json.Marshal(toSerialize)
}
type NullableAuthorizationAllOf struct {
value *AuthorizationAllOf
isSet bool
}
func (v NullableAuthorizationAllOf) Get() *AuthorizationAllOf {
return v.value
}
func (v *NullableAuthorizationAllOf) Set(val *AuthorizationAllOf) {
v.value = val
v.isSet = true
}
func (v NullableAuthorizationAllOf) IsSet() bool {
return v.isSet
}
func (v *NullableAuthorizationAllOf) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableAuthorizationAllOf(val *AuthorizationAllOf) *NullableAuthorizationAllOf {
return &NullableAuthorizationAllOf{value: val, isSet: true}
}
func (v NullableAuthorizationAllOf) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableAuthorizationAllOf) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,151 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// AuthorizationAllOfLinks struct for AuthorizationAllOfLinks
type AuthorizationAllOfLinks struct {
// URI of resource.
Self *string `json:"self,omitempty"`
// URI of resource.
User *string `json:"user,omitempty"`
}
// NewAuthorizationAllOfLinks instantiates a new AuthorizationAllOfLinks object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewAuthorizationAllOfLinks() *AuthorizationAllOfLinks {
this := AuthorizationAllOfLinks{}
return &this
}
// NewAuthorizationAllOfLinksWithDefaults instantiates a new AuthorizationAllOfLinks object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewAuthorizationAllOfLinksWithDefaults() *AuthorizationAllOfLinks {
this := AuthorizationAllOfLinks{}
return &this
}
// GetSelf returns the Self field value if set, zero value otherwise.
func (o *AuthorizationAllOfLinks) GetSelf() string {
if o == nil || o.Self == nil {
var ret string
return ret
}
return *o.Self
}
// GetSelfOk returns a tuple with the Self field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOfLinks) GetSelfOk() (*string, bool) {
if o == nil || o.Self == nil {
return nil, false
}
return o.Self, true
}
// HasSelf returns a boolean if a field has been set.
func (o *AuthorizationAllOfLinks) HasSelf() bool {
if o != nil && o.Self != nil {
return true
}
return false
}
// SetSelf gets a reference to the given string and assigns it to the Self field.
func (o *AuthorizationAllOfLinks) SetSelf(v string) {
o.Self = &v
}
// GetUser returns the User field value if set, zero value otherwise.
func (o *AuthorizationAllOfLinks) GetUser() string {
if o == nil || o.User == nil {
var ret string
return ret
}
return *o.User
}
// GetUserOk returns a tuple with the User field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationAllOfLinks) GetUserOk() (*string, bool) {
if o == nil || o.User == nil {
return nil, false
}
return o.User, true
}
// HasUser returns a boolean if a field has been set.
func (o *AuthorizationAllOfLinks) HasUser() bool {
if o != nil && o.User != nil {
return true
}
return false
}
// SetUser gets a reference to the given string and assigns it to the User field.
func (o *AuthorizationAllOfLinks) SetUser(v string) {
o.User = &v
}
func (o AuthorizationAllOfLinks) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Self != nil {
toSerialize["self"] = o.Self
}
if o.User != nil {
toSerialize["user"] = o.User
}
return json.Marshal(toSerialize)
}
type NullableAuthorizationAllOfLinks struct {
value *AuthorizationAllOfLinks
isSet bool
}
func (v NullableAuthorizationAllOfLinks) Get() *AuthorizationAllOfLinks {
return v.value
}
func (v *NullableAuthorizationAllOfLinks) Set(val *AuthorizationAllOfLinks) {
v.value = val
v.isSet = true
}
func (v NullableAuthorizationAllOfLinks) IsSet() bool {
return v.isSet
}
func (v *NullableAuthorizationAllOfLinks) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableAuthorizationAllOfLinks(val *AuthorizationAllOfLinks) *NullableAuthorizationAllOfLinks {
return &NullableAuthorizationAllOfLinks{value: val, isSet: true}
}
func (v NullableAuthorizationAllOfLinks) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableAuthorizationAllOfLinks) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,155 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// AuthorizationUpdateRequest struct for AuthorizationUpdateRequest
type AuthorizationUpdateRequest struct {
// If inactive the token is inactive and requests using the token will be rejected.
Status *string `json:"status,omitempty"`
// A description of the token.
Description *string `json:"description,omitempty"`
}
// NewAuthorizationUpdateRequest instantiates a new AuthorizationUpdateRequest object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewAuthorizationUpdateRequest() *AuthorizationUpdateRequest {
this := AuthorizationUpdateRequest{}
var status string = "active"
this.Status = &status
return &this
}
// NewAuthorizationUpdateRequestWithDefaults instantiates a new AuthorizationUpdateRequest object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewAuthorizationUpdateRequestWithDefaults() *AuthorizationUpdateRequest {
this := AuthorizationUpdateRequest{}
var status string = "active"
this.Status = &status
return &this
}
// GetStatus returns the Status field value if set, zero value otherwise.
func (o *AuthorizationUpdateRequest) GetStatus() string {
if o == nil || o.Status == nil {
var ret string
return ret
}
return *o.Status
}
// GetStatusOk returns a tuple with the Status field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationUpdateRequest) GetStatusOk() (*string, bool) {
if o == nil || o.Status == nil {
return nil, false
}
return o.Status, true
}
// HasStatus returns a boolean if a field has been set.
func (o *AuthorizationUpdateRequest) HasStatus() bool {
if o != nil && o.Status != nil {
return true
}
return false
}
// SetStatus gets a reference to the given string and assigns it to the Status field.
func (o *AuthorizationUpdateRequest) SetStatus(v string) {
o.Status = &v
}
// GetDescription returns the Description field value if set, zero value otherwise.
func (o *AuthorizationUpdateRequest) GetDescription() string {
if o == nil || o.Description == nil {
var ret string
return ret
}
return *o.Description
}
// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *AuthorizationUpdateRequest) GetDescriptionOk() (*string, bool) {
if o == nil || o.Description == nil {
return nil, false
}
return o.Description, true
}
// HasDescription returns a boolean if a field has been set.
func (o *AuthorizationUpdateRequest) HasDescription() bool {
if o != nil && o.Description != nil {
return true
}
return false
}
// SetDescription gets a reference to the given string and assigns it to the Description field.
func (o *AuthorizationUpdateRequest) SetDescription(v string) {
o.Description = &v
}
func (o AuthorizationUpdateRequest) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Status != nil {
toSerialize["status"] = o.Status
}
if o.Description != nil {
toSerialize["description"] = o.Description
}
return json.Marshal(toSerialize)
}
type NullableAuthorizationUpdateRequest struct {
value *AuthorizationUpdateRequest
isSet bool
}
func (v NullableAuthorizationUpdateRequest) Get() *AuthorizationUpdateRequest {
return v.value
}
func (v *NullableAuthorizationUpdateRequest) Set(val *AuthorizationUpdateRequest) {
v.value = val
v.isSet = true
}
func (v NullableAuthorizationUpdateRequest) IsSet() bool {
return v.isSet
}
func (v *NullableAuthorizationUpdateRequest) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableAuthorizationUpdateRequest(val *AuthorizationUpdateRequest) *NullableAuthorizationUpdateRequest {
return &NullableAuthorizationUpdateRequest{value: val, isSet: true}
}
func (v NullableAuthorizationUpdateRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableAuthorizationUpdateRequest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,465 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
"time"
)
// Bucket struct for Bucket
type Bucket struct {
Links *BucketLinks `json:"links,omitempty"`
Id *string `json:"id,omitempty"`
Type *string `json:"type,omitempty"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
OrgID *string `json:"orgID,omitempty"`
Rp *string `json:"rp,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
// Rules to expire or retain data. No rules means data never expires.
RetentionRules []RetentionRule `json:"retentionRules"`
Labels *[]Label `json:"labels,omitempty"`
}
// NewBucket instantiates a new Bucket object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBucket(name string, retentionRules []RetentionRule) *Bucket {
this := Bucket{}
var type_ string = "user"
this.Type = &type_
this.Name = name
this.RetentionRules = retentionRules
return &this
}
// NewBucketWithDefaults instantiates a new Bucket object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBucketWithDefaults() *Bucket {
this := Bucket{}
var type_ string = "user"
this.Type = &type_
return &this
}
// GetLinks returns the Links field value if set, zero value otherwise.
func (o *Bucket) GetLinks() BucketLinks {
if o == nil || o.Links == nil {
var ret BucketLinks
return ret
}
return *o.Links
}
// GetLinksOk returns a tuple with the Links field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Bucket) GetLinksOk() (*BucketLinks, bool) {
if o == nil || o.Links == nil {
return nil, false
}
return o.Links, true
}
// HasLinks returns a boolean if a field has been set.
func (o *Bucket) HasLinks() bool {
if o != nil && o.Links != nil {
return true
}
return false
}
// SetLinks gets a reference to the given BucketLinks and assigns it to the Links field.
func (o *Bucket) SetLinks(v BucketLinks) {
o.Links = &v
}
// GetId returns the Id field value if set, zero value otherwise.
func (o *Bucket) GetId() string {
if o == nil || o.Id == nil {
var ret string
return ret
}
return *o.Id
}
// GetIdOk returns a tuple with the Id field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Bucket) GetIdOk() (*string, bool) {
if o == nil || o.Id == nil {
return nil, false
}
return o.Id, true
}
// HasId returns a boolean if a field has been set.
func (o *Bucket) HasId() bool {
if o != nil && o.Id != nil {
return true
}
return false
}
// SetId gets a reference to the given string and assigns it to the Id field.
func (o *Bucket) SetId(v string) {
o.Id = &v
}
// GetType returns the Type field value if set, zero value otherwise.
func (o *Bucket) GetType() string {
if o == nil || o.Type == nil {
var ret string
return ret
}
return *o.Type
}
// GetTypeOk returns a tuple with the Type field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Bucket) GetTypeOk() (*string, bool) {
if o == nil || o.Type == nil {
return nil, false
}
return o.Type, true
}
// HasType returns a boolean if a field has been set.
func (o *Bucket) HasType() bool {
if o != nil && o.Type != nil {
return true
}
return false
}
// SetType gets a reference to the given string and assigns it to the Type field.
func (o *Bucket) SetType(v string) {
o.Type = &v
}
// GetName returns the Name field value
func (o *Bucket) GetName() string {
if o == nil {
var ret string
return ret
}
return o.Name
}
// GetNameOk returns a tuple with the Name field value
// and a boolean to check if the value has been set.
func (o *Bucket) GetNameOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Name, true
}
// SetName sets field value
func (o *Bucket) SetName(v string) {
o.Name = v
}
// GetDescription returns the Description field value if set, zero value otherwise.
func (o *Bucket) GetDescription() string {
if o == nil || o.Description == nil {
var ret string
return ret
}
return *o.Description
}
// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Bucket) GetDescriptionOk() (*string, bool) {
if o == nil || o.Description == nil {
return nil, false
}
return o.Description, true
}
// HasDescription returns a boolean if a field has been set.
func (o *Bucket) HasDescription() bool {
if o != nil && o.Description != nil {
return true
}
return false
}
// SetDescription gets a reference to the given string and assigns it to the Description field.
func (o *Bucket) SetDescription(v string) {
o.Description = &v
}
// GetOrgID returns the OrgID field value if set, zero value otherwise.
func (o *Bucket) GetOrgID() string {
if o == nil || o.OrgID == nil {
var ret string
return ret
}
return *o.OrgID
}
// GetOrgIDOk returns a tuple with the OrgID field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Bucket) GetOrgIDOk() (*string, bool) {
if o == nil || o.OrgID == nil {
return nil, false
}
return o.OrgID, true
}
// HasOrgID returns a boolean if a field has been set.
func (o *Bucket) HasOrgID() bool {
if o != nil && o.OrgID != nil {
return true
}
return false
}
// SetOrgID gets a reference to the given string and assigns it to the OrgID field.
func (o *Bucket) SetOrgID(v string) {
o.OrgID = &v
}
// GetRp returns the Rp field value if set, zero value otherwise.
func (o *Bucket) GetRp() string {
if o == nil || o.Rp == nil {
var ret string
return ret
}
return *o.Rp
}
// GetRpOk returns a tuple with the Rp field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Bucket) GetRpOk() (*string, bool) {
if o == nil || o.Rp == nil {
return nil, false
}
return o.Rp, true
}
// HasRp returns a boolean if a field has been set.
func (o *Bucket) HasRp() bool {
if o != nil && o.Rp != nil {
return true
}
return false
}
// SetRp gets a reference to the given string and assigns it to the Rp field.
func (o *Bucket) SetRp(v string) {
o.Rp = &v
}
// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise.
func (o *Bucket) GetCreatedAt() time.Time {
if o == nil || o.CreatedAt == nil {
var ret time.Time
return ret
}
return *o.CreatedAt
}
// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Bucket) GetCreatedAtOk() (*time.Time, bool) {
if o == nil || o.CreatedAt == nil {
return nil, false
}
return o.CreatedAt, true
}
// HasCreatedAt returns a boolean if a field has been set.
func (o *Bucket) HasCreatedAt() bool {
if o != nil && o.CreatedAt != nil {
return true
}
return false
}
// SetCreatedAt gets a reference to the given time.Time and assigns it to the CreatedAt field.
func (o *Bucket) SetCreatedAt(v time.Time) {
o.CreatedAt = &v
}
// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise.
func (o *Bucket) GetUpdatedAt() time.Time {
if o == nil || o.UpdatedAt == nil {
var ret time.Time
return ret
}
return *o.UpdatedAt
}
// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Bucket) GetUpdatedAtOk() (*time.Time, bool) {
if o == nil || o.UpdatedAt == nil {
return nil, false
}
return o.UpdatedAt, true
}
// HasUpdatedAt returns a boolean if a field has been set.
func (o *Bucket) HasUpdatedAt() bool {
if o != nil && o.UpdatedAt != nil {
return true
}
return false
}
// SetUpdatedAt gets a reference to the given time.Time and assigns it to the UpdatedAt field.
func (o *Bucket) SetUpdatedAt(v time.Time) {
o.UpdatedAt = &v
}
// GetRetentionRules returns the RetentionRules field value
func (o *Bucket) GetRetentionRules() []RetentionRule {
if o == nil {
var ret []RetentionRule
return ret
}
return o.RetentionRules
}
// GetRetentionRulesOk returns a tuple with the RetentionRules field value
// and a boolean to check if the value has been set.
func (o *Bucket) GetRetentionRulesOk() (*[]RetentionRule, bool) {
if o == nil {
return nil, false
}
return &o.RetentionRules, true
}
// SetRetentionRules sets field value
func (o *Bucket) SetRetentionRules(v []RetentionRule) {
o.RetentionRules = v
}
// GetLabels returns the Labels field value if set, zero value otherwise.
func (o *Bucket) GetLabels() []Label {
if o == nil || o.Labels == nil {
var ret []Label
return ret
}
return *o.Labels
}
// GetLabelsOk returns a tuple with the Labels field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Bucket) GetLabelsOk() (*[]Label, bool) {
if o == nil || o.Labels == nil {
return nil, false
}
return o.Labels, true
}
// HasLabels returns a boolean if a field has been set.
func (o *Bucket) HasLabels() bool {
if o != nil && o.Labels != nil {
return true
}
return false
}
// SetLabels gets a reference to the given []Label and assigns it to the Labels field.
func (o *Bucket) SetLabels(v []Label) {
o.Labels = &v
}
func (o Bucket) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Links != nil {
toSerialize["links"] = o.Links
}
if o.Id != nil {
toSerialize["id"] = o.Id
}
if o.Type != nil {
toSerialize["type"] = o.Type
}
if true {
toSerialize["name"] = o.Name
}
if o.Description != nil {
toSerialize["description"] = o.Description
}
if o.OrgID != nil {
toSerialize["orgID"] = o.OrgID
}
if o.Rp != nil {
toSerialize["rp"] = o.Rp
}
if o.CreatedAt != nil {
toSerialize["createdAt"] = o.CreatedAt
}
if o.UpdatedAt != nil {
toSerialize["updatedAt"] = o.UpdatedAt
}
if true {
toSerialize["retentionRules"] = o.RetentionRules
}
if o.Labels != nil {
toSerialize["labels"] = o.Labels
}
return json.Marshal(toSerialize)
}
type NullableBucket struct {
value *Bucket
isSet bool
}
func (v NullableBucket) Get() *Bucket {
return v.value
}
func (v *NullableBucket) Set(val *Bucket) {
v.value = val
v.isSet = true
}
func (v NullableBucket) IsSet() bool {
return v.isSet
}
func (v *NullableBucket) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBucket(val *Bucket) *NullableBucket {
return &NullableBucket{value: val, isSet: true}
}
func (v NullableBucket) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBucket) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,299 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// BucketLinks struct for BucketLinks
type BucketLinks struct {
// URI of resource.
Labels *string `json:"labels,omitempty"`
// URI of resource.
Members *string `json:"members,omitempty"`
// URI of resource.
Org *string `json:"org,omitempty"`
// URI of resource.
Owners *string `json:"owners,omitempty"`
// URI of resource.
Self *string `json:"self,omitempty"`
// URI of resource.
Write *string `json:"write,omitempty"`
}
// NewBucketLinks instantiates a new BucketLinks object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewBucketLinks() *BucketLinks {
this := BucketLinks{}
return &this
}
// NewBucketLinksWithDefaults instantiates a new BucketLinks object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewBucketLinksWithDefaults() *BucketLinks {
this := BucketLinks{}
return &this
}
// GetLabels returns the Labels field value if set, zero value otherwise.
func (o *BucketLinks) GetLabels() string {
if o == nil || o.Labels == nil {
var ret string
return ret
}
return *o.Labels
}
// GetLabelsOk returns a tuple with the Labels field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *BucketLinks) GetLabelsOk() (*string, bool) {
if o == nil || o.Labels == nil {
return nil, false
}
return o.Labels, true
}
// HasLabels returns a boolean if a field has been set.
func (o *BucketLinks) HasLabels() bool {
if o != nil && o.Labels != nil {
return true
}
return false
}
// SetLabels gets a reference to the given string and assigns it to the Labels field.
func (o *BucketLinks) SetLabels(v string) {
o.Labels = &v
}
// GetMembers returns the Members field value if set, zero value otherwise.
func (o *BucketLinks) GetMembers() string {
if o == nil || o.Members == nil {
var ret string
return ret
}
return *o.Members
}
// GetMembersOk returns a tuple with the Members field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *BucketLinks) GetMembersOk() (*string, bool) {
if o == nil || o.Members == nil {
return nil, false
}
return o.Members, true
}
// HasMembers returns a boolean if a field has been set.
func (o *BucketLinks) HasMembers() bool {
if o != nil && o.Members != nil {
return true
}
return false
}
// SetMembers gets a reference to the given string and assigns it to the Members field.
func (o *BucketLinks) SetMembers(v string) {
o.Members = &v
}
// GetOrg returns the Org field value if set, zero value otherwise.
func (o *BucketLinks) GetOrg() string {
if o == nil || o.Org == nil {
var ret string
return ret
}
return *o.Org
}
// GetOrgOk returns a tuple with the Org field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *BucketLinks) GetOrgOk() (*string, bool) {
if o == nil || o.Org == nil {
return nil, false
}
return o.Org, true
}
// HasOrg returns a boolean if a field has been set.
func (o *BucketLinks) HasOrg() bool {
if o != nil && o.Org != nil {
return true
}
return false
}
// SetOrg gets a reference to the given string and assigns it to the Org field.
func (o *BucketLinks) SetOrg(v string) {
o.Org = &v
}
// GetOwners returns the Owners field value if set, zero value otherwise.
func (o *BucketLinks) GetOwners() string {
if o == nil || o.Owners == nil {
var ret string
return ret
}
return *o.Owners
}
// GetOwnersOk returns a tuple with the Owners field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *BucketLinks) GetOwnersOk() (*string, bool) {
if o == nil || o.Owners == nil {
return nil, false
}
return o.Owners, true
}
// HasOwners returns a boolean if a field has been set.
func (o *BucketLinks) HasOwners() bool {
if o != nil && o.Owners != nil {
return true
}
return false
}
// SetOwners gets a reference to the given string and assigns it to the Owners field.
func (o *BucketLinks) SetOwners(v string) {
o.Owners = &v
}
// GetSelf returns the Self field value if set, zero value otherwise.
func (o *BucketLinks) GetSelf() string {
if o == nil || o.Self == nil {
var ret string
return ret
}
return *o.Self
}
// GetSelfOk returns a tuple with the Self field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *BucketLinks) GetSelfOk() (*string, bool) {
if o == nil || o.Self == nil {
return nil, false
}
return o.Self, true
}
// HasSelf returns a boolean if a field has been set.
func (o *BucketLinks) HasSelf() bool {
if o != nil && o.Self != nil {
return true
}
return false
}
// SetSelf gets a reference to the given string and assigns it to the Self field.
func (o *BucketLinks) SetSelf(v string) {
o.Self = &v
}
// GetWrite returns the Write field value if set, zero value otherwise.
func (o *BucketLinks) GetWrite() string {
if o == nil || o.Write == nil {
var ret string
return ret
}
return *o.Write
}
// GetWriteOk returns a tuple with the Write field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *BucketLinks) GetWriteOk() (*string, bool) {
if o == nil || o.Write == nil {
return nil, false
}
return o.Write, true
}
// HasWrite returns a boolean if a field has been set.
func (o *BucketLinks) HasWrite() bool {
if o != nil && o.Write != nil {
return true
}
return false
}
// SetWrite gets a reference to the given string and assigns it to the Write field.
func (o *BucketLinks) SetWrite(v string) {
o.Write = &v
}
func (o BucketLinks) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Labels != nil {
toSerialize["labels"] = o.Labels
}
if o.Members != nil {
toSerialize["members"] = o.Members
}
if o.Org != nil {
toSerialize["org"] = o.Org
}
if o.Owners != nil {
toSerialize["owners"] = o.Owners
}
if o.Self != nil {
toSerialize["self"] = o.Self
}
if o.Write != nil {
toSerialize["write"] = o.Write
}
return json.Marshal(toSerialize)
}
type NullableBucketLinks struct {
value *BucketLinks
isSet bool
}
func (v NullableBucketLinks) Get() *BucketLinks {
return v.value
}
func (v *NullableBucketLinks) Set(val *BucketLinks) {
v.value = val
v.isSet = true
}
func (v NullableBucketLinks) IsSet() bool {
return v.isSet
}
func (v *NullableBucketLinks) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBucketLinks(val *BucketLinks) *NullableBucketLinks {
return &NullableBucketLinks{value: val, isSet: true}
}
func (v NullableBucketLinks) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBucketLinks) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,114 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// InlineResponse200 struct for InlineResponse200
type InlineResponse200 struct {
// True means that the influxdb instance has NOT had initial setup; false means that the database has been setup.
Allowed *bool `json:"allowed,omitempty"`
}
// NewInlineResponse200 instantiates a new InlineResponse200 object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewInlineResponse200() *InlineResponse200 {
this := InlineResponse200{}
return &this
}
// NewInlineResponse200WithDefaults instantiates a new InlineResponse200 object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewInlineResponse200WithDefaults() *InlineResponse200 {
this := InlineResponse200{}
return &this
}
// GetAllowed returns the Allowed field value if set, zero value otherwise.
func (o *InlineResponse200) GetAllowed() bool {
if o == nil || o.Allowed == nil {
var ret bool
return ret
}
return *o.Allowed
}
// GetAllowedOk returns a tuple with the Allowed field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *InlineResponse200) GetAllowedOk() (*bool, bool) {
if o == nil || o.Allowed == nil {
return nil, false
}
return o.Allowed, true
}
// HasAllowed returns a boolean if a field has been set.
func (o *InlineResponse200) HasAllowed() bool {
if o != nil && o.Allowed != nil {
return true
}
return false
}
// SetAllowed gets a reference to the given bool and assigns it to the Allowed field.
func (o *InlineResponse200) SetAllowed(v bool) {
o.Allowed = &v
}
func (o InlineResponse200) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Allowed != nil {
toSerialize["allowed"] = o.Allowed
}
return json.Marshal(toSerialize)
}
type NullableInlineResponse200 struct {
value *InlineResponse200
isSet bool
}
func (v NullableInlineResponse200) Get() *InlineResponse200 {
return v.value
}
func (v *NullableInlineResponse200) Set(val *InlineResponse200) {
v.value = val
v.isSet = true
}
func (v NullableInlineResponse200) IsSet() bool {
return v.isSet
}
func (v *NullableInlineResponse200) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableInlineResponse200(val *InlineResponse200) *NullableInlineResponse200 {
return &NullableInlineResponse200{value: val, isSet: true}
}
func (v NullableInlineResponse200) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableInlineResponse200) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

222
internal/api/model_label.go Normal file
View File

@ -0,0 +1,222 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// Label struct for Label
type Label struct {
Id *string `json:"id,omitempty"`
OrgID *string `json:"orgID,omitempty"`
Name *string `json:"name,omitempty"`
// Key/Value pairs associated with this label. Keys can be removed by sending an update with an empty value.
Properties *map[string]string `json:"properties,omitempty"`
}
// NewLabel instantiates a new Label object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewLabel() *Label {
this := Label{}
return &this
}
// NewLabelWithDefaults instantiates a new Label object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewLabelWithDefaults() *Label {
this := Label{}
return &this
}
// GetId returns the Id field value if set, zero value otherwise.
func (o *Label) GetId() string {
if o == nil || o.Id == nil {
var ret string
return ret
}
return *o.Id
}
// GetIdOk returns a tuple with the Id field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Label) GetIdOk() (*string, bool) {
if o == nil || o.Id == nil {
return nil, false
}
return o.Id, true
}
// HasId returns a boolean if a field has been set.
func (o *Label) HasId() bool {
if o != nil && o.Id != nil {
return true
}
return false
}
// SetId gets a reference to the given string and assigns it to the Id field.
func (o *Label) SetId(v string) {
o.Id = &v
}
// GetOrgID returns the OrgID field value if set, zero value otherwise.
func (o *Label) GetOrgID() string {
if o == nil || o.OrgID == nil {
var ret string
return ret
}
return *o.OrgID
}
// GetOrgIDOk returns a tuple with the OrgID field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Label) GetOrgIDOk() (*string, bool) {
if o == nil || o.OrgID == nil {
return nil, false
}
return o.OrgID, true
}
// HasOrgID returns a boolean if a field has been set.
func (o *Label) HasOrgID() bool {
if o != nil && o.OrgID != nil {
return true
}
return false
}
// SetOrgID gets a reference to the given string and assigns it to the OrgID field.
func (o *Label) SetOrgID(v string) {
o.OrgID = &v
}
// GetName returns the Name field value if set, zero value otherwise.
func (o *Label) GetName() string {
if o == nil || o.Name == nil {
var ret string
return ret
}
return *o.Name
}
// GetNameOk returns a tuple with the Name field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Label) GetNameOk() (*string, bool) {
if o == nil || o.Name == nil {
return nil, false
}
return o.Name, true
}
// HasName returns a boolean if a field has been set.
func (o *Label) HasName() bool {
if o != nil && o.Name != nil {
return true
}
return false
}
// SetName gets a reference to the given string and assigns it to the Name field.
func (o *Label) SetName(v string) {
o.Name = &v
}
// GetProperties returns the Properties field value if set, zero value otherwise.
func (o *Label) GetProperties() map[string]string {
if o == nil || o.Properties == nil {
var ret map[string]string
return ret
}
return *o.Properties
}
// GetPropertiesOk returns a tuple with the Properties field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Label) GetPropertiesOk() (*map[string]string, bool) {
if o == nil || o.Properties == nil {
return nil, false
}
return o.Properties, true
}
// HasProperties returns a boolean if a field has been set.
func (o *Label) HasProperties() bool {
if o != nil && o.Properties != nil {
return true
}
return false
}
// SetProperties gets a reference to the given map[string]string and assigns it to the Properties field.
func (o *Label) SetProperties(v map[string]string) {
o.Properties = &v
}
func (o Label) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Id != nil {
toSerialize["id"] = o.Id
}
if o.OrgID != nil {
toSerialize["orgID"] = o.OrgID
}
if o.Name != nil {
toSerialize["name"] = o.Name
}
if o.Properties != nil {
toSerialize["properties"] = o.Properties
}
return json.Marshal(toSerialize)
}
type NullableLabel struct {
value *Label
isSet bool
}
func (v NullableLabel) Get() *Label {
return v.value
}
func (v *NullableLabel) Set(val *Label) {
v.value = val
v.isSet = true
}
func (v NullableLabel) IsSet() bool {
return v.isSet
}
func (v *NullableLabel) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableLabel(val *Label) *NullableLabel {
return &NullableLabel{value: val, isSet: true}
}
func (v NullableLabel) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableLabel) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,310 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// OnboardingRequest struct for OnboardingRequest
type OnboardingRequest struct {
Username string `json:"username"`
Password *string `json:"password,omitempty"`
Org string `json:"org"`
Bucket string `json:"bucket"`
RetentionPeriodSeconds *int64 `json:"retentionPeriodSeconds,omitempty"`
// Retention period *in nanoseconds* for the new bucket. This key's name has been misleading since OSS 2.0 GA, please transition to use `retentionPeriodSeconds`
RetentionPeriodHrs *int32 `json:"retentionPeriodHrs,omitempty"`
// Authentication token to set on the initial user. If not specified, the server will generate a token.
Token *string `json:"token,omitempty"`
}
// NewOnboardingRequest instantiates a new OnboardingRequest object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewOnboardingRequest(username string, org string, bucket string) *OnboardingRequest {
this := OnboardingRequest{}
this.Username = username
this.Org = org
this.Bucket = bucket
return &this
}
// NewOnboardingRequestWithDefaults instantiates a new OnboardingRequest object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewOnboardingRequestWithDefaults() *OnboardingRequest {
this := OnboardingRequest{}
return &this
}
// GetUsername returns the Username field value
func (o *OnboardingRequest) GetUsername() string {
if o == nil {
var ret string
return ret
}
return o.Username
}
// GetUsernameOk returns a tuple with the Username field value
// and a boolean to check if the value has been set.
func (o *OnboardingRequest) GetUsernameOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Username, true
}
// SetUsername sets field value
func (o *OnboardingRequest) SetUsername(v string) {
o.Username = v
}
// GetPassword returns the Password field value if set, zero value otherwise.
func (o *OnboardingRequest) GetPassword() string {
if o == nil || o.Password == nil {
var ret string
return ret
}
return *o.Password
}
// GetPasswordOk returns a tuple with the Password field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OnboardingRequest) GetPasswordOk() (*string, bool) {
if o == nil || o.Password == nil {
return nil, false
}
return o.Password, true
}
// HasPassword returns a boolean if a field has been set.
func (o *OnboardingRequest) HasPassword() bool {
if o != nil && o.Password != nil {
return true
}
return false
}
// SetPassword gets a reference to the given string and assigns it to the Password field.
func (o *OnboardingRequest) SetPassword(v string) {
o.Password = &v
}
// GetOrg returns the Org field value
func (o *OnboardingRequest) GetOrg() string {
if o == nil {
var ret string
return ret
}
return o.Org
}
// GetOrgOk returns a tuple with the Org field value
// and a boolean to check if the value has been set.
func (o *OnboardingRequest) GetOrgOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Org, true
}
// SetOrg sets field value
func (o *OnboardingRequest) SetOrg(v string) {
o.Org = v
}
// GetBucket returns the Bucket field value
func (o *OnboardingRequest) GetBucket() string {
if o == nil {
var ret string
return ret
}
return o.Bucket
}
// GetBucketOk returns a tuple with the Bucket field value
// and a boolean to check if the value has been set.
func (o *OnboardingRequest) GetBucketOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Bucket, true
}
// SetBucket sets field value
func (o *OnboardingRequest) SetBucket(v string) {
o.Bucket = v
}
// GetRetentionPeriodSeconds returns the RetentionPeriodSeconds field value if set, zero value otherwise.
func (o *OnboardingRequest) GetRetentionPeriodSeconds() int64 {
if o == nil || o.RetentionPeriodSeconds == nil {
var ret int64
return ret
}
return *o.RetentionPeriodSeconds
}
// GetRetentionPeriodSecondsOk returns a tuple with the RetentionPeriodSeconds field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OnboardingRequest) GetRetentionPeriodSecondsOk() (*int64, bool) {
if o == nil || o.RetentionPeriodSeconds == nil {
return nil, false
}
return o.RetentionPeriodSeconds, true
}
// HasRetentionPeriodSeconds returns a boolean if a field has been set.
func (o *OnboardingRequest) HasRetentionPeriodSeconds() bool {
if o != nil && o.RetentionPeriodSeconds != nil {
return true
}
return false
}
// SetRetentionPeriodSeconds gets a reference to the given int64 and assigns it to the RetentionPeriodSeconds field.
func (o *OnboardingRequest) SetRetentionPeriodSeconds(v int64) {
o.RetentionPeriodSeconds = &v
}
// GetRetentionPeriodHrs returns the RetentionPeriodHrs field value if set, zero value otherwise.
func (o *OnboardingRequest) GetRetentionPeriodHrs() int32 {
if o == nil || o.RetentionPeriodHrs == nil {
var ret int32
return ret
}
return *o.RetentionPeriodHrs
}
// GetRetentionPeriodHrsOk returns a tuple with the RetentionPeriodHrs field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OnboardingRequest) GetRetentionPeriodHrsOk() (*int32, bool) {
if o == nil || o.RetentionPeriodHrs == nil {
return nil, false
}
return o.RetentionPeriodHrs, true
}
// HasRetentionPeriodHrs returns a boolean if a field has been set.
func (o *OnboardingRequest) HasRetentionPeriodHrs() bool {
if o != nil && o.RetentionPeriodHrs != nil {
return true
}
return false
}
// SetRetentionPeriodHrs gets a reference to the given int32 and assigns it to the RetentionPeriodHrs field.
func (o *OnboardingRequest) SetRetentionPeriodHrs(v int32) {
o.RetentionPeriodHrs = &v
}
// GetToken returns the Token field value if set, zero value otherwise.
func (o *OnboardingRequest) GetToken() string {
if o == nil || o.Token == nil {
var ret string
return ret
}
return *o.Token
}
// GetTokenOk returns a tuple with the Token field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OnboardingRequest) GetTokenOk() (*string, bool) {
if o == nil || o.Token == nil {
return nil, false
}
return o.Token, true
}
// HasToken returns a boolean if a field has been set.
func (o *OnboardingRequest) HasToken() bool {
if o != nil && o.Token != nil {
return true
}
return false
}
// SetToken gets a reference to the given string and assigns it to the Token field.
func (o *OnboardingRequest) SetToken(v string) {
o.Token = &v
}
func (o OnboardingRequest) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
toSerialize["username"] = o.Username
}
if o.Password != nil {
toSerialize["password"] = o.Password
}
if true {
toSerialize["org"] = o.Org
}
if true {
toSerialize["bucket"] = o.Bucket
}
if o.RetentionPeriodSeconds != nil {
toSerialize["retentionPeriodSeconds"] = o.RetentionPeriodSeconds
}
if o.RetentionPeriodHrs != nil {
toSerialize["retentionPeriodHrs"] = o.RetentionPeriodHrs
}
if o.Token != nil {
toSerialize["token"] = o.Token
}
return json.Marshal(toSerialize)
}
type NullableOnboardingRequest struct {
value *OnboardingRequest
isSet bool
}
func (v NullableOnboardingRequest) Get() *OnboardingRequest {
return v.value
}
func (v *NullableOnboardingRequest) Set(val *OnboardingRequest) {
v.value = val
v.isSet = true
}
func (v NullableOnboardingRequest) IsSet() bool {
return v.isSet
}
func (v *NullableOnboardingRequest) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableOnboardingRequest(val *OnboardingRequest) *NullableOnboardingRequest {
return &NullableOnboardingRequest{value: val, isSet: true}
}
func (v NullableOnboardingRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableOnboardingRequest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,221 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// OnboardingResponse struct for OnboardingResponse
type OnboardingResponse struct {
User *UserResponse `json:"user,omitempty"`
Org *Organization `json:"org,omitempty"`
Bucket *Bucket `json:"bucket,omitempty"`
Auth *Authorization `json:"auth,omitempty"`
}
// NewOnboardingResponse instantiates a new OnboardingResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewOnboardingResponse() *OnboardingResponse {
this := OnboardingResponse{}
return &this
}
// NewOnboardingResponseWithDefaults instantiates a new OnboardingResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewOnboardingResponseWithDefaults() *OnboardingResponse {
this := OnboardingResponse{}
return &this
}
// GetUser returns the User field value if set, zero value otherwise.
func (o *OnboardingResponse) GetUser() UserResponse {
if o == nil || o.User == nil {
var ret UserResponse
return ret
}
return *o.User
}
// GetUserOk returns a tuple with the User field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OnboardingResponse) GetUserOk() (*UserResponse, bool) {
if o == nil || o.User == nil {
return nil, false
}
return o.User, true
}
// HasUser returns a boolean if a field has been set.
func (o *OnboardingResponse) HasUser() bool {
if o != nil && o.User != nil {
return true
}
return false
}
// SetUser gets a reference to the given UserResponse and assigns it to the User field.
func (o *OnboardingResponse) SetUser(v UserResponse) {
o.User = &v
}
// GetOrg returns the Org field value if set, zero value otherwise.
func (o *OnboardingResponse) GetOrg() Organization {
if o == nil || o.Org == nil {
var ret Organization
return ret
}
return *o.Org
}
// GetOrgOk returns a tuple with the Org field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OnboardingResponse) GetOrgOk() (*Organization, bool) {
if o == nil || o.Org == nil {
return nil, false
}
return o.Org, true
}
// HasOrg returns a boolean if a field has been set.
func (o *OnboardingResponse) HasOrg() bool {
if o != nil && o.Org != nil {
return true
}
return false
}
// SetOrg gets a reference to the given Organization and assigns it to the Org field.
func (o *OnboardingResponse) SetOrg(v Organization) {
o.Org = &v
}
// GetBucket returns the Bucket field value if set, zero value otherwise.
func (o *OnboardingResponse) GetBucket() Bucket {
if o == nil || o.Bucket == nil {
var ret Bucket
return ret
}
return *o.Bucket
}
// GetBucketOk returns a tuple with the Bucket field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OnboardingResponse) GetBucketOk() (*Bucket, bool) {
if o == nil || o.Bucket == nil {
return nil, false
}
return o.Bucket, true
}
// HasBucket returns a boolean if a field has been set.
func (o *OnboardingResponse) HasBucket() bool {
if o != nil && o.Bucket != nil {
return true
}
return false
}
// SetBucket gets a reference to the given Bucket and assigns it to the Bucket field.
func (o *OnboardingResponse) SetBucket(v Bucket) {
o.Bucket = &v
}
// GetAuth returns the Auth field value if set, zero value otherwise.
func (o *OnboardingResponse) GetAuth() Authorization {
if o == nil || o.Auth == nil {
var ret Authorization
return ret
}
return *o.Auth
}
// GetAuthOk returns a tuple with the Auth field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OnboardingResponse) GetAuthOk() (*Authorization, bool) {
if o == nil || o.Auth == nil {
return nil, false
}
return o.Auth, true
}
// HasAuth returns a boolean if a field has been set.
func (o *OnboardingResponse) HasAuth() bool {
if o != nil && o.Auth != nil {
return true
}
return false
}
// SetAuth gets a reference to the given Authorization and assigns it to the Auth field.
func (o *OnboardingResponse) SetAuth(v Authorization) {
o.Auth = &v
}
func (o OnboardingResponse) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.User != nil {
toSerialize["user"] = o.User
}
if o.Org != nil {
toSerialize["org"] = o.Org
}
if o.Bucket != nil {
toSerialize["bucket"] = o.Bucket
}
if o.Auth != nil {
toSerialize["auth"] = o.Auth
}
return json.Marshal(toSerialize)
}
type NullableOnboardingResponse struct {
value *OnboardingResponse
isSet bool
}
func (v NullableOnboardingResponse) Get() *OnboardingResponse {
return v.value
}
func (v *NullableOnboardingResponse) Set(val *OnboardingResponse) {
v.value = val
v.isSet = true
}
func (v NullableOnboardingResponse) IsSet() bool {
return v.isSet
}
func (v *NullableOnboardingResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableOnboardingResponse(val *OnboardingResponse) *NullableOnboardingResponse {
return &NullableOnboardingResponse{value: val, isSet: true}
}
func (v NullableOnboardingResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableOnboardingResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,328 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
"time"
)
// Organization struct for Organization
type Organization struct {
Links *OrganizationLinks `json:"links,omitempty"`
Id *string `json:"id,omitempty"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
// If inactive the organization is inactive.
Status *string `json:"status,omitempty"`
}
// NewOrganization instantiates a new Organization object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewOrganization(name string) *Organization {
this := Organization{}
this.Name = name
var status string = "active"
this.Status = &status
return &this
}
// NewOrganizationWithDefaults instantiates a new Organization object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewOrganizationWithDefaults() *Organization {
this := Organization{}
var status string = "active"
this.Status = &status
return &this
}
// GetLinks returns the Links field value if set, zero value otherwise.
func (o *Organization) GetLinks() OrganizationLinks {
if o == nil || o.Links == nil {
var ret OrganizationLinks
return ret
}
return *o.Links
}
// GetLinksOk returns a tuple with the Links field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Organization) GetLinksOk() (*OrganizationLinks, bool) {
if o == nil || o.Links == nil {
return nil, false
}
return o.Links, true
}
// HasLinks returns a boolean if a field has been set.
func (o *Organization) HasLinks() bool {
if o != nil && o.Links != nil {
return true
}
return false
}
// SetLinks gets a reference to the given OrganizationLinks and assigns it to the Links field.
func (o *Organization) SetLinks(v OrganizationLinks) {
o.Links = &v
}
// GetId returns the Id field value if set, zero value otherwise.
func (o *Organization) GetId() string {
if o == nil || o.Id == nil {
var ret string
return ret
}
return *o.Id
}
// GetIdOk returns a tuple with the Id field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Organization) GetIdOk() (*string, bool) {
if o == nil || o.Id == nil {
return nil, false
}
return o.Id, true
}
// HasId returns a boolean if a field has been set.
func (o *Organization) HasId() bool {
if o != nil && o.Id != nil {
return true
}
return false
}
// SetId gets a reference to the given string and assigns it to the Id field.
func (o *Organization) SetId(v string) {
o.Id = &v
}
// GetName returns the Name field value
func (o *Organization) GetName() string {
if o == nil {
var ret string
return ret
}
return o.Name
}
// GetNameOk returns a tuple with the Name field value
// and a boolean to check if the value has been set.
func (o *Organization) GetNameOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Name, true
}
// SetName sets field value
func (o *Organization) SetName(v string) {
o.Name = v
}
// GetDescription returns the Description field value if set, zero value otherwise.
func (o *Organization) GetDescription() string {
if o == nil || o.Description == nil {
var ret string
return ret
}
return *o.Description
}
// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Organization) GetDescriptionOk() (*string, bool) {
if o == nil || o.Description == nil {
return nil, false
}
return o.Description, true
}
// HasDescription returns a boolean if a field has been set.
func (o *Organization) HasDescription() bool {
if o != nil && o.Description != nil {
return true
}
return false
}
// SetDescription gets a reference to the given string and assigns it to the Description field.
func (o *Organization) SetDescription(v string) {
o.Description = &v
}
// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise.
func (o *Organization) GetCreatedAt() time.Time {
if o == nil || o.CreatedAt == nil {
var ret time.Time
return ret
}
return *o.CreatedAt
}
// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Organization) GetCreatedAtOk() (*time.Time, bool) {
if o == nil || o.CreatedAt == nil {
return nil, false
}
return o.CreatedAt, true
}
// HasCreatedAt returns a boolean if a field has been set.
func (o *Organization) HasCreatedAt() bool {
if o != nil && o.CreatedAt != nil {
return true
}
return false
}
// SetCreatedAt gets a reference to the given time.Time and assigns it to the CreatedAt field.
func (o *Organization) SetCreatedAt(v time.Time) {
o.CreatedAt = &v
}
// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise.
func (o *Organization) GetUpdatedAt() time.Time {
if o == nil || o.UpdatedAt == nil {
var ret time.Time
return ret
}
return *o.UpdatedAt
}
// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Organization) GetUpdatedAtOk() (*time.Time, bool) {
if o == nil || o.UpdatedAt == nil {
return nil, false
}
return o.UpdatedAt, true
}
// HasUpdatedAt returns a boolean if a field has been set.
func (o *Organization) HasUpdatedAt() bool {
if o != nil && o.UpdatedAt != nil {
return true
}
return false
}
// SetUpdatedAt gets a reference to the given time.Time and assigns it to the UpdatedAt field.
func (o *Organization) SetUpdatedAt(v time.Time) {
o.UpdatedAt = &v
}
// GetStatus returns the Status field value if set, zero value otherwise.
func (o *Organization) GetStatus() string {
if o == nil || o.Status == nil {
var ret string
return ret
}
return *o.Status
}
// GetStatusOk returns a tuple with the Status field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Organization) GetStatusOk() (*string, bool) {
if o == nil || o.Status == nil {
return nil, false
}
return o.Status, true
}
// HasStatus returns a boolean if a field has been set.
func (o *Organization) HasStatus() bool {
if o != nil && o.Status != nil {
return true
}
return false
}
// SetStatus gets a reference to the given string and assigns it to the Status field.
func (o *Organization) SetStatus(v string) {
o.Status = &v
}
func (o Organization) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Links != nil {
toSerialize["links"] = o.Links
}
if o.Id != nil {
toSerialize["id"] = o.Id
}
if true {
toSerialize["name"] = o.Name
}
if o.Description != nil {
toSerialize["description"] = o.Description
}
if o.CreatedAt != nil {
toSerialize["createdAt"] = o.CreatedAt
}
if o.UpdatedAt != nil {
toSerialize["updatedAt"] = o.UpdatedAt
}
if o.Status != nil {
toSerialize["status"] = o.Status
}
return json.Marshal(toSerialize)
}
type NullableOrganization struct {
value *Organization
isSet bool
}
func (v NullableOrganization) Get() *Organization {
return v.value
}
func (v *NullableOrganization) Set(val *Organization) {
v.value = val
v.isSet = true
}
func (v NullableOrganization) IsSet() bool {
return v.isSet
}
func (v *NullableOrganization) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableOrganization(val *Organization) *NullableOrganization {
return &NullableOrganization{value: val, isSet: true}
}
func (v NullableOrganization) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableOrganization) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,373 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// OrganizationLinks struct for OrganizationLinks
type OrganizationLinks struct {
// URI of resource.
Self *string `json:"self,omitempty"`
// URI of resource.
Members *string `json:"members,omitempty"`
// URI of resource.
Owners *string `json:"owners,omitempty"`
// URI of resource.
Labels *string `json:"labels,omitempty"`
// URI of resource.
Secrets *string `json:"secrets,omitempty"`
// URI of resource.
Buckets *string `json:"buckets,omitempty"`
// URI of resource.
Tasks *string `json:"tasks,omitempty"`
// URI of resource.
Dashboards *string `json:"dashboards,omitempty"`
}
// NewOrganizationLinks instantiates a new OrganizationLinks object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewOrganizationLinks() *OrganizationLinks {
this := OrganizationLinks{}
return &this
}
// NewOrganizationLinksWithDefaults instantiates a new OrganizationLinks object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewOrganizationLinksWithDefaults() *OrganizationLinks {
this := OrganizationLinks{}
return &this
}
// GetSelf returns the Self field value if set, zero value otherwise.
func (o *OrganizationLinks) GetSelf() string {
if o == nil || o.Self == nil {
var ret string
return ret
}
return *o.Self
}
// GetSelfOk returns a tuple with the Self field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OrganizationLinks) GetSelfOk() (*string, bool) {
if o == nil || o.Self == nil {
return nil, false
}
return o.Self, true
}
// HasSelf returns a boolean if a field has been set.
func (o *OrganizationLinks) HasSelf() bool {
if o != nil && o.Self != nil {
return true
}
return false
}
// SetSelf gets a reference to the given string and assigns it to the Self field.
func (o *OrganizationLinks) SetSelf(v string) {
o.Self = &v
}
// GetMembers returns the Members field value if set, zero value otherwise.
func (o *OrganizationLinks) GetMembers() string {
if o == nil || o.Members == nil {
var ret string
return ret
}
return *o.Members
}
// GetMembersOk returns a tuple with the Members field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OrganizationLinks) GetMembersOk() (*string, bool) {
if o == nil || o.Members == nil {
return nil, false
}
return o.Members, true
}
// HasMembers returns a boolean if a field has been set.
func (o *OrganizationLinks) HasMembers() bool {
if o != nil && o.Members != nil {
return true
}
return false
}
// SetMembers gets a reference to the given string and assigns it to the Members field.
func (o *OrganizationLinks) SetMembers(v string) {
o.Members = &v
}
// GetOwners returns the Owners field value if set, zero value otherwise.
func (o *OrganizationLinks) GetOwners() string {
if o == nil || o.Owners == nil {
var ret string
return ret
}
return *o.Owners
}
// GetOwnersOk returns a tuple with the Owners field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OrganizationLinks) GetOwnersOk() (*string, bool) {
if o == nil || o.Owners == nil {
return nil, false
}
return o.Owners, true
}
// HasOwners returns a boolean if a field has been set.
func (o *OrganizationLinks) HasOwners() bool {
if o != nil && o.Owners != nil {
return true
}
return false
}
// SetOwners gets a reference to the given string and assigns it to the Owners field.
func (o *OrganizationLinks) SetOwners(v string) {
o.Owners = &v
}
// GetLabels returns the Labels field value if set, zero value otherwise.
func (o *OrganizationLinks) GetLabels() string {
if o == nil || o.Labels == nil {
var ret string
return ret
}
return *o.Labels
}
// GetLabelsOk returns a tuple with the Labels field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OrganizationLinks) GetLabelsOk() (*string, bool) {
if o == nil || o.Labels == nil {
return nil, false
}
return o.Labels, true
}
// HasLabels returns a boolean if a field has been set.
func (o *OrganizationLinks) HasLabels() bool {
if o != nil && o.Labels != nil {
return true
}
return false
}
// SetLabels gets a reference to the given string and assigns it to the Labels field.
func (o *OrganizationLinks) SetLabels(v string) {
o.Labels = &v
}
// GetSecrets returns the Secrets field value if set, zero value otherwise.
func (o *OrganizationLinks) GetSecrets() string {
if o == nil || o.Secrets == nil {
var ret string
return ret
}
return *o.Secrets
}
// GetSecretsOk returns a tuple with the Secrets field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OrganizationLinks) GetSecretsOk() (*string, bool) {
if o == nil || o.Secrets == nil {
return nil, false
}
return o.Secrets, true
}
// HasSecrets returns a boolean if a field has been set.
func (o *OrganizationLinks) HasSecrets() bool {
if o != nil && o.Secrets != nil {
return true
}
return false
}
// SetSecrets gets a reference to the given string and assigns it to the Secrets field.
func (o *OrganizationLinks) SetSecrets(v string) {
o.Secrets = &v
}
// GetBuckets returns the Buckets field value if set, zero value otherwise.
func (o *OrganizationLinks) GetBuckets() string {
if o == nil || o.Buckets == nil {
var ret string
return ret
}
return *o.Buckets
}
// GetBucketsOk returns a tuple with the Buckets field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OrganizationLinks) GetBucketsOk() (*string, bool) {
if o == nil || o.Buckets == nil {
return nil, false
}
return o.Buckets, true
}
// HasBuckets returns a boolean if a field has been set.
func (o *OrganizationLinks) HasBuckets() bool {
if o != nil && o.Buckets != nil {
return true
}
return false
}
// SetBuckets gets a reference to the given string and assigns it to the Buckets field.
func (o *OrganizationLinks) SetBuckets(v string) {
o.Buckets = &v
}
// GetTasks returns the Tasks field value if set, zero value otherwise.
func (o *OrganizationLinks) GetTasks() string {
if o == nil || o.Tasks == nil {
var ret string
return ret
}
return *o.Tasks
}
// GetTasksOk returns a tuple with the Tasks field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OrganizationLinks) GetTasksOk() (*string, bool) {
if o == nil || o.Tasks == nil {
return nil, false
}
return o.Tasks, true
}
// HasTasks returns a boolean if a field has been set.
func (o *OrganizationLinks) HasTasks() bool {
if o != nil && o.Tasks != nil {
return true
}
return false
}
// SetTasks gets a reference to the given string and assigns it to the Tasks field.
func (o *OrganizationLinks) SetTasks(v string) {
o.Tasks = &v
}
// GetDashboards returns the Dashboards field value if set, zero value otherwise.
func (o *OrganizationLinks) GetDashboards() string {
if o == nil || o.Dashboards == nil {
var ret string
return ret
}
return *o.Dashboards
}
// GetDashboardsOk returns a tuple with the Dashboards field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *OrganizationLinks) GetDashboardsOk() (*string, bool) {
if o == nil || o.Dashboards == nil {
return nil, false
}
return o.Dashboards, true
}
// HasDashboards returns a boolean if a field has been set.
func (o *OrganizationLinks) HasDashboards() bool {
if o != nil && o.Dashboards != nil {
return true
}
return false
}
// SetDashboards gets a reference to the given string and assigns it to the Dashboards field.
func (o *OrganizationLinks) SetDashboards(v string) {
o.Dashboards = &v
}
func (o OrganizationLinks) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Self != nil {
toSerialize["self"] = o.Self
}
if o.Members != nil {
toSerialize["members"] = o.Members
}
if o.Owners != nil {
toSerialize["owners"] = o.Owners
}
if o.Labels != nil {
toSerialize["labels"] = o.Labels
}
if o.Secrets != nil {
toSerialize["secrets"] = o.Secrets
}
if o.Buckets != nil {
toSerialize["buckets"] = o.Buckets
}
if o.Tasks != nil {
toSerialize["tasks"] = o.Tasks
}
if o.Dashboards != nil {
toSerialize["dashboards"] = o.Dashboards
}
return json.Marshal(toSerialize)
}
type NullableOrganizationLinks struct {
value *OrganizationLinks
isSet bool
}
func (v NullableOrganizationLinks) Get() *OrganizationLinks {
return v.value
}
func (v *NullableOrganizationLinks) Set(val *OrganizationLinks) {
v.value = val
v.isSet = true
}
func (v NullableOrganizationLinks) IsSet() bool {
return v.isSet
}
func (v *NullableOrganizationLinks) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableOrganizationLinks(val *OrganizationLinks) *NullableOrganizationLinks {
return &NullableOrganizationLinks{value: val, isSet: true}
}
func (v NullableOrganizationLinks) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableOrganizationLinks) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,135 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// Permission struct for Permission
type Permission struct {
Action string `json:"action"`
Resource PermissionResource `json:"resource"`
}
// NewPermission instantiates a new Permission object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewPermission(action string, resource PermissionResource) *Permission {
this := Permission{}
this.Action = action
this.Resource = resource
return &this
}
// NewPermissionWithDefaults instantiates a new Permission object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewPermissionWithDefaults() *Permission {
this := Permission{}
return &this
}
// GetAction returns the Action field value
func (o *Permission) GetAction() string {
if o == nil {
var ret string
return ret
}
return o.Action
}
// GetActionOk returns a tuple with the Action field value
// and a boolean to check if the value has been set.
func (o *Permission) GetActionOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Action, true
}
// SetAction sets field value
func (o *Permission) SetAction(v string) {
o.Action = v
}
// GetResource returns the Resource field value
func (o *Permission) GetResource() PermissionResource {
if o == nil {
var ret PermissionResource
return ret
}
return o.Resource
}
// GetResourceOk returns a tuple with the Resource field value
// and a boolean to check if the value has been set.
func (o *Permission) GetResourceOk() (*PermissionResource, bool) {
if o == nil {
return nil, false
}
return &o.Resource, true
}
// SetResource sets field value
func (o *Permission) SetResource(v PermissionResource) {
o.Resource = v
}
func (o Permission) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
toSerialize["action"] = o.Action
}
if true {
toSerialize["resource"] = o.Resource
}
return json.Marshal(toSerialize)
}
type NullablePermission struct {
value *Permission
isSet bool
}
func (v NullablePermission) Get() *Permission {
return v.value
}
func (v *NullablePermission) Set(val *Permission) {
v.value = val
v.isSet = true
}
func (v NullablePermission) IsSet() bool {
return v.isSet
}
func (v *NullablePermission) Unset() {
v.value = nil
v.isSet = false
}
func NewNullablePermission(val *Permission) *NullablePermission {
return &NullablePermission{value: val, isSet: true}
}
func (v NullablePermission) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullablePermission) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,298 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// PermissionResource struct for PermissionResource
type PermissionResource struct {
Type string `json:"type"`
// If ID is set that is a permission for a specific resource. if it is not set it is a permission for all resources of that resource type.
Id NullableString `json:"id,omitempty"`
// Optional name of the resource if the resource has a name field.
Name NullableString `json:"name,omitempty"`
// If orgID is set that is a permission for all resources owned my that org. if it is not set it is a permission for all resources of that resource type.
OrgID NullableString `json:"orgID,omitempty"`
// Optional name of the organization of the organization with orgID.
Org NullableString `json:"org,omitempty"`
}
// NewPermissionResource instantiates a new PermissionResource object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewPermissionResource(type_ string) *PermissionResource {
this := PermissionResource{}
this.Type = type_
return &this
}
// NewPermissionResourceWithDefaults instantiates a new PermissionResource object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewPermissionResourceWithDefaults() *PermissionResource {
this := PermissionResource{}
return &this
}
// GetType returns the Type field value
func (o *PermissionResource) GetType() string {
if o == nil {
var ret string
return ret
}
return o.Type
}
// GetTypeOk returns a tuple with the Type field value
// and a boolean to check if the value has been set.
func (o *PermissionResource) GetTypeOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Type, true
}
// SetType sets field value
func (o *PermissionResource) SetType(v string) {
o.Type = v
}
// GetId returns the Id field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *PermissionResource) GetId() string {
if o == nil || o.Id.Get() == nil {
var ret string
return ret
}
return *o.Id.Get()
}
// GetIdOk returns a tuple with the Id field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *PermissionResource) GetIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Id.Get(), o.Id.IsSet()
}
// HasId returns a boolean if a field has been set.
func (o *PermissionResource) HasId() bool {
if o != nil && o.Id.IsSet() {
return true
}
return false
}
// SetId gets a reference to the given NullableString and assigns it to the Id field.
func (o *PermissionResource) SetId(v string) {
o.Id.Set(&v)
}
// SetIdNil sets the value for Id to be an explicit nil
func (o *PermissionResource) SetIdNil() {
o.Id.Set(nil)
}
// UnsetId ensures that no value is present for Id, not even an explicit nil
func (o *PermissionResource) UnsetId() {
o.Id.Unset()
}
// GetName returns the Name field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *PermissionResource) GetName() string {
if o == nil || o.Name.Get() == nil {
var ret string
return ret
}
return *o.Name.Get()
}
// GetNameOk returns a tuple with the Name field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *PermissionResource) GetNameOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Name.Get(), o.Name.IsSet()
}
// HasName returns a boolean if a field has been set.
func (o *PermissionResource) HasName() bool {
if o != nil && o.Name.IsSet() {
return true
}
return false
}
// SetName gets a reference to the given NullableString and assigns it to the Name field.
func (o *PermissionResource) SetName(v string) {
o.Name.Set(&v)
}
// SetNameNil sets the value for Name to be an explicit nil
func (o *PermissionResource) SetNameNil() {
o.Name.Set(nil)
}
// UnsetName ensures that no value is present for Name, not even an explicit nil
func (o *PermissionResource) UnsetName() {
o.Name.Unset()
}
// GetOrgID returns the OrgID field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *PermissionResource) GetOrgID() string {
if o == nil || o.OrgID.Get() == nil {
var ret string
return ret
}
return *o.OrgID.Get()
}
// GetOrgIDOk returns a tuple with the OrgID field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *PermissionResource) GetOrgIDOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.OrgID.Get(), o.OrgID.IsSet()
}
// HasOrgID returns a boolean if a field has been set.
func (o *PermissionResource) HasOrgID() bool {
if o != nil && o.OrgID.IsSet() {
return true
}
return false
}
// SetOrgID gets a reference to the given NullableString and assigns it to the OrgID field.
func (o *PermissionResource) SetOrgID(v string) {
o.OrgID.Set(&v)
}
// SetOrgIDNil sets the value for OrgID to be an explicit nil
func (o *PermissionResource) SetOrgIDNil() {
o.OrgID.Set(nil)
}
// UnsetOrgID ensures that no value is present for OrgID, not even an explicit nil
func (o *PermissionResource) UnsetOrgID() {
o.OrgID.Unset()
}
// GetOrg returns the Org field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *PermissionResource) GetOrg() string {
if o == nil || o.Org.Get() == nil {
var ret string
return ret
}
return *o.Org.Get()
}
// GetOrgOk returns a tuple with the Org field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *PermissionResource) GetOrgOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Org.Get(), o.Org.IsSet()
}
// HasOrg returns a boolean if a field has been set.
func (o *PermissionResource) HasOrg() bool {
if o != nil && o.Org.IsSet() {
return true
}
return false
}
// SetOrg gets a reference to the given NullableString and assigns it to the Org field.
func (o *PermissionResource) SetOrg(v string) {
o.Org.Set(&v)
}
// SetOrgNil sets the value for Org to be an explicit nil
func (o *PermissionResource) SetOrgNil() {
o.Org.Set(nil)
}
// UnsetOrg ensures that no value is present for Org, not even an explicit nil
func (o *PermissionResource) UnsetOrg() {
o.Org.Unset()
}
func (o PermissionResource) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
toSerialize["type"] = o.Type
}
if o.Id.IsSet() {
toSerialize["id"] = o.Id.Get()
}
if o.Name.IsSet() {
toSerialize["name"] = o.Name.Get()
}
if o.OrgID.IsSet() {
toSerialize["orgID"] = o.OrgID.Get()
}
if o.Org.IsSet() {
toSerialize["org"] = o.Org.Get()
}
return json.Marshal(toSerialize)
}
type NullablePermissionResource struct {
value *PermissionResource
isSet bool
}
func (v NullablePermissionResource) Get() *PermissionResource {
return v.value
}
func (v *NullablePermissionResource) Set(val *PermissionResource) {
v.value = val
v.isSet = true
}
func (v NullablePermissionResource) IsSet() bool {
return v.isSet
}
func (v *NullablePermissionResource) Unset() {
v.value = nil
v.isSet = false
}
func NewNullablePermissionResource(val *PermissionResource) *NullablePermissionResource {
return &NullablePermissionResource{value: val, isSet: true}
}
func (v NullablePermissionResource) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullablePermissionResource) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,175 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// RetentionRule struct for RetentionRule
type RetentionRule struct {
Type string `json:"type"`
// Duration in seconds for how long data will be kept in the database. 0 means infinite.
EverySeconds int64 `json:"everySeconds"`
// Shard duration measured in seconds.
ShardGroupDurationSeconds *int64 `json:"shardGroupDurationSeconds,omitempty"`
}
// NewRetentionRule instantiates a new RetentionRule object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewRetentionRule(type_ string, everySeconds int64) *RetentionRule {
this := RetentionRule{}
this.Type = type_
this.EverySeconds = everySeconds
return &this
}
// NewRetentionRuleWithDefaults instantiates a new RetentionRule object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewRetentionRuleWithDefaults() *RetentionRule {
this := RetentionRule{}
var type_ string = "expire"
this.Type = type_
return &this
}
// GetType returns the Type field value
func (o *RetentionRule) GetType() string {
if o == nil {
var ret string
return ret
}
return o.Type
}
// GetTypeOk returns a tuple with the Type field value
// and a boolean to check if the value has been set.
func (o *RetentionRule) GetTypeOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Type, true
}
// SetType sets field value
func (o *RetentionRule) SetType(v string) {
o.Type = v
}
// GetEverySeconds returns the EverySeconds field value
func (o *RetentionRule) GetEverySeconds() int64 {
if o == nil {
var ret int64
return ret
}
return o.EverySeconds
}
// GetEverySecondsOk returns a tuple with the EverySeconds field value
// and a boolean to check if the value has been set.
func (o *RetentionRule) GetEverySecondsOk() (*int64, bool) {
if o == nil {
return nil, false
}
return &o.EverySeconds, true
}
// SetEverySeconds sets field value
func (o *RetentionRule) SetEverySeconds(v int64) {
o.EverySeconds = v
}
// GetShardGroupDurationSeconds returns the ShardGroupDurationSeconds field value if set, zero value otherwise.
func (o *RetentionRule) GetShardGroupDurationSeconds() int64 {
if o == nil || o.ShardGroupDurationSeconds == nil {
var ret int64
return ret
}
return *o.ShardGroupDurationSeconds
}
// GetShardGroupDurationSecondsOk returns a tuple with the ShardGroupDurationSeconds field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RetentionRule) GetShardGroupDurationSecondsOk() (*int64, bool) {
if o == nil || o.ShardGroupDurationSeconds == nil {
return nil, false
}
return o.ShardGroupDurationSeconds, true
}
// HasShardGroupDurationSeconds returns a boolean if a field has been set.
func (o *RetentionRule) HasShardGroupDurationSeconds() bool {
if o != nil && o.ShardGroupDurationSeconds != nil {
return true
}
return false
}
// SetShardGroupDurationSeconds gets a reference to the given int64 and assigns it to the ShardGroupDurationSeconds field.
func (o *RetentionRule) SetShardGroupDurationSeconds(v int64) {
o.ShardGroupDurationSeconds = &v
}
func (o RetentionRule) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
toSerialize["type"] = o.Type
}
if true {
toSerialize["everySeconds"] = o.EverySeconds
}
if o.ShardGroupDurationSeconds != nil {
toSerialize["shardGroupDurationSeconds"] = o.ShardGroupDurationSeconds
}
return json.Marshal(toSerialize)
}
type NullableRetentionRule struct {
value *RetentionRule
isSet bool
}
func (v NullableRetentionRule) Get() *RetentionRule {
return v.value
}
func (v *NullableRetentionRule) Set(val *RetentionRule) {
v.value = val
v.isSet = true
}
func (v NullableRetentionRule) IsSet() bool {
return v.isSet
}
func (v *NullableRetentionRule) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableRetentionRule(val *RetentionRule) *NullableRetentionRule {
return &NullableRetentionRule{value: val, isSet: true}
}
func (v NullableRetentionRule) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableRetentionRule) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,255 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// UserResponse struct for UserResponse
type UserResponse struct {
Id *string `json:"id,omitempty"`
OauthID *string `json:"oauthID,omitempty"`
Name string `json:"name"`
// If inactive the user is inactive.
Status *string `json:"status,omitempty"`
Links *UserResponseLinks `json:"links,omitempty"`
}
// NewUserResponse instantiates a new UserResponse object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewUserResponse(name string) *UserResponse {
this := UserResponse{}
this.Name = name
var status string = "active"
this.Status = &status
return &this
}
// NewUserResponseWithDefaults instantiates a new UserResponse object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewUserResponseWithDefaults() *UserResponse {
this := UserResponse{}
var status string = "active"
this.Status = &status
return &this
}
// GetId returns the Id field value if set, zero value otherwise.
func (o *UserResponse) GetId() string {
if o == nil || o.Id == nil {
var ret string
return ret
}
return *o.Id
}
// GetIdOk returns a tuple with the Id field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *UserResponse) GetIdOk() (*string, bool) {
if o == nil || o.Id == nil {
return nil, false
}
return o.Id, true
}
// HasId returns a boolean if a field has been set.
func (o *UserResponse) HasId() bool {
if o != nil && o.Id != nil {
return true
}
return false
}
// SetId gets a reference to the given string and assigns it to the Id field.
func (o *UserResponse) SetId(v string) {
o.Id = &v
}
// GetOauthID returns the OauthID field value if set, zero value otherwise.
func (o *UserResponse) GetOauthID() string {
if o == nil || o.OauthID == nil {
var ret string
return ret
}
return *o.OauthID
}
// GetOauthIDOk returns a tuple with the OauthID field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *UserResponse) GetOauthIDOk() (*string, bool) {
if o == nil || o.OauthID == nil {
return nil, false
}
return o.OauthID, true
}
// HasOauthID returns a boolean if a field has been set.
func (o *UserResponse) HasOauthID() bool {
if o != nil && o.OauthID != nil {
return true
}
return false
}
// SetOauthID gets a reference to the given string and assigns it to the OauthID field.
func (o *UserResponse) SetOauthID(v string) {
o.OauthID = &v
}
// GetName returns the Name field value
func (o *UserResponse) GetName() string {
if o == nil {
var ret string
return ret
}
return o.Name
}
// GetNameOk returns a tuple with the Name field value
// and a boolean to check if the value has been set.
func (o *UserResponse) GetNameOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Name, true
}
// SetName sets field value
func (o *UserResponse) SetName(v string) {
o.Name = v
}
// GetStatus returns the Status field value if set, zero value otherwise.
func (o *UserResponse) GetStatus() string {
if o == nil || o.Status == nil {
var ret string
return ret
}
return *o.Status
}
// GetStatusOk returns a tuple with the Status field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *UserResponse) GetStatusOk() (*string, bool) {
if o == nil || o.Status == nil {
return nil, false
}
return o.Status, true
}
// HasStatus returns a boolean if a field has been set.
func (o *UserResponse) HasStatus() bool {
if o != nil && o.Status != nil {
return true
}
return false
}
// SetStatus gets a reference to the given string and assigns it to the Status field.
func (o *UserResponse) SetStatus(v string) {
o.Status = &v
}
// GetLinks returns the Links field value if set, zero value otherwise.
func (o *UserResponse) GetLinks() UserResponseLinks {
if o == nil || o.Links == nil {
var ret UserResponseLinks
return ret
}
return *o.Links
}
// GetLinksOk returns a tuple with the Links field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *UserResponse) GetLinksOk() (*UserResponseLinks, bool) {
if o == nil || o.Links == nil {
return nil, false
}
return o.Links, true
}
// HasLinks returns a boolean if a field has been set.
func (o *UserResponse) HasLinks() bool {
if o != nil && o.Links != nil {
return true
}
return false
}
// SetLinks gets a reference to the given UserResponseLinks and assigns it to the Links field.
func (o *UserResponse) SetLinks(v UserResponseLinks) {
o.Links = &v
}
func (o UserResponse) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Id != nil {
toSerialize["id"] = o.Id
}
if o.OauthID != nil {
toSerialize["oauthID"] = o.OauthID
}
if true {
toSerialize["name"] = o.Name
}
if o.Status != nil {
toSerialize["status"] = o.Status
}
if o.Links != nil {
toSerialize["links"] = o.Links
}
return json.Marshal(toSerialize)
}
type NullableUserResponse struct {
value *UserResponse
isSet bool
}
func (v NullableUserResponse) Get() *UserResponse {
return v.value
}
func (v *NullableUserResponse) Set(val *UserResponse) {
v.value = val
v.isSet = true
}
func (v NullableUserResponse) IsSet() bool {
return v.isSet
}
func (v *NullableUserResponse) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableUserResponse(val *UserResponse) *NullableUserResponse {
return &NullableUserResponse{value: val, isSet: true}
}
func (v NullableUserResponse) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableUserResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,113 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// UserResponseLinks struct for UserResponseLinks
type UserResponseLinks struct {
Self *string `json:"self,omitempty"`
}
// NewUserResponseLinks instantiates a new UserResponseLinks object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewUserResponseLinks() *UserResponseLinks {
this := UserResponseLinks{}
return &this
}
// NewUserResponseLinksWithDefaults instantiates a new UserResponseLinks object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewUserResponseLinksWithDefaults() *UserResponseLinks {
this := UserResponseLinks{}
return &this
}
// GetSelf returns the Self field value if set, zero value otherwise.
func (o *UserResponseLinks) GetSelf() string {
if o == nil || o.Self == nil {
var ret string
return ret
}
return *o.Self
}
// GetSelfOk returns a tuple with the Self field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *UserResponseLinks) GetSelfOk() (*string, bool) {
if o == nil || o.Self == nil {
return nil, false
}
return o.Self, true
}
// HasSelf returns a boolean if a field has been set.
func (o *UserResponseLinks) HasSelf() bool {
if o != nil && o.Self != nil {
return true
}
return false
}
// SetSelf gets a reference to the given string and assigns it to the Self field.
func (o *UserResponseLinks) SetSelf(v string) {
o.Self = &v
}
func (o UserResponseLinks) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Self != nil {
toSerialize["self"] = o.Self
}
return json.Marshal(toSerialize)
}
type NullableUserResponseLinks struct {
value *UserResponseLinks
isSet bool
}
func (v NullableUserResponseLinks) Get() *UserResponseLinks {
return v.value
}
func (v *NullableUserResponseLinks) Set(val *UserResponseLinks) {
v.value = val
v.isSet = true
}
func (v NullableUserResponseLinks) IsSet() bool {
return v.isSet
}
func (v *NullableUserResponseLinks) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableUserResponseLinks(val *UserResponseLinks) *NullableUserResponseLinks {
return &NullableUserResponseLinks{value: val, isSet: true}
}
func (v NullableUserResponseLinks) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableUserResponseLinks) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -1,13 +1,41 @@
package internal
import (
"io"
"encoding/json"
"github.com/influxdata/influx-cli/v2/internal/config"
"github.com/influxdata/influx-cli/v2/internal/stdio"
"github.com/influxdata/influx-cli/v2/internal/tabwriter"
)
// CLI is a container for common functionality used to execute commands.
type CLI struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
StdIO stdio.StdIO
TraceId string
TraceId string
HideTableHeaders bool
PrintAsJSON bool
ActiveConfig config.Config
ConfigService config.Service
}
func (c *CLI) PrintJSON(v interface{}) error {
enc := json.NewEncoder(c.StdIO)
enc.SetIndent("", "\t")
return enc.Encode(v)
}
func (c *CLI) PrintTable(headers []string, rows ...map[string]interface{}) error {
w := tabwriter.NewTabWriter(c.StdIO, c.HideTableHeaders)
defer w.Flush()
if err := w.WriteHeaders(headers...); err != nil {
return err
}
for _, r := range rows {
if err := w.Write(r); err != nil {
return err
}
}
return nil
}

View File

@ -54,55 +54,15 @@ type Service interface {
DeleteConfig(name string) (Config, error)
UpdateConfig(Config) (Config, error)
SwitchActive(name string) (Config, error)
Active() (Config, error)
ListConfigs() (Configs, error)
}
// Configs is map of configs indexed by name.
type Configs map[string]Config
func GetConfigsOrDefault(path string) Configs {
r, err := os.Open(path)
if err != nil {
return Configs{
DefaultConfig.Name: DefaultConfig,
}
}
defer r.Close()
cfgs, err := NewLocalConfigService(path).ListConfigs()
if err != nil {
return Configs{
DefaultConfig.Name: DefaultConfig,
}
}
return cfgs
}
var badNames = map[string]bool{
"-": false,
"list": false,
"update": false,
"set": false,
"delete": false,
"switch": false,
"create": false,
}
func blockBadName(cfgs Configs) error {
for n := range cfgs {
if _, ok := badNames[n]; ok {
return &api.Error{
Code: api.ERRORCODE_INVALID,
Message: fmt.Sprintf("%q is not a valid config name", n),
}
}
}
return nil
}
// Switch to another config.
func (cfgs Configs) Switch(name string) error {
func (cfgs Configs) switchActive(name string) error {
if _, ok := cfgs[name]; !ok {
return &api.Error{
Code: api.ERRORCODE_NOT_FOUND,
@ -117,7 +77,7 @@ func (cfgs Configs) Switch(name string) error {
return nil
}
func (cfgs Configs) Active() Config {
func (cfgs Configs) active() Config {
for _, cfg := range cfgs {
if cfg.Active {
return cfg

View File

@ -51,7 +51,7 @@ func (svc localConfigsSVC) CreateConfig(cfg Config) (Config, error) {
}
cfgs[cfg.Name] = cfg
if cfg.Active {
if err := cfgs.Switch(cfg.Name); err != nil {
if err := cfgs.switchActive(cfg.Name); err != nil {
return Config{}, err
}
}
@ -86,6 +86,14 @@ func (svc localConfigsSVC) DeleteConfig(name string) (Config, error) {
return p, svc.writeConfigs(cfgs)
}
func (svc localConfigsSVC) Active() (Config, error) {
cfgs, err := svc.ListConfigs()
if err != nil {
return Config{}, err
}
return cfgs.active(), nil
}
// SwitchActive will active the config by name, if name is "-", active the previous one.
func (svc localConfigsSVC) SwitchActive(name string) (Config, error) {
var up Config
@ -127,7 +135,7 @@ func (svc localConfigsSVC) UpdateConfig(up Config) (Config, error) {
cfgs[up.Name] = p0
if up.Active {
if err := cfgs.Switch(up.Name); err != nil {
if err := cfgs.switchActive(up.Name); err != nil {
return Config{}, err
}
}
@ -192,6 +200,28 @@ func (s baseRW) writeConfigs(cfgs Configs) error {
return nil
}
var badNames = map[string]bool{
"-": false,
"list": false,
"update": false,
"set": false,
"delete": false,
"switch": false,
"create": false,
}
func blockBadName(cfgs Configs) error {
for n := range cfgs {
if _, ok := badNames[n]; ok {
return &api.Error{
Code: api.ERRORCODE_INVALID,
Message: fmt.Sprintf("%q is not a valid config name", n),
}
}
}
return nil
}
func (s baseRW) parseActiveConfig(currentOrPrevious bool) (Config, error) {
previousText := ""
if !currentOrPrevious {

150
internal/duration/parser.go Normal file
View File

@ -0,0 +1,150 @@
package duration
import (
"errors"
"fmt"
"strconv"
"time"
"unicode"
"unicode/utf8"
)
const (
Day = 24 * time.Hour
Week = 7 * Day
)
type durations []duration
type duration struct {
magnitude int64
unit string
}
var (
ErrInvalidUnit = errors.New("duration must be week(w), day(d), hour(h), min(m), sec(s), millisec(ms), microsec(us), or nanosec(ns)")
ErrInvalidRune = errors.New("invalid rune in declaration")
)
// RawDurationToTimeDuration extends the builtin duration-parser to support days(d) and weeks(w) as parseable units.
// The core implementation is copied from InfluxDB OSS's task engine, which itself copied the logic from an
// internal module in Flux.
func RawDurationToTimeDuration(raw string) (time.Duration, error) {
if raw == "" {
return 0, nil
}
if dur, err := time.ParseDuration(raw); err == nil {
return dur, nil
}
parsed, err := parseSignedDuration(raw)
if err != nil {
return 0, err
}
var dur time.Duration
for _, d := range parsed {
if d.magnitude < 0 {
return 0, errors.New("must be greater than 0")
}
mag := time.Duration(d.magnitude)
switch d.unit {
case "w":
dur += mag * Week
case "d":
dur += mag * Day
case "h":
dur += mag * time.Hour
case "m":
dur += mag * time.Minute
case "s":
dur += mag * time.Second
case "ms":
dur += mag * time.Millisecond
case "us":
dur += mag * time.Microsecond
case "ns":
dur += mag * time.Nanosecond
default:
return 0, ErrInvalidUnit
}
}
return dur, nil
}
func parseSignedDuration(text string) (durations, error) {
if r, s := utf8.DecodeRuneInString(text); r == '-' {
d, err := parseDuration(text[s:])
if err != nil {
return nil, err
}
for i := range d {
d[i].magnitude = -d[i].magnitude
}
return d, nil
}
d, err := parseDuration(text)
if err != nil {
return nil, err
}
return d, nil
}
// parseDuration will convert a string into components of the duration.
func parseDuration(lit string) (durations, error) {
var values durations
for len(lit) > 0 {
n := 0
for n < len(lit) {
ch, size := utf8.DecodeRuneInString(lit[n:])
if size == 0 {
return nil, ErrInvalidRune
}
if !unicode.IsDigit(ch) {
break
}
n += size
}
if n == 0 {
return nil, fmt.Errorf("invalid duration %s", lit)
}
magnitude, err := strconv.ParseInt(lit[:n], 10, 64)
if err != nil {
return nil, err
}
lit = lit[n:]
n = 0
for n < len(lit) {
ch, size := utf8.DecodeRuneInString(lit[n:])
if size == 0 {
return nil, ErrInvalidRune
}
if !unicode.IsLetter(ch) {
break
}
n += size
}
if n == 0 {
return nil, fmt.Errorf("duration is missing a unit: %s", lit)
}
unit := lit[:n]
if unit == "µs" {
unit = "us"
}
values = append(values, duration{
magnitude: magnitude,
unit: unit,
})
lit = lit[n:]
}
return values, nil
}

View File

@ -0,0 +1,91 @@
package duration_test
import (
"testing"
"time"
"github.com/influxdata/influx-cli/v2/internal/duration"
"github.com/stretchr/testify/require"
)
func Test_RawDurationToTimeDuration(t *testing.T) {
testCases := []struct {
name string
input string
expected time.Duration
expectErr bool
}{
{
name: "nanos",
input: "10ns",
expected: 10,
},
{
name: "micros",
input: "12345us",
expected: 12345 * time.Microsecond,
},
{
name: "millis",
input: "9876ms",
expected: 9876 * time.Millisecond,
},
{
name: "seconds",
input: "300s",
expected: 300 * time.Second,
},
{
name: "minutes",
input: "654m",
expected: 654 * time.Minute,
},
{
name: "hours",
input: "127h",
expected: 127 * time.Hour,
},
{
name: "days",
input: "29d",
expected: 29 * duration.Day,
},
{
name: "weeks",
input: "396w",
expected: 396 * duration.Week,
},
{
name: "weeks+hours+seconds+micros",
input: "1w2h3s4us",
expected: duration.Week + 2*time.Hour + 3*time.Second + 4*time.Microsecond,
},
{
name: "days+minutes+millis+nanos",
input: "9d8m7ms6ns",
expected: 9*duration.Day + 8*time.Minute + 7*time.Millisecond + 6,
},
{
name: "negative",
input: "-1d",
expectErr: true,
},
{
name: "missing unit",
input: "123",
expectErr: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
parsed, err := duration.RawDurationToTimeDuration(tc.input)
if tc.expectErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, tc.expected, parsed)
})
}
}

55
internal/mock/stdio.go Normal file
View File

@ -0,0 +1,55 @@
package mock
import (
"bytes"
"errors"
)
type Stdio struct {
answers map[string]string
confirm bool
out bytes.Buffer
}
func NewMockStdio(promptAnswers map[string]string, confirm bool) *Stdio {
return &Stdio{answers: promptAnswers, confirm: confirm, out: bytes.Buffer{}}
}
func (m *Stdio) Write(p []byte) (int, error) {
return m.out.Write(p)
}
func (m *Stdio) Banner(string) error {
return nil
}
func (m *Stdio) Error(string) error {
return nil
}
func (m *Stdio) GetStringInput(prompt, defaultValue string) (string, error) {
v, ok := m.answers[prompt]
if !ok {
return defaultValue, nil
}
return v, nil
}
func (m *Stdio) GetPassword(prompt string, minLen int) (string, error) {
v, ok := m.answers[prompt]
if !ok {
return "", errors.New("no password given")
}
if len(v) < minLen {
return "", errors.New("password too short")
}
return v, nil
}
func (m *Stdio) GetConfirm(string) bool {
return m.confirm
}
func (m *Stdio) Stdout() string {
return m.out.String()
}

View File

@ -28,6 +28,6 @@ func (c *CLI) Ping(ctx context.Context, client api.HealthApi) error {
return fmt.Errorf("health check failed: %s", message)
}
c.Stdout.Write([]byte("OK\n"))
return nil
_, err = c.StdIO.Write([]byte("OK\n"))
return err
}

View File

@ -1,7 +1,6 @@
package internal_test
import (
"bytes"
"context"
"errors"
"net/http"
@ -9,45 +8,46 @@ import (
"github.com/influxdata/influx-cli/v2/internal"
"github.com/influxdata/influx-cli/v2/internal/api"
"github.com/influxdata/influx-cli/v2/internal/mock"
"github.com/stretchr/testify/require"
)
type testClient struct {
type pingTestClient struct {
GetHealthExecuteFn func(api.ApiGetHealthRequest) (api.HealthCheck, *http.Response, error)
}
func (tc *testClient) GetHealth(context.Context) api.ApiGetHealthRequest {
func (tc *pingTestClient) GetHealth(context.Context) api.ApiGetHealthRequest {
return api.ApiGetHealthRequest{
ApiService: tc,
}
}
func (tc *testClient) GetHealthExecute(req api.ApiGetHealthRequest) (api.HealthCheck, *http.Response, error) {
func (tc *pingTestClient) GetHealthExecute(req api.ApiGetHealthRequest) (api.HealthCheck, *http.Response, error) {
return tc.GetHealthExecuteFn(req)
}
func Test_PingSuccess(t *testing.T) {
t.Parallel()
client := &testClient{
client := &pingTestClient{
GetHealthExecuteFn: func(req api.ApiGetHealthRequest) (api.HealthCheck, *http.Response, error) {
require.Nil(t, req.GetZapTraceSpan())
return api.HealthCheck{Status: api.HEALTHCHECKSTATUS_PASS}, nil, nil
},
}
out := &bytes.Buffer{}
cli := &internal.CLI{Stdout: out}
stdio := mock.NewMockStdio(nil, true)
cli := &internal.CLI{StdIO: stdio}
require.NoError(t, cli.Ping(context.Background(), client))
require.Equal(t, "OK\n", out.String())
require.Equal(t, "OK\n", stdio.Stdout())
}
func Test_PingSuccessWithTracing(t *testing.T) {
t.Parallel()
traceId := "trace-id"
client := &testClient{
client := &pingTestClient{
GetHealthExecuteFn: func(req api.ApiGetHealthRequest) (api.HealthCheck, *http.Response, error) {
require.NotNil(t, req.GetZapTraceSpan())
require.Equal(t, traceId, *req.GetZapTraceSpan())
@ -55,66 +55,57 @@ func Test_PingSuccessWithTracing(t *testing.T) {
},
}
out := &bytes.Buffer{}
cli := &internal.CLI{Stdout: out, TraceId: traceId}
stdio := mock.NewMockStdio(nil, true)
cli := &internal.CLI{TraceId: traceId, StdIO: stdio}
require.NoError(t, cli.Ping(context.Background(), client))
require.Equal(t, "OK\n", out.String())
require.Equal(t, "OK\n", stdio.Stdout())
}
func Test_PingFailedRequest(t *testing.T) {
t.Parallel()
e := "the internet is down"
client := &testClient{
client := &pingTestClient{
GetHealthExecuteFn: func(api.ApiGetHealthRequest) (api.HealthCheck, *http.Response, error) {
return api.HealthCheck{}, nil, errors.New(e)
},
}
out := &bytes.Buffer{}
cli := &internal.CLI{Stdout: out}
cli := &internal.CLI{}
err := cli.Ping(context.Background(), client)
require.Error(t, err)
require.Contains(t, err.Error(), e)
require.Empty(t, out.String())
}
func Test_PingFailedStatus(t *testing.T) {
t.Parallel()
e := "I broke"
client := &testClient{
client := &pingTestClient{
GetHealthExecuteFn: func(api.ApiGetHealthRequest) (api.HealthCheck, *http.Response, error) {
return api.HealthCheck{Status: api.HEALTHCHECKSTATUS_FAIL, Message: &e}, nil, nil
},
}
out := &bytes.Buffer{}
cli := &internal.CLI{Stdout: out}
cli := &internal.CLI{}
err := cli.Ping(context.Background(), client)
require.Error(t, err)
require.Contains(t, err.Error(), e)
require.Empty(t, out.String())
}
func Test_PingFailedStatusNoMessage(t *testing.T) {
t.Parallel()
name := "foo"
client := &testClient{
client := &pingTestClient{
GetHealthExecuteFn: func(api.ApiGetHealthRequest) (api.HealthCheck, *http.Response, error) {
return api.HealthCheck{Status: api.HEALTHCHECKSTATUS_FAIL, Name: name}, nil, nil
},
}
out := &bytes.Buffer{}
cli := &internal.CLI{Stdout: out}
cli := &internal.CLI{}
err := cli.Ping(context.Background(), client)
require.Error(t, err)
require.Contains(t, err.Error(), name)
require.Empty(t, out.String())
}

242
internal/setup.go Normal file
View File

@ -0,0 +1,242 @@
package internal
import (
"context"
"errors"
"fmt"
"math"
"strconv"
"time"
"github.com/influxdata/influx-cli/v2/internal/api"
"github.com/influxdata/influx-cli/v2/internal/config"
"github.com/influxdata/influx-cli/v2/internal/duration"
)
type SetupParams struct {
Username string
Password string
AuthToken string
Org string
Bucket string
Retention string
Force bool
ConfigName string
}
var (
ErrPasswordIsTooShort = errors.New("password is too short")
ErrAlreadySetUp = errors.New("instance has already been set up")
ErrConfigNameRequired = errors.New("config name is required if you already have existing configs")
ErrSetupCanceled = errors.New("setup was canceled")
)
const (
InfiniteRetention = 0
MinPasswordLen = 8
)
func (c *CLI) Setup(ctx context.Context, client api.SetupApi, params *SetupParams) error {
// Ensure we'll be able to write onboarding results to local config.
// Do this first so we catch any problems before modifying state on the server side.
if err := c.validateNoNameCollision(params.ConfigName); err != nil {
return err
}
// Check if setup is even allowed.
checkReq := client.GetSetup(ctx)
if c.TraceId != "" {
checkReq = checkReq.ZapTraceSpan(c.TraceId)
}
checkResp, _, err := client.GetSetupExecute(checkReq)
if err != nil {
return fmt.Errorf("failed to check if already set up: %w", err)
}
if checkResp.Allowed == nil || !*checkResp.Allowed {
return ErrAlreadySetUp
}
// Initialize the server.
setupBody, err := c.onboardingRequest(params)
if err != nil {
return err
}
setupReq := client.PostSetup(ctx).OnboardingRequest(setupBody)
if c.TraceId != "" {
setupReq = setupReq.ZapTraceSpan(c.TraceId)
}
resp, _, err := client.PostSetupExecute(setupReq)
if err != nil {
return fmt.Errorf("failed to setup instance: %w", err)
}
cfg := config.Config{
Name: config.DefaultConfig.Name,
Host: c.ActiveConfig.Host,
Token: *resp.Auth.Token,
Org: resp.Org.Name,
}
if params.ConfigName != "" {
cfg.Name = params.ConfigName
}
if _, err := c.ConfigService.CreateConfig(cfg); err != nil {
return fmt.Errorf("setup succeeded, but failed to write new config to local path: %w", err)
}
if c.PrintAsJSON {
return c.PrintJSON(map[string]interface{}{
"user": resp.User.Name,
"organization": resp.Org.Name,
"bucket": resp.Bucket.Name,
})
}
return c.PrintTable([]string{"User", "Organization", "Bucket"}, map[string]interface{}{
"User": resp.User.Name,
"Organization": resp.Org.Name,
"Bucket": resp.Bucket.Name,
})
}
// validateNoNameCollision checks that we will be able to write onboarding results to local config:
// - If a custom name was given, check that it doesn't collide with existing config
// - If no custom name was given, check that we don't already have configs
func (c *CLI) validateNoNameCollision(configName string) error {
existingConfigs, err := c.ConfigService.ListConfigs()
if err != nil {
return fmt.Errorf("error checking existing configs: %w", err)
}
if len(existingConfigs) == 0 {
return nil
}
// If there are existing configs then require that a name be
// specified in order to distinguish this new config from what's
// there already.
if configName == "" {
return ErrConfigNameRequired
}
if _, ok := existingConfigs[configName]; ok {
return fmt.Errorf("config name %q already exists", configName)
}
return nil
}
// onboardingRequest constructs a request body for the onboarding API.
// Unless the 'force' parameter is set, the user will be prompted to enter any missing information
// and to confirm the final request parameters.
func (c *CLI) onboardingRequest(params *SetupParams) (req api.OnboardingRequest, err error) {
if (params.Force || params.Password != "") && len(params.Password) < MinPasswordLen {
return req, ErrPasswordIsTooShort
}
// Populate the request with CLI args.
req.Username = params.Username
req.Org = params.Org
req.Bucket = params.Bucket
if params.Password != "" {
req.Password = &params.Password
}
if params.AuthToken != "" {
req.Token = &params.AuthToken
}
rpSecs := int64(InfiniteRetention)
if params.Retention != "" {
dur, err := duration.RawDurationToTimeDuration(params.Retention)
if err != nil {
return req, fmt.Errorf("failed to parse %q: %w", params.Retention, err)
}
secs, nanos := math.Modf(dur.Seconds())
if nanos > 0 {
return req, fmt.Errorf("retention policy %q is too precise, must be divisible by 1s", params.Retention)
}
rpSecs = int64(secs)
}
req.RetentionPeriodSeconds = &rpSecs
if params.Force {
return req, nil
}
// Ask the user for any missing information.
if err := c.StdIO.Banner("Welcome to InfluxDB 2.0!"); err != nil {
return req, err
}
if params.Username == "" {
req.Username, err = c.StdIO.GetStringInput("Please type your primary username", "")
if err != nil {
return req, err
}
}
if params.Password == "" {
for {
pass1, err := c.StdIO.GetPassword("Please type your password", MinPasswordLen)
if err != nil {
return req, err
}
// Don't bother with the length check the 2nd time, since we check equality to pass1.
pass2, err := c.StdIO.GetPassword("Please type your password again", 0)
if err != nil {
return req, err
}
if pass1 == pass2 {
req.Password = &pass1
break
}
if err := c.StdIO.Error("Passwords do not match"); err != nil {
return req, err
}
}
}
if params.Org == "" {
req.Org, err = c.StdIO.GetStringInput("Please type your primary organization name", "")
if err != nil {
return req, err
}
}
if params.Bucket == "" {
req.Bucket, err = c.StdIO.GetStringInput("Please type your primary bucket name", "")
if err != nil {
return req, err
}
}
if params.Retention == "" {
infiniteStr := strconv.Itoa(InfiniteRetention)
for {
rpStr, err := c.StdIO.GetStringInput("Please type your retention period in hours, or 0 for infinite", infiniteStr)
if err != nil {
return req, err
}
rp, err := strconv.Atoi(rpStr)
if err != nil {
return req, err
}
if rp >= 0 {
rpSeconds := int64((time.Duration(rp) * time.Hour).Seconds())
req.RetentionPeriodSeconds = &rpSeconds
break
} else if err := c.StdIO.Error("Retention period cannot be negative"); err != nil {
return req, err
}
}
}
if confirmed := c.StdIO.GetConfirm(func() string {
rp := "infinite"
if req.RetentionPeriodSeconds != nil && *req.RetentionPeriodSeconds > 0 {
rp = (time.Duration(*req.RetentionPeriodSeconds) * time.Second).String()
}
return fmt.Sprintf(`Setup with these parameters?
Username: %s
Organization: %s
Bucket: %s
Retention Period: %s
`, req.Username, req.Org, req.Bucket, rp)
}()); !confirmed {
return api.OnboardingRequest{}, ErrSetupCanceled
}
return req, nil
}

392
internal/setup_test.go Normal file
View File

@ -0,0 +1,392 @@
package internal_test
import (
"context"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"testing"
"github.com/influxdata/influx-cli/v2/internal"
"github.com/influxdata/influx-cli/v2/internal/api"
"github.com/influxdata/influx-cli/v2/internal/config"
"github.com/influxdata/influx-cli/v2/internal/duration"
"github.com/influxdata/influx-cli/v2/internal/mock"
"github.com/stretchr/testify/require"
)
type setupTestConfigSvc struct {
CreateConfigFn func(config.Config) (config.Config, error)
DeleteConfigFn func(string) (config.Config, error)
UpdateConfigFn func(config.Config) (config.Config, error)
SwitchActiveFn func(string) (config.Config, error)
ActiveFn func() (config.Config, error)
ListConfigsFn func() (config.Configs, error)
}
func (ts *setupTestConfigSvc) CreateConfig(cfg config.Config) (config.Config, error) {
return ts.CreateConfigFn(cfg)
}
func (ts *setupTestConfigSvc) DeleteConfig(name string) (config.Config, error) {
return ts.DeleteConfigFn(name)
}
func (ts *setupTestConfigSvc) UpdateConfig(cfg config.Config) (config.Config, error) {
return ts.UpdateConfigFn(cfg)
}
func (ts *setupTestConfigSvc) SwitchActive(name string) (config.Config, error) {
return ts.SwitchActiveFn(name)
}
func (ts *setupTestConfigSvc) Active() (config.Config, error) {
return ts.ActiveFn()
}
func (ts *setupTestConfigSvc) ListConfigs() (config.Configs, error) {
return ts.ListConfigsFn()
}
type setupTestClient struct {
GetSetupExecuteFn func(api.ApiGetSetupRequest) (api.InlineResponse200, *http.Response, error)
PostSetupExecuteFn func(api.ApiPostSetupRequest) (api.OnboardingResponse, *http.Response, error)
}
func (tc *setupTestClient) GetSetup(context.Context) api.ApiGetSetupRequest {
return api.ApiGetSetupRequest{
ApiService: tc,
}
}
func (tc *setupTestClient) GetSetupExecute(req api.ApiGetSetupRequest) (api.InlineResponse200, *http.Response, error) {
return tc.GetSetupExecuteFn(req)
}
func (tc *setupTestClient) PostSetup(context.Context) api.ApiPostSetupRequest {
return api.ApiPostSetupRequest{
ApiService: tc,
}
}
func (tc *setupTestClient) PostSetupExecute(req api.ApiPostSetupRequest) (api.OnboardingResponse, *http.Response, error) {
return tc.PostSetupExecuteFn(req)
}
func Test_SetupConfigNameCollision(t *testing.T) {
t.Parallel()
cfg := "foo"
configSvc := &setupTestConfigSvc{
ListConfigsFn: func() (config.Configs, error) {
return map[string]config.Config{cfg: {}}, nil
},
}
cli := &internal.CLI{ConfigService: configSvc}
err := cli.Setup(context.Background(), &setupTestClient{}, &internal.SetupParams{ConfigName: cfg})
require.Error(t, err)
require.Contains(t, err.Error(), cfg)
require.Contains(t, err.Error(), "already exists")
}
func Test_SetupConfigNameRequired(t *testing.T) {
t.Parallel()
configSvc := &setupTestConfigSvc{
ListConfigsFn: func() (config.Configs, error) {
return map[string]config.Config{"foo": {}}, nil
},
}
cli := &internal.CLI{ConfigService: configSvc}
err := cli.Setup(context.Background(), &setupTestClient{}, &internal.SetupParams{})
require.Error(t, err)
require.Equal(t, internal.ErrConfigNameRequired, err)
}
func Test_SetupAlreadySetup(t *testing.T) {
t.Parallel()
client := &setupTestClient{
GetSetupExecuteFn: func(api.ApiGetSetupRequest) (api.InlineResponse200, *http.Response, error) {
return api.InlineResponse200{Allowed: api.PtrBool(false)}, nil, nil
},
}
configSvc := &setupTestConfigSvc{
ListConfigsFn: func() (config.Configs, error) {
return nil, nil
},
}
cli := &internal.CLI{ConfigService: configSvc}
err := cli.Setup(context.Background(), client, &internal.SetupParams{})
require.Error(t, err)
require.Equal(t, internal.ErrAlreadySetUp, err)
}
func Test_SetupCheckFailed(t *testing.T) {
t.Parallel()
e := "oh no"
client := &setupTestClient{
GetSetupExecuteFn: func(api.ApiGetSetupRequest) (api.InlineResponse200, *http.Response, error) {
return api.InlineResponse200{}, nil, errors.New(e)
},
}
configSvc := &setupTestConfigSvc{
ListConfigsFn: func() (config.Configs, error) {
return nil, nil
},
}
cli := &internal.CLI{ConfigService: configSvc}
err := cli.Setup(context.Background(), client, &internal.SetupParams{})
require.Error(t, err)
require.Contains(t, err.Error(), e)
}
func Test_SetupSuccessNoninteractive(t *testing.T) {
t.Parallel()
retentionSecs := int64(duration.Week.Seconds())
params := internal.SetupParams{
Username: "user",
Password: "mysecretpassword",
AuthToken: "mytoken",
Org: "org",
Bucket: "bucket",
Retention: fmt.Sprintf("%ds", retentionSecs),
Force: true,
ConfigName: "my-config",
}
resp := api.OnboardingResponse{
Auth: &api.Authorization{Token: &params.AuthToken},
Org: &api.Organization{Name: params.Org},
User: &api.UserResponse{Name: params.Username},
Bucket: &api.Bucket{Name: params.Bucket},
}
client := &setupTestClient{
GetSetupExecuteFn: func(api.ApiGetSetupRequest) (api.InlineResponse200, *http.Response, error) {
return api.InlineResponse200{Allowed: api.PtrBool(true)}, nil, nil
},
PostSetupExecuteFn: func(req api.ApiPostSetupRequest) (api.OnboardingResponse, *http.Response, error) {
body := req.GetOnboardingRequest()
require.Equal(t, params.Username, body.Username)
require.Equal(t, params.Password, *body.Password)
require.Equal(t, params.AuthToken, *body.Token)
require.Equal(t, params.Org, body.Org)
require.Equal(t, params.Bucket, body.Bucket)
require.Equal(t, retentionSecs, *body.RetentionPeriodSeconds)
return resp, nil, nil
},
}
host := "fake-host"
configSvc := &setupTestConfigSvc{
ListConfigsFn: func() (config.Configs, error) {
return nil, nil
},
CreateConfigFn: func(cfg config.Config) (config.Config, error) {
require.Equal(t, params.ConfigName, cfg.Name)
require.Equal(t, params.AuthToken, cfg.Token)
require.Equal(t, host, cfg.Host)
require.Equal(t, params.Org, cfg.Org)
return cfg, nil
},
}
stdio := mock.NewMockStdio(nil, true)
cli := &internal.CLI{ConfigService: configSvc, ActiveConfig: config.Config{Host: host}, StdIO: stdio}
require.NoError(t, cli.Setup(context.Background(), client, &params))
outLines := strings.Split(strings.TrimSpace(stdio.Stdout()), "\n")
require.Len(t, outLines, 2)
header, data := outLines[0], outLines[1]
require.Regexp(t, "User\\s+Organization\\s+Bucket", header)
require.Regexp(t, fmt.Sprintf("%s\\s+%s\\s+%s", params.Username, params.Org, params.Bucket), data)
}
func Test_SetupSuccessNoninteractiveWithTracing(t *testing.T) {
t.Parallel()
traceId := "trace-id"
retentionSecs := int64(duration.Week.Seconds())
params := internal.SetupParams{
Username: "user",
Password: "mysecretpassword",
AuthToken: "mytoken",
Org: "org",
Bucket: "bucket",
Retention: fmt.Sprintf("%ds", retentionSecs),
Force: true,
ConfigName: "my-config",
}
resp := api.OnboardingResponse{
Auth: &api.Authorization{Token: &params.AuthToken},
Org: &api.Organization{Name: params.Org},
User: &api.UserResponse{Name: params.Username},
Bucket: &api.Bucket{Name: params.Bucket},
}
client := &setupTestClient{
GetSetupExecuteFn: func(req api.ApiGetSetupRequest) (api.InlineResponse200, *http.Response, error) {
require.Equal(t, traceId, *req.GetZapTraceSpan())
return api.InlineResponse200{Allowed: api.PtrBool(true)}, nil, nil
},
PostSetupExecuteFn: func(req api.ApiPostSetupRequest) (api.OnboardingResponse, *http.Response, error) {
require.Equal(t, traceId, *req.GetZapTraceSpan())
body := req.GetOnboardingRequest()
require.Equal(t, params.Username, body.Username)
require.Equal(t, params.Password, *body.Password)
require.Equal(t, params.AuthToken, *body.Token)
require.Equal(t, params.Org, body.Org)
require.Equal(t, params.Bucket, body.Bucket)
require.Equal(t, retentionSecs, *body.RetentionPeriodSeconds)
return resp, nil, nil
},
}
host := "fake-host"
configSvc := &setupTestConfigSvc{
ListConfigsFn: func() (config.Configs, error) {
return nil, nil
},
CreateConfigFn: func(cfg config.Config) (config.Config, error) {
require.Equal(t, params.ConfigName, cfg.Name)
require.Equal(t, params.AuthToken, cfg.Token)
require.Equal(t, host, cfg.Host)
require.Equal(t, params.Org, cfg.Org)
return cfg, nil
},
}
stdio := mock.NewMockStdio(nil, true)
cli := &internal.CLI{ConfigService: configSvc, ActiveConfig: config.Config{Host: host}, StdIO: stdio, TraceId: traceId}
require.NoError(t, cli.Setup(context.Background(), client, &params))
outLines := strings.Split(strings.TrimSpace(stdio.Stdout()), "\n")
require.Len(t, outLines, 2)
header, data := outLines[0], outLines[1]
require.Regexp(t, "User\\s+Organization\\s+Bucket", header)
require.Regexp(t, fmt.Sprintf("%s\\s+%s\\s+%s", params.Username, params.Org, params.Bucket), data)
}
func Test_SetupSuccessInteractive(t *testing.T) {
t.Parallel()
retentionSecs := int64(duration.Week.Seconds())
retentionHrs := int(duration.Week.Hours())
username := "user"
password := "mysecretpassword"
token := "mytoken"
org := "org"
bucket := "bucket"
resp := api.OnboardingResponse{
Auth: &api.Authorization{Token: &token},
Org: &api.Organization{Name: org},
User: &api.UserResponse{Name: username},
Bucket: &api.Bucket{Name: bucket},
}
client := &setupTestClient{
GetSetupExecuteFn: func(api.ApiGetSetupRequest) (api.InlineResponse200, *http.Response, error) {
return api.InlineResponse200{Allowed: api.PtrBool(true)}, nil, nil
},
PostSetupExecuteFn: func(req api.ApiPostSetupRequest) (api.OnboardingResponse, *http.Response, error) {
body := req.GetOnboardingRequest()
require.Equal(t, username, body.Username)
require.Equal(t, password, *body.Password)
require.Nil(t, body.Token)
require.Equal(t, org, body.Org)
require.Equal(t, bucket, body.Bucket)
require.Equal(t, retentionSecs, *body.RetentionPeriodSeconds)
return resp, nil, nil
},
}
host := "fake-host"
configSvc := &setupTestConfigSvc{
ListConfigsFn: func() (config.Configs, error) {
return nil, nil
},
CreateConfigFn: func(cfg config.Config) (config.Config, error) {
require.Equal(t, config.DefaultConfig.Name, cfg.Name)
require.Equal(t, token, cfg.Token)
require.Equal(t, host, cfg.Host)
require.Equal(t, org, cfg.Org)
return cfg, nil
},
}
stdio := mock.NewMockStdio(map[string]string{
"Please type your primary username": username,
"Please type your password": password,
"Please type your password again": password,
"Please type your primary organization name": org,
"Please type your primary bucket name": bucket,
"Please type your retention period in hours, or 0 for infinite": strconv.Itoa(retentionHrs),
}, true)
cli := &internal.CLI{ConfigService: configSvc, ActiveConfig: config.Config{Host: host}, StdIO: stdio}
require.NoError(t, cli.Setup(context.Background(), client, &internal.SetupParams{}))
outLines := strings.Split(strings.TrimSpace(stdio.Stdout()), "\n")
require.Len(t, outLines, 2)
header, data := outLines[0], outLines[1]
require.Regexp(t, "User\\s+Organization\\s+Bucket", header)
require.Regexp(t, fmt.Sprintf("%s\\s+%s\\s+%s", username, org, bucket), data)
}
func Test_SetupPasswordParamToShort(t *testing.T) {
t.Parallel()
retentionSecs := int64(duration.Week.Seconds())
params := internal.SetupParams{
Username: "user",
Password: "2short",
AuthToken: "mytoken",
Org: "org",
Bucket: "bucket",
Retention: fmt.Sprintf("%ds", retentionSecs),
Force: false,
}
client := &setupTestClient{
GetSetupExecuteFn: func(api.ApiGetSetupRequest) (api.InlineResponse200, *http.Response, error) {
return api.InlineResponse200{Allowed: api.PtrBool(true)}, nil, nil
},
}
host := "fake-host"
configSvc := &setupTestConfigSvc{
ListConfigsFn: func() (config.Configs, error) {
return nil, nil
},
}
stdio := mock.NewMockStdio(nil, false)
cli := &internal.CLI{ConfigService: configSvc, ActiveConfig: config.Config{Host: host}, StdIO: stdio}
err := cli.Setup(context.Background(), client, &params)
require.Equal(t, internal.ErrPasswordIsTooShort, err)
}
func Test_SetupCancelAtConfirmation(t *testing.T) {
t.Parallel()
retentionSecs := int64(duration.Week.Seconds())
params := internal.SetupParams{
Username: "user",
Password: "mysecretpassword",
AuthToken: "mytoken",
Org: "org",
Bucket: "bucket",
Retention: fmt.Sprintf("%ds", retentionSecs),
Force: false,
}
client := &setupTestClient{
GetSetupExecuteFn: func(api.ApiGetSetupRequest) (api.InlineResponse200, *http.Response, error) {
return api.InlineResponse200{Allowed: api.PtrBool(true)}, nil, nil
},
}
host := "fake-host"
configSvc := &setupTestConfigSvc{
ListConfigsFn: func() (config.Configs, error) {
return nil, nil
},
}
stdio := mock.NewMockStdio(nil, false)
cli := &internal.CLI{ConfigService: configSvc, ActiveConfig: config.Config{Host: host}, StdIO: stdio}
err := cli.Setup(context.Background(), client, &params)
require.Equal(t, internal.ErrSetupCanceled, err)
}

86
internal/stdio/console.go Normal file
View File

@ -0,0 +1,86 @@
package stdio
import (
"errors"
"io"
"os"
"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
)
// terminalStdio interacts with the user via an interactive terminal.
type terminalStdio struct {
Stdin terminal.FileReader
Stdout terminal.FileWriter
Stderr io.Writer
}
// TerminalStdio interacts with users over stdin/stdout/stderr.
var TerminalStdio StdIO = &terminalStdio{
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
}
// Write prints some bytes to stdout.
func (t *terminalStdio) Write(p []byte) (int, error) {
return t.Stdout.Write(p)
}
type bannerTemplateData struct {
Message string
}
var bannerTemplate = `{{color "cyan+hb"}}> {{ .Message }}{{color "reset"}}
`
// Banner displays informational text to the user.
func (t *terminalStdio) Banner(message string) error {
r := survey.Renderer{}
r.WithStdio(terminal.Stdio{In: t.Stdin, Out: t.Stdout, Err: t.Stderr})
return r.Render(bannerTemplate, &bannerTemplateData{Message: message})
}
// Error displays an error message to the user.
func (t *terminalStdio) Error(message string) error {
r := survey.Renderer{}
r.WithStdio(terminal.Stdio{In: t.Stdin, Out: t.Stdout, Err: t.Stderr})
cfg := survey.PromptConfig{Icons: survey.IconSet{Error: survey.Icon{Text: "X", Format: "red"}}}
return r.Error(&cfg, errors.New(message))
}
// GetStringInput prompts the user for arbitrary input.
func (t *terminalStdio) GetStringInput(prompt, defaultValue string) (input string, err error) {
question := survey.Input{
Message: prompt,
Default: defaultValue,
}
err = survey.AskOne(&question, &input,
survey.WithStdio(t.Stdin, t.Stdout, t.Stderr),
survey.WithValidator(survey.Required))
return
}
// GetPassword prompts the user for a password.
func (t *terminalStdio) GetPassword(prompt string, minLen int) (password string, err error) {
question := survey.Password{Message: prompt}
opts := []survey.AskOpt{survey.WithStdio(t.Stdin, t.Stdout, t.Stderr)}
if minLen > 0 {
opts = append(opts, survey.WithValidator(survey.MinLength(minLen)))
}
err = survey.AskOne(&question, &password, opts...)
question.NewCursor().HorizontalAbsolute(0)
return
}
// GetConfirm asks the user for a y/n answer to a prompt.
func (t *terminalStdio) GetConfirm(prompt string) (answer bool) {
question := survey.Confirm{
Message: prompt,
}
if err := survey.AskOne(&question, &answer, survey.WithStdio(t.Stdin, t.Stdout, t.Stderr)); err != nil {
answer = false
}
return
}

12
internal/stdio/stdio.go Normal file
View File

@ -0,0 +1,12 @@
package stdio
import "io"
type StdIO interface {
io.Writer
Banner(message string) error
Error(message string) error
GetStringInput(prompt, defaultValue string) (string, error)
GetPassword(prompt string, minLen int) (string, error)
GetConfirm(prompt string) bool
}

View File

@ -0,0 +1,68 @@
package tabwriter
import (
"fmt"
"io"
"strings"
"text/tabwriter"
)
// TabWriter wraps tab writer headers logic.
type TabWriter struct {
writer *tabwriter.Writer
headers []string
hideHeaders bool
}
// NewTabWriter creates a new tab writer.
func NewTabWriter(w io.Writer, hideHeaders bool) *TabWriter {
return &TabWriter{
writer: tabwriter.NewWriter(w, 0, 8, 1, '\t', 0),
hideHeaders: hideHeaders,
}
}
// WriteHeaders will Write headers.
func (w *TabWriter) WriteHeaders(h ...string) error {
w.headers = h
if !w.hideHeaders {
if _, err := fmt.Fprintln(w.writer, strings.Join(h, "\t")); err != nil {
return err
}
}
return nil
}
// Write will Write the map into embed tab writer.
func (w *TabWriter) Write(m map[string]interface{}) error {
body := make([]interface{}, len(w.headers))
types := make([]string, len(w.headers))
for i, h := range w.headers {
v := m[h]
body[i] = v
types[i] = formatStringType(v)
}
formatString := strings.Join(types, "\t")
if _, err := fmt.Fprintf(w.writer, formatString+"\n", body...); err != nil {
return err
}
return nil
}
// Flush should be called after the last call to Write to ensure
// that any data buffered in the Writer is written to output. Any
// incomplete escape sequence at the end is considered
// complete for formatting purposes.
func (w *TabWriter) Flush() error {
return w.writer.Flush()
}
func formatStringType(v interface{}) string {
switch v.(type) {
case int:
return "%d"
case string:
return "%s"
}
return "%v"
}

View File

@ -0,0 +1,38 @@
package tabwriter_test
import (
"bytes"
"testing"
"github.com/influxdata/influx-cli/v2/internal/tabwriter"
"github.com/stretchr/testify/require"
)
func Test_WriteHeaders(t *testing.T) {
out := bytes.Buffer{}
w := tabwriter.NewTabWriter(&out, false)
require.NoError(t, w.WriteHeaders("foo", "bar", "baz"))
require.NoError(t, w.Flush())
require.Equal(t, "foo\tbar\tbaz\n", out.String())
}
func Test_WriteHeadersDisabled(t *testing.T) {
out := bytes.Buffer{}
w := tabwriter.NewTabWriter(&out, true)
require.NoError(t, w.WriteHeaders("foo", "bar", "baz"))
require.NoError(t, w.Flush())
require.Empty(t, out.String())
}
func Test_Write(t *testing.T) {
out := bytes.Buffer{}
w := tabwriter.NewTabWriter(&out, true)
require.NoError(t, w.WriteHeaders("foo", "bar", "baz"))
require.NoError(t, w.Write(map[string]interface{}{
"bar": 123,
"foo": "a string!",
"baz": false,
}))
require.NoError(t, w.Flush())
require.Equal(t, "a string!\t123\tfalse\n", out.String())
}