@@ -49,7 +49,6 @@ class PdpPullRequest(BaseModel):
4949class PdpPullResponse (BaseModel ):
5050 """Fields for the PDP pull response."""
5151
52- sftp_files : list [dict ]
5352 pdp_inst_generated : list [Any ]
5453 pdp_inst_not_found : list [Any ]
5554 upload_status : dict
@@ -58,6 +57,12 @@ class Config:
5857 json_encoders = {np .int64 : lambda v : int (v )}
5958
6059
60+ class PdpListFiles (BaseModel ):
61+ """Fields for the PDP pull response."""
62+
63+ sftp_files : list [dict ]
64+
65+
6166@app .on_event ("startup" )
6267def on_startup ():
6368 print ("Starting up app..." )
@@ -162,8 +167,8 @@ async def process_file(
162167 }
163168
164169
165- @app .post ("/execute-pdp-pull " , response_model = PdpPullResponse )
166- async def execute_pdp_pull (
170+ @app .get ("/sftp_files " , response_model = PdpListFiles )
171+ def sftp_files (
167172 req : PdpPullRequest ,
168173 current_username : Annotated [str , Depends (get_current_username )],
169174 storage_control : Annotated [StorageControl , Depends (StorageControl )],
@@ -181,15 +186,30 @@ async def execute_pdp_pull(
181186 remote_path = "./receive" ,
182187 )
183188
184- results = []
185- for file in files :
186- gcs_blob = sftp_file_to_gcs_helper (storage_control , file )
187- result = await process_file (storage_control , gcs_blob , env_vars )
188- results .append (result )
189-
190189 # Aggregate results to return
191190 return {
192191 "sftp_files" : files ,
192+ }
193+
194+
195+ @app .post ("/execute-pdp-pull" , response_model = PdpPullResponse )
196+ async def execute_pdp_pull (
197+ req : PdpPullRequest ,
198+ sftp_source_filename : str ,
199+ current_username : Annotated [str , Depends (get_current_username )],
200+ storage_control : Annotated [StorageControl , Depends (StorageControl )],
201+ ) -> Any :
202+ """Performs the PDP pull of the file."""
203+
204+ storage_control .create_bucket_if_not_exists (
205+ get_sftp_bucket_name (env_vars ["BUCKET_ENV" ])
206+ )
207+
208+ gcs_blob = sftp_file_to_gcs_helper (storage_control , sftp_source_filename )
209+ result = await process_file (storage_control , gcs_blob , env_vars )
210+
211+ # Aggregate results to return
212+ return {
193213 "pdp_inst_generated" : list (result ["valid_inst_ids" ]),
194214 "pdp_inst_not_found" : list (result ["invalid_ids" ]),
195215 "upload_status" : dict (result ["uploads" ]),
0 commit comments