feat(apps): add databricks.apps module for Apps runtime client construction#1398
Open
jamesbroadhead wants to merge 1 commit intodatabricks:mainfrom
Open
feat(apps): add databricks.apps module for Apps runtime client construction#1398jamesbroadhead wants to merge 1 commit intodatabricks:mainfrom
jamesbroadhead wants to merge 1 commit intodatabricks:mainfrom
Conversation
Adds a first-class `databricks.apps` module with three helpers for code
running inside Databricks Apps containers:
- get_workspace_client(): SP-authenticated client. Uses OAuth M2M with the
SP credentials injected by the Apps runtime. Pins auth_type="oauth-m2m"
so the SDK does not also attempt to read DATABRICKS_TOKEN and raise a
dual-auth validation error.
- get_user_workspace_client(request=..., token=...): OBO client. Reads the
user's access token from X-Forwarded-Access-Token on the request, or
accepts an explicit token kwarg. Pins auth_type="pat" for the same
reason. Does not mutate os.environ, so it is safe to call concurrently
from multiple request handlers (the historical workaround of popping SP
env vars is not thread-safe).
- get_mcp_client(): placeholder that raises NotImplementedError with a
clear pointer to the SDK-02 follow-up. Lets dependent code import the
symbol today and adopt the real implementation when it lands.
Tests assert on the kwargs passed to WorkspaceClient rather than on its
constructed Config object to avoid the SDK's eager host-metadata resolution
during unit tests.
Addresses the "SDK-01" gap from the EMEA Apps Gaps That Matter doc.
Co-authored-by: Isaac
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a first-class
databricks.appsmodule with helpers for code running inside Databricks Apps containers. Addresses the SDK-01 gap from internal field feedback — the historical workaround (poppingDATABRICKS_CLIENT_ID/DATABRICKS_CLIENT_SECRETfromos.environto avoid a dual-auth validation error) is not thread-safe and forces ~50 lines of boilerplate into every custom agent app.Public API
Why this is the right fix
The root cause is that
WorkspaceClient(token=..., host=...)raisesmore than one authorization method configured: oauth and patwhen SP env vars arealso set — which is always true inside an Apps container. Both helpers here pin
auth_typeexplicitly (oauth-m2mandpat) so the validator never sees ambiguousconfig. No env mutation, no global state, safe under concurrency.
get_mcp_client()is a placeholder that raisesNotImplementedErrorwith a pointerto the SDK-02 follow-up so dependent code can import the symbol today and adopt the
real implementation when it lands.
Test plan
pytest tests/apps/— 8 tests covering OAuth-M2M wiring, OBO header extraction (case-insensitive), explicit-token path, dual-auth regression, env-non-mutation invariant, missing-creds error paths, MCP placeholderimport databricks.sdk; import databricks.appsboth succeedWorkspaceClientconstructor kwargs rather than the constructedConfigobject, avoiding the SDK's eager host-metadata resolution in unit testsOut of scope
get_mcp_client()real implementation — tracked as SDK-02 (depends onmcp_serverresource type being honored at runtime)This pull request and its description were written by Claude (claude.ai).