@@ -91,44 +91,50 @@ impl AwsCredentials {
9191 let ( plain_sync, encrypted_sync) =
9292 ( Arc :: new ( Semaphore :: new ( 32 ) ) , Arc :: new ( Semaphore :: new ( 4 ) ) ) ;
9393
94- let handles = ReadDirStream :: new ( fs:: read_dir ( & creds_d) . await . map_err ( |e| {
95- log:: error!( "Unable to read directory: {}" , e) ;
96- e
97- } ) ?)
98- . filter_map ( |e| {
99- // NOTE according to docs, this will only fail if there is an intermittent I/O error, not worth handling
100- e. ok ( )
101- } )
102- . map ( |e| e. path ( ) )
103- . chain ( stream:: iter ( vec ! [ aws_config_dir. join( "credentials" ) ] ) )
104- . filter ( |p| p. is_file ( ) )
105- . map ( |p| {
106- let ( plain_permit, encrypted_permit) = ( plain_sync. clone ( ) , encrypted_sync. clone ( ) ) ;
107-
108- tokio:: spawn ( async {
109- let name = p. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
110-
111- if name. ends_with ( ".asc" ) || name. ends_with ( ".gpg" ) || name. ends_with ( ".pgp" ) {
112- Some ( {
113- let work = encrypted_permit. acquire_owned ( ) . await . unwrap ( ) ;
114- let r = AwsCredentialsFile :: load_encrypted ( p) . await ;
115- drop ( work) ;
116- r
117- } )
118- } else if name. ends_with ( ".ini" ) || name. ends_with ( "" ) {
119- Some ( {
120- let work = plain_permit. acquire_owned ( ) . await . unwrap ( ) ;
121- let r = AwsCredentialsFile :: load ( p) . await ;
122- drop ( work) ;
123- r
124- } )
125- } else {
126- log:: debug!( "Skipping file with unknown extension {}" , p. display( ) ) ;
127- None
128- }
94+ let creds_files: Vec < PathBuf > = match fs:: read_dir ( & creds_d) . await {
95+ Ok ( creds) => {
96+ ReadDirStream :: new ( creds)
97+ . filter_map ( |f| f. ok ( ) )
98+ . map ( |f| f. path ( ) )
99+ . collect ( )
100+ . await
101+ }
102+ Err ( _) => {
103+ log:: debug!( "No $HOME/.aws/credentials.d directory found" ) ;
104+ vec ! [ ]
105+ }
106+ } ;
107+
108+ let handles = stream:: iter ( creds_files)
109+ . chain ( stream:: iter ( vec ! [ aws_config_dir. join( "credentials" ) ] ) )
110+ . filter ( |p| p. is_file ( ) )
111+ . map ( |p| {
112+ let ( plain_permit, encrypted_permit) = ( plain_sync. clone ( ) , encrypted_sync. clone ( ) ) ;
113+
114+ tokio:: spawn ( async {
115+ let name = p. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
116+
117+ if name. ends_with ( ".asc" ) || name. ends_with ( ".gpg" ) || name. ends_with ( ".pgp" ) {
118+ Some ( {
119+ let work = encrypted_permit. acquire_owned ( ) . await . unwrap ( ) ;
120+ let r = AwsCredentialsFile :: load_encrypted ( p) . await ;
121+ drop ( work) ;
122+ r
123+ } )
124+ } else if name. ends_with ( ".ini" ) || name. ends_with ( "" ) {
125+ Some ( {
126+ let work = plain_permit. acquire_owned ( ) . await . unwrap ( ) ;
127+ let r = AwsCredentialsFile :: load ( p) . await ;
128+ drop ( work) ;
129+ r
130+ } )
131+ } else {
132+ log:: debug!( "Skipping file with unknown extension {}" , p. display( ) ) ;
133+ None
134+ }
135+ } )
129136 } )
130- } )
131- . collect :: < Vec < JoinHandle < _ > > > ( ) ;
137+ . collect :: < Vec < JoinHandle < _ > > > ( ) ;
132138
133139 let mut credentials = BTreeSet :: new ( ) ;
134140
0 commit comments