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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
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
DatabricksWorkspaceConfigArgumentsinstance 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
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
which_databricks
which_databricks() -> str
Find the databricks executable, or install the Databricks CLI if not
found.
Source code in src/decorative_secrets/databricks.py
205 206 207 208 209 210 211 212 213 214 215 216 | |
databricks_auth_login
databricks_auth_login(
host: str | None = None,
profile: str | None = None,
target: str | None = None,
) -> 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.
Source code in src/decorative_secrets/databricks.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
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 = "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
) -> databricks.sdk.WorkspaceClient
Get a Databricks WorkspaceClient configured from environment variables.
Source code in src/decorative_secrets/databricks.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
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
) -> 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
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 | |
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
) -> 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.
Source code in src/decorative_secrets/databricks.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | |
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
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 | |