Skip to content

decorative_secrets.databricks

DatabricksWorkspaceClientArguments dataclass

An object holding arguments to pass to a Databricks workspace client if/when retrieving secrets remotely.

Source code in src/decorative_secrets/databricks.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@dataclass
class DatabricksWorkspaceClientArguments:
    """
    An object holding arguments to pass to a Databricks workspace client
    if/when retrieving secrets remotely.
    """

    host: str | None = None
    account_id: str | None = None
    username: str | None = None
    password: str | None = None
    client_id: str | None = None
    client_secret: str | None = None
    token: str | None = None
    profile: str | None = None
    config_file: str | None = None
    azure_workspace_resource_id: str | None = None
    azure_client_secret: str | None = None
    azure_client_id: str | None = None
    azure_tenant_id: str | None = None
    azure_environment: str | None = None
    auth_type: str | None = None
    cluster_id: str | None = None
    google_credentials: str | None = None
    google_service_account: str | None = None
    debug_truncate_bytes: int | None = None
    debug_headers: bool | None = None
    product: str | None = None
    product_version: str | None = None
    credentials_strategy: CredentialsStrategy | None = None
    credentials_provider: CredentialsStrategy | None = None
    token_audience: str | None = None
    timeout: float | None = 60

apply_databricks_secrets_arguments

apply_databricks_secrets_arguments(
    *args: decorative_secrets.databricks.DatabricksWorkspaceClientArguments,
    **kwargs: str
) -> collections.abc.Callable

This decorator maps parameter names to Databricks secrets. Each key in databricks_secret_arguments represents the name of a parameter in the decorated function which accepts an explicit input, and the corresponding mapped value is a parameter name accepting a tuple with the secret scope and key with which to lookup a secret to pass to the mapped parameter in lieu of an explicitly provided argument.

Parameters:

  • *args (decorative_secrets.databricks.DatabricksWorkspaceClientArguments, default: () ) –

    A DatabricksWorkspaceConfigArguments instance to configure a workspace client when retrieving secrets remotely (if more than one is provided, only the first is used).

  • **kwargs (str, default: {} ) –

    A mapping of static parameter names to the parameter names of arguments accepting Databricks secret scope + key tuples from which to retrieve a value when the key argument is not explicitly provided.

Example
from functools import (
    cache,
)
from decorative_secrets.databricks import (
    apply_databricks_secret_arguments,
)
from my_client_sdk import (
    Client,
)


@cache
@apply_databricks_secret_arguments(
    client_id="client_id_databricks_secret",
    client_secret="client_secret_databricks_secret",
)
def get_client(
    client_id: str | None = None,
    client_secret: str = None,
    client_id_databricks_secret: str | None = None,
    client_secret_databricks_secret: str | None = None,
) -> Client:
    return Client(
        oauth2_client_id=client_id,
        oauth2_client_secret=client_secret,
    )


client: Client = get_client(
    client_id_databricks_secret=(
        "client",
        "client-id",
    ),
    client_secret_databricks_secret=(
        "client",
        "client-secret",
    ),
)
Source code in src/decorative_secrets/databricks.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
def apply_databricks_secrets_arguments(
    *args: DatabricksWorkspaceClientArguments,
    **kwargs: str,
) -> Callable:
    """
    This decorator maps parameter names to Databricks secrets.
    Each key in `databricks_secret_arguments` represents the name of a
    parameter in the decorated function which accepts an explicit input, and
    the corresponding mapped value is a parameter name accepting a tuple with
    the secret scope and key with which to lookup a secret to pass to the
    mapped parameter in lieu of an explicitly provided argument.

    Parameters:
        *args: A `DatabricksWorkspaceConfigArguments` instance to configure
            a workspace client when retrieving secrets remotely
            (if more than one  is provided, only the first is used).
        **kwargs: A mapping of static parameter names to the parameter names
            of arguments accepting Databricks secret scope + key tuples
            from which to retrieve a value when the key argument is not
            explicitly provided.

    Example:
        ```python
        from functools import (
            cache,
        )
        from decorative_secrets.databricks import (
            apply_databricks_secret_arguments,
        )
        from my_client_sdk import (
            Client,
        )


        @cache
        @apply_databricks_secret_arguments(
            client_id="client_id_databricks_secret",
            client_secret="client_secret_databricks_secret",
        )
        def get_client(
            client_id: str | None = None,
            client_secret: str = None,
            client_id_databricks_secret: str | None = None,
            client_secret_databricks_secret: str | None = None,
        ) -> Client:
            return Client(
                oauth2_client_id=client_id,
                oauth2_client_secret=client_secret,
            )


        client: Client = get_client(
            client_id_databricks_secret=(
                "client",
                "client-id",
            ),
            client_secret_databricks_secret=(
                "client",
                "client-secret",
            ),
        )
        ```
    """
    databricks_workspace_client_arguments: (
        DatabricksWorkspaceClientArguments | None
    ) = _get_args_options(*args)[1]
    get_scope_key_secret: Callable[[str | tuple[str, str]], str] = (
        partial(
            _get_scope_key_secret,
            **asdict(databricks_workspace_client_arguments),
        )
        if databricks_workspace_client_arguments
        else _get_scope_key_secret
    )
    return apply_callback_arguments(
        get_scope_key_secret,
        **kwargs,
    )

which_databricks

which_databricks(*, timeout: float | None = 60) -> str

Find the databricks executable, or install the Databricks CLI if not found.

Source code in src/decorative_secrets/databricks.py
274
275
276
277
278
279
280
281
282
283
284
285
def which_databricks(*, timeout: float | None = 60) -> str:
    """
    Find the `databricks` executable, or install the Databricks CLI if not
    found.
    """
    databricks: str = which("databricks") or "databricks"
    try:
        check_output((databricks, "--version"), timeout=timeout)
    except (CalledProcessError, FileNotFoundError):  # pragma: no cover
        _install_databricks_cli(timeout=timeout)
        databricks = which("databricks") or "databricks"
    return databricks

databricks_auth_login

databricks_auth_login(
    host: str | None = None,
    profile: str | None = None,
    target: str | None = None,
    *,
    force: bool = False,
    timeout: float | None = 60
) -> None

Log in to Databricks using the CLI if not already logged in.

Parameters:

  • host (str | None, default: None ) –

    A Databricks workspace host URL.

  • profile (str | None, default: None ) –

    A Databricks Configuration Profile.

  • target (str | None, default: None ) –

    A Databricks CLI target.

  • force (bool, default: False ) –

    Whether to force login even if already authenticated.

  • timeout (float | None, default: 60 ) –

    A timeout in seconds for the login operation.

Raises:

  • subprocess.CalledProcessError –

    If the Databricks CLI command returns a non-zero exit code

  • FileNotFoundError –

    If the Databricks CLI is not found.

  • decorative_secrets.errors.DatabricksCLINotInstalledError –

    If the Databricks CLI cannot be installed.

  • TimeoutExpired –

    If the command takes longer than timeout seconds to complete

Source code in src/decorative_secrets/databricks.py
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
def databricks_auth_login(
    host: str | None = None,
    profile: str | None = None,
    target: str | None = None,
    *,
    force: bool = False,
    timeout: float | None = 60,
) -> None:  # pragma: no cover
    """
    Log in to Databricks using the CLI if not already logged in.

    Parameters:
        host: A Databricks workspace host URL.
        profile: A Databricks Configuration Profile.
        target: A Databricks CLI target.
        force: Whether to force login even if already authenticated.
        timeout: A timeout in seconds for the login operation.

    Raises:
        CalledProcessError: If the Databricks CLI command returns a non-zero
            exit code
        FileNotFoundError: If the Databricks CLI is not found.
        DatabricksCLINotInstalledError: If the Databricks CLI cannot be
            installed.
        TimeoutExpired: If the command takes longer than `timeout` seconds to
            complete
    """
    if (host is None) and (profile is None) and (target is None):
        host = os.getenv("DATABRICKS_HOST")
        profile = os.getenv("DATABRICKS_CONFIG_PROFILE")
    # If we are already authenticated and not forcing login, don't attempt to
    # log in again
    if not force and (
        _databricks_auth_describe(
            host=host,
            profile=profile,
            target=target,
            timeout=timeout,
        ).get("status")
        == "success"
    ):
        return
    if force:
        _databricks_auth_login.cache_clear()
    return _databricks_auth_login(
        host=host,
        profile=profile,
        target=target,
        timeout=timeout,
        **get_prefixed_environ("DATABRICKS_"),
    )

get_databricks_workspace_client

get_databricks_workspace_client(
    host: str | None = None,
    account_id: str | None = None,
    username: str | None = None,
    password: str | None = None,
    client_id: str | None = None,
    client_secret: str | None = None,
    token: str | None = None,
    profile: str | None = None,
    config_file: str | None = None,
    azure_workspace_resource_id: str | None = None,
    azure_client_secret: str | None = None,
    azure_client_id: str | None = None,
    azure_tenant_id: str | None = None,
    azure_environment: str | None = None,
    auth_type: str | None = None,
    cluster_id: str | None = None,
    google_credentials: str | None = None,
    google_service_account: str | None = None,
    debug_truncate_bytes: int | None = None,
    *,
    debug_headers: bool | None = None,
    product: str | None = None,
    product_version: str | None = None,
    credentials_strategy: (
        databricks.sdk.credentials_provider.CredentialsStrategy
        | None
    ) = None,
    credentials_provider: (
        databricks.sdk.credentials_provider.CredentialsStrategy
        | None
    ) = None,
    token_audience: str | None = None,
    config: databricks.sdk.config.Config | None = None,
    timeout: float | None = 60
) -> databricks.sdk.WorkspaceClient

Get a Databricks WorkspaceClient configured from environment variables.

Source code in src/decorative_secrets/databricks.py
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
def get_databricks_workspace_client(
    host: str | None = None,
    account_id: str | None = None,
    username: str | None = None,
    password: str | None = None,
    client_id: str | None = None,
    client_secret: str | None = None,
    token: str | None = None,
    profile: str | None = None,
    config_file: str | None = None,
    azure_workspace_resource_id: str | None = None,
    azure_client_secret: str | None = None,
    azure_client_id: str | None = None,
    azure_tenant_id: str | None = None,
    azure_environment: str | None = None,
    auth_type: str | None = None,
    cluster_id: str | None = None,
    google_credentials: str | None = None,
    google_service_account: str | None = None,
    debug_truncate_bytes: int | None = None,
    *,
    debug_headers: bool | None = None,
    product: str | None = None,
    product_version: str | None = None,
    credentials_strategy: CredentialsStrategy | None = None,
    credentials_provider: CredentialsStrategy | None = None,
    token_audience: str | None = None,
    config: Config | None = None,
    timeout: float | None = 60,
) -> WorkspaceClient:
    """
    Get a Databricks WorkspaceClient configured from environment variables.
    """
    return _get_env_databricks_workspace_client(
        host=host,
        account_id=account_id,
        username=username,
        password=password,
        client_id=client_id,
        client_secret=client_secret,
        token=token,
        profile=profile,
        config_file=config_file,
        azure_workspace_resource_id=azure_workspace_resource_id,
        azure_client_secret=azure_client_secret,
        azure_client_id=azure_client_id,
        azure_tenant_id=azure_tenant_id,
        azure_environment=azure_environment,
        auth_type=auth_type,
        cluster_id=cluster_id,
        google_credentials=google_credentials,
        google_service_account=google_service_account,
        debug_truncate_bytes=debug_truncate_bytes,
        debug_headers=debug_headers,
        product=product,
        product_version=product_version,
        credentials_strategy=credentials_strategy,
        credentials_provider=credentials_provider,
        token_audience=token_audience,
        config=config,
        timeout=timeout,
        **get_prefixed_environ("DATABRICKS_", "ARM_", "GOOGLE_"),
    )

get_dbutils

get_dbutils(
    host: str | None = None,
    account_id: str | None = None,
    username: str | None = None,
    password: str | None = None,
    client_id: str | None = None,
    client_secret: str | None = None,
    token: str | None = None,
    profile: str | None = None,
    config_file: str | None = None,
    azure_workspace_resource_id: str | None = None,
    azure_client_secret: str | None = None,
    azure_client_id: str | None = None,
    azure_tenant_id: str | None = None,
    azure_environment: str | None = None,
    auth_type: str | None = None,
    cluster_id: str | None = None,
    google_credentials: str | None = None,
    google_service_account: str | None = None,
    debug_truncate_bytes: int | None = None,
    *,
    debug_headers: bool | None = None,
    product: str = "unknown",
    product_version: str = "0.0.0",
    credentials_strategy: (
        databricks.sdk.credentials_provider.CredentialsStrategy
        | None
    ) = None,
    credentials_provider: (
        databricks.sdk.credentials_provider.CredentialsStrategy
        | None
    ) = None,
    token_audience: str | None = None,
    config: databricks.sdk.config.Config | None = None,
    timeout: float | None = 60
) -> databricks.sdk.dbutils.RemoteDbUtils

Get dbutils using an existing instance from the runtime if found, otherwise, creating one using a workspace client (this requires either having these environment variables set , or providing the equivalent optional arguments.

Source code in src/decorative_secrets/databricks.py
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
def get_dbutils(
    host: str | None = None,
    account_id: str | None = None,
    username: str | None = None,
    password: str | None = None,
    client_id: str | None = None,
    client_secret: str | None = None,
    token: str | None = None,
    profile: str | None = None,
    config_file: str | None = None,
    azure_workspace_resource_id: str | None = None,
    azure_client_secret: str | None = None,
    azure_client_id: str | None = None,
    azure_tenant_id: str | None = None,
    azure_environment: str | None = None,
    auth_type: str | None = None,
    cluster_id: str | None = None,
    google_credentials: str | None = None,
    google_service_account: str | None = None,
    debug_truncate_bytes: int | None = None,
    *,
    debug_headers: bool | None = None,
    product: str = "unknown",
    product_version: str = "0.0.0",
    credentials_strategy: CredentialsStrategy | None = None,
    credentials_provider: CredentialsStrategy | None = None,
    token_audience: str | None = None,
    config: Config | None = None,
    timeout: float | None = 60,
) -> RemoteDbUtils:
    """
    Get [dbutils](https://docs.databricks.com/dev-tools/databricks-utils.html)
    using an existing instance from the runtime if found, otherwise,
    creating one using a workspace client (this requires either having
    [these environment variables set
    ](https://docs.databricks.com/aws/en/dev-tools/auth#environment-variables),
    or providing the equivalent optional arguments.
    """
    dbutils: RemoteDbUtils | None = None
    with suppress(ImportError):
        from IPython.core.getipython import (  # type: ignore[import-not-found]  # noqa: PLC0415
            get_ipython,
        )

        if TYPE_CHECKING:
            from IPython.core.interactiveshell import (  # type: ignore[import-not-found]  # noqa: PLC0415
                InteractiveShell,
            )

        ipython: InteractiveShell = get_ipython()
        if ipython is not None:
            user_namespace_attribute: str
            user_namespace: dict
            for user_namespace_attribute in "user_ns", "user_global_ns":
                dbutils = getattr(ipython, user_namespace_attribute, {}).get(
                    "dbutils", None
                )
                if dbutils is not None:
                    return dbutils
    dbutils = globals().get("dbutils")
    if dbutils is not None:
        return dbutils
    databricks_workspace_client: WorkspaceClient = (
        get_databricks_workspace_client(
            host=host,
            account_id=account_id,
            username=username,
            password=password,
            client_id=client_id,
            client_secret=client_secret,
            token=token,
            profile=profile,
            config_file=config_file,
            azure_workspace_resource_id=azure_workspace_resource_id,
            azure_client_secret=azure_client_secret,
            azure_client_id=azure_client_id,
            azure_tenant_id=azure_tenant_id,
            azure_environment=azure_environment,
            auth_type=auth_type,
            cluster_id=cluster_id,
            google_credentials=google_credentials,
            google_service_account=google_service_account,
            debug_truncate_bytes=debug_truncate_bytes,
            debug_headers=debug_headers,
            product=product,
            product_version=product_version,
            credentials_strategy=credentials_strategy,
            credentials_provider=credentials_provider,
            token_audience=token_audience,
            config=config,
            timeout=timeout,
        )
    )
    return databricks_workspace_client.dbutils

get_databricks_secret

get_databricks_secret(
    scope: str,
    key: str,
    host: str | None = None,
    account_id: str | None = None,
    username: str | None = None,
    password: str | None = None,
    client_id: str | None = None,
    client_secret: str | None = None,
    token: str | None = None,
    profile: str | None = None,
    config_file: str | None = None,
    azure_workspace_resource_id: str | None = None,
    azure_client_secret: str | None = None,
    azure_client_id: str | None = None,
    azure_tenant_id: str | None = None,
    azure_environment: str | None = None,
    auth_type: str | None = None,
    cluster_id: str | None = None,
    google_credentials: str | None = None,
    google_service_account: str | None = None,
    debug_truncate_bytes: int | None = None,
    *,
    debug_headers: bool | None = None,
    product: str = "unknown",
    product_version: str = "0.0.0",
    credentials_strategy: (
        databricks.sdk.credentials_provider.CredentialsStrategy
        | None
    ) = None,
    credentials_provider: (
        databricks.sdk.credentials_provider.CredentialsStrategy
        | None
    ) = None,
    token_audience: str | None = None,
    config: databricks.sdk.config.Config | None = None,
    timeout: float | None = 60
) -> str

Get a secret from Databricks.

Parameters:

  • scope (str) –

    The Databricks secret scope.

  • key (str) –

    The Databricks secret key.

  • host (str | None, default: None ) –

    A Databricks workspace host URL.

  • account_id (str | None, default: None ) –

    A Databricks account ID.

  • username (str | None, default: None ) –

    A Databricks username.

  • password (str | None, default: None ) –

    A Databricks password.

  • client_id (str | None, default: None ) –

    A Databricks OAuth2 Client ID.

  • client_secret (str | None, default: None ) –

    A Databricks OAuth2 Client Secret.

  • token (str | None, default: None ) –

    A Databricks Personal Access Token.

  • profile (str | None, default: None ) –

    A Databricks Configuration Profile.

  • config_file (str | None, default: None ) –

    A Databricks Configuration File path.

  • azure_workspace_resource_id (str | None, default: None ) –

    An Azure Databricks Workspace Resource ID.

  • azure_client_secret (str | None, default: None ) –

    An Azure Client Secret for Azure Databricks auth.

  • azure_client_id (str | None, default: None ) –

    An Azure Client ID for Azure Databricks auth.

  • azure_tenant_id (str | None, default: None ) –

    An Azure Tenant ID for Azure Databricks auth.

  • azure_environment (str | None, default: None ) –

    An Azure Environment for Azure Databricks auth.

  • auth_type (str | None, default: None ) –

    A Databricks authentication type.

  • cluster_id (str | None, default: None ) –

    A Databricks cluster ID.

  • google_credentials (str | None, default: None ) –

    Google Cloud credentials for GCP Databricks auth.

  • google_service_account (str | None, default: None ) –

    A Google Service Account for GCP Databricks auth.

  • debug_truncate_bytes (int | None, default: None ) –

    Number of bytes to truncate in debug logs.

  • debug_headers (bool | None, default: None ) –

    Whether to enable debug logging of HTTP headers.

  • product (str, default: 'unknown' ) –

    The product name using the SDK.

  • product_version (str, default: '0.0.0' ) –

    The product version using the SDK.

  • credentials_strategy (databricks.sdk.credentials_provider.CredentialsStrategy | None, default: None ) –

    A credentials strategy for the SDK.

  • credentials_provider (databricks.sdk.credentials_provider.CredentialsStrategy | None, default: None ) –

    A credentials provider for the SDK.

  • token_audience (str | None, default: None ) –

    A token audience for the SDK.

  • config (databricks.sdk.config.Config | None, default: None ) –

    A Databricks SDK Config instance.

  • timeout (float | None, default: 60 ) –

    A timeout in seconds for any underlying Databricks CLI invocation (e.g. an implicit databricks auth login).

Source code in src/decorative_secrets/databricks.py
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
def get_databricks_secret(
    scope: str,
    key: str,
    host: str | None = None,
    account_id: str | None = None,
    username: str | None = None,
    password: str | None = None,
    client_id: str | None = None,
    client_secret: str | None = None,
    token: str | None = None,
    profile: str | None = None,
    config_file: str | None = None,
    azure_workspace_resource_id: str | None = None,
    azure_client_secret: str | None = None,
    azure_client_id: str | None = None,
    azure_tenant_id: str | None = None,
    azure_environment: str | None = None,
    auth_type: str | None = None,
    cluster_id: str | None = None,
    google_credentials: str | None = None,
    google_service_account: str | None = None,
    debug_truncate_bytes: int | None = None,
    *,
    debug_headers: bool | None = None,
    product: str = "unknown",
    product_version: str = "0.0.0",
    credentials_strategy: CredentialsStrategy | None = None,
    credentials_provider: CredentialsStrategy | None = None,
    token_audience: str | None = None,
    config: Config | None = None,
    timeout: float | None = 60,
) -> str:
    """
    Get a secret from Databricks.

    Parameters:
        scope: The Databricks secret scope.
        key: The Databricks secret key.
        host: A Databricks workspace host URL.
        account_id: A Databricks account ID.
        username: A Databricks username.
        password: A Databricks password.
        client_id: A Databricks OAuth2 Client ID.
        client_secret: A Databricks OAuth2 Client Secret.
        token: A Databricks Personal Access Token.
        profile: A Databricks Configuration Profile.
        config_file: A Databricks Configuration File path.
        azure_workspace_resource_id: An Azure Databricks Workspace Resource ID.
        azure_client_secret: An Azure Client Secret for Azure Databricks auth.
        azure_client_id: An Azure Client ID for Azure Databricks auth.
        azure_tenant_id: An Azure Tenant ID for Azure Databricks auth.
        azure_environment: An Azure Environment for Azure Databricks auth.
        auth_type: A Databricks authentication type.
        cluster_id: A Databricks cluster ID.
        google_credentials: Google Cloud credentials for GCP Databricks auth.
        google_service_account: A Google Service Account for GCP Databricks
            auth.
        debug_truncate_bytes: Number of bytes to truncate in debug logs.
        debug_headers: Whether to enable debug logging of HTTP headers.
        product: The product name using the SDK.
        product_version: The product version using the SDK.
        credentials_strategy: A credentials strategy for the SDK.
        credentials_provider: A credentials provider for the SDK.
        token_audience: A token audience for the SDK.
        config: A Databricks SDK Config instance.
        timeout: A timeout in seconds for any underlying Databricks CLI
            invocation (e.g. an implicit `databricks auth login`).
    """
    return _get_secret(
        scope,
        key,
        host=host,
        account_id=account_id,
        username=username,
        password=password,
        client_id=client_id,
        client_secret=client_secret,
        token=token,
        profile=profile,
        config_file=config_file,
        azure_workspace_resource_id=azure_workspace_resource_id,
        azure_client_secret=azure_client_secret,
        azure_client_id=azure_client_id,
        azure_tenant_id=azure_tenant_id,
        azure_environment=azure_environment,
        auth_type=auth_type,
        cluster_id=cluster_id,
        google_credentials=google_credentials,
        google_service_account=google_service_account,
        debug_truncate_bytes=debug_truncate_bytes,
        debug_headers=debug_headers,
        product=product,
        product_version=product_version,
        credentials_strategy=credentials_strategy,
        credentials_provider=credentials_provider,
        token_audience=token_audience,
        config=config,
        timeout=timeout,
        **get_prefixed_environ("DATABRICKS_", "ARM_", "GOOGLE_"),
    )

main

main() -> None

Run a command: - install: Install the Databricks CLI if not already installed - get: Get a secret from Databricks and print it to stdout

Source code in src/decorative_secrets/databricks.py
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
def main() -> None:
    """
    Run a command:
    -   install: Install the Databricks CLI if not already installed
    -   get: Get a secret from Databricks and print it to stdout
    """
    command = _get_command()
    if command in ("--help", "-h"):
        _print_help()
        return
    parser: argparse.ArgumentParser
    if command == "install":
        parser = argparse.ArgumentParser(
            prog="decorative-secrets databricks install",
            description="Install the Databricks CLI",
        )
        parser.add_argument(
            "--timeout",
            default=None,
            type=float,
            help="A timeout, in seconds, for the install command",
        )
        namespace: argparse.Namespace = parser.parse_args()
        _install_databricks_cli(timeout=namespace.timeout)
    elif command == "get":
        parser = argparse.ArgumentParser(
            prog="decorative-secrets databricks get",
            description="Get a secret from Databricks",
        )
        parser.add_argument(
            "scope",
            type=str,
        )
        parser.add_argument(
            "key",
            type=str,
        )
        parser.add_argument(
            "--host",
            default=None,
            type=str,
            help="A Databricks workspace host URL",
        )
        parser.add_argument(
            "-cid",
            "--client-id",
            default=None,
            type=str,
            help="A Databricks OAuth2 Client ID",
        )
        parser.add_argument(
            "-cs",
            "--client-secret",
            default=None,
            type=str,
            help="A Databricks OAuth2 Client Secret",
        )
        parser.add_argument(
            "-t",
            "--token",
            default=None,
            type=str,
            help="A Databricks Personal Access Token",
        )
        parser.add_argument(
            "-p",
            "--profile",
            default=None,
            type=str,
            help="A Databricks Configuration Profile",
        )
        parser.add_argument(
            "--timeout",
            default=60,
            type=float,
            help="A timeout, in seconds, for any underlying Databricks CLI "
            "invocation",
        )
        namespace = parser.parse_args()
        print(  # noqa: T201
            get_databricks_secret(
                namespace.scope,
                namespace.key,
                host=namespace.host,
                client_id=namespace.client_id,
                client_secret=namespace.client_secret,
                token=namespace.token,
                profile=namespace.profile,
                timeout=namespace.timeout,
            )
        )