File tree Expand file tree Collapse file tree 2 files changed +25
-8
lines changed
src/posit/workbench/external
tests/posit/workbench/external Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -71,16 +71,30 @@ def text():
71
71
"""
72
72
73
73
def __init__ (self , config : Optional [Config ] = None ):
74
- self ._config = config or Config ( profile = "workbench" )
74
+ self .__config = config
75
75
76
76
def auth_type (self ) -> str :
77
77
return POSIT_WORKBENCH_AUTH_TYPE
78
78
79
+ @property
80
+ def _config (self ) -> Config :
81
+ """The Databricks SDK `Config` object used by this strategy.
82
+
83
+ Returns
84
+ -------
85
+ Config
86
+ The provided `Config` object, defaulting to a new `Config` with the profile set to "workbench" if not provided.
87
+ """
88
+ if self .__config is None :
89
+ # Do not create this configuration object until it is needed.
90
+ # This avoids failing if the 'workbench' profile is not defined in the user's
91
+ # `~/.databrickscfg` file until this strategy is actually used.
92
+ self .__config = Config (profile = "workbench" )
93
+
94
+ return self .__config
95
+
79
96
def __call__ (self , * args , ** kwargs ) -> CredentialsProvider : # noqa: ARG002
80
97
if self ._config .token is None :
81
98
raise ValueError ("Missing value for field 'token' in Config." )
82
99
83
- def cp ():
84
- return {"Authorization" : f"Bearer { self ._config .token } " }
85
-
86
- return cp
100
+ return lambda : {"Authorization" : f"Bearer { self ._config .token } " }
Original file line number Diff line number Diff line change 14
14
15
15
16
16
class TestPositCredentialsHelpers :
17
- def test_workbench_strategy (self ):
18
- # default will attempt to load the workbench profile
17
+ def test_default_workbench_strategy (self ):
18
+ # By default, the WorkbenchStrategy should use "workbench" profile.
19
+ strategy = WorkbenchStrategy ()
20
+
19
21
with pytest .raises (ValueError , match = "profile=workbench" ):
20
- WorkbenchStrategy ()
22
+ strategy ()
21
23
24
+ def test_workbench_strategy (self ):
22
25
# providing a Config is allowed
23
26
cs = WorkbenchStrategy (
24
27
config = Config (host = "https://databricks.com/workspace" , token = "token" ) # pyright: ignore[reportPossiblyUnboundVariable]
You can’t perform that action at this time.
0 commit comments