Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Synapse Spark Authentication Option #155

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dbt/adapters/fabric/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.8.1"
version = "1.8.2"
25 changes: 25 additions & 0 deletions dbt/adapters/fabric/fabric_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from dbt.adapters.fabric.fabric_credentials import FabricCredentials

AZURE_CREDENTIAL_SCOPE = "https://database.windows.net//.default"
SYNAPSE_SPARK_CREDENTIAL_SCOPE = "DW"
_TOKEN: Optional[AccessToken] = None
AZURE_AUTH_FUNCTION_TYPE = Callable[[FabricCredentials], AccessToken]

Expand Down Expand Up @@ -87,6 +88,29 @@ def convert_access_token_to_mswindows_byte_string(token: AccessToken) -> bytes:
return convert_bytes_to_mswindows_byte_string(value)


def get_synapse_spark_access_token(credentials: FabricCredentials) -> AccessToken:
"""
Get an Azure access token by using mspsarkutils
Parameters
-----------
credentials: FabricCredentials
Credentials.
Returns
-------
out : AccessToken
The access token.
"""
from notebookutils import mssparkutils

aad_token = mssparkutils.credentials.getToken(SYNAPSE_SPARK_CREDENTIAL_SCOPE)
expires_on = int(time.time() + 4500.0)
token = AccessToken(
token=aad_token,
expires_on=expires_on,
)
return token


def get_cli_access_token(credentials: FabricCredentials) -> AccessToken:
"""
Get an Azure access token using the CLI credentials
Expand Down Expand Up @@ -152,6 +176,7 @@ def get_environment_access_token(credentials: FabricCredentials) -> AccessToken:
"cli": get_cli_access_token,
"auto": get_auto_access_token,
"environment": get_environment_access_token,
"synapsespark": get_synapse_spark_access_token,
}


Expand Down
Loading