From b3ceef677c3edbc098de4e38578e008f08dc0df1 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 22 Jun 2026 17:55:44 +0200 Subject: [PATCH 1/2] Expose bundle-deployments as a top-level command The auto-generated `bundle-deployments` workspace service (DMS) was filtered out of top-level registration in cmd/cmd.go, and its read-only verbs were re-attached as hidden commands under the DAB `bundle` tree (via cmd/bundle/metadata_service.go). Drop both: register the generated command at the top level like every other workspace service, and remove the hand-wired DMS sub-groups from the `bundle` tree. The generated command is `Hidden: true` in the SDK output, so it resolves (`databricks bundle-deployments ...`) without appearing in `--help`. Removes the dedicated dms-read-only acceptance test, which exercised the now-removed `bundle deployment/version/resource/operation get/list` commands. Co-authored-by: Isaac --- .../cmd/bundle/dms-read-only/out.test.toml | 3 - .../cmd/bundle/dms-read-only/output.txt | 81 ------------ acceptance/cmd/bundle/dms-read-only/script | 8 -- acceptance/cmd/bundle/dms-read-only/test.toml | 117 ------------------ cmd/bundle/bundle.go | 54 +------- cmd/bundle/metadata_service.go | 40 ------ cmd/cmd.go | 7 -- 7 files changed, 1 insertion(+), 309 deletions(-) delete mode 100644 acceptance/cmd/bundle/dms-read-only/out.test.toml delete mode 100644 acceptance/cmd/bundle/dms-read-only/output.txt delete mode 100644 acceptance/cmd/bundle/dms-read-only/script delete mode 100644 acceptance/cmd/bundle/dms-read-only/test.toml delete mode 100644 cmd/bundle/metadata_service.go diff --git a/acceptance/cmd/bundle/dms-read-only/out.test.toml b/acceptance/cmd/bundle/dms-read-only/out.test.toml deleted file mode 100644 index f784a183258..00000000000 --- a/acceptance/cmd/bundle/dms-read-only/out.test.toml +++ /dev/null @@ -1,3 +0,0 @@ -Local = true -Cloud = false -EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] diff --git a/acceptance/cmd/bundle/dms-read-only/output.txt b/acceptance/cmd/bundle/dms-read-only/output.txt deleted file mode 100644 index 6b702e746e3..00000000000 --- a/acceptance/cmd/bundle/dms-read-only/output.txt +++ /dev/null @@ -1,81 +0,0 @@ - ->>> [CLI] bundle deployment list -[ - { - "display_name": "first deployment", - "name": "deployments/abc", - "status": "DEPLOYMENT_STATUS_ACTIVE", - "target_name": "dev" - }, - { - "display_name": "second deployment", - "name": "deployments/def", - "status": "DEPLOYMENT_STATUS_ACTIVE", - "target_name": "prod" - } -] - ->>> [CLI] bundle deployment get deployments/abc -{ - "display_name": "first deployment", - "last_version_id": "v1", - "name": "deployments/abc", - "status": "DEPLOYMENT_STATUS_ACTIVE", - "target_name": "dev" -} - ->>> [CLI] bundle version list deployments/abc -[ - { - "cli_version": "[DEV_VERSION]", - "name": "deployments/abc/versions/v1", - "status": "VERSION_STATUS_COMPLETED", - "version_type": "" - } -] - ->>> [CLI] bundle version get deployments/abc/versions/v1 -{ - "cli_version": "[DEV_VERSION]", - "name": "deployments/abc/versions/v1", - "status": "VERSION_STATUS_COMPLETED", - "version_type": "" -} - ->>> [CLI] bundle resource list deployments/abc -[ - { - "last_action_type": "OPERATION_ACTION_TYPE_CREATE", - "last_version_id": "v1", - "name": "deployments/abc/resources/my_job", - "resource_id": "12345", - "resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB" - } -] - ->>> [CLI] bundle resource get deployments/abc/resources/my_job -{ - "last_action_type": "OPERATION_ACTION_TYPE_CREATE", - "last_version_id": "v1", - "name": "deployments/abc/resources/my_job", - "resource_id": "12345", - "resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB" -} - ->>> [CLI] bundle operation list deployments/abc/versions/v1 -[ - { - "action_type": "OPERATION_ACTION_TYPE_CREATE", - "name": "deployments/abc/versions/v1/operations/my_job", - "resource_id": "12345", - "status": "OPERATION_STATUS_SUCCEEDED" - } -] - ->>> [CLI] bundle operation get deployments/abc/versions/v1/operations/my_job -{ - "action_type": "OPERATION_ACTION_TYPE_CREATE", - "name": "deployments/abc/versions/v1/operations/my_job", - "resource_id": "12345", - "status": "OPERATION_STATUS_SUCCEEDED" -} diff --git a/acceptance/cmd/bundle/dms-read-only/script b/acceptance/cmd/bundle/dms-read-only/script deleted file mode 100644 index 1a39de6a77d..00000000000 --- a/acceptance/cmd/bundle/dms-read-only/script +++ /dev/null @@ -1,8 +0,0 @@ -trace $CLI bundle deployment list -trace $CLI bundle deployment get deployments/abc -trace $CLI bundle version list deployments/abc -trace $CLI bundle version get deployments/abc/versions/v1 -trace $CLI bundle resource list deployments/abc -trace $CLI bundle resource get deployments/abc/resources/my_job -trace $CLI bundle operation list deployments/abc/versions/v1 -trace $CLI bundle operation get deployments/abc/versions/v1/operations/my_job diff --git a/acceptance/cmd/bundle/dms-read-only/test.toml b/acceptance/cmd/bundle/dms-read-only/test.toml deleted file mode 100644 index b7a8cbd5901..00000000000 --- a/acceptance/cmd/bundle/dms-read-only/test.toml +++ /dev/null @@ -1,117 +0,0 @@ -# Local-only acceptance test for the read-only DMS commands under -# `databricks bundle {deployment,version,resource,operation}`. The DMS APIs -# aren't on test workspaces yet, so we stub the eight read endpoints with -# fixed response bodies and assert the CLI renders them as expected. -Local = true -Cloud = false - -[[Server]] -Pattern = "GET /api/2.0/bundle/deployments" -Response.Body = ''' -{ - "deployments": [ - { - "name": "deployments/abc", - "display_name": "first deployment", - "target_name": "dev", - "status": "DEPLOYMENT_STATUS_ACTIVE" - }, - { - "name": "deployments/def", - "display_name": "second deployment", - "target_name": "prod", - "status": "DEPLOYMENT_STATUS_ACTIVE" - } - ] -} -''' - -[[Server]] -Pattern = "GET /api/2.0/bundle/deployments/abc" -Response.Body = ''' -{ - "name": "deployments/abc", - "display_name": "first deployment", - "target_name": "dev", - "status": "DEPLOYMENT_STATUS_ACTIVE", - "last_version_id": "v1" -} -''' - -[[Server]] -Pattern = "GET /api/2.0/bundle/deployments/abc/versions" -Response.Body = ''' -{ - "versions": [ - { - "name": "deployments/abc/versions/v1", - "cli_version": "0.0.0-dev", - "status": "VERSION_STATUS_COMPLETED" - } - ] -} -''' - -[[Server]] -Pattern = "GET /api/2.0/bundle/deployments/abc/versions/v1" -Response.Body = ''' -{ - "name": "deployments/abc/versions/v1", - "cli_version": "0.0.0-dev", - "status": "VERSION_STATUS_COMPLETED" -} -''' - -[[Server]] -Pattern = "GET /api/2.0/bundle/deployments/abc/resources" -Response.Body = ''' -{ - "resources": [ - { - "name": "deployments/abc/resources/my_job", - "resource_id": "12345", - "resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB", - "last_version_id": "v1", - "last_action_type": "OPERATION_ACTION_TYPE_CREATE" - } - ] -} -''' - -[[Server]] -Pattern = "GET /api/2.0/bundle/deployments/abc/resources/my_job" -Response.Body = ''' -{ - "name": "deployments/abc/resources/my_job", - "resource_id": "12345", - "resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB", - "last_version_id": "v1", - "last_action_type": "OPERATION_ACTION_TYPE_CREATE" -} -''' - -[[Server]] -Pattern = "GET /api/2.0/bundle/deployments/abc/versions/v1/operations" -Response.Body = ''' -{ - "operations": [ - { - "name": "deployments/abc/versions/v1/operations/my_job", - "action_type": "OPERATION_ACTION_TYPE_CREATE", - "resource_id": "12345", - "status": "OPERATION_STATUS_SUCCEEDED" - } - ] -} -''' - -[[Server]] -Pattern = "GET /api/2.0/bundle/deployments/abc/versions/v1/operations/my_job" -Response.Body = ''' -{ - "name": "deployments/abc/versions/v1/operations/my_job", - "action_type": "OPERATION_ACTION_TYPE_CREATE", - "resource_id": "12345", - "status": "OPERATION_STATUS_SUCCEEDED" -} -''' diff --git a/cmd/bundle/bundle.go b/cmd/bundle/bundle.go index 7189b1d431d..d8334d38289 100644 --- a/cmd/bundle/bundle.go +++ b/cmd/bundle/bundle.go @@ -36,62 +36,10 @@ Online documentation: https://docs.databricks.com/en/dev-tools/bundles/index.htm cmd.AddCommand(newSummaryCommand()) cmd.AddCommand(newGenerateCommand()) cmd.AddCommand(newDebugCommand()) + cmd.AddCommand(deployment.NewDeploymentCommand()) cmd.AddCommand(newOpenCommand()) cmd.AddCommand(newPlanCommand()) cmd.AddCommand(newConfigRemoteSyncCommand()) - // Bundle Metadata Service (DMS) read-only command groups. Only `get` - // and `list` are surfaced here; mutating verbs (create/delete/heartbeat/ - // complete) are not user-facing yet and stay in the auto-generated - // `cmd/workspace/bundle` tree (which is filtered out of top-level - // registration in cmd/cmd.go). - // - // Hide everything from help output for now: the DMS API surface isn't - // documented as a user-facing CLI feature yet. Commands still route - // through cobra so callers who know about them can invoke them; they - // just don't show up in `bundle --help` / `bundle --help`. - dms := metadataServiceCommands() - for _, c := range dms { - c.Hidden = true - } - - // The DAB `deployment` group already exists for bind/unbind/migrate. - // Augment it additively with the (hidden) DMS read-side verbs. - deploymentCmd := deployment.NewDeploymentCommand() - deploymentCmd.AddCommand(renameTo(dms["get-deployment"], "get")) - deploymentCmd.AddCommand(renameTo(dms["list-deployments"], "list")) - cmd.AddCommand(deploymentCmd) - - // The three new groups are hidden too; cobra hides a parent when all - // of its children are hidden, but we set the flag explicitly so the - // group disappears from `bundle --help` even if a future child is - // added without the hide flag. - versionCmd := &cobra.Command{ - Use: "version", - Short: "Read version records in the bundle metadata service.", - Hidden: true, - } - versionCmd.AddCommand(renameTo(dms["get-version"], "get")) - versionCmd.AddCommand(renameTo(dms["list-versions"], "list")) - cmd.AddCommand(versionCmd) - - resourceCmd := &cobra.Command{ - Use: "resource", - Short: "Read resource records from the bundle metadata service.", - Hidden: true, - } - resourceCmd.AddCommand(renameTo(dms["get-resource"], "get")) - resourceCmd.AddCommand(renameTo(dms["list-resources"], "list")) - cmd.AddCommand(resourceCmd) - - operationCmd := &cobra.Command{ - Use: "operation", - Short: "Read operation records in the bundle metadata service.", - Hidden: true, - } - operationCmd.AddCommand(renameTo(dms["get-operation"], "get")) - operationCmd.AddCommand(renameTo(dms["list-operations"], "list")) - cmd.AddCommand(operationCmd) - return cmd } diff --git a/cmd/bundle/metadata_service.go b/cmd/bundle/metadata_service.go deleted file mode 100644 index 6221d082ffe..00000000000 --- a/cmd/bundle/metadata_service.go +++ /dev/null @@ -1,40 +0,0 @@ -package bundle - -import ( - "strings" - - workspacebundle "github.com/databricks/cli/cmd/workspace/bundle-deployments" - "github.com/spf13/cobra" -) - -// metadataServiceCommands returns the auto-generated workspace bundle service -// commands keyed by their original cobra Name (e.g. "get-deployment"). -// -// The auto-generated `databricks bundle ` namespace collides with the -// DAB `bundle` command tree; cmd/cmd.go filters the workspace bundle root out -// of top-level registration. Here we call into the workspace package once, -// detach each subcommand from its (discarded) parent, and let the DAB bundle -// re-attach them under proper sub-groups with shorter names. -func metadataServiceCommands() map[string]*cobra.Command { - ws := workspacebundle.New() - subs := ws.Commands() - out := make(map[string]*cobra.Command, len(subs)) - for _, sub := range subs { - ws.RemoveCommand(sub) - out[sub.Name()] = sub - } - return out -} - -// renameTo replaces the first whitespace-separated token of cobra's Use field -// with newName, preserving the trailing positional-arg syntax that cobra renders -// in usage strings (e.g. "get-deployment NAME" -> "get NAME"). Returns the -// command for inline chaining. -func renameTo(c *cobra.Command, newName string) *cobra.Command { - rest := "" - if i := strings.IndexByte(c.Use, ' '); i >= 0 { - rest = c.Use[i:] - } - c.Use = newName + rest - return c -} diff --git a/cmd/cmd.go b/cmd/cmd.go index 718d3a8fda3..a2c3280b940 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -68,13 +68,6 @@ func New(ctx context.Context) *cobra.Command { // Add workspace subcommands. workspaceCommands := workspace.All() for _, cmd := range workspaceCommands { - // The auto-generated `bundle-deployments` workspace service (DMS) is - // surfaced under the DAB `bundle` command tree (cmd/bundle). Skip the - // generated top-level command; callers still have `databricks api ...` - // for the DMS endpoints. - if cmd.Name() == "bundle-deployments" { - continue - } // Order the permissions subcommands after the main commands. for _, sub := range cmd.Commands() { // some commands override groups in overrides.go, leave them as-is From e3cfea39f5770fc3efbc6a73a5a8501450143494 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 24 Jun 2026 11:07:11 +0200 Subject: [PATCH 2/2] acc: update dms-read-only test to use the generated command The unskip change removes the hidden `bundle get/list` aliases, so point the existing dms-read-only acceptance test at the generated top-level command (`databricks bundle-deployments `) instead of deleting it. The deployment/version stubs now carry git_info so the test asserts the field round-trips through the generated command. Opts out of the DATABRICKS_BUNDLE_ENGINE matrix since this is a workspace-service command independent of the deploy engine. Co-authored-by: Isaac --- .../cmd/bundle/dms-read-only/out.test.toml | 3 + .../cmd/bundle/dms-read-only/output.txt | 91 +++++++++++ acceptance/cmd/bundle/dms-read-only/script | 8 + acceptance/cmd/bundle/dms-read-only/test.toml | 141 ++++++++++++++++++ 4 files changed, 243 insertions(+) create mode 100644 acceptance/cmd/bundle/dms-read-only/out.test.toml create mode 100644 acceptance/cmd/bundle/dms-read-only/output.txt create mode 100644 acceptance/cmd/bundle/dms-read-only/script create mode 100644 acceptance/cmd/bundle/dms-read-only/test.toml diff --git a/acceptance/cmd/bundle/dms-read-only/out.test.toml b/acceptance/cmd/bundle/dms-read-only/out.test.toml new file mode 100644 index 00000000000..d6187dcb046 --- /dev/null +++ b/acceptance/cmd/bundle/dms-read-only/out.test.toml @@ -0,0 +1,3 @@ +Local = true +Cloud = false +EnvMatrix.DATABRICKS_BUNDLE_ENGINE = [] diff --git a/acceptance/cmd/bundle/dms-read-only/output.txt b/acceptance/cmd/bundle/dms-read-only/output.txt new file mode 100644 index 00000000000..0da34d23e7d --- /dev/null +++ b/acceptance/cmd/bundle/dms-read-only/output.txt @@ -0,0 +1,91 @@ + +>>> [CLI] bundle-deployments list-deployments +[ + { + "display_name": "first deployment", + "name": "deployments/abc", + "status": "DEPLOYMENT_STATUS_ACTIVE", + "target_name": "dev" + }, + { + "display_name": "second deployment", + "name": "deployments/def", + "status": "DEPLOYMENT_STATUS_ACTIVE", + "target_name": "prod" + } +] + +>>> [CLI] bundle-deployments get-deployment deployments/abc +{ + "display_name": "first deployment", + "git_info": { + "branch": "main", + "commit": "[COMMIT_SHA]", + "origin_url": "https://github.com/databricks/cli" + }, + "last_version_id": "v1", + "name": "deployments/abc", + "status": "DEPLOYMENT_STATUS_ACTIVE", + "target_name": "dev" +} + +>>> [CLI] bundle-deployments list-versions deployments/abc +[ + { + "cli_version": "[DEV_VERSION]", + "name": "deployments/abc/versions/v1", + "status": "VERSION_STATUS_COMPLETED", + "version_type": "" + } +] + +>>> [CLI] bundle-deployments get-version deployments/abc/versions/v1 +{ + "cli_version": "[DEV_VERSION]", + "git_info": { + "branch": "main", + "commit": "[COMMIT_SHA]", + "origin_url": "https://github.com/databricks/cli" + }, + "name": "deployments/abc/versions/v1", + "status": "VERSION_STATUS_COMPLETED", + "version_type": "" +} + +>>> [CLI] bundle-deployments list-resources deployments/abc +[ + { + "last_action_type": "OPERATION_ACTION_TYPE_CREATE", + "last_version_id": "v1", + "name": "deployments/abc/resources/my_job", + "resource_id": "12345", + "resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB" + } +] + +>>> [CLI] bundle-deployments get-resource deployments/abc/resources/my_job +{ + "last_action_type": "OPERATION_ACTION_TYPE_CREATE", + "last_version_id": "v1", + "name": "deployments/abc/resources/my_job", + "resource_id": "12345", + "resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB" +} + +>>> [CLI] bundle-deployments list-operations deployments/abc/versions/v1 +[ + { + "action_type": "OPERATION_ACTION_TYPE_CREATE", + "name": "deployments/abc/versions/v1/operations/my_job", + "resource_id": "12345", + "status": "OPERATION_STATUS_SUCCEEDED" + } +] + +>>> [CLI] bundle-deployments get-operation deployments/abc/versions/v1/operations/my_job +{ + "action_type": "OPERATION_ACTION_TYPE_CREATE", + "name": "deployments/abc/versions/v1/operations/my_job", + "resource_id": "12345", + "status": "OPERATION_STATUS_SUCCEEDED" +} diff --git a/acceptance/cmd/bundle/dms-read-only/script b/acceptance/cmd/bundle/dms-read-only/script new file mode 100644 index 00000000000..a0fac2ea4e0 --- /dev/null +++ b/acceptance/cmd/bundle/dms-read-only/script @@ -0,0 +1,8 @@ +trace $CLI bundle-deployments list-deployments +trace $CLI bundle-deployments get-deployment deployments/abc +trace $CLI bundle-deployments list-versions deployments/abc +trace $CLI bundle-deployments get-version deployments/abc/versions/v1 +trace $CLI bundle-deployments list-resources deployments/abc +trace $CLI bundle-deployments get-resource deployments/abc/resources/my_job +trace $CLI bundle-deployments list-operations deployments/abc/versions/v1 +trace $CLI bundle-deployments get-operation deployments/abc/versions/v1/operations/my_job diff --git a/acceptance/cmd/bundle/dms-read-only/test.toml b/acceptance/cmd/bundle/dms-read-only/test.toml new file mode 100644 index 00000000000..f4984b3c5b7 --- /dev/null +++ b/acceptance/cmd/bundle/dms-read-only/test.toml @@ -0,0 +1,141 @@ +# Local-only acceptance test for the read-only verbs of the auto-generated +# `databricks bundle-deployments` command (DMS). The DMS APIs aren't on test +# workspaces yet, so we stub the eight read endpoints with fixed response +# bodies and assert the generated command renders them as expected. +# +# The deployment/version stubs include git_info: it is the field of interest +# for this service and is silently dropped by older CLI releases whose SDK +# model predates it, so we assert it round-trips through the generated command. +Local = true +Cloud = false + +# bundle-deployments is a workspace-service command independent of the bundle +# deploy engine, so opt out of the inherited terraform/direct matrix. +EnvMatrix.DATABRICKS_BUNDLE_ENGINE = [] + +# Normalize the git commit SHA so the golden output isn't tied to a specific +# commit value. +[[Repls]] +Old = '\b[0-9a-f]{40}\b' +New = '[COMMIT_SHA]' + +[[Server]] +Pattern = "GET /api/2.0/bundle/deployments" +Response.Body = ''' +{ + "deployments": [ + { + "name": "deployments/abc", + "display_name": "first deployment", + "target_name": "dev", + "status": "DEPLOYMENT_STATUS_ACTIVE" + }, + { + "name": "deployments/def", + "display_name": "second deployment", + "target_name": "prod", + "status": "DEPLOYMENT_STATUS_ACTIVE" + } + ] +} +''' + +[[Server]] +Pattern = "GET /api/2.0/bundle/deployments/abc" +Response.Body = ''' +{ + "name": "deployments/abc", + "display_name": "first deployment", + "target_name": "dev", + "status": "DEPLOYMENT_STATUS_ACTIVE", + "last_version_id": "v1", + "git_info": { + "branch": "main", + "commit": "b3ceef677c3edbc098de4e38578e008f08dc0df1", + "origin_url": "https://github.com/databricks/cli" + } +} +''' + +[[Server]] +Pattern = "GET /api/2.0/bundle/deployments/abc/versions" +Response.Body = ''' +{ + "versions": [ + { + "name": "deployments/abc/versions/v1", + "cli_version": "0.0.0-dev", + "status": "VERSION_STATUS_COMPLETED" + } + ] +} +''' + +[[Server]] +Pattern = "GET /api/2.0/bundle/deployments/abc/versions/v1" +Response.Body = ''' +{ + "name": "deployments/abc/versions/v1", + "cli_version": "0.0.0-dev", + "status": "VERSION_STATUS_COMPLETED", + "git_info": { + "branch": "main", + "commit": "b3ceef677c3edbc098de4e38578e008f08dc0df1", + "origin_url": "https://github.com/databricks/cli" + } +} +''' + +[[Server]] +Pattern = "GET /api/2.0/bundle/deployments/abc/resources" +Response.Body = ''' +{ + "resources": [ + { + "name": "deployments/abc/resources/my_job", + "resource_id": "12345", + "resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB", + "last_version_id": "v1", + "last_action_type": "OPERATION_ACTION_TYPE_CREATE" + } + ] +} +''' + +[[Server]] +Pattern = "GET /api/2.0/bundle/deployments/abc/resources/my_job" +Response.Body = ''' +{ + "name": "deployments/abc/resources/my_job", + "resource_id": "12345", + "resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB", + "last_version_id": "v1", + "last_action_type": "OPERATION_ACTION_TYPE_CREATE" +} +''' + +[[Server]] +Pattern = "GET /api/2.0/bundle/deployments/abc/versions/v1/operations" +Response.Body = ''' +{ + "operations": [ + { + "name": "deployments/abc/versions/v1/operations/my_job", + "action_type": "OPERATION_ACTION_TYPE_CREATE", + "resource_id": "12345", + "status": "OPERATION_STATUS_SUCCEEDED" + } + ] +} +''' + +[[Server]] +Pattern = "GET /api/2.0/bundle/deployments/abc/versions/v1/operations/my_job" +Response.Body = ''' +{ + "name": "deployments/abc/versions/v1/operations/my_job", + "action_type": "OPERATION_ACTION_TYPE_CREATE", + "resource_id": "12345", + "status": "OPERATION_STATUS_SUCCEEDED" +} +'''