Skip to content

Commit

Permalink
Properly detect Azure China and Azure GovCloud (#331)
Browse files Browse the repository at this point in the history
Needed for databricks/databricks-vscode#544

Tested manually:

Before
```
% DATABRICKS_HOST=https://adb-XXXXX.3.databricks.azure.cn/ DATABRICKS_AUTH_TYPE=azure-cli ../../bricks/bricks sync . /Repos/fabian.jakobs@XXXXX.cn/hackathon-q1-2023.ide --watch
2023/03/09 13:11:39 [INFO] Ignoring server auth, because azure-cli is preferred
2023/03/09 13:11:39 [INFO] Ignoring pat auth, because azure-cli is preferred
2023/03/09 13:11:39 [INFO] Ignoring basic auth, because azure-cli is preferred
2023/03/09 13:11:39 [INFO] Ignoring oauth-m2m auth, because azure-cli is preferred
2023/03/09 13:11:39 [INFO] Ignoring bricks-cli auth, because azure-cli is preferred
2023/03/09 13:11:39 [INFO] Ignoring azure-msi auth, because azure-cli is preferred
2023/03/09 13:11:39 [INFO] Ignoring azure-client-secret auth, because azure-cli is preferred
2023/03/09 13:11:39 [INFO] Ignoring google-credentials auth, because azure-cli is preferred
2023/03/09 13:11:39 [INFO] Ignoring google-id auth, because azure-cli is preferred
Error: default auth: cannot configure default credentials. Config: host=https://adb-XXXXX.3.databricks.azure.cn, bricks_cli_path=../../bricks/bricks. Env: DATABRICKS_HOST, BRICKS_CLI_PATH
```

After
```
% DATABRICKS_HOST=https://adb-XXXXX.3.databricks.azure.cn/ DATABRICKS_AUTH_TYPE=azure-cli ../../bricks/bricks sync . /Repos/fabian.jakobs@XXXXX.cn/hackathon-q1-2023.ide --watch
2023/03/09 13:15:10 [INFO] Ignoring pat auth, because azure-cli is preferred
2023/03/09 13:15:10 [INFO] Ignoring basic auth, because azure-cli is preferred
2023/03/09 13:15:10 [INFO] Ignoring oauth-m2m auth, because azure-cli is preferred
2023/03/09 13:15:10 [INFO] Ignoring bricks-cli auth, because azure-cli is preferred
2023/03/09 13:15:10 [INFO] Ignoring azure-msi auth, because azure-cli is preferred
2023/03/09 13:15:10 [INFO] Ignoring azure-client-secret auth, because azure-cli is preferred
2023/03/09 13:15:10 [INFO] Refreshed OAuth token for XXXXX from Azure CLI, which expires on 2023-03-09 14:08:18.000000
2023/03/09 13:15:10 [INFO] Using Azure CLI authentication with AAD tokens
2023/03/09 13:15:10 [INFO] Refreshed OAuth token for XXXXX from Azure CLI, which expires on 2023-03-09 14:08:18.000000
2023/03/09 13:15:13 [INFO] Initial Sync Complete
```
  • Loading branch information
fjakobs committed Mar 9, 2023
1 parent 049d955 commit df5956f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func (c *Config) Authenticate(r *http.Request) error {

// IsAzure returns true if client is configured for Azure Databricks
func (c *Config) IsAzure() bool {
return strings.Contains(c.Host, ".azuredatabricks.net") || c.AzureResourceID != ""
isAzureHost := strings.Contains(c.Host, ".azuredatabricks.net") ||
strings.Contains(c.Host, "databricks.azure.cn") ||
strings.Contains(c.Host, ".databricks.azure.us")

return isAzureHost || c.AzureResourceID != ""
}

// IsGcp returns true if client is configured for GCP
Expand Down

0 comments on commit df5956f

Please sign in to comment.