@@ -7,7 +7,7 @@ mod util;
77
88use std:: collections:: { BTreeMap , HashMap } ;
99use std:: ffi:: OsString ;
10- use std:: fs:: { read_to_string , File } ;
10+ use std:: fs;
1111use std:: io:: { Read , Write } ;
1212use std:: net:: { Ipv4Addr , SocketAddr } ;
1313use std:: path:: { Path , PathBuf } ;
@@ -1293,22 +1293,22 @@ impl Shuttle {
12931293 . find ( |& secrets_file| secrets_file. exists ( ) && secrets_file. is_file ( ) )
12941294 } ) ;
12951295
1296- Ok ( if let Some ( secrets_file) = secrets_file {
1297- trace ! ( "Loading secrets from {}" , secrets_file . display ( ) ) ;
1298- if let Ok ( secrets_str ) = read_to_string ( secrets_file ) {
1299- let secrets = toml :: from_str :: < HashMap < String , String > > ( & secrets_str ) ? ;
1296+ let Some ( secrets_file) = secrets_file else {
1297+ trace ! ( "No secrets file was found" ) ;
1298+ return Ok ( None ) ;
1299+ } ;
13001300
1301- trace ! ( keys = ?secrets. keys( ) , "available secrets" ) ;
1301+ trace ! ( "Loading secrets from {}" , secrets_file. display( ) ) ;
1302+ let Ok ( secrets_str) = fs:: read_to_string ( secrets_file) else {
1303+ tracing:: warn!( "Failed to read secrets file, no secrets were loaded" ) ;
1304+ return Ok ( None ) ;
1305+ } ;
13021306
1303- Some ( secrets)
1304- } else {
1305- trace ! ( "No secrets were loaded" ) ;
1306- None
1307- }
1308- } else {
1309- trace ! ( "No secrets file was found" ) ;
1310- None
1311- } )
1307+ let secrets = toml:: from_str :: < HashMap < String , String > > ( & secrets_str)
1308+ . context ( "parsing secrets file" ) ?;
1309+ trace ! ( keys = ?secrets. keys( ) , "Loaded secrets" ) ;
1310+
1311+ Ok ( Some ( secrets) )
13121312 }
13131313
13141314 async fn pre_local_run ( & self , run_args : & RunArgs ) -> Result < BuiltService > {
@@ -1676,7 +1676,7 @@ impl Shuttle {
16761676 }
16771677
16781678 eprintln ! ( "Packing files..." ) ;
1679- let archive = self . make_archive ( args . secret_args . secrets . clone ( ) ) ?;
1679+ let archive = self . make_archive ( ) ?;
16801680
16811681 if let Some ( path) = args. output_archive {
16821682 eprintln ! ( "Writing archive to {}" , path. display( ) ) ;
@@ -1935,7 +1935,8 @@ impl Shuttle {
19351935 Ok ( ( ) )
19361936 }
19371937
1938- fn make_archive ( & self , secrets_file : Option < PathBuf > ) -> Result < Vec < u8 > > {
1938+ /// Find list of all files to include in a build, ready for placing in a zip archive
1939+ fn gather_build_files ( & self ) -> Result < BTreeMap < PathBuf , PathBuf > > {
19391940 let include_patterns = self . ctx . include ( ) ;
19401941
19411942 let project_directory = self . ctx . project_directory ( ) ;
@@ -1964,16 +1965,8 @@ impl Shuttle {
19641965 entries. push ( r. context ( "list dir entry" ) ?. into_path ( ) )
19651966 }
19661967
1967- let mut globs = GlobSetBuilder :: new ( ) ;
1968-
1969- if let Some ( secrets_file) = secrets_file. clone ( ) {
1970- entries. push ( secrets_file) ;
1971- } else {
1972- // Default: Include all Secrets.toml files
1973- globs. add ( Glob :: new ( "**/Secrets.toml" ) . unwrap ( ) ) ;
1974- }
1975-
19761968 // User provided includes
1969+ let mut globs = GlobSetBuilder :: new ( ) ;
19771970 if let Some ( rules) = include_patterns {
19781971 for r in rules {
19791972 globs. add ( Glob :: new ( r. as_str ( ) ) . context ( format ! ( "parsing glob pattern {:?}" , r) ) ?) ;
@@ -2006,20 +1999,19 @@ impl Shuttle {
20061999 }
20072000
20082001 // zip file puts all files in root
2009- let mut name = path
2002+ let name = path
20102003 . strip_prefix ( project_directory)
20112004 . context ( "strip prefix of path" ) ?
20122005 . to_owned ( ) ;
20132006
2014- // if this is the custom secrets file, rename it to Secrets.toml
2015- if secrets_file. as_ref ( ) . is_some_and ( |sf| sf == & path) {
2016- name. pop ( ) ;
2017- name. push ( "Secrets.toml" ) ;
2018- }
2019-
20202007 archive_files. insert ( path, name) ;
20212008 }
20222009
2010+ Ok ( archive_files)
2011+ }
2012+
2013+ fn make_archive ( & self ) -> Result < Vec < u8 > > {
2014+ let archive_files = self . gather_build_files ( ) ?;
20232015 if archive_files. is_empty ( ) {
20242016 error ! ( "No files included in upload. Aborting..." ) ;
20252017 bail ! ( "No files included in upload." ) ;
@@ -2036,7 +2028,7 @@ impl Shuttle {
20362028 zip. start_file ( name, FileOptions :: < ( ) > :: default ( ) ) ?;
20372029
20382030 let mut b = Vec :: new ( ) ;
2039- File :: open ( path) ?. read_to_end ( & mut b) ?;
2031+ fs :: File :: open ( path) ?. read_to_end ( & mut b) ?;
20402032 zip. write_all ( & b) ?;
20412033 }
20422034 let r = zip. finish ( ) . context ( "finish encoding zip archive" ) ?;
@@ -2104,7 +2096,7 @@ fn create_spinner() -> ProgressBar {
21042096mod tests {
21052097 use zip:: ZipArchive ;
21062098
2107- use crate :: args:: { DeployArgs , ProjectArgs , SecretsArgs } ;
2099+ use crate :: args:: ProjectArgs ;
21082100 use crate :: Shuttle ;
21092101 use std:: fs:: { self , canonicalize} ;
21102102 use std:: io:: Cursor ;
@@ -2118,19 +2110,14 @@ mod tests {
21182110 dunce:: canonicalize ( path) . unwrap ( )
21192111 }
21202112
2121- async fn get_archive_entries (
2122- project_args : ProjectArgs ,
2123- deploy_args : DeployArgs ,
2124- ) -> Vec < String > {
2113+ async fn get_archive_entries ( project_args : ProjectArgs ) -> Vec < String > {
21252114 let mut shuttle = Shuttle :: new ( crate :: Binary :: Shuttle , None ) . unwrap ( ) ;
21262115 shuttle
21272116 . load_project ( & project_args, false , false )
21282117 . await
21292118 . unwrap ( ) ;
21302119
2131- let archive = shuttle
2132- . make_archive ( deploy_args. secret_args . secrets )
2133- . unwrap ( ) ;
2120+ let archive = shuttle. make_archive ( ) . unwrap ( ) ;
21342121
21352122 let mut zip = ZipArchive :: new ( Cursor :: new ( archive) ) . unwrap ( ) ;
21362123 ( 0 ..zip. len ( ) )
@@ -2160,14 +2147,13 @@ mod tests {
21602147 name : None ,
21612148 id : Some ( "proj_archiving-test" . to_owned ( ) ) ,
21622149 } ;
2163- let mut entries = get_archive_entries ( project_args. clone ( ) , Default :: default ( ) ) . await ;
2150+ let mut entries = get_archive_entries ( project_args. clone ( ) ) . await ;
21642151 entries. sort ( ) ;
21652152
21662153 let expected = vec ! [
21672154 ".gitignore" ,
21682155 ".ignore" ,
21692156 "Cargo.toml" ,
2170- "Secrets.toml" , // always included by default
21712157 "Secrets.toml.example" ,
21722158 "Shuttle.toml" ,
21732159 "asset1" , // normal file
@@ -2181,40 +2167,6 @@ mod tests {
21812167 "src/main.rs" ,
21822168 ] ;
21832169 assert_eq ! ( entries, expected) ;
2184-
2185- fs:: remove_file ( working_directory. join ( "Secrets.toml" ) ) . unwrap ( ) ;
2186- let mut entries = get_archive_entries (
2187- project_args,
2188- DeployArgs {
2189- secret_args : SecretsArgs {
2190- secrets : Some ( working_directory. join ( "Secrets.toml.example" ) ) ,
2191- } ,
2192- ..Default :: default ( )
2193- } ,
2194- )
2195- . await ;
2196- entries. sort ( ) ;
2197-
2198- assert_eq ! (
2199- entries,
2200- vec![
2201- ".gitignore" ,
2202- ".ignore" ,
2203- "Cargo.toml" ,
2204- "Secrets.toml" , // got moved here
2205- // Secrets.toml.example was the given secrets file, so it got moved
2206- "Shuttle.toml" ,
2207- "asset1" , // normal file
2208- "asset2" , // .gitignore'd, but included in Shuttle.toml
2209- // asset3 is .ignore'd
2210- "asset4" , // .gitignore'd, but un-ignored in .ignore
2211- "asset5" , // .ignore'd, but included in Shuttle.toml
2212- "dist/dist1" , // .gitignore'd, but included in Shuttle.toml
2213- "nested/static/nested1" , // normal file
2214- // nested/static/nestedignore is .gitignore'd
2215- "src/main.rs" ,
2216- ]
2217- ) ;
22182170 }
22192171
22202172 #[ tokio:: test]
0 commit comments