@@ -2,7 +2,7 @@ use crate::contexts::SessionId;
22use crate :: datasets:: upload:: VolumeName ;
33use crate :: error:: { self , Result } ;
44use crate :: util:: parsing:: { deserialize_api_prefix, deserialize_base_url_option} ;
5- use config:: { Config , Environment , File } ;
5+ use config:: { Config , Environment , File , FileFormat } ;
66use geoengine_datatypes:: primitives:: TimeInterval ;
77use geoengine_operators:: util:: raster_stream_to_geotiff:: GdalCompressionNumThreads ;
88use serde:: Deserialize ;
@@ -15,26 +15,33 @@ use url::Url;
1515
1616static SETTINGS : OnceLock < RwLock < Config > > = OnceLock :: new ( ) ;
1717
18+ const SETTINGS_FILE_PATH_OVERRIDE_ENV_VAR : & str = "GEOENGINE_SETTINGS_FILE_PATH" ;
19+
1820// TODO: change to `LazyLock' once stable
1921fn init_settings ( ) -> RwLock < Config > {
2022 let mut settings = Config :: builder ( ) ;
2123
2224 let dir: PathBuf = retrieve_settings_dir ( ) . expect ( "settings directory should exist" ) ;
2325
24- #[ cfg( test) ]
25- let files = [ "Settings-default.toml" , "Settings-test.toml" ] ;
26-
27- #[ cfg( not( test) ) ]
28- let files = [ "Settings-default.toml" , "Settings.toml" ] ;
26+ // include the default settings in the binary
27+ let default_settings = include_str ! ( "../../../Settings-default.toml" ) ;
2928
30- let files: Vec < File < _ , _ > > = files
31- . iter ( )
32- . map ( |f| dir. join ( f) )
33- . filter ( |p| p. exists ( ) )
34- . map ( File :: from)
35- . collect ( ) ;
29+ settings = settings. add_source ( File :: from_str ( default_settings, FileFormat :: Toml ) ) ;
3630
37- settings = settings. add_source ( files) ;
31+ if let Ok ( settings_file_path) = std:: env:: var ( SETTINGS_FILE_PATH_OVERRIDE_ENV_VAR ) {
32+ // override the settings file path
33+ settings = settings. add_source ( File :: with_name ( & settings_file_path) ) ;
34+ } else {
35+ // use the default settings file path
36+ #[ cfg( test) ]
37+ {
38+ settings = settings. add_source ( File :: from ( dir. join ( "Settings-test.toml" ) ) ) ;
39+ }
40+ #[ cfg( not( test) ) ]
41+ {
42+ settings = settings. add_source ( File :: from ( dir. join ( "Settings.toml" ) ) ) ;
43+ }
44+ }
3845
3946 // Override config with environment variables that start with `GEOENGINE_`,
4047 // e.g. `GEOENGINE_WEB__EXTERNAL_ADDRESS=https://path.to.geoengine.io`
0 commit comments