Compare commits

..

No commits in common. "4d858dd24730c6194a2820b3d12556578ce8a8a4" and "91ad4df7bf7f0ee488ccddd44c30fd6f22a01795" have entirely different histories.

12 changed files with 59 additions and 308 deletions

View File

@ -130,26 +130,21 @@ func new{{.PascalName}}() *cobra.Command {
cmd.Flags().BoolVar(&{{.CamelName}}SkipWait, "no-wait", {{.CamelName}}SkipWait, `do not wait to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state`) cmd.Flags().BoolVar(&{{.CamelName}}SkipWait, "no-wait", {{.CamelName}}SkipWait, `do not wait to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state`)
cmd.Flags().DurationVar(&{{.CamelName}}Timeout, "timeout", {{.Wait.Timeout}}*time.Minute, `maximum amount of time to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state`) cmd.Flags().DurationVar(&{{.CamelName}}Timeout, "timeout", {{.Wait.Timeout}}*time.Minute, `maximum amount of time to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state`)
{{end -}} {{end -}}
{{- $request := .Request -}} {{if .Request}}// TODO: short flags
{{- if .RequestBodyField -}}
{{- $request = .RequestBodyField.Entity -}}
{{- end -}}
{{if $request }}// TODO: short flags
{{- if .CanUseJson}} {{- if .CanUseJson}}
cmd.Flags().Var(&{{.CamelName}}Json, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&{{.CamelName}}Json, "json", `either inline JSON string or @path/to/file.json with request body`)
{{- end}} {{- end}}
{{$method := .}} {{$method := .}}
{{ if not .IsJsonOnly }} {{ if not .IsJsonOnly }}
{{range $request.Fields -}} {{range .Request.Fields -}}
{{- if not .Required -}} {{- if not .Required -}}
{{if .Entity.IsObject }}// TODO: complex arg: {{.Name}} {{if .Entity.IsObject }}// TODO: complex arg: {{.Name}}
{{else if .Entity.IsAny }}// TODO: any: {{.Name}} {{else if .Entity.IsAny }}// TODO: any: {{.Name}}
{{else if .Entity.ArrayValue }}// TODO: array: {{.Name}} {{else if .Entity.ArrayValue }}// TODO: array: {{.Name}}
{{else if .Entity.MapValue }}// TODO: map via StringToStringVar: {{.Name}} {{else if .Entity.MapValue }}// TODO: map via StringToStringVar: {{.Name}}
{{else if .Entity.IsEmpty }}// TODO: output-only field {{else if .Entity.IsEmpty }}// TODO: output-only field
{{else if .Entity.IsComputed -}} {{else if .Entity.Enum }}cmd.Flags().Var(&{{$method.CamelName}}Req.{{.PascalName}}, "{{.KebabName}}", `{{.Summary | without "`" | trimSuffix "."}}. Supported values: {{template "printArray" .Entity.Enum}}`)
{{else if .Entity.Enum }}cmd.Flags().Var(&{{- template "request-body-obj" (dict "Method" $method "Field" .)}}, "{{.KebabName}}", `{{.Summary | without "`" | trimSuffix "."}}. Supported values: {{template "printArray" .Entity.Enum}}`) {{else}}cmd.Flags().{{template "arg-type" .Entity}}(&{{$method.CamelName}}Req.{{.PascalName}}, "{{.KebabName}}", {{$method.CamelName}}Req.{{.PascalName}}, `{{.Summary | without "`"}}`)
{{else}}cmd.Flags().{{template "arg-type" .Entity}}(&{{- template "request-body-obj" (dict "Method" $method "Field" .)}}, "{{.KebabName}}", {{- template "request-body-obj" (dict "Method" $method "Field" .)}}, `{{.Summary | without "`"}}`)
{{end}} {{end}}
{{- end -}} {{- end -}}
{{- end}} {{- end}}
@ -169,14 +164,14 @@ func new{{.PascalName}}() *cobra.Command {
{{- $noPrompt := or .IsCrudCreate (in $excludeFromPrompts $fullCommandName) }} {{- $noPrompt := or .IsCrudCreate (in $excludeFromPrompts $fullCommandName) }}
{{- $hasPosArgs := .HasRequiredPositionalArguments -}} {{- $hasPosArgs := .HasRequiredPositionalArguments -}}
{{- $hasSinglePosArg := and $hasPosArgs (eq 1 (len $request.RequiredFields)) -}} {{- $hasSinglePosArg := and $hasPosArgs (eq 1 (len .Request.RequiredFields)) -}}
{{- $serviceHasNamedIdMap := and (and .Service.List .Service.List.NamedIdMap) (not (eq .PascalName "List")) -}} {{- $serviceHasNamedIdMap := and (and .Service.List .Service.List.NamedIdMap) (not (eq .PascalName "List")) -}}
{{- $hasIdPrompt := and (not $noPrompt) (and $hasSinglePosArg $serviceHasNamedIdMap) -}} {{- $hasIdPrompt := and (not $noPrompt) (and $hasSinglePosArg $serviceHasNamedIdMap) -}}
{{- $wait := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}} {{- $wait := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}}
{{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}} {{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}}
{{- $hasSingleRequiredRequestBodyFieldWithPrompt := and (and $hasIdPrompt $request) (eq 1 (len $request.RequiredRequestBodyFields)) -}} {{- $hasSingleRequiredRequestBodyFieldWithPrompt := and (and $hasIdPrompt .Request) (eq 1 (len .Request.RequiredRequestBodyFields)) -}}
{{- $onlyPathArgsRequiredAsPositionalArguments := and $request (eq (len .RequiredPositionalArguments) (len $request.RequiredPathFields)) -}} {{- $onlyPathArgsRequiredAsPositionalArguments := and .Request (eq (len .RequiredPositionalArguments) (len .Request.RequiredPathFields)) -}}
{{- $hasDifferentArgsWithJsonFlag := and (not $onlyPathArgsRequiredAsPositionalArguments) (and .CanUseJson (or $request.HasRequiredRequestBodyFields )) -}} {{- $hasDifferentArgsWithJsonFlag := and (not $onlyPathArgsRequiredAsPositionalArguments) (and .CanUseJson .Request.HasRequiredRequestBodyFields) -}}
{{- $hasCustomArgHandler := or $hasRequiredArgs $hasDifferentArgsWithJsonFlag -}} {{- $hasCustomArgHandler := or $hasRequiredArgs $hasDifferentArgsWithJsonFlag -}}
{{- $atleastOneArgumentWithDescription := false -}} {{- $atleastOneArgumentWithDescription := false -}}
@ -214,12 +209,12 @@ func new{{.PascalName}}() *cobra.Command {
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
{{- if $hasDifferentArgsWithJsonFlag }} {{- if $hasDifferentArgsWithJsonFlag }}
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
err := root.ExactArgs({{len $request.RequiredPathFields}})(cmd, args) err := root.ExactArgs({{len .Request.RequiredPathFields}})(cmd, args)
if err != nil { if err != nil {
{{- if eq 0 (len $request.RequiredPathFields) }} {{- if eq 0 (len .Request.RequiredPathFields) }}
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide{{- range $index, $field := $request.RequiredFields}}{{if $index}},{{end}} '{{$field.Name}}'{{end}} in your JSON input") return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide{{- range $index, $field := .Request.RequiredFields}}{{if $index}},{{end}} '{{$field.Name}}'{{end}} in your JSON input")
{{- else }} {{- else }}
return fmt.Errorf("when --json flag is specified, provide only{{- range $index, $field := $request.RequiredPathFields}}{{if $index}},{{end}} {{$field.ConstantName}}{{end}} as positional arguments. Provide{{- range $index, $field := $request.RequiredRequestBodyFields}}{{if $index}},{{end}} '{{$field.Name}}'{{end}} in your JSON input") return fmt.Errorf("when --json flag is specified, provide only{{- range $index, $field := .Request.RequiredPathFields}}{{if $index}},{{end}} {{$field.ConstantName}}{{end}} as positional arguments. Provide{{- range $index, $field := .Request.RequiredRequestBodyFields}}{{if $index}},{{end}} '{{$field.Name}}'{{end}} in your JSON input")
{{- end }} {{- end }}
} }
return nil return nil
@ -259,20 +254,20 @@ func new{{.PascalName}}() *cobra.Command {
{{- if $hasIdPrompt}} {{- if $hasIdPrompt}}
if len(args) == 0 { if len(args) == 0 {
promptSpinner := cmdio.Spinner(ctx) promptSpinner := cmdio.Spinner(ctx)
promptSpinner <- "No{{range $request.RequiredFields}} {{.ConstantName}}{{end}} argument specified. Loading names for {{.Service.TitleName}} drop-down." promptSpinner <- "No{{range .Request.RequiredFields}} {{.ConstantName}}{{end}} argument specified. Loading names for {{.Service.TitleName}} drop-down."
names, err := {{if .Service.IsAccounts}}a{{else}}w{{end}}.{{(.Service.TrimPrefix "account").PascalName}}.{{.Service.List.NamedIdMap.PascalName}}(ctx{{if .Service.List.Request}}, {{.Service.Package.Name}}.{{.Service.List.Request.PascalName}}{}{{end}}) names, err := {{if .Service.IsAccounts}}a{{else}}w{{end}}.{{(.Service.TrimPrefix "account").PascalName}}.{{.Service.List.NamedIdMap.PascalName}}(ctx{{if .Service.List.Request}}, {{.Service.Package.Name}}.{{.Service.List.Request.PascalName}}{}{{end}})
close(promptSpinner) close(promptSpinner)
if err != nil { if err != nil {
return fmt.Errorf("failed to load names for {{.Service.TitleName}} drop-down. Please manually specify required arguments. Original error: %w", err) return fmt.Errorf("failed to load names for {{.Service.TitleName}} drop-down. Please manually specify required arguments. Original error: %w", err)
} }
id, err := cmdio.Select(ctx, names, "{{range $request.RequiredFields}}{{.Summary | trimSuffix "."}}{{end}}") id, err := cmdio.Select(ctx, names, "{{range .Request.RequiredFields}}{{.Summary | trimSuffix "."}}{{end}}")
if err != nil { if err != nil {
return err return err
} }
args = append(args, id) args = append(args, id)
} }
if len(args) != 1 { if len(args) != 1 {
return fmt.Errorf("expected to have {{range $request.RequiredFields}}{{.Summary | trimSuffix "." | lower}}{{end}}") return fmt.Errorf("expected to have {{range .Request.RequiredFields}}{{.Summary | trimSuffix "." | lower}}{{end}}")
} }
{{- end -}} {{- end -}}
@ -396,19 +391,13 @@ func new{{.PascalName}}() *cobra.Command {
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
{{- end }} {{- end }}
{{if not $field.Entity.IsString -}} {{if not $field.Entity.IsString -}}
_, err = fmt.Sscan(args[{{$arg}}], &{{- template "request-body-obj" (dict "Method" $method "Field" $field)}}) _, err = fmt.Sscan(args[{{$arg}}], &{{$method.CamelName}}Req.{{$field.PascalName}})
if err != nil { if err != nil {
return fmt.Errorf("invalid {{$field.ConstantName}}: %s", args[{{$arg}}]) return fmt.Errorf("invalid {{$field.ConstantName}}: %s", args[{{$arg}}])
}{{else -}} }{{else -}}
{{- template "request-body-obj" (dict "Method" $method "Field" $field)}} = args[{{$arg}}] {{$method.CamelName}}Req.{{ if $method.RequestBodyField }}{{$method.RequestBodyField.PascalName}}.{{end}}{{$field.PascalName}} = args[{{$arg}}]
{{- end -}} {{- end -}}
{{- if $optionalIfJsonIsUsed }} {{- if $optionalIfJsonIsUsed }}
} }
{{- end }} {{- end }}
{{- end -}} {{- end -}}
{{- define "request-body-obj" -}}
{{- $method := .Method -}}
{{- $field := .Field -}}
{{$method.CamelName}}Req{{ if (and $method.RequestBodyField (not $field.IsPath)) }}.{{$method.RequestBodyField.PascalName}}{{end}}.{{$field.PascalName}}
{{- end -}}

View File

@ -1,26 +1,5 @@
# Version changelog # Version changelog
## [Release] Release v0.233.0
CLI:
* Clean host URL in the `auth login` command ([#1879](https://github.com/databricks/cli/pull/1879)).
Bundles:
* Fix bundle run when run interactively ([#1880](https://github.com/databricks/cli/pull/1880)).
* Fix relative path resolution for dashboards on Windows ([#1881](https://github.com/databricks/cli/pull/1881)).
Internal:
* Address goreleaser deprecation warning ([#1872](https://github.com/databricks/cli/pull/1872)).
* Update actions/github-script to v7 ([#1873](https://github.com/databricks/cli/pull/1873)).
* Use Go 1.23 ([#1871](https://github.com/databricks/cli/pull/1871)).
* [Internal] Always write message for manual integration test trigger ([#1874](https://github.com/databricks/cli/pull/1874)).
* Add `cmd-exec-id` to user agent ([#1808](https://github.com/databricks/cli/pull/1808)).
* Added E2E test to run Python wheels on interactive cluster created in bundle ([#1864](https://github.com/databricks/cli/pull/1864)).
Dependency updates:
* Bump github.com/hashicorp/terraform-json from 0.22.1 to 0.23.0 ([#1877](https://github.com/databricks/cli/pull/1877)).
## [Release] Release v0.232.1 ## [Release] Release v0.232.1
This patch release fixes the following error observed when deploying to /Shared root folder This patch release fixes the following error observed when deploying to /Shared root folder

View File

@ -163,7 +163,7 @@ func (t *translateContext) translateNoOp(literal, localFullPath, localRelPath, r
} }
func (t *translateContext) retainLocalAbsoluteFilePath(literal, localFullPath, localRelPath, remotePath string) (string, error) { func (t *translateContext) retainLocalAbsoluteFilePath(literal, localFullPath, localRelPath, remotePath string) (string, error) {
info, err := t.b.SyncRoot.Stat(filepath.ToSlash(localRelPath)) info, err := t.b.SyncRoot.Stat(localRelPath)
if errors.Is(err, fs.ErrNotExist) { if errors.Is(err, fs.ErrNotExist) {
return "", fmt.Errorf("file %s not found", literal) return "", fmt.Errorf("file %s not found", literal)
} }

View File

@ -1,54 +0,0 @@
package mutator_test
import (
"context"
"path/filepath"
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/mutator"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/bundle/internal/bundletest"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/vfs"
"github.com/databricks/databricks-sdk-go/service/dashboards"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTranslatePathsDashboards_FilePathRelativeSubDirectory(t *testing.T) {
dir := t.TempDir()
touchEmptyFile(t, filepath.Join(dir, "src", "my_dashboard.lvdash.json"))
b := &bundle.Bundle{
SyncRootPath: dir,
SyncRoot: vfs.MustNew(dir),
Config: config.Root{
Resources: config.Resources{
Dashboards: map[string]*resources.Dashboard{
"dashboard": {
Dashboard: &dashboards.Dashboard{
DisplayName: "My Dashboard",
},
FilePath: "../src/my_dashboard.lvdash.json",
},
},
},
},
}
bundletest.SetLocation(b, "resources.dashboards", []dyn.Location{{
File: filepath.Join(dir, "resources/dashboard.yml"),
}})
diags := bundle.Apply(context.Background(), b, mutator.TranslatePaths())
require.NoError(t, diags.Error())
// Assert that the file path for the dashboard has been converted to its local absolute path.
assert.Equal(
t,
filepath.Join(dir, "src", "my_dashboard.lvdash.json"),
b.Config.Resources.Dashboards["dashboard"].FilePath,
)
}

View File

@ -6,7 +6,6 @@ import (
"os" "os"
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config/mutator"
"github.com/databricks/cli/bundle/phases" "github.com/databricks/cli/bundle/phases"
"github.com/databricks/cli/cmd/bundle/utils" "github.com/databricks/cli/cmd/bundle/utils"
"github.com/databricks/cli/cmd/root" "github.com/databricks/cli/cmd/root"
@ -63,12 +62,7 @@ func newDestroyCommand() *cobra.Command {
diags = bundle.Apply(ctx, b, bundle.Seq( diags = bundle.Apply(ctx, b, bundle.Seq(
phases.Initialize(), phases.Initialize(),
// We need to resolve artifact variable (how we do it in build phase) phases.Build(),
// because some of the to-be-destroyed resource might use this variable.
// Not resolving might lead to terraform "Reference to undeclared resource" error
mutator.ResolveVariableReferences(
"artifacts",
),
phases.Destroy(), phases.Destroy(),
)) ))
if err := diags.Error(); err != nil { if err := diags.Error(); err != nil {

View File

@ -35,23 +35,17 @@ func promptRunArgument(ctx context.Context, b *bundle.Bundle) (string, error) {
return key, nil return key, nil
} }
// resolveRunArgument resolves the resource key to run. func resolveRunArgument(ctx context.Context, b *bundle.Bundle, args []string) (string, error) {
// It returns the remaining arguments to pass to the runner, if applicable.
func resolveRunArgument(ctx context.Context, b *bundle.Bundle, args []string) (string, []string, error) {
// If no arguments are specified, prompt the user to select something to run. // If no arguments are specified, prompt the user to select something to run.
if len(args) == 0 && cmdio.IsPromptSupported(ctx) { if len(args) == 0 && cmdio.IsPromptSupported(ctx) {
key, err := promptRunArgument(ctx, b) return promptRunArgument(ctx, b)
if err != nil {
return "", nil, err
}
return key, args, nil
} }
if len(args) < 1 { if len(args) < 1 {
return "", nil, fmt.Errorf("expected a KEY of the resource to run") return "", fmt.Errorf("expected a KEY of the resource to run")
} }
return args[0], args[1:], nil return args[0], nil
} }
func keyToRunner(b *bundle.Bundle, arg string) (run.Runner, error) { func keyToRunner(b *bundle.Bundle, arg string) (run.Runner, error) {
@ -115,7 +109,7 @@ task or a Python wheel task, the second example applies.
return err return err
} }
key, args, err := resolveRunArgument(ctx, b, args) arg, err := resolveRunArgument(ctx, b, args)
if err != nil { if err != nil {
return err return err
} }
@ -130,13 +124,13 @@ task or a Python wheel task, the second example applies.
return err return err
} }
runner, err := keyToRunner(b, key) runner, err := keyToRunner(b, arg)
if err != nil { if err != nil {
return err return err
} }
// Parse additional positional arguments. // Parse additional positional arguments.
err = runner.ParseArgs(args, &runOptions) err = runner.ParseArgs(args[1:], &runOptions)
if err != nil { if err != nil {
return err return err
} }

View File

@ -78,13 +78,7 @@ func newCreate() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: complex arg: active_deployment // TODO: complex arg: app
// TODO: complex arg: app_status
// TODO: complex arg: compute_status
cmd.Flags().StringVar(&createReq.App.DefaultSourceCodePath, "default-source-code-path", createReq.App.DefaultSourceCodePath, `The default workspace file system path of the source code from which app deployment are created.`)
cmd.Flags().StringVar(&createReq.App.Description, "description", createReq.App.Description, `The description of the app.`)
// TODO: complex arg: pending_deployment
// TODO: array: resources
cmd.Use = "create NAME" cmd.Use = "create NAME"
cmd.Short = `Create an app.` cmd.Short = `Create an app.`
@ -99,13 +93,6 @@ func newCreate() *cobra.Command {
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("json") {
err := root.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
}
check := root.ExactArgs(1) check := root.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -251,25 +238,18 @@ func newDeploy() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().Var(&deployJson, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&deployJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: complex arg: deployment_artifacts // TODO: complex arg: app_deployment
cmd.Flags().StringVar(&deployReq.AppDeployment.DeploymentId, "deployment-id", deployReq.AppDeployment.DeploymentId, `The unique id of the deployment.`)
cmd.Flags().Var(&deployReq.AppDeployment.Mode, "mode", `The mode of which the deployment will manage the source code. Supported values: [AUTO_SYNC, SNAPSHOT]`)
cmd.Flags().StringVar(&deployReq.AppDeployment.SourceCodePath, "source-code-path", deployReq.AppDeployment.SourceCodePath, `The workspace file system path of the source code used to create the app deployment.`)
// TODO: complex arg: status
cmd.Use = "deploy APP_NAME" cmd.Use = "deploy"
cmd.Short = `Create an app deployment.` cmd.Short = `Create an app deployment.`
cmd.Long = `Create an app deployment. cmd.Long = `Create an app deployment.
Creates an app deployment for the app with the supplied name. Creates an app deployment for the app with the supplied name.`
Arguments:
APP_NAME: The name of the app.`
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1) check := root.ExactArgs(0)
return check(cmd, args) return check(cmd, args)
} }
@ -290,7 +270,6 @@ func newDeploy() *cobra.Command {
} }
} }
} }
deployReq.AppName = args[0]
wait, err := w.Apps.Deploy(ctx, deployReq) wait, err := w.Apps.Deploy(ctx, deployReq)
if err != nil { if err != nil {
@ -935,36 +914,22 @@ func newUpdate() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: complex arg: active_deployment // TODO: complex arg: app
// TODO: complex arg: app_status
// TODO: complex arg: compute_status
cmd.Flags().StringVar(&updateReq.App.DefaultSourceCodePath, "default-source-code-path", updateReq.App.DefaultSourceCodePath, `The default workspace file system path of the source code from which app deployment are created.`)
cmd.Flags().StringVar(&updateReq.App.Description, "description", updateReq.App.Description, `The description of the app.`)
// TODO: complex arg: pending_deployment
// TODO: array: resources
cmd.Use = "update NAME NAME" cmd.Use = "update NAME"
cmd.Short = `Update an app.` cmd.Short = `Update an app.`
cmd.Long = `Update an app. cmd.Long = `Update an app.
Updates the app with the supplied name. Updates the app with the supplied name.
Arguments: Arguments:
NAME: The name of the app.
NAME: The name of the app. The name must contain only lowercase alphanumeric NAME: The name of the app. The name must contain only lowercase alphanumeric
characters and hyphens. It must be unique within the workspace.` characters and hyphens. It must be unique within the workspace.`
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("json") { check := root.ExactArgs(1)
err := root.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'name' in your JSON input")
}
return nil
}
check := root.ExactArgs(2)
return check(cmd, args) return check(cmd, args)
} }
@ -985,9 +950,8 @@ func newUpdate() *cobra.Command {
} }
} }
} }
updateReq.Name = args[0]
if !cmd.Flags().Changed("json") { if !cmd.Flags().Changed("json") {
updateReq.App.Name = args[1] updateReq.App.Name = args[0]
} }
response, err := w.Apps.Update(ctx, updateReq) response, err := w.Apps.Update(ctx, updateReq)

View File

@ -76,10 +76,7 @@ func newCreate() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&createReq.Dashboard.DisplayName, "display-name", createReq.Dashboard.DisplayName, `The display name of the dashboard.`) // TODO: complex arg: dashboard
cmd.Flags().Var(&createReq.Dashboard.LifecycleState, "lifecycle-state", `The state of the dashboard resource. Supported values: [ACTIVE, TRASHED]`)
cmd.Flags().StringVar(&createReq.Dashboard.SerializedDashboard, "serialized-dashboard", createReq.Dashboard.SerializedDashboard, `The contents of the dashboard in serialized string form.`)
cmd.Flags().StringVar(&createReq.Dashboard.WarehouseId, "warehouse-id", createReq.Dashboard.WarehouseId, `The warehouse ID used to run the dashboard.`)
cmd.Use = "create" cmd.Use = "create"
cmd.Short = `Create dashboard.` cmd.Short = `Create dashboard.`
@ -150,33 +147,17 @@ func newCreateSchedule() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().Var(&createScheduleJson, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&createScheduleJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&createScheduleReq.Schedule.DisplayName, "display-name", createScheduleReq.Schedule.DisplayName, `The display name for schedule.`) // TODO: complex arg: schedule
cmd.Flags().Var(&createScheduleReq.Schedule.PauseStatus, "pause-status", `The status indicates whether this schedule is paused or not. Supported values: [PAUSED, UNPAUSED]`)
cmd.Use = "create-schedule DASHBOARD_ID" cmd.Use = "create-schedule"
cmd.Short = `Create dashboard schedule.` cmd.Short = `Create dashboard schedule.`
cmd.Long = `Create dashboard schedule. cmd.Long = `Create dashboard schedule.`
Arguments:
DASHBOARD_ID: UUID identifying the dashboard to which the schedule belongs.`
// This command is being previewed; hide from help output. // This command is being previewed; hide from help output.
cmd.Hidden = true cmd.Hidden = true
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("json") {
err := root.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'cron_schedule' in your JSON input")
}
return nil
}
check := root.ExactArgs(1)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) { cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context() ctx := cmd.Context()
@ -194,7 +175,6 @@ func newCreateSchedule() *cobra.Command {
} }
} }
} }
createScheduleReq.DashboardId = args[0]
response, err := w.Lakeview.CreateSchedule(ctx, createScheduleReq) response, err := w.Lakeview.CreateSchedule(ctx, createScheduleReq)
if err != nil { if err != nil {
@ -234,31 +214,17 @@ func newCreateSubscription() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().Var(&createSubscriptionJson, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&createSubscriptionJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Use = "create-subscription DASHBOARD_ID SCHEDULE_ID" // TODO: complex arg: subscription
cmd.Short = `Create schedule subscription.`
cmd.Long = `Create schedule subscription.
Arguments: cmd.Use = "create-subscription"
DASHBOARD_ID: UUID identifying the dashboard to which the subscription belongs. cmd.Short = `Create schedule subscription.`
SCHEDULE_ID: UUID identifying the schedule to which the subscription belongs.` cmd.Long = `Create schedule subscription.`
// This command is being previewed; hide from help output. // This command is being previewed; hide from help output.
cmd.Hidden = true cmd.Hidden = true
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("json") {
err := root.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'subscriber' in your JSON input")
}
return nil
}
check := root.ExactArgs(2)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) { cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context() ctx := cmd.Context()
@ -276,8 +242,6 @@ func newCreateSubscription() *cobra.Command {
} }
} }
} }
createSubscriptionReq.DashboardId = args[0]
createSubscriptionReq.ScheduleId = args[1]
response, err := w.Lakeview.CreateSubscription(ctx, createSubscriptionReq) response, err := w.Lakeview.CreateSubscription(ctx, createSubscriptionReq)
if err != nil { if err != nil {
@ -314,6 +278,8 @@ func newDeleteSchedule() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().StringVar(&deleteScheduleReq.Etag, "etag", deleteScheduleReq.Etag, `The etag for the schedule.`)
cmd.Use = "delete-schedule DASHBOARD_ID SCHEDULE_ID" cmd.Use = "delete-schedule DASHBOARD_ID SCHEDULE_ID"
cmd.Short = `Delete dashboard schedule.` cmd.Short = `Delete dashboard schedule.`
cmd.Long = `Delete dashboard schedule. cmd.Long = `Delete dashboard schedule.
@ -375,6 +341,8 @@ func newDeleteSubscription() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().StringVar(&deleteSubscriptionReq.Etag, "etag", deleteSubscriptionReq.Etag, `The etag for the subscription.`)
cmd.Use = "delete-subscription DASHBOARD_ID SCHEDULE_ID SUBSCRIPTION_ID" cmd.Use = "delete-subscription DASHBOARD_ID SCHEDULE_ID SUBSCRIPTION_ID"
cmd.Short = `Delete schedule subscription.` cmd.Short = `Delete schedule subscription.`
cmd.Long = `Delete schedule subscription. cmd.Long = `Delete schedule subscription.
@ -679,6 +647,7 @@ func newList() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().IntVar(&listReq.PageSize, "page-size", listReq.PageSize, `The number of dashboards to return per page.`) cmd.Flags().IntVar(&listReq.PageSize, "page-size", listReq.PageSize, `The number of dashboards to return per page.`)
cmd.Flags().StringVar(&listReq.PageToken, "page-token", listReq.PageToken, `A page token, received from a previous ListDashboards call.`)
cmd.Flags().BoolVar(&listReq.ShowTrashed, "show-trashed", listReq.ShowTrashed, `The flag to include dashboards located in the trash.`) cmd.Flags().BoolVar(&listReq.ShowTrashed, "show-trashed", listReq.ShowTrashed, `The flag to include dashboards located in the trash.`)
cmd.Flags().Var(&listReq.View, "view", `DASHBOARD_VIEW_BASIConly includes summary metadata from the dashboard. Supported values: [DASHBOARD_VIEW_BASIC]`) cmd.Flags().Var(&listReq.View, "view", `DASHBOARD_VIEW_BASIConly includes summary metadata from the dashboard. Supported values: [DASHBOARD_VIEW_BASIC]`)
@ -731,6 +700,7 @@ func newListSchedules() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().IntVar(&listSchedulesReq.PageSize, "page-size", listSchedulesReq.PageSize, `The number of schedules to return per page.`) cmd.Flags().IntVar(&listSchedulesReq.PageSize, "page-size", listSchedulesReq.PageSize, `The number of schedules to return per page.`)
cmd.Flags().StringVar(&listSchedulesReq.PageToken, "page-token", listSchedulesReq.PageToken, `A page token, received from a previous ListSchedules call.`)
cmd.Use = "list-schedules DASHBOARD_ID" cmd.Use = "list-schedules DASHBOARD_ID"
cmd.Short = `List dashboard schedules.` cmd.Short = `List dashboard schedules.`
@ -789,6 +759,7 @@ func newListSubscriptions() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().IntVar(&listSubscriptionsReq.PageSize, "page-size", listSubscriptionsReq.PageSize, `The number of subscriptions to return per page.`) cmd.Flags().IntVar(&listSubscriptionsReq.PageSize, "page-size", listSubscriptionsReq.PageSize, `The number of subscriptions to return per page.`)
cmd.Flags().StringVar(&listSubscriptionsReq.PageToken, "page-token", listSubscriptionsReq.PageToken, `A page token, received from a previous ListSubscriptions call.`)
cmd.Use = "list-subscriptions DASHBOARD_ID SCHEDULE_ID" cmd.Use = "list-subscriptions DASHBOARD_ID SCHEDULE_ID"
cmd.Short = `List schedule subscriptions.` cmd.Short = `List schedule subscriptions.`
@ -1126,24 +1097,18 @@ func newUpdate() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.Dashboard.DisplayName, "display-name", updateReq.Dashboard.DisplayName, `The display name of the dashboard.`) // TODO: complex arg: dashboard
cmd.Flags().Var(&updateReq.Dashboard.LifecycleState, "lifecycle-state", `The state of the dashboard resource. Supported values: [ACTIVE, TRASHED]`)
cmd.Flags().StringVar(&updateReq.Dashboard.SerializedDashboard, "serialized-dashboard", updateReq.Dashboard.SerializedDashboard, `The contents of the dashboard in serialized string form.`)
cmd.Flags().StringVar(&updateReq.Dashboard.WarehouseId, "warehouse-id", updateReq.Dashboard.WarehouseId, `The warehouse ID used to run the dashboard.`)
cmd.Use = "update DASHBOARD_ID" cmd.Use = "update"
cmd.Short = `Update dashboard.` cmd.Short = `Update dashboard.`
cmd.Long = `Update dashboard. cmd.Long = `Update dashboard.
Update a draft dashboard. Update a draft dashboard.`
Arguments:
DASHBOARD_ID: UUID identifying the dashboard.`
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1) check := root.ExactArgs(0)
return check(cmd, args) return check(cmd, args)
} }
@ -1164,7 +1129,6 @@ func newUpdate() *cobra.Command {
} }
} }
} }
updateReq.DashboardId = args[0]
response, err := w.Lakeview.Update(ctx, updateReq) response, err := w.Lakeview.Update(ctx, updateReq)
if err != nil { if err != nil {
@ -1204,34 +1168,17 @@ func newUpdateSchedule() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().Var(&updateScheduleJson, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&updateScheduleJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateScheduleReq.Schedule.DisplayName, "display-name", updateScheduleReq.Schedule.DisplayName, `The display name for schedule.`) // TODO: complex arg: schedule
cmd.Flags().Var(&updateScheduleReq.Schedule.PauseStatus, "pause-status", `The status indicates whether this schedule is paused or not. Supported values: [PAUSED, UNPAUSED]`)
cmd.Use = "update-schedule DASHBOARD_ID SCHEDULE_ID" cmd.Use = "update-schedule"
cmd.Short = `Update dashboard schedule.` cmd.Short = `Update dashboard schedule.`
cmd.Long = `Update dashboard schedule. cmd.Long = `Update dashboard schedule.`
Arguments:
DASHBOARD_ID: UUID identifying the dashboard to which the schedule belongs.
SCHEDULE_ID: UUID identifying the schedule.`
// This command is being previewed; hide from help output. // This command is being previewed; hide from help output.
cmd.Hidden = true cmd.Hidden = true
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("json") {
err := root.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are required. Provide 'cron_schedule' in your JSON input")
}
return nil
}
check := root.ExactArgs(2)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) { cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context() ctx := cmd.Context()
@ -1249,8 +1196,6 @@ func newUpdateSchedule() *cobra.Command {
} }
} }
} }
updateScheduleReq.DashboardId = args[0]
updateScheduleReq.ScheduleId = args[1]
response, err := w.Lakeview.UpdateSchedule(ctx, updateScheduleReq) response, err := w.Lakeview.UpdateSchedule(ctx, updateScheduleReq)
if err != nil { if err != nil {

View File

@ -66,10 +66,7 @@ func newCreate() *cobra.Command {
// TODO: short flags // TODO: short flags
cmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) cmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&createReq.Table.Name, "name", createReq.Table.Name, `Full three-part (catalog, schema, table) name of the table.`) // TODO: complex arg: table
// TODO: complex arg: spec
// TODO: complex arg: status
cmd.Flags().Var(&createReq.Table.UnityCatalogProvisioningState, "unity-catalog-provisioning-state", `The provisioning state of the online table entity in Unity Catalog. Supported values: [ACTIVE, DELETING, FAILED, PROVISIONING, UPDATING]`)
cmd.Use = "create" cmd.Use = "create"
cmd.Short = `Create an Online Table.` cmd.Short = `Create an Online Table.`

View File

@ -391,6 +391,7 @@ func newUpdate() *cobra.Command {
cmd.Flags().StringVar(&updateReq.Comment, "comment", updateReq.Comment, `User-provided free-form text description.`) cmd.Flags().StringVar(&updateReq.Comment, "comment", updateReq.Comment, `User-provided free-form text description.`)
cmd.Flags().StringVar(&updateReq.NewName, "new-name", updateReq.NewName, `New name for the share.`) cmd.Flags().StringVar(&updateReq.NewName, "new-name", updateReq.NewName, `New name for the share.`)
cmd.Flags().StringVar(&updateReq.Owner, "owner", updateReq.Owner, `Username of current owner of share.`)
cmd.Flags().StringVar(&updateReq.StorageRoot, "storage-root", updateReq.StorageRoot, `Storage root URL for the share.`) cmd.Flags().StringVar(&updateReq.StorageRoot, "storage-root", updateReq.StorageRoot, `Storage root URL for the share.`)
// TODO: array: updates // TODO: array: updates

View File

@ -9,7 +9,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"net" "net"
"net/url"
"strings" "strings"
"time" "time"
@ -144,26 +143,6 @@ func (a *PersistentAuth) Challenge(ctx context.Context) error {
return nil return nil
} }
// This function cleans up the host URL by only retaining the scheme and the host.
// This function thus removes any path, query arguments, or fragments from the URL.
func (a *PersistentAuth) cleanHost() {
parsedHost, err := url.Parse(a.Host)
if err != nil {
return
}
// when either host or scheme is empty, we don't want to clean it. This is because
// the Go url library parses a raw "abc" string as the path of a URL and cleaning
// it will return thus return an empty string.
if parsedHost.Host == "" || parsedHost.Scheme == "" {
return
}
host := url.URL{
Scheme: parsedHost.Scheme,
Host: parsedHost.Host,
}
a.Host = host.String()
}
func (a *PersistentAuth) init(ctx context.Context) error { func (a *PersistentAuth) init(ctx context.Context) error {
if a.Host == "" && a.AccountID == "" { if a.Host == "" && a.AccountID == "" {
return ErrFetchCredentials return ErrFetchCredentials
@ -177,9 +156,6 @@ func (a *PersistentAuth) init(ctx context.Context) error {
if a.browser == nil { if a.browser == nil {
a.browser = browser.OpenURL a.browser = browser.OpenURL
} }
a.cleanHost()
// try acquire listener, which we also use as a machine-local // try acquire listener, which we also use as a machine-local
// exclusive lock to prevent token cache corruption in the scope // exclusive lock to prevent token cache corruption in the scope
// of developer machine, where this command runs. // of developer machine, where this command runs.

View File

@ -228,37 +228,3 @@ func TestChallengeFailed(t *testing.T) {
assert.EqualError(t, err, "authorize: access_denied: Policy evaluation failed for this request") assert.EqualError(t, err, "authorize: access_denied: Policy evaluation failed for this request")
}) })
} }
func TestPersistentAuthCleanHost(t *testing.T) {
for _, tcases := range []struct {
in string
out string
}{
{"https://example.com", "https://example.com"},
{"https://example.com/", "https://example.com"},
{"https://example.com/path", "https://example.com"},
{"https://example.com/path/subpath", "https://example.com"},
{"https://example.com/path?query=1", "https://example.com"},
{"https://example.com/path?query=1&other=2", "https://example.com"},
{"https://example.com/path#fragment", "https://example.com"},
{"https://example.com/path?query=1#fragment", "https://example.com"},
{"https://example.com/path?query=1&other=2#fragment", "https://example.com"},
{"https://example.com/path/subpath?query=1", "https://example.com"},
{"https://example.com/path/subpath?query=1&other=2", "https://example.com"},
{"https://example.com/path/subpath#fragment", "https://example.com"},
{"https://example.com/path/subpath?query=1#fragment", "https://example.com"},
{"https://example.com/path/subpath?query=1&other=2#fragment", "https://example.com"},
{"https://example.com/path?query=1%20value&other=2%20value", "https://example.com"},
{"http://example.com/path/subpath?query=1%20value&other=2%20value", "http://example.com"},
// URLs without scheme should be left as is
{"abc", "abc"},
{"abc.com/def", "abc.com/def"},
} {
p := &PersistentAuth{
Host: tcases.in,
}
p.cleanHost()
assert.Equal(t, tcases.out, p.Host)
}
}