@@ -56,9 +56,9 @@ def __init__(
56
56
desc: The description of the remote tool (used as its docstring).
57
57
params: A list of `inspect.Parameter` objects defining the tool's
58
58
arguments and their types/defaults.
59
- required_authn_params: A dict of required authenticated parameters that
60
- need a auth_service_token_getter set for them yet .
61
- auth_service_tokens : A dict of authService -> token (or callables that
59
+ required_authn_params: A dict of required authenticated parameters to a list
60
+ of services that provide values for them.
61
+ auth_service_token_getters : A dict of authService -> token (or callables that
62
62
produce a token)
63
63
"""
64
64
@@ -108,15 +108,19 @@ def __copy(
108
108
that produce a token)
109
109
110
110
"""
111
+ check = lambda val , default : val if val is not None else default
111
112
return ToolboxTool (
112
- session = session or self .__session ,
113
- base_url = base_url or self .__base_url ,
114
- name = name or self .__name__ ,
115
- desc = desc or self .__desc ,
116
- params = params or self .__params ,
117
- required_authn_params = required_authn_params or self .__required_authn_params ,
118
- auth_service_token_getters = auth_service_token_getters
119
- or self .__auth_service_token_getters ,
113
+ session = check (session , self .__session ),
114
+ base_url = check (base_url , self .__base_url ),
115
+ name = check (name , self .__name__ ),
116
+ desc = check (desc , self .__desc ),
117
+ params = check (params , self .__params ),
118
+ required_authn_params = check (
119
+ required_authn_params , self .__required_authn_params
120
+ ),
121
+ auth_service_token_getters = check (
122
+ auth_service_token_getters , self .__auth_service_token_getters
123
+ ),
120
124
)
121
125
122
126
async def __call__ (self , * args : Any , ** kwargs : Any ) -> str :
@@ -138,7 +142,7 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
138
142
if len (self .__required_authn_params ) > 0 :
139
143
req_auth_services = set (l for l in self .__required_authn_params .keys ())
140
144
raise Exception (
141
- f"One of more of the following authn services are required to invoke this tool: { ',' .join (req_auth_services )} "
145
+ f"One or more of the following authn services are required to invoke this tool: { ',' .join (req_auth_services )} "
142
146
)
143
147
144
148
# validate inputs to this call using the signature
@@ -167,7 +171,7 @@ def add_auth_token_getters(
167
171
auth_token_getters : Mapping [str , Callable [[], str ]],
168
172
) -> "ToolboxTool" :
169
173
"""
170
- Registers a auth token getter function that is used for AuthServices when tools
174
+ Registers an auth token getter function that is used for AuthServices when tools
171
175
are invoked.
172
176
173
177
Args:
@@ -204,25 +208,27 @@ def add_auth_token_getters(
204
208
205
209
206
210
def filter_required_authn_params (
207
- req_authn_params : Mapping [str , list [str ]], auth_services : Iterable [str ]
211
+ req_authn_params : Mapping [str , list [str ]], auth_service_names : Iterable [str ]
208
212
) -> dict [str , list [str ]]:
209
213
"""
210
- Utility function for reducing 'req_authn_params' to a subset of parameters that aren't supplied by a least one service in auth_services.
214
+ Utility function for reducing 'req_authn_params' to a subset of parameters that
215
+ aren't supplied by at least one service in auth_services.
211
216
212
217
Args:
213
218
req_authn_params: A mapping of parameter names to sets of required
214
219
authentication services.
215
- auth_services : An iterable of authentication service names for which
220
+ auth_service_names : An iterable of authentication service names for which
216
221
token getters are available.
217
222
218
223
Returns:
219
224
A new dictionary representing the subset of required authentication
220
- parameters that are not covered by the provided `auth_services `.
225
+ parameters that are not covered by the provided `auth_service_names `.
221
226
"""
222
- req_params = {}
227
+ required_params = {} # params that are still required with provided auth_services
223
228
for param , services in req_authn_params .items ():
224
- # if we don't have a token_getter for any of the services required by the param, the param is still required
225
- required = not any (s in services for s in auth_services )
229
+ # if we don't have a token_getter for any of the services required by the param,
230
+ # the param is still required
231
+ required = not any (s in services for s in auth_service_names )
226
232
if required :
227
- req_params [param ] = services
228
- return req_params
233
+ required_params [param ] = services
234
+ return required_params
0 commit comments