@@ -102,35 +102,35 @@ fn find_cfg_file(file_path: &Path) -> PyResult<PathBuf> {
102102 ) ;
103103 return Ok ( current_path) ;
104104 }
105-
106105 let cwd = env:: current_dir ( ) ?;
107-
108106 let cfg_file_name = "client_credentials.json" ;
109- let mut start_dir = match file_path. parent ( ) {
107+ let cfg_folder_name = "config" ;
108+ let start_dir = match current_path. parent ( ) {
110109 Some ( parent) => match parent. exists ( ) {
111110 true => parent. to_path_buf ( ) ,
112111 false => cwd,
113112 } ,
114113 None => cwd,
115114 } ;
116- let start_dir_init = start_dir. clone ( ) ;
117-
115+ let mut start_dir_abs = start_dir. canonicalize ( ) ? ;
116+ let start_dir_init = start_dir_abs . clone ( ) ;
118117 loop {
119- let full_path = start_dir . join ( cfg_file_name) ;
118+ let full_path = start_dir_abs . join ( cfg_folder_name ) . join ( cfg_file_name) ;
120119 if full_path. is_file ( ) {
121120 debug ! ( "Found file at: {}" , full_path. display( ) ) ;
122121 return Ok ( full_path) ;
123122 }
124123
125124 // Move to the parent directory
126- if let Some ( parent) = start_dir . parent ( ) {
127- start_dir = parent. to_path_buf ( ) ;
125+ if let Some ( parent) = start_dir_abs . parent ( ) {
126+ start_dir_abs = parent. to_path_buf ( ) . canonicalize ( ) ? ;
128127 } else {
129128 // Reached the root directory
130129 let error_message = format ! (
131- "File {} not found in {} or any of its parents" ,
130+ "File {} not found in {} or any of its parents. Current parent: {} " ,
132131 cfg_file_name,
133- start_dir_init. display( )
132+ start_dir_init. display( ) ,
133+ start_dir. display( )
134134 ) ;
135135 return Err ( PyFileNotFoundError :: new_err ( error_message) ) ;
136136 }
@@ -781,16 +781,17 @@ impl FusionCredentials {
781781 . client_id
782782 . or_else ( || std:: env:: var ( "FUSION_CLIENT_ID" ) . ok ( ) )
783783 . ok_or_else ( || CredentialError :: new_err ( "Missing client ID" ) ) ?;
784- let client_secret = credentials
785- . client_secret
786- . or_else ( || std:: env:: var ( "FUSION_CLIENT_SECRET" ) . ok ( ) )
787- . ok_or_else ( || CredentialError :: new_err ( "Missing client secret" ) ) ?;
788784
789785 let full_creds = match credentials. grant_type . as_str ( ) {
790786 "client_credentials" => FusionCredentials :: from_client_id (
791787 cls,
792788 Some ( client_id) ,
793- Some ( client_secret) ,
789+ Some (
790+ credentials
791+ . client_secret
792+ . or_else ( || std:: env:: var ( "FUSION_CLIENT_SECRET" ) . ok ( ) )
793+ . ok_or_else ( || CredentialError :: new_err ( "Missing client secret" ) ) ?,
794+ ) ,
794795 credentials. resource ,
795796 credentials. auth_url ,
796797 Some ( untyped_proxies ( credentials. proxies ) ) ,
@@ -886,11 +887,13 @@ mod tests {
886887 let temp_dir = TempDir :: new ( "test_find_cfg_file" ) . unwrap ( ) ;
887888 let parent_dir = temp_dir. path ( ) . join ( "parent" ) ;
888889 let child_dir = parent_dir. join ( "child" ) ;
890+ let dir_path = Path :: new ( "config" ) ;
889891
890892 fs:: create_dir_all ( & child_dir) . unwrap ( ) ;
891- let cfg_file_path = parent_dir. join ( "client_credentials.json" ) ;
893+ let cfg_file_path = parent_dir. join ( "config" ) . join ( " client_credentials.json") ;
892894
893895 // Create the config file in the parent directory
896+ fs:: create_dir_all ( parent_dir. join ( dir_path) ) . expect ( "Failed to create directory" ) ;
894897 let mut file = File :: create ( & cfg_file_path) . unwrap ( ) ;
895898 writeln ! ( file, "{{\" key\" : \" value\" }}" ) . unwrap ( ) ;
896899
0 commit comments