Skip to content

Commit 00bb466

Browse files
authored
Revert "Detect mismatch between host defined in config and env variable (#2549) (#2685)
## Changes This reverts commit 314766a. ## Why In the Web Terminal, the `DATABRICKS_HOST` environment variable is always set to the shard host, which may cause unexpected host mismatch validation errors. Addresses #2672.
1 parent fb31c1a commit 00bb466

File tree

18 files changed

+147
-258
lines changed

18 files changed

+147
-258
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
* Removed pipeline 'deployment' field from jsonschema ([#2653](https://github.com/databricks/cli/pull/2653))
1717
* Updated JSON schema for deprecated pipeline fields ([#2646](https://github.com/databricks/cli/pull/2646))
1818
* The --config-dir and --source-dir flags for "bundle generate app" are now relative to CWD, not bundle root ([#2683](https://github.com/databricks/cli/pull/2683))
19+
* Reverts [#2549](https://github.com/databricks/cli/pull/2549) to resolve issues with Web Terminal host mismatch ([#2685](https://github.com/databricks/cli/pull/2685))
1920

2021
### API Changes

acceptance/auth/bundle_and_env/.databrickscfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

acceptance/auth/bundle_and_env/databricks.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

acceptance/auth/bundle_and_env/output.txt

Lines changed: 0 additions & 35 deletions
This file was deleted.

acceptance/auth/bundle_and_env/script

Lines changed: 0 additions & 15 deletions
This file was deleted.

acceptance/auth/bundle_and_env/test.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.

acceptance/bundle/debug/out.stderr.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
10:07:59 Debug: Apply pid=12345 mutator=<func>
1717
10:07:59 Info: Phase: initialize pid=12345
1818
10:07:59 Debug: Apply pid=12345 mutator=validate:AllResourcesHaveValues
19+
10:07:59 Debug: Apply pid=12345 mutator=validate:interpolation_in_auth_config
1920
10:07:59 Debug: Apply pid=12345 mutator=RewriteSyncPaths
2021
10:07:59 Debug: Apply pid=12345 mutator=SyncDefaultPath
2122
10:07:59 Debug: Apply pid=12345 mutator=SyncInferRoot

acceptance/bundle/variables/host/output.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ Warning: Variable interpolation is not supported for fields that configure authe
77
Interpolation is not supported for the field workspace.host. Please set
88
the DATABRICKS_HOST environment variable if you wish to configure this field at runtime.
99

10-
Error: cannot resolve bundle auth configuration: config host mismatch: DATABRICKS_HOST is defined as [DATABRICKS_URL], but CLI configured to use ${var.host}
10+
Error: failed during request visitor: parse "https://${var.host}": invalid character "{" in host name
1111

1212
{
1313
"bundle": {
1414
"environment": "default",
1515
"name": "host",
1616
"target": "default"
1717
},
18+
"sync": {
19+
"paths": [
20+
"."
21+
]
22+
},
1823
"targets": null,
1924
"variables": {
2025
"host": {
@@ -36,7 +41,7 @@ Warning: Variable interpolation is not supported for fields that configure authe
3641
Interpolation is not supported for the field workspace.host. Please set
3742
the DATABRICKS_HOST environment variable if you wish to configure this field at runtime.
3843

39-
Error: cannot resolve bundle auth configuration: config host mismatch: DATABRICKS_HOST is defined as [DATABRICKS_URL], but CLI configured to use ${var.host}
44+
Error: failed during request visitor: parse "https://${var.host}": invalid character "{" in host name
4045

4146
Name: host
4247
Target: default
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package validate
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/databricks/cli/bundle"
8+
"github.com/databricks/cli/libs/auth"
9+
"github.com/databricks/cli/libs/diag"
10+
"github.com/databricks/cli/libs/dyn"
11+
"github.com/databricks/cli/libs/dyn/dynvar"
12+
)
13+
14+
type noInterpolationInAuthConfig struct{}
15+
16+
func NoInterpolationInAuthConfig() bundle.Mutator {
17+
return &noInterpolationInAuthConfig{}
18+
}
19+
20+
func (f *noInterpolationInAuthConfig) Name() string {
21+
return "validate:interpolation_in_auth_config"
22+
}
23+
24+
func (f *noInterpolationInAuthConfig) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
25+
authFields := []string{
26+
// Generic attributes.
27+
"host",
28+
"profile",
29+
"auth_type",
30+
"metadata_service_url",
31+
32+
// OAuth specific attributes.
33+
"client_id",
34+
35+
// Google specific attributes.
36+
"google_service_account",
37+
38+
// Azure specific attributes.
39+
"azure_resource_id",
40+
"azure_use_msi",
41+
"azure_client_id",
42+
"azure_tenant_id",
43+
"azure_environment",
44+
"azure_login_app_id",
45+
}
46+
47+
diags := diag.Diagnostics{}
48+
49+
for _, fieldName := range authFields {
50+
p := dyn.NewPath(dyn.Key("workspace"), dyn.Key(fieldName))
51+
v, err := dyn.GetByPath(b.Config.Value(), p)
52+
if dyn.IsNoSuchKeyError(err) {
53+
continue
54+
}
55+
if err != nil {
56+
return diag.FromErr(err)
57+
}
58+
59+
vv, ok := v.AsString()
60+
if !ok {
61+
continue
62+
}
63+
64+
// Check if the field contains interpolation.
65+
if dynvar.ContainsVariableReference(vv) {
66+
envVar, ok := auth.GetEnvFor(fieldName)
67+
if !ok {
68+
continue
69+
}
70+
71+
diags = append(diags, diag.Diagnostic{
72+
Severity: diag.Warning,
73+
Summary: "Variable interpolation is not supported for fields that configure authentication",
74+
Detail: fmt.Sprintf(`Interpolation is not supported for the field %s. Please set
75+
the %s environment variable if you wish to configure this field at runtime.`, p.String(), envVar),
76+
Locations: v.Locations(),
77+
Paths: []dyn.Path{p},
78+
})
79+
}
80+
}
81+
82+
return diags
83+
}

bundle/config/workspace.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package config
22

33
import (
4-
"fmt"
54
"os"
65
"path/filepath"
76

87
"github.com/databricks/cli/libs/databrickscfg"
9-
"github.com/databricks/cli/libs/workspace"
108
"github.com/databricks/databricks-sdk-go"
119
"github.com/databricks/databricks-sdk-go/config"
1210
"github.com/databricks/databricks-sdk-go/marshal"
@@ -150,34 +148,9 @@ func (w *Workspace) Client() (*databricks.WorkspaceClient, error) {
150148
}
151149
}
152150

153-
if w.Host != "" && w.Profile == "" {
154-
err := validateConfigAndEnvHost(cfg)
155-
if err != nil {
156-
return nil, err
157-
}
158-
}
159-
160151
return databricks.NewWorkspaceClient((*databricks.Config)(cfg))
161152
}
162153

163-
func validateConfigAndEnvHost(cfg *config.Config) error {
164-
var hostEnvName, hostEnvVal string
165-
for _, attr := range config.ConfigAttributes {
166-
if attr.Name == "host" {
167-
hostEnvVal, hostEnvName = attr.ReadEnv()
168-
break
169-
}
170-
}
171-
if hostEnvName == "" || hostEnvVal == "" {
172-
return nil
173-
}
174-
175-
if !workspace.MatchHost(hostEnvVal, cfg.Host) {
176-
return fmt.Errorf("config host mismatch: %s is defined as %s, but CLI configured to use %s", hostEnvName, hostEnvVal, cfg.Host)
177-
}
178-
return nil
179-
}
180-
181154
func init() {
182155
arg0 := os.Args[0]
183156

0 commit comments

Comments
 (0)