1111 FieldItem ,
1212)
1313
14+ from fmu_settings_api .config import HttpHeader
1415from fmu_settings_api .deps import (
1516 ProjectSmdaSessionDep ,
1617 SessionDep ,
3334
3435def _add_response_headers (response : Response ) -> Generator [None ]:
3536 """Adds headers specific to the /smda route."""
36- response .headers ["x-upstream-source" ] = "SMDA"
37+ response .headers [HttpHeader . UPSTREAM_SOURCE_KEY ] = HttpHeader . UPSTREAM_SOURCE_SMDA
3738 yield
3839
3940
@@ -70,7 +71,7 @@ async def get_health(session: SessionDep) -> Ok:
7071 raise HTTPException (
7172 status_code = 401 ,
7273 detail = "SMDA access token is not set" ,
73- headers = {"x-upstream-source" : "SMDA" },
74+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
7475 )
7576
7677 try :
@@ -86,13 +87,13 @@ async def get_health(session: SessionDep) -> Ok:
8687 raise HTTPException (
8788 status_code = e .response .status_code ,
8889 detail = f"SMDA error requesting { e .request .url } " ,
89- headers = {"x-upstream-source" : "SMDA" },
90+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
9091 ) from e
9192 except Exception as e :
9293 raise HTTPException (
9394 status_code = 500 ,
9495 detail = str (e ),
95- headers = {"x-upstream-source" : "SMDA" },
96+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
9697 ) from e
9798
9899
@@ -125,7 +126,7 @@ async def post_field(session: SessionDep, field: SmdaField) -> SmdaFieldSearchRe
125126 raise HTTPException (
126127 status_code = 401 ,
127128 detail = "SMDA access token is not set" ,
128- headers = {"x-upstream-source" : "SMDA" },
129+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
129130 )
130131
131132 try :
@@ -143,25 +144,25 @@ async def post_field(session: SessionDep, field: SmdaField) -> SmdaFieldSearchRe
143144 raise HTTPException (
144145 status_code = e .response .status_code ,
145146 detail = f"SMDA error requesting { e .request .url !r} " ,
146- headers = {"x-upstream-source" : "SMDA" },
147+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
147148 ) from e
148149 except KeyError as e :
149150 raise HTTPException (
150151 status_code = 500 ,
151152 detail = "Malformed response from SMDA: no 'data' field present" ,
152- headers = {"x-upstream-source" : "SMDA" },
153+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
153154 ) from e
154155 except TimeoutError as e :
155156 raise HTTPException (
156157 status_code = 503 ,
157158 detail = "SMDA API request timed out. Please try again." ,
158- headers = {"x-upstream-source" : "SMDA" },
159+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
159160 ) from e
160161 except Exception as e :
161162 raise HTTPException (
162163 status_code = 500 ,
163164 detail = str (e ),
164- headers = {"x-upstream-source" : "SMDA" },
165+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
165166 ) from e
166167
167168
@@ -215,7 +216,7 @@ async def post_masterdata(
215216 raise HTTPException (
216217 status_code = 401 ,
217218 detail = "SMDA access token is not set" ,
218- headers = {"x-upstream-source" : "SMDA" },
219+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
219220 )
220221
221222 # Sorted for tests as sets don't guarantee order
@@ -243,7 +244,9 @@ async def post_masterdata(
243244 raise HTTPException (
244245 status_code = 404 ,
245246 detail = f"No fields found for identifiers: { unique_field_identifiers } " ,
246- headers = {"x-upstream-source" : "SMDA" },
247+ headers = {
248+ HttpHeader .UPSTREAM_SOURCE_KEY : HttpHeader .UPSTREAM_SOURCE_SMDA
249+ },
247250 )
248251
249252 field_items = [FieldItem (** field ) for field in field_results ]
@@ -277,7 +280,9 @@ async def post_masterdata(
277280 raise HTTPException (
278281 status_code = 404 ,
279282 detail = "Projected field coordinate system not found" ,
280- headers = {"x-upstream-source" : "SMDA" },
283+ headers = {
284+ HttpHeader .UPSTREAM_SOURCE_KEY : HttpHeader .UPSTREAM_SOURCE_SMDA
285+ },
281286 )
282287
283288 return SmdaMasterdataResult (
@@ -294,23 +299,23 @@ async def post_masterdata(
294299 raise HTTPException (
295300 status_code = e .response .status_code ,
296301 detail = f"SMDA error requesting { e .request .url } " ,
297- headers = {"x-upstream-source" : "SMDA" },
302+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
298303 ) from e
299304 except KeyError as e :
300305 raise HTTPException (
301306 status_code = 500 ,
302307 detail = "Malformed response from SMDA: {e}" ,
303- headers = {"x-upstream-source" : "SMDA" },
308+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
304309 ) from e
305310 except Exception as e :
306311 raise HTTPException (
307312 status_code = 500 ,
308313 detail = str (e ),
309- headers = {"x-upstream-source" : "SMDA" },
314+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
310315 ) from e
311316 except TimeoutError as e :
312317 raise HTTPException (
313318 status_code = 503 ,
314319 detail = "SMDA API request timed out. Please try again." ,
315- headers = {"x-upstream-source" : "SMDA" },
320+ headers = {HttpHeader . UPSTREAM_SOURCE_KEY : HttpHeader . UPSTREAM_SOURCE_SMDA },
316321 ) from e
0 commit comments