2020from uuid import UUID
2121
2222import httpx
23- from ghga_service_commons .utils .crypt import encrypt
2423from ghga_service_commons .utils .utc_dates import UTCDatetime
2524from jwcrypto import jwk
2625from pydantic import UUID4 , Field , SecretStr
2726from pydantic_settings import BaseSettings
2827
2928from uos .core .models import (
29+ BaseWorkOrderToken ,
3030 ChangeFileBoxWorkOrder ,
3131 CreateFileBoxWorkOrder ,
3232 UploadGrant ,
@@ -64,10 +64,6 @@ class UCSApiConfig(BaseSettings):
6464 description = "The private key for signing work order tokens" ,
6565 examples = ['{"crv": "P-256", "kty": "EC", "x": "...", "y": "..."}' ],
6666 )
67- ucs_public_key : str = Field (
68- ...,
69- description = "The public key used to encrypt work order tokens sent to the UCS" ,
70- )
7167
7268
7369class AccessClient (AccessClientPort ):
@@ -261,7 +257,6 @@ class UCSClient(UCSClientPort):
261257
262258 def __init__ (self , * , config : UCSApiConfig ):
263259 self ._ucs_url = config .ucs_url
264- self ._ucs_public_key = config .ucs_public_key
265260 self ._signing_key = jwk .JWK .from_json (
266261 config .work_order_signing_key .get_secret_value ()
267262 )
@@ -270,9 +265,9 @@ def __init__(self, *, config: UCSApiConfig):
270265 log .error (key_error )
271266 raise key_error
272267
273- def _auth_header (self , signed_wot : str ) -> dict [str , str ]:
274- encrypted_wot = encrypt ( signed_wot , self ._ucs_public_key )
275- headers = {"Authorization" : f"Bearer { encrypted_wot } " }
268+ def _auth_header (self , wot : BaseWorkOrderToken ) -> dict [str , str ]:
269+ signed_wot = sign_work_order_token ( wot , self ._signing_key )
270+ headers = {"Authorization" : f"Bearer { signed_wot } " }
276271 return headers
277272
278273 async def create_file_upload_box (self , * , storage_alias : str ) -> UUID4 :
@@ -281,8 +276,7 @@ async def create_file_upload_box(self, *, storage_alias: str) -> UUID4:
281276 Raises:
282277 UCSCallError if there's a problem with the operation.
283278 """
284- signed_wot = sign_work_order_token (CreateFileBoxWorkOrder (), self ._signing_key )
285- headers = self ._auth_header (signed_wot )
279+ headers = self ._auth_header (CreateFileBoxWorkOrder ())
286280 body = {"storage_alias" : storage_alias }
287281 response = httpx .post (f"{ self ._ucs_url } /boxes" , headers = headers , json = body )
288282 if response .status_code != 201 :
@@ -310,8 +304,7 @@ async def lock_file_upload_box(self, *, box_id: UUID4) -> None:
310304 UCSCallError if there's a problem with the operation.
311305 """
312306 wot = ChangeFileBoxWorkOrder (work_type = "lock" , box_id = box_id )
313- signed_wot = sign_work_order_token (wot , self ._signing_key )
314- headers = self ._auth_header (signed_wot )
307+ headers = self ._auth_header (wot )
315308 body = {"lock" : True }
316309 response = httpx .patch (
317310 f"{ self ._ucs_url } /boxes/{ box_id } " , headers = headers , json = body
@@ -334,8 +327,8 @@ async def unlock_file_upload_box(self, *, box_id: UUID4) -> None:
334327 UCSCallError if there's a problem with the operation.
335328 """
336329 wot = ChangeFileBoxWorkOrder (work_type = "unlock" , box_id = box_id )
337- signed_wot = sign_work_order_token ( wot , self . _signing_key )
338- headers = self ._auth_header (signed_wot )
330+
331+ headers = self ._auth_header (wot )
339332 body = {"lock" : False }
340333 response = httpx .patch (
341334 f"{ self ._ucs_url } /boxes/{ box_id } " , headers = headers , json = body
@@ -358,8 +351,7 @@ async def get_file_upload_list(self, *, box_id: UUID4) -> list[UUID4]:
358351 UCSCallError if there's a problem with the operation.
359352 """
360353 wot = ViewFileBoxWorkOrder (box_id = box_id )
361- signed_wot = sign_work_order_token (wot , self ._signing_key )
362- headers = self ._auth_header (signed_wot )
354+ headers = self ._auth_header (wot )
363355 response = httpx .get (f"{ self ._ucs_url } /boxes/{ box_id } /uploads" , headers = headers )
364356 if response .status_code != 200 :
365357 log .error (
0 commit comments