Fixed jobs create command to only accept JSON payload

This commit is contained in:
Andrew Nester 2023-06-19 14:21:47 +02:00
parent 63e80a0b71
commit f88605c032
No known key found for this signature in database
GPG Key ID: 12BC628A44B7DA57
20 changed files with 71 additions and 80 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 .OnlyPayload }}
{{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 .OnlyPayload) -}}
{{- 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

@ -18,26 +18,26 @@ var Cmd = &cobra.Command{
Short: `The Clusters API allows you to create, start, edit, list, terminate, and delete clusters.`,
Long: `The Clusters API allows you to create, start, edit, list, terminate, and
delete clusters.
Databricks maps cluster node instance types to compute units known as DBUs.
See the instance type pricing page for a list of the supported instance types
and their corresponding DBUs.
A Databricks cluster is a set of computation resources and configurations on
which you run data engineering, data science, and data analytics workloads,
such as production ETL pipelines, streaming analytics, ad-hoc analytics, and
machine learning.
You run these workloads as a set of commands in a notebook or as an automated
job. Databricks makes a distinction between all-purpose clusters and job
clusters. You use all-purpose clusters to analyze data collaboratively using
interactive notebooks. You use job clusters to run fast and robust automated
jobs.
You can create an all-purpose cluster using the UI, CLI, or REST API. You can
manually terminate and restart an all-purpose cluster. Multiple users can
share such clusters to do collaborative interactive analysis.
IMPORTANT: Databricks retains cluster configuration information for up to 200
all-purpose clusters terminated in the last 30 days and up to 30 job clusters
recently terminated by the job scheduler. To keep an all-purpose cluster
@ -64,7 +64,7 @@ var changeOwnerCmd = &cobra.Command{
Use: "change-owner CLUSTER_ID OWNER_USERNAME",
Short: `Change cluster owner.`,
Long: `Change cluster owner.
Change the owner of the cluster. You must be an admin to perform this
operation.`,
@ -147,17 +147,17 @@ var createCmd = &cobra.Command{
Use: "create SPARK_VERSION",
Short: `Create new cluster.`,
Long: `Create new cluster.
Creates a new Spark cluster. This method will acquire new instances from the
cloud provider if necessary. This method is asynchronous; the returned
cluster_id can be used to poll the cluster status. When this method returns,
the cluster will be in a PENDING state. The cluster will be usable once it
enters a RUNNING state.
Note: Databricks may not be able to acquire some of the requested nodes, due
to cloud provider limitations (account limits, spot price, etc.) or transient
network issues.
If Databricks acquires at least 85% of the requested on-demand nodes, cluster
creation will succeed. Otherwise the cluster will terminate with an
informative error message.`,
@ -227,7 +227,7 @@ var deleteCmd = &cobra.Command{
Use: "delete CLUSTER_ID",
Short: `Terminate cluster.`,
Long: `Terminate cluster.
Terminates the Spark cluster with the specified ID. The cluster is removed
asynchronously. Once the termination has completed, the cluster will be in a
TERMINATED state. If the cluster is already in a TERMINATING or
@ -336,18 +336,18 @@ var editCmd = &cobra.Command{
Use: "edit CLUSTER_ID SPARK_VERSION",
Short: `Update cluster configuration.`,
Long: `Update cluster configuration.
Updates the configuration of a cluster to match the provided attributes and
size. A cluster can be updated if it is in a RUNNING or TERMINATED state.
If a cluster is updated while in a RUNNING state, it will be restarted so
that the new attributes can take effect.
If a cluster is updated while in a TERMINATED state, it will remain
TERMINATED. The next time it is started using the clusters/start API, the
new attributes will take effect. Any attempt to update a cluster in any other
state will be rejected with an INVALID_STATE error code.
Clusters created by the Databricks Jobs service cannot be edited.`,
Annotations: map[string]string{},
@ -418,7 +418,7 @@ var eventsCmd = &cobra.Command{
Use: "events CLUSTER_ID",
Short: `List cluster activity events.`,
Long: `List cluster activity events.
Retrieves a list of events about the activity of a cluster. This API is
paginated. If there are more events to read, the response includes all the
nparameters necessary to request the next page of events.`,
@ -486,7 +486,7 @@ var getCmd = &cobra.Command{
Use: "get CLUSTER_ID",
Short: `Get cluster info.`,
Long: `Get cluster info.
Retrieves the information for a cluster given its identifier. Clusters can be
described while they are running, or up to 60 days after they are terminated.`,
@ -550,11 +550,11 @@ var listCmd = &cobra.Command{
Use: "list",
Short: `List all clusters.`,
Long: `List all clusters.
Return information about all pinned clusters, active clusters, up to 200 of
the most recently terminated all-purpose clusters in the past 30 days, and up
to 30 of the most recently terminated job clusters in the past 30 days.
For example, if there is 1 pinned cluster, 4 active clusters, 45 terminated
all-purpose clusters in the past 30 days, and 50 terminated job clusters in
the past 30 days, then this API returns the 1 pinned cluster, 4 active
@ -603,7 +603,7 @@ var listNodeTypesCmd = &cobra.Command{
Use: "list-node-types",
Short: `List node types.`,
Long: `List node types.
Returns a list of supported Spark node types. These node types can be used to
launch a cluster.`,
@ -634,7 +634,7 @@ var listZonesCmd = &cobra.Command{
Use: "list-zones",
Short: `List availability zones.`,
Long: `List availability zones.
Returns a list of availability zones where clusters can be created in (For
example, us-west-2a). These zones can be used to launch a cluster.`,
@ -670,10 +670,10 @@ var permanentDeleteCmd = &cobra.Command{
Use: "permanent-delete CLUSTER_ID",
Short: `Permanently delete cluster.`,
Long: `Permanently delete cluster.
Permanently deletes a Spark cluster. This cluster is terminated and resources
are asynchronously removed.
In addition, users will no longer see permanently deleted clusters in the
cluster list, and API users can no longer perform any action on permanently
deleted clusters.`,
@ -736,7 +736,7 @@ var pinCmd = &cobra.Command{
Use: "pin CLUSTER_ID",
Short: `Pin cluster.`,
Long: `Pin cluster.
Pinning a cluster ensures that the cluster will always be returned by the
ListClusters API. Pinning a cluster that is already pinned will have no
effect. This API can only be called by workspace admins.`,
@ -807,7 +807,7 @@ var resizeCmd = &cobra.Command{
Use: "resize CLUSTER_ID",
Short: `Resize cluster.`,
Long: `Resize cluster.
Resizes a cluster to have a desired number of workers. This will fail unless
the cluster is in a RUNNING state.`,
@ -888,7 +888,7 @@ var restartCmd = &cobra.Command{
Use: "restart CLUSTER_ID",
Short: `Restart cluster.`,
Long: `Restart cluster.
Restarts a Spark cluster with the supplied ID. If the cluster is not currently
in a RUNNING state, nothing will happen.`,
@ -957,7 +957,7 @@ var sparkVersionsCmd = &cobra.Command{
Use: "spark-versions",
Short: `List available Spark versions.`,
Long: `List available Spark versions.
Returns the list of available Spark versions. These versions can be used to
launch a cluster.`,
@ -998,10 +998,10 @@ var startCmd = &cobra.Command{
Use: "start CLUSTER_ID",
Short: `Start terminated cluster.`,
Long: `Start terminated cluster.
Starts a terminated Spark cluster with the supplied ID. This works similar to
createCluster except:
* The previous cluster id and attributes are preserved. * The cluster starts
with the last specified cluster size. * If the previous cluster was an
autoscaling cluster, the current cluster starts with the minimum number of
@ -1078,7 +1078,7 @@ var unpinCmd = &cobra.Command{
Use: "unpin CLUSTER_ID",
Short: `Unpin cluster.`,
Long: `Unpin cluster.
Unpinning a cluster will allow the cluster to eventually be removed from the
ListClusters API. Unpinning a cluster that is not pinned will have no effect.
This API can only be called by workspace admins.`,

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

@ -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

@ -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)