@@ -115,47 +115,45 @@ async def set_runtime_config(client: httpx.AsyncClient):
115115 - wps_api_url
116116 - dcs_api_url
117117 - ucs_api_url
118+
119+ Raises:
120+ WellKnownValueNotFound: If one of the well-known values is not found in the
121+ response from the WKVS.
122+ ConnectionFailedError: If the request fails due to a timeout/connection problem
123+ RequestFailedError: If the request fails for any other reason
118124 """
119- ghga_pubkey = await _get_wkvs_value (client , value_name = "crypt4gh_public_key" )
120- wps_api_url = (await _get_wkvs_value (client , value_name = "wps_api_url" )).rstrip ("/" )
121- dcs_api_url = (await _get_wkvs_value (client , value_name = "dcs_api_url" )).rstrip ("/" )
122- ucs_api_url = (await _get_wkvs_value (client , value_name = "ucs_api_url" )).rstrip ("/" )
125+ values = await _get_wkvs_values (client )
126+ for value_name in [
127+ "crypt4gh_public_key" ,
128+ "wps_api_url" ,
129+ "dcs_api_url" ,
130+ "ucs_api_url" ,
131+ ]:
132+ if value_name not in values :
133+ raise exceptions .WellKnownValueNotFound (value_name = value_name )
123134
124135 async with (
125- set_context_var (ghga_pubkey_var , ghga_pubkey ),
126- set_context_var (wps_api_url_var , wps_api_url ),
127- set_context_var (dcs_api_url_var , dcs_api_url ),
128- set_context_var (ucs_api_url_var , ucs_api_url ),
136+ set_context_var (ghga_pubkey_var , values [ "crypt4gh_public_key" ] ),
137+ set_context_var (wps_api_url_var , values [ " wps_api_url" ]. rstrip ( "/" ) ),
138+ set_context_var (dcs_api_url_var , values [ " dcs_api_url" ]. rstrip ( "/" ) ),
139+ set_context_var (ucs_api_url_var , values [ " ucs_api_url" ]. rstrip ( "/" ) ),
129140 ):
130141 yield
131142
132143
133- async def _get_wkvs_value (client : httpx .AsyncClient , * , value_name : str ) -> Any :
134- """Retrieve a value from the well-known-value-service.
135-
136- Args:
137- value_name (str): the name of the value to be retrieved
144+ async def _get_wkvs_values (client : httpx .AsyncClient ) -> dict [str , Any ]:
145+ """Retrieve a value from the well-known-value-service using the supplied client.
138146
139147 Raises:
140- WellKnownValueNotFound: when a 404 response is received from the WKVS
141- KeyError: when a successful response is received but doesn't contain the expected value
148+ ConnectionFailedError: If the request fails due to a timeout/connection problem
149+ RequestFailedError: If the request fails for any other reason
142150 """
143- url = f"{ CONFIG .wkvs_api_url } /values/{ value_name } "
151+ url = f"{ CONFIG .wkvs_api_url } /values/"
144152
145153 try :
146- response = await client .get (url ) # verify is True by default
154+ response = await client .get (url )
147155 except httpx .RequestError as request_error :
148156 exceptions .raise_if_connection_failed (request_error = request_error , url = url )
149157 raise exceptions .RequestFailedError (url = url ) from request_error
150158
151- if response .status_code == 404 :
152- raise exceptions .WellKnownValueNotFound (value_name = value_name )
153-
154- try :
155- value = response .json ()[value_name ]
156- except KeyError as err :
157- raise KeyError (
158- "Response from well-known-value-service did not include expected field"
159- + f" '{ value_name } '"
160- ) from err
161- return value
159+ return response .json ()
0 commit comments