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():
7171 """
7272
7373 def __init__ (self , config : Optional [Config ] = None ):
74- self ._config = config or Config ( profile = "workbench" )
74+ self .__config = config
7575
7676 def auth_type (self ) -> str :
7777 return POSIT_WORKBENCH_AUTH_TYPE
7878
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+
7996 def __call__ (self , * args , ** kwargs ) -> CredentialsProvider : # noqa: ARG002
8097 if self ._config .token is None :
8198 raise ValueError ("Missing value for field 'token' in Config." )
8299
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 1414
1515
1616class 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+
1921 with pytest .raises (ValueError , match = "profile=workbench" ):
20- WorkbenchStrategy ()
22+ strategy ()
2123
24+ def test_workbench_strategy (self ):
2225 # providing a Config is allowed
2326 cs = WorkbenchStrategy (
2427 config = Config (host = "https://databricks.com/workspace" , token = "token" ) # pyright: ignore[reportPossiblyUnboundVariable]
You can’t perform that action at this time.
0 commit comments