Skip to content

Commit 33d18c2

Browse files
authored
[Internal] Add support for workspace_id in profiles command (#4404)
## Changes <!-- Brief summary of your changes that is easy to understand --> - Add support for `workspace_id` in the profiles command ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> VSCode Extension filters out the account hosts after running the CLI profiles command. By adding workspace_id, we would not filter the profiles that have workspace_id set and keep the existing behaviour for filtering out the account hosts. ## Tests <!-- How have you tested the changes? --> - Acceptance tests - Manually ran `$ databricks auth profiles list --output json` on local CLI build over the changes and verify workspace_id is present. - All existing tests passed. <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent aec85f6 commit 33d18c2

File tree

6 files changed

+70
-9
lines changed

6 files changed

+70
-9
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### CLI
88

99
* Add Lakebase Autoscaling support to `psql` command ([#4399](https://github.com/databricks/cli/pull/4399))
10+
* Add `workspace_id` to the profiles command ([#4404](https://github.com/databricks/cli/pull/4404))
1011

1112
### Bundles
1213

acceptance/cmd/auth/profiles/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
=== Profiles with workspace_id (JSON output)
3+
{
4+
"profiles": [
5+
{
6+
"name":"workspace-profile",
7+
"host":"https://test.cloud.databricks.com",
8+
"cloud":"aws",
9+
"auth_type":"",
10+
"valid":false
11+
},
12+
{
13+
"name":"account-profile",
14+
"host":"https://accounts.cloud.databricks.com",
15+
"account_id":"test-account-123",
16+
"cloud":"aws",
17+
"auth_type":"",
18+
"valid":false
19+
},
20+
{
21+
"name":"unified-profile",
22+
"host":"https://unified.databricks.com",
23+
"account_id":"unified-account-456",
24+
"workspace_id":"[NUMID]",
25+
"cloud":"aws",
26+
"auth_type":"",
27+
"valid":false
28+
}
29+
]
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
sethome "./home"
2+
3+
# Create profiles including one with workspace_id
4+
cat > "./home/.databrickscfg" <<EOF
5+
[workspace-profile]
6+
host = https://test.cloud.databricks.com
7+
8+
[account-profile]
9+
host = https://accounts.cloud.databricks.com
10+
account_id = test-account-123
11+
12+
[unified-profile]
13+
host = https://unified.databricks.com
14+
account_id = unified-account-456
15+
workspace_id = 987654321
16+
experimental_is_unified_host = true
17+
EOF
18+
19+
title "Profiles with workspace_id (JSON output)\n"
20+
$CLI auth profiles --skip-validate --output json
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ignore = [
2+
"home"
3+
]

cmd/auth/profiles.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import (
1818
)
1919

2020
type profileMetadata struct {
21-
Name string `json:"name"`
22-
Host string `json:"host,omitempty"`
23-
AccountID string `json:"account_id,omitempty"`
24-
Cloud string `json:"cloud"`
25-
AuthType string `json:"auth_type"`
26-
Valid bool `json:"valid"`
21+
Name string `json:"name"`
22+
Host string `json:"host,omitempty"`
23+
AccountID string `json:"account_id,omitempty"`
24+
WorkspaceID string `json:"workspace_id,omitempty"`
25+
Cloud string `json:"cloud"`
26+
AuthType string `json:"auth_type"`
27+
Valid bool `json:"valid"`
2728
}
2829

2930
func (c *profileMetadata) IsEmpty() bool {
@@ -112,9 +113,10 @@ func newProfilesCommand() *cobra.Command {
112113
for _, v := range iniFile.Sections() {
113114
hash := v.KeysHash()
114115
profile := &profileMetadata{
115-
Name: v.Name(),
116-
Host: hash["host"],
117-
AccountID: hash["account_id"],
116+
Name: v.Name(),
117+
Host: hash["host"],
118+
AccountID: hash["account_id"],
119+
WorkspaceID: hash["workspace_id"],
118120
}
119121
if profile.IsEmpty() {
120122
continue

0 commit comments

Comments
 (0)