@@ -117,6 +117,7 @@ class ValidationResult(BaseModel):
117117 name : str
118118 inst_id : str
119119 file_types : set [SchemaType ]
120+ source : str
120121
121122
122123class DataOverview (BaseModel ):
@@ -261,7 +262,7 @@ def read_inst_all_input_files(
261262 }
262263
263264
264- @router .get ("/{inst_id}/input_debugging " , response_model = list [str ])
265+ @router .get ("/{inst_id}/input-debugging " , response_model = list [str ])
265266def get_all_files_in_bucket (
266267 inst_id : str ,
267268 current_user : Annotated [BaseUser , Depends (get_current_active_user )],
@@ -549,7 +550,6 @@ def update_batch(
549550 model_owner_and_higher_or_err (current_user , "modify batch" )
550551
551552 update_data = request .model_dump (exclude_unset = True )
552- print ("aaaaaaaaaaaaaaaaaaaaaaaa:" + str (update_data ))
553553 local_session .set (sql_session )
554554 # Check that the batch exists.
555555 query_result = (
@@ -676,7 +676,7 @@ def update_batch(
676676# TODO: check expiration of files and batches
677677
678678
679- @router .get ("/{inst_id}/file_id /{file_id}" , response_model = DataInfo )
679+ @router .get ("/{inst_id}/file-id /{file_id}" , response_model = DataInfo )
680680def read_file_id_info (
681681 inst_id : str ,
682682 file_id : str ,
@@ -796,7 +796,7 @@ def read_file_info(
796796
797797
798798# TODO: ADD TESTS for the below
799- @router .get ("/{inst_id}/download_url /{file_name}" , response_model = str )
799+ @router .get ("/{inst_id}/download-url /{file_name}" , response_model = str )
800800def download_url_inst_file (
801801 inst_id : str ,
802802 file_name : str ,
@@ -867,15 +867,14 @@ def download_url_inst_file(
867867# 3. Validate the file
868868
869869
870- @ router . post ( "/{inst_id}/input/validate/{file_name}" , response_model = ValidationResult )
871- def validate_file (
870+ def validation_helper (
871+ source_str : str ,
872872 inst_id : str ,
873873 file_name : str ,
874- current_user : Annotated [ BaseUser , Depends ( get_current_active_user )] ,
875- storage_control : Annotated [ StorageControl , Depends ( StorageControl )] ,
876- sql_session : Annotated [ Session , Depends ( get_session )] ,
874+ current_user : BaseUser ,
875+ storage_control : StorageControl ,
876+ sql_session : Session ,
877877) -> Any :
878- """Validate a given file. The file_name should not contain slashes."""
879878 has_access_to_inst_or_err (inst_id , current_user )
880879 if file_name .find ("/" ) != - 1 :
881880 raise HTTPException (
@@ -916,7 +915,7 @@ def validate_file(
916915 name = file_name ,
917916 inst_id = str_to_uuid (inst_id ),
918917 uploader = str_to_uuid (current_user .user_id ),
919- source = "MANUAL_UPLOAD" ,
918+ source = source_str ,
920919 sst_generated = False ,
921920 schemas = list (inferred_schemas ),
922921 valid = True ,
@@ -926,10 +925,48 @@ def validate_file(
926925 "name" : file_name ,
927926 "inst_id" : inst_id ,
928927 "file_types" : inferred_schemas ,
928+ "source" : source_str ,
929929 }
930930
931931
932- @router .get ("/{inst_id}/upload_url/{file_name}" , response_model = str )
932+ @router .post (
933+ "/{inst_id}/input/validate-sftp/{file_name}" , response_model = ValidationResult
934+ )
935+ def validate_file_sftp (
936+ inst_id : str ,
937+ file_name : str ,
938+ current_user : Annotated [BaseUser , Depends (get_current_active_user )],
939+ storage_control : Annotated [StorageControl , Depends (StorageControl )],
940+ sql_session : Annotated [Session , Depends (get_session )],
941+ ) -> Any :
942+ """Validate a given file pulled from SFTP. The file_name should not contain slashes."""
943+ if not current_user .is_datakinder :
944+ raise HTTPException (
945+ status_code = status .HTTP_401_UNAUTHORIZED ,
946+ detail = "SFTP validation needs to be done by a datakinder." ,
947+ )
948+ return validation_helper (
949+ "PDP_SFTP" , inst_id , file_name , current_user , storage_control , sql_session
950+ )
951+
952+
953+ @router .post (
954+ "/{inst_id}/input/validate-upload/{file_name}" , response_model = ValidationResult
955+ )
956+ def validate_file_manual_upload (
957+ inst_id : str ,
958+ file_name : str ,
959+ current_user : Annotated [BaseUser , Depends (get_current_active_user )],
960+ storage_control : Annotated [StorageControl , Depends (StorageControl )],
961+ sql_session : Annotated [Session , Depends (get_session )],
962+ ) -> Any :
963+ """Validate a given file. The file_name should not contain slashes."""
964+ return validation_helper (
965+ "MANUAL_UPLOAD" , inst_id , file_name , current_user , storage_control , sql_session
966+ )
967+
968+
969+ @router .get ("/{inst_id}/upload-url/{file_name}" , response_model = str )
933970def get_upload_url (
934971 inst_id : str ,
935972 file_name : str ,
0 commit comments