@@ -14,17 +14,20 @@ class Client:
1414 def __init__ (self , client : httpx .AsyncClient ) -> None :
1515 self ._client = client
1616
17+ async def get (self , blueprint_id : str ) -> Blueprint :
18+ url = f"v3/blueprints/{ blueprint_id } "
19+ response = await self ._client .get (url )
20+ api .check_error (response )
21+ return Blueprint .from_dto (response .json ()["blueprint" ])
22+
1723 async def upload_file (self , path : pathlib .Path ) -> Blueprint :
1824 with path .open ("rb" ) as file :
1925 data = file .read ()
2026 return await self .upload (data )
2127
2228 async def upload_directory (self , path : pathlib .Path ) -> Blueprint :
23- buffer = io .BytesIO ()
24- with zipfile .ZipFile (buffer , "w" , zipfile .ZIP_DEFLATED ) as zip_file :
25- for file_path in path .rglob ("*" ):
26- zip_file .write (file_path , arcname = file_path .relative_to (path ))
27- return await self .upload (buffer .getvalue ())
29+ data = await self ._zip_directory (path )
30+ return await self .upload (data )
2831
2932 async def upload (self , data : bytes ) -> Blueprint :
3033 url = "v3/blueprints/upload"
@@ -39,3 +42,29 @@ async def download(
3942 response = await self ._client .get (url , params = {"view" : view .value })
4043 api .check_error (response )
4144 return response .content
45+
46+ async def validate_file (self , path : pathlib .Path ) -> None :
47+ with path .open ("rb" ) as file :
48+ data = file .read ()
49+ await self .validate (data )
50+
51+ async def validate_directory (self , path : pathlib .Path ) -> None :
52+ data = await self ._zip_directory (path )
53+ await self .validate (data )
54+
55+ async def validate (self , data : bytes ) -> None :
56+ url = "v3/blueprints/validate"
57+ response = await self ._client .post (url , content = data )
58+ api .check_error (response )
59+ validation_errors = response .json ().get ("validation_errors" , [])
60+ if validation_errors :
61+ raise api .MultiError (
62+ [api .Error (msg , code = None , details = None ) for msg in validation_errors ]
63+ )
64+
65+ async def _zip_directory (self , path : pathlib .Path ) -> bytes :
66+ buffer = io .BytesIO ()
67+ with zipfile .ZipFile (buffer , "w" , zipfile .ZIP_DEFLATED ) as zip_file :
68+ for file_path in path .rglob ("*" ):
69+ zip_file .write (file_path , arcname = file_path .relative_to (path ))
70+ return buffer .getvalue ()
0 commit comments