Fixed jobs create command to only accept JSON payload (#498)

## Changes
Fixed jobs create command to only accept JSON payload.

Note: relies on this PR from Go SDK
https://github.com/databricks/databricks-sdk-go/pull/522

## Tests

```
andrew.nester@HFW9Y94129 cli % ./cli jobs create -h
Create a new job.

  Create a new job.

Usage:
  databricks jobs create [flags]

Flags:
  -h, --help        help for create
      --json JSON   either inline JSON string or @path/to/file.json with request body (default JSON (0 bytes))

Global Flags:
  -e, --environment string       bundle environment to use (if applicable)
      --log-file file            file to write logs to (default stderr)
      --log-format type          log output format (text or json) (default text)
      --log-level format         log level (default disabled)
  -o, --output type              output type: text or json (default text)
  -p, --profile string           ~/.databrickscfg profile
      --progress-format format   format for progress logs (append, inplace, json) (default default)
 ```
This commit is contained in:
Andrew Nester 2023-06-21 09:25:29 +02:00 committed by GitHub
parent ddeb7487b3
commit d11128c638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 74 additions and 111 deletions

View File

@ -58,7 +58,8 @@ func init() {
{{if .Request}}// TODO: short flags
{{.CamelName}}Cmd.Flags().Var(&{{.CamelName}}Json, "json", `either inline JSON string or @path/to/file.json with request body`)
{{$method := .}}
{{range .Request.Fields -}}
{{ if not .IsJsonOnly }}
{{range .Request.Fields -}}
{{- if not .Required -}}
{{if .Entity.IsObject }}// TODO: complex arg: {{.Name}}
{{else if .Entity.IsAny }}// TODO: any: {{.Name}}
@ -69,8 +70,9 @@ func init() {
{{else}}{{$method.CamelName}}Cmd.Flags().{{template "arg-type" .Entity}}(&{{$method.CamelName}}Req.{{.PascalName}}, "{{.KebabName}}", {{$method.CamelName}}Req.{{.PascalName}}, `{{.Summary | without "`"}}`)
{{end}}
{{- end -}}
{{- end}}
{{end}}
{{- end}}
{{- end}}
{{end}}
}
{{- $excludeFromPrompts := list "workspace get-status" -}}
{{- $fullCommandName := (print $serviceName " " .KebabName) -}}
@ -133,7 +135,7 @@ var {{.CamelName}}Cmd = &cobra.Command{
}
{{- end -}}
{{$method := .}}
{{- if .Request.IsAllRequiredFieldsPrimitive -}}
{{- if and .Request.IsAllRequiredFieldsPrimitive (not .IsJsonOnly) -}}
{{- range $arg, $field := .Request.RequiredFields}}
{{if not $field.Entity.IsString -}}
_, err = fmt.Sscan(args[{{$arg}}], &{{$method.CamelName}}Req.{{$field.PascalName}})

View File

@ -55,7 +55,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := a.Budgets.Create(ctx, createReq)
@ -254,7 +254,7 @@ var updateCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = a.Budgets.Update(ctx, updateReq)

View File

@ -68,7 +68,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := a.Credentials.Create(ctx, createReq)

View File

@ -63,7 +63,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := a.CustomAppIntegration.Create(ctx, createReq)

View File

@ -85,7 +85,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := a.EncryptionKeys.Create(ctx, createReq)

View File

@ -85,7 +85,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := a.IpAccessLists.Create(ctx, createReq)
@ -292,7 +292,7 @@ var replaceCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = a.IpAccessLists.Replace(ctx, replaceReq)
@ -351,7 +351,7 @@ var updateCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = a.IpAccessLists.Update(ctx, updateReq)

View File

@ -65,7 +65,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := a.Storage.Create(ctx, createReq)

View File

@ -221,7 +221,7 @@ var updateCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = a.WorkspaceAssignment.Update(ctx, updateReq)

View File

@ -60,7 +60,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.Alerts.Create(ctx, createReq)
@ -260,7 +260,7 @@ var updateCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = w.Alerts.Update(ctx, updateReq)

View File

@ -73,7 +73,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.Connections.Create(ctx, createReq)
@ -269,7 +269,7 @@ var updateCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.Connections.Update(ctx, updateReq)

View File

@ -36,11 +36,6 @@ func init() {
// TODO: short flags
createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
createCmd.Flags().BoolVar(&createReq.IsFavorite, "is-favorite", createReq.IsFavorite, `Indicates whether this query object should appear in the current user's favorites list.`)
createCmd.Flags().StringVar(&createReq.Name, "name", createReq.Name, `The title of this dashboard that appears in list views and at the top of the dashboard page.`)
createCmd.Flags().StringVar(&createReq.Parent, "parent", createReq.Parent, `The identifier of the workspace folder containing the dashboard.`)
// TODO: array: tags
}
var createCmd = &cobra.Command{
@ -66,6 +61,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.Dashboards.Create(ctx, createReq)

View File

@ -66,7 +66,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.Functions.Create(ctx, createReq)

View File

@ -86,7 +86,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.IpAccessLists.Create(ctx, createReq)
@ -295,7 +295,7 @@ var replaceCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = w.IpAccessLists.Replace(ctx, replaceReq)
@ -356,7 +356,7 @@ var updateCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = w.IpAccessLists.Update(ctx, updateReq)

View File

@ -203,23 +203,6 @@ func init() {
// TODO: short flags
createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: array: access_control_list
// TODO: complex arg: continuous
// TODO: complex arg: email_notifications
createCmd.Flags().Var(&createReq.Format, "format", `Used to tell what is the format of the job.`)
// TODO: complex arg: git_source
// TODO: array: job_clusters
createCmd.Flags().IntVar(&createReq.MaxConcurrentRuns, "max-concurrent-runs", createReq.MaxConcurrentRuns, `An optional maximum allowed number of concurrent runs of the job.`)
createCmd.Flags().StringVar(&createReq.Name, "name", createReq.Name, `An optional name for the job.`)
// TODO: complex arg: notification_settings
// TODO: complex arg: run_as
// TODO: complex arg: schedule
// TODO: map via StringToStringVar: tags
// TODO: array: tasks
createCmd.Flags().IntVar(&createReq.TimeoutSeconds, "timeout-seconds", createReq.TimeoutSeconds, `An optional timeout applied to each run of this job.`)
// TODO: complex arg: trigger
// TODO: complex arg: webhook_notifications
}
var createCmd = &cobra.Command{
@ -247,6 +230,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.Jobs.Create(ctx, createReq)
@ -912,7 +896,7 @@ var resetCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = w.Jobs.Reset(ctx, resetReq)

View File

@ -172,7 +172,7 @@ var installCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = w.Libraries.Install(ctx, installReq)
@ -218,7 +218,7 @@ var uninstallCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
err = w.Libraries.Uninstall(ctx, uninstallReq)

View File

@ -349,7 +349,7 @@ var createWebhookCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.ModelRegistry.CreateWebhook(ctx, createWebhookReq)

View File

@ -45,25 +45,6 @@ func init() {
// TODO: short flags
createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
createCmd.Flags().BoolVar(&createReq.AllowDuplicateNames, "allow-duplicate-names", createReq.AllowDuplicateNames, `If false, deployment will fail if name conflicts with that of another pipeline.`)
createCmd.Flags().StringVar(&createReq.Catalog, "catalog", createReq.Catalog, `A catalog in Unity Catalog to publish data from this pipeline to.`)
createCmd.Flags().StringVar(&createReq.Channel, "channel", createReq.Channel, `DLT Release Channel that specifies which version to use.`)
// TODO: array: clusters
// TODO: map via StringToStringVar: configuration
createCmd.Flags().BoolVar(&createReq.Continuous, "continuous", createReq.Continuous, `Whether the pipeline is continuous or triggered.`)
createCmd.Flags().BoolVar(&createReq.Development, "development", createReq.Development, `Whether the pipeline is in Development mode.`)
createCmd.Flags().BoolVar(&createReq.DryRun, "dry-run", createReq.DryRun, ``)
createCmd.Flags().StringVar(&createReq.Edition, "edition", createReq.Edition, `Pipeline product edition.`)
// TODO: complex arg: filters
createCmd.Flags().StringVar(&createReq.Id, "id", createReq.Id, `Unique identifier for this pipeline.`)
// TODO: array: libraries
createCmd.Flags().StringVar(&createReq.Name, "name", createReq.Name, `Friendly identifier for this pipeline.`)
createCmd.Flags().BoolVar(&createReq.Photon, "photon", createReq.Photon, `Whether Photon is enabled for this pipeline.`)
createCmd.Flags().BoolVar(&createReq.Serverless, "serverless", createReq.Serverless, `Whether serverless compute is enabled for this pipeline.`)
createCmd.Flags().StringVar(&createReq.Storage, "storage", createReq.Storage, `DBFS root directory for storing checkpoints and tables.`)
createCmd.Flags().StringVar(&createReq.Target, "target", createReq.Target, `Target schema (database) to add tables in this pipeline to.`)
// TODO: complex arg: trigger
}
var createCmd = &cobra.Command{
@ -92,6 +73,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.Pipelines.Create(ctx, createReq)

View File

@ -34,13 +34,6 @@ func init() {
// TODO: short flags
createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
createCmd.Flags().StringVar(&createReq.DataSourceId, "data-source-id", createReq.DataSourceId, `The ID of the data source / SQL warehouse where this query will run.`)
createCmd.Flags().StringVar(&createReq.Description, "description", createReq.Description, `General description that can convey additional information about this query such as usage notes.`)
createCmd.Flags().StringVar(&createReq.Name, "name", createReq.Name, `The name or title of this query to display in list views.`)
// TODO: any: options
createCmd.Flags().StringVar(&createReq.Parent, "parent", createReq.Parent, `The identifier of the workspace folder containing the query.`)
createCmd.Flags().StringVar(&createReq.Query, "query", createReq.Query, `The text of the query.`)
}
var createCmd = &cobra.Command{
@ -76,6 +69,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.Queries.Create(ctx, createReq)

View File

@ -42,8 +42,8 @@ func init() {
// TODO: short flags
createScopeCmd.Flags().Var(&createScopeJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: complex arg: backend_azure_keyvault
createScopeCmd.Flags().StringVar(&createScopeReq.InitialManagePrincipal, "initial-manage-principal", createScopeReq.InitialManagePrincipal, `The principal that is initially granted MANAGE permission to the created scope.`)
// TODO: complex arg: keyvault_metadata
createScopeCmd.Flags().Var(&createScopeReq.ScopeBackendType, "scope-backend-type", `The backend type the scope will be created with.`)
}
@ -502,9 +502,9 @@ var putAclCmd = &cobra.Command{
Throws RESOURCE_DOES_NOT_EXIST if no such secret scope exists. Throws
RESOURCE_ALREADY_EXISTS if a permission for the principal already exists.
Throws INVALID_PARAMETER_VALUE if the permission is invalid. Throws
PERMISSION_DENIED if the user does not have permission to make this API
call.`,
Throws INVALID_PARAMETER_VALUE if the permission or principal is invalid.
Throws PERMISSION_DENIED if the user does not have permission to make this
API call.`,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {

View File

@ -120,7 +120,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
wait, err := w.ServingEndpoints.Create(ctx, createReq)
@ -470,7 +470,7 @@ var updateConfigCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
wait, err := w.ServingEndpoints.UpdateConfig(ctx, updateConfigReq)

View File

@ -3,6 +3,8 @@
package system_schemas
import (
"fmt"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags"
@ -63,7 +65,10 @@ var disableCmd = &cobra.Command{
}
} else {
disableReq.MetastoreId = args[0]
disableReq.SchemaName = args[1]
_, err = fmt.Sscan(args[1], &disableReq.SchemaName)
if err != nil {
return fmt.Errorf("invalid SCHEMA_NAME: %s", args[1])
}
}
err = w.SystemSchemas.Disable(ctx, disableReq)

View File

@ -72,7 +72,7 @@ var createCmd = &cobra.Command{
return err
}
} else {
return fmt.Errorf("provide command input in JSON format by specifying --json option")
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := w.TableConstraints.Create(ctx, createReq)