diff --git a/acceptance/cmd/bundle/dms-read-only/out.test.toml b/acceptance/cmd/bundle/dms-read-only/out.test.toml index f784a183258..d6187dcb046 100644 --- a/acceptance/cmd/bundle/dms-read-only/out.test.toml +++ b/acceptance/cmd/bundle/dms-read-only/out.test.toml @@ -1,3 +1,3 @@ Local = true Cloud = false -EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] +EnvMatrix.DATABRICKS_BUNDLE_ENGINE = [] diff --git a/acceptance/cmd/bundle/dms-read-only/output.txt b/acceptance/cmd/bundle/dms-read-only/output.txt index 6b702e746e3..0da34d23e7d 100644 --- a/acceptance/cmd/bundle/dms-read-only/output.txt +++ b/acceptance/cmd/bundle/dms-read-only/output.txt @@ -1,5 +1,5 @@ ->>> [CLI] bundle deployment list +>>> [CLI] bundle-deployments list-deployments [ { "display_name": "first deployment", @@ -15,16 +15,21 @@ } ] ->>> [CLI] bundle deployment get deployments/abc +>>> [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 version list deployments/abc +>>> [CLI] bundle-deployments list-versions deployments/abc [ { "cli_version": "[DEV_VERSION]", @@ -34,15 +39,20 @@ } ] ->>> [CLI] bundle version get deployments/abc/versions/v1 +>>> [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 resource list deployments/abc +>>> [CLI] bundle-deployments list-resources deployments/abc [ { "last_action_type": "OPERATION_ACTION_TYPE_CREATE", @@ -53,7 +63,7 @@ } ] ->>> [CLI] bundle resource get deployments/abc/resources/my_job +>>> [CLI] bundle-deployments get-resource deployments/abc/resources/my_job { "last_action_type": "OPERATION_ACTION_TYPE_CREATE", "last_version_id": "v1", @@ -62,7 +72,7 @@ "resource_type": "DEPLOYMENT_RESOURCE_TYPE_JOB" } ->>> [CLI] bundle operation list deployments/abc/versions/v1 +>>> [CLI] bundle-deployments list-operations deployments/abc/versions/v1 [ { "action_type": "OPERATION_ACTION_TYPE_CREATE", @@ -72,7 +82,7 @@ } ] ->>> [CLI] bundle operation get deployments/abc/versions/v1/operations/my_job +>>> [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", diff --git a/acceptance/cmd/bundle/dms-read-only/script b/acceptance/cmd/bundle/dms-read-only/script index 1a39de6a77d..a0fac2ea4e0 100644 --- a/acceptance/cmd/bundle/dms-read-only/script +++ b/acceptance/cmd/bundle/dms-read-only/script @@ -1,8 +1,8 @@ -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 +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 index b7a8cbd5901..f4984b3c5b7 100644 --- a/acceptance/cmd/bundle/dms-read-only/test.toml +++ b/acceptance/cmd/bundle/dms-read-only/test.toml @@ -1,10 +1,24 @@ -# 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-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 = ''' @@ -34,7 +48,12 @@ Response.Body = ''' "display_name": "first deployment", "target_name": "dev", "status": "DEPLOYMENT_STATUS_ACTIVE", - "last_version_id": "v1" + "last_version_id": "v1", + "git_info": { + "branch": "main", + "commit": "b3ceef677c3edbc098de4e38578e008f08dc0df1", + "origin_url": "https://github.com/databricks/cli" + } } ''' @@ -58,7 +77,12 @@ Response.Body = ''' { "name": "deployments/abc/versions/v1", "cli_version": "0.0.0-dev", - "status": "VERSION_STATUS_COMPLETED" + "status": "VERSION_STATUS_COMPLETED", + "git_info": { + "branch": "main", + "commit": "b3ceef677c3edbc098de4e38578e008f08dc0df1", + "origin_url": "https://github.com/databricks/cli" + } } ''' 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