-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set necessary headers when authenticating via Azure CLI (#290)
## Changes The Python SDK request authentication logic is inconsistent between the Azure login types: for service principal auth, the SDK correctly adds the X-Databricks-Azure-Workspace-Resource-Id when configured, but this is missed for Azure CLI auth. This PR fixes this by defining the logic to attach this header in a common function that is used by all Azure-specific authentication types. See databricks/databricks-sdk-go#584 for the same change in Go SDK. ## Tests - [x] Added a unit test to ensure the header is being set for Azure CLI login - [ ] `make test` run locally - [ ] `make fmt` applied - [ ] relevant integration tests applied
- Loading branch information
Showing
4 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from databricks.sdk.core import Config | ||
|
||
from .conftest import __tests__ | ||
|
||
|
||
def test_azure_cli_workspace_header_present(monkeypatch): | ||
monkeypatch.setenv('HOME', __tests__ + '/testdata/azure') | ||
monkeypatch.setenv('PATH', __tests__ + '/testdata:/bin') | ||
resource_id = '/subscriptions/123/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/abc123' | ||
cfg = Config(auth_type='azure-cli', host='x', azure_workspace_resource_id=resource_id) | ||
assert 'X-Databricks-Azure-Workspace-Resource-Id' in cfg.authenticate() | ||
assert cfg.authenticate()['X-Databricks-Azure-Workspace-Resource-Id'] == resource_id | ||
|
||
|
||
def test_azure_cli_user_with_management_access(monkeypatch): | ||
monkeypatch.setenv('HOME', __tests__ + '/testdata/azure') | ||
monkeypatch.setenv('PATH', __tests__ + '/testdata:/bin') | ||
resource_id = '/subscriptions/123/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/abc123' | ||
cfg = Config(auth_type='azure-cli', host='x', azure_workspace_resource_id=resource_id) | ||
assert 'X-Databricks-Azure-SP-Management-Token' in cfg.authenticate() | ||
|
||
|
||
def test_azure_cli_user_no_management_access(monkeypatch): | ||
monkeypatch.setenv('HOME', __tests__ + '/testdata/azure') | ||
monkeypatch.setenv('PATH', __tests__ + '/testdata:/bin') | ||
monkeypatch.setenv('FAIL_IF', 'https://management.core.windows.net/') | ||
resource_id = '/subscriptions/123/resourceGroups/abc/providers/Microsoft.Databricks/workspaces/abc123' | ||
cfg = Config(auth_type='azure-cli', host='x', azure_workspace_resource_id=resource_id) | ||
assert 'X-Databricks-Azure-SP-Management-Token' not in cfg.authenticate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters