Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/postgres-resource-urls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add workspace URLs for Postgres projects, branches, endpoints, and roles. ([#6567](https://github.com/databricks/cli/pull/6567))
2 changes: 1 addition & 1 deletion acceptance/bundle/deployment/bind/postgres_role/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Resources:
Postgres roles:
role1:
Name:
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-project/branches/main/roles-and-databases?w=[NUMID]

>>> [CLI] bundle deployment unbind role1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ Resources:
Postgres branches:
main:
Name:
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]/branches/main
Postgres projects:
my_project:
Name: Test Project for Branch
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]

>>> print_requests.py --del-body project_id,branch_id,endpoint_id,database_id,role_id,catalog_id,synced_table_id --keep --get //postgres ^//workspace-files/ ^//workspace/ ^//telemetry-ext ^//operations/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Resources:
Postgres projects:
my_project:
Name: Test Project for Catalog
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]

>>> print_requests.py --del-body project_id,branch_id,endpoint_id,database_id,role_id,catalog_id,synced_table_id --keep --get //postgres ^//workspace-files/ ^//workspace/ ^//telemetry-ext ^//operations/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ Resources:
Postgres branches:
main:
Name:
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]/branches/main?w=[NUMID]
Postgres databases:
my_database:
Name:
URL: (not deployed)
Postgres projects:
my_project:
Name: Test Project for Database
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]?w=[NUMID]
Postgres roles:
owner:
Name:
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles-and-databases?w=[NUMID]

>>> print_requests.py --del-body project_id,branch_id,endpoint_id,database_id,role_id,catalog_id,synced_table_id --keep --get //postgres ^//workspace-files/ ^//workspace/ ^//telemetry-ext ^//operations/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ Resources:
Postgres branches:
main:
Name:
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]/branches/main
Postgres endpoints:
custom:
Name:
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/computes
Postgres projects:
my_project:
Name: Test Project for Endpoint
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]

>>> print_requests.py --del-body project_id,branch_id,endpoint_id,database_id,role_id,catalog_id,synced_table_id --keep --get //postgres ^//workspace-files/ ^//workspace/ ^//telemetry-ext ^//operations/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Resources:
Postgres projects:
my_project:
Name: Test Postgres Project
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]

>>> print_requests.py --del-body project_id,branch_id,endpoint_id,database_id,role_id,catalog_id,synced_table_id --keep --get //postgres ^//workspace-files/ ^//workspace/ ^//telemetry-ext ^//operations/

Expand Down
6 changes: 3 additions & 3 deletions acceptance/bundle/resources/postgres_roles/basic/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ Resources:
Postgres branches:
main:
Name:
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]/branches/main?w=[NUMID]
Postgres projects:
my_project:
Name: Test Project for Role
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]?w=[NUMID]
Postgres roles:
my_role:
Name:
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles-and-databases?w=[NUMID]

>>> print_requests.py --del-body project_id,branch_id,endpoint_id,database_id,role_id,catalog_id,synced_table_id --keep --get //postgres ^//workspace-files/ ^//workspace/ ^//telemetry-ext ^//operations/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Resources:
Postgres projects:
my_project:
Name: Test Project for Synced Table
URL: (not deployed)
URL: [DATABRICKS_URL]/lakebase/projects/test-pg-proj-[UNIQUE_NAME]
Postgres synced tables:
my_table:
Name: lakebase_test_[UNIQUE_NAME].public.trips_synced
Expand Down
6 changes: 5 additions & 1 deletion acceptance/experimental/open/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

=== unknown resource type
>>> [CLI] experimental open --url unknown 123
Error: unknown resource type "unknown", must be one of: alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, genie_spaces, instance_pools, jobs, model_serving_endpoints, models, notebooks, pipelines, postgres_catalogs, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses
Error: unknown resource type "unknown", must be one of: alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, genie_spaces, instance_pools, jobs, model_serving_endpoints, models, notebooks, pipelines, postgres_branches, postgres_catalogs, postgres_endpoints, postgres_projects, postgres_roles, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses

=== test auto-completion handler
>>> [CLI] __complete experimental open ,
Expand All @@ -29,7 +29,11 @@ model_serving_endpoints
models
notebooks
pipelines
postgres_branches
postgres_catalogs
postgres_endpoints
postgres_projects
postgres_roles
postgres_synced_tables
quality_monitors
queries
Expand Down
24 changes: 24 additions & 0 deletions bundle/config/mutator/initialize_urls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ func TestInitializeURLs(t *testing.T) {
},
},
},
PostgresProjects: map[string]*resources.PostgresProject{
"project1": {
BaseResource: resources.BaseResource{ID: "projects/myproject"},
},
},
PostgresBranches: map[string]*resources.PostgresBranch{
"branch1": {
BaseResource: resources.BaseResource{ID: "projects/myproject/branches/main"},
},
},
PostgresEndpoints: map[string]*resources.PostgresEndpoint{
"endpoint1": {
BaseResource: resources.BaseResource{ID: "projects/myproject/branches/main/endpoints/primary"},
},
},
PostgresRoles: map[string]*resources.PostgresRole{
"role1": {
BaseResource: resources.BaseResource{ID: "projects/myproject/branches/main/roles/admin"},
},
},
},
},
}
Expand All @@ -117,6 +137,10 @@ func TestInitializeURLs(t *testing.T) {
"schema1": "https://mycompany.databricks.com/explore/data/catalog/schema?w=123456",
"cluster1": "https://mycompany.databricks.com/compute/clusters/1017-103929-vlr7jzcf?w=123456",
"dashboard1": "https://mycompany.databricks.com/dashboardsv3/01ef8d56871e1d50ae30ce7375e42478/published?w=123456",
"project1": "https://mycompany.databricks.com/lakebase/projects/myproject?w=123456",
"branch1": "https://mycompany.databricks.com/lakebase/projects/myproject/branches/main?w=123456",
"endpoint1": "https://mycompany.databricks.com/lakebase/projects/myproject/branches/main/computes?w=123456",
"role1": "https://mycompany.databricks.com/lakebase/projects/myproject/branches/main/roles-and-databases?w=123456",
}

err := initializeForWorkspace(b, "123456", "https://mycompany.databricks.com/")
Expand Down
13 changes: 9 additions & 4 deletions bundle/config/resources/postgres_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/url"

"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/workspaceurls"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
"github.com/databricks/databricks-sdk-go/service/postgres"
Expand Down Expand Up @@ -83,10 +84,14 @@ func (b *PostgresBranch) GetName() string {
}

func (b *PostgresBranch) GetURL() string {
// The IDs in the API do not (yet) map to IDs in the web UI.
return ""
return b.URL
}

func (b *PostgresBranch) InitializeURL(_ url.URL) {
// The IDs in the API do not (yet) map to IDs in the web UI.
// InitializeURL points at the branch's Lakebase page. ID is the branch's
// hierarchical name "projects/{project_id}/branches/{branch_id}".
func (b *PostgresBranch) InitializeURL(baseURL url.URL) {
if b.ID == "" {
return
}
b.URL = workspaceurls.ResourceURL(baseURL, "postgres_branches", b.ID)
}
17 changes: 13 additions & 4 deletions bundle/config/resources/postgres_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package resources
import (
"context"
"net/url"
"strings"

"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/workspaceurls"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
"github.com/databricks/databricks-sdk-go/service/postgres"
Expand Down Expand Up @@ -71,10 +73,17 @@ func (e *PostgresEndpoint) GetName() string {
}

func (e *PostgresEndpoint) GetURL() string {
// The IDs in the API do not (yet) map to IDs in the web UI.
return ""
return e.URL
}

func (e *PostgresEndpoint) InitializeURL(_ url.URL) {
// The IDs in the API do not (yet) map to IDs in the web UI.
// InitializeURL points at the parent branch's computes page, where endpoints
// surface. The branch is derived from this endpoint's resolved ID
// ("projects/{project_id}/branches/{branch_id}/endpoints/{endpoint_id}") rather
// than from Parent, which may still hold an unresolved "${...}" reference.
func (e *PostgresEndpoint) InitializeURL(baseURL url.URL) {
branch, _, ok := strings.Cut(e.ID, "/endpoints/")
if !ok {
return
}
e.URL = workspaceurls.ResourceURL(baseURL, "postgres_endpoints", branch)
}
13 changes: 9 additions & 4 deletions bundle/config/resources/postgres_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/url"

"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/workspaceurls"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
"github.com/databricks/databricks-sdk-go/service/postgres"
Expand Down Expand Up @@ -76,10 +77,14 @@ func (p *PostgresProject) GetName() string {
}

func (p *PostgresProject) GetURL() string {
// The IDs in the API do not (yet) map to IDs in the web UI.
return ""
return p.URL
}

func (p *PostgresProject) InitializeURL(_ url.URL) {
// The IDs in the API do not (yet) map to IDs in the web UI.
// InitializeURL points at the project's Lakebase page. ID is the project's
// hierarchical name "projects/{project_id}".
func (p *PostgresProject) InitializeURL(baseURL url.URL) {
if p.ID == "" {
return
}
p.URL = workspaceurls.ResourceURL(baseURL, "postgres_projects", p.ID)
}
17 changes: 13 additions & 4 deletions bundle/config/resources/postgres_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package resources
import (
"context"
"net/url"
"strings"

"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/workspaceurls"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/databricks-sdk-go/marshal"
Expand Down Expand Up @@ -76,10 +78,17 @@ func (r *PostgresRole) GetName() string {
}

func (r *PostgresRole) GetURL() string {
// The IDs in the API do not (yet) map to IDs in the web UI.
return ""
return r.URL
}

func (r *PostgresRole) InitializeURL(_ url.URL) {
// The IDs in the API do not (yet) map to IDs in the web UI.
// InitializeURL points at the parent branch's roles-and-databases page, where
// roles surface. The branch is derived from this role's resolved ID
// ("projects/{project_id}/branches/{branch_id}/roles/{role_id}") rather than
// from Parent, which may still hold an unresolved "${...}" reference.
func (r *PostgresRole) InitializeURL(baseURL url.URL) {
branch, _, ok := strings.Cut(r.ID, "/roles/")
if !ok {
return
}
r.URL = workspaceurls.ResourceURL(baseURL, "postgres_roles", branch)
}
4 changes: 0 additions & 4 deletions bundle/config/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ func TestBundleResourcePluralNamesResolveInWorkspaceURLs(t *testing.T) {
// (job + run) so it can't be expressed as a single-ID pattern here; it's
// built in JobRun.InitializeURL via workspaceurls.JobRunURL instead.
"job_runs": true,
"postgres_branches": true,
"postgres_databases": true,
"postgres_endpoints": true,
"postgres_projects": true,
"postgres_roles": true,
"secret_scopes": true,
}

Expand Down
8 changes: 6 additions & 2 deletions cmd/experimental/workspace_open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestBuildWorkspaceURLFragmentBasedResources(t *testing.T) {
func TestBuildWorkspaceURLUnknownResourceType(t *testing.T) {
_, err := workspaceurls.BuildResourceURL("https://myworkspace.databricks.com", "unknown", "123", "")
assert.ErrorContains(t, err, "unknown resource type \"unknown\"")
assert.ErrorContains(t, err, "alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, genie_spaces, instance_pools, jobs, model_serving_endpoints, models, notebooks, pipelines, postgres_catalogs, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses")
assert.ErrorContains(t, err, "alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, genie_spaces, instance_pools, jobs, model_serving_endpoints, models, notebooks, pipelines, postgres_branches, postgres_catalogs, postgres_endpoints, postgres_projects, postgres_roles, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses")
}

func TestBuildWorkspaceURLHostWithTrailingSlash(t *testing.T) {
Expand Down Expand Up @@ -123,7 +123,11 @@ func TestWorkspaceOpenCommandCompletion(t *testing.T) {
"models",
"notebooks",
"pipelines",
"postgres_branches",
"postgres_catalogs",
"postgres_endpoints",
"postgres_projects",
"postgres_roles",
"postgres_synced_tables",
"quality_monitors",
"queries",
Expand All @@ -149,7 +153,7 @@ func TestWorkspaceOpenCommandCompletionSecondArg(t *testing.T) {
func TestWorkspaceOpenCommandHelpText(t *testing.T) {
cmd := newWorkspaceOpenCommand()

assert.Contains(t, cmd.Long, "Supported resource types: alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, genie_spaces, instance_pools, jobs, model_serving_endpoints, models, notebooks, pipelines, postgres_catalogs, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses.")
assert.Contains(t, cmd.Long, "Supported resource types: alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, genie_spaces, instance_pools, jobs, model_serving_endpoints, models, notebooks, pipelines, postgres_branches, postgres_catalogs, postgres_endpoints, postgres_projects, postgres_roles, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses.")
assert.Contains(t, cmd.Long, "databricks experimental open jobs 123456789")
assert.Contains(t, cmd.Long, "databricks experimental open notebooks /Users/user@example.com/my-notebook")
assert.Contains(t, cmd.Long, "databricks experimental open registered_models catalog.schema.my_model")
Expand Down
4 changes: 4 additions & 0 deletions libs/workspaceurls/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ var resourceURLPatterns = map[string]string{
"model_serving_endpoints": "ml/endpoints/%s",
"notebooks": "#notebook/%s",
"pipelines": "pipelines/%s",
"postgres_branches": "lakebase/%s",
"postgres_catalogs": "explore/data/%s",
"postgres_endpoints": "lakebase/%s/computes",
"postgres_projects": "lakebase/%s",
"postgres_roles": "lakebase/%s/roles-and-databases",
"postgres_synced_tables": "explore/data/%s",
"quality_monitors": "explore/data/%s",
"queries": "sql/editor/%s",
Expand Down
Loading