@@ -382,10 +382,7 @@ fn normalize_path(path: &Path) -> PathBuf {
382382 ret
383383}
384384
385- pub fn is_allowed_file_location (
386- job_dir : & str ,
387- user_defined_path : & str ,
388- ) -> error:: Result < PathBuf > {
385+ pub fn is_allowed_file_location ( job_dir : & str , user_defined_path : & str ) -> error:: Result < PathBuf > {
389386 let job_dir = Path :: new ( job_dir) ;
390387 let user_path = PathBuf :: from ( user_defined_path) ;
391388
@@ -1398,18 +1395,66 @@ pub async fn load_worker_config(
13981395 tracing:: debug!( "Custom tags priority set: {:?}" , priority_tags_sorted) ;
13991396
14001397 let env_vars_static = config. env_vars_static . unwrap_or_default ( ) . clone ( ) ;
1401- let resolved_env_vars: HashMap < String , String > = env_vars_static
1402- . keys ( )
1403- . map ( |x| x. to_string ( ) )
1404- . chain ( config. env_vars_allowlist . unwrap_or_default ( ) )
1405- . chain (
1406- std:: env:: var ( "WHITELIST_ENVS" )
1407- . ok ( )
1408- . map ( |x| x. split ( ',' ) . map ( |x| x. to_string ( ) ) . collect_vec ( ) )
1409- . unwrap_or_default ( )
1410- . into_iter ( ) ,
1411- )
1412- . sorted ( )
1398+ let resolved_env_vars: HashMap < String , String > = load_env_vars (
1399+ config
1400+ . env_vars_allowlist
1401+ . unwrap_or_default ( )
1402+ . into_iter ( )
1403+ . chain ( load_whitelist_env_vars_from_env ( ) )
1404+ . chain ( env_vars_static. keys ( ) . map ( |x| x. to_string ( ) ) ) ,
1405+ & env_vars_static,
1406+ ) ;
1407+
1408+ Ok ( WorkerConfig {
1409+ worker_tags,
1410+ priority_tags_sorted,
1411+ dedicated_worker,
1412+ init_bash : config
1413+ . init_bash
1414+ . or_else ( || load_init_bash_from_env ( ) )
1415+ . and_then ( |x| if x. is_empty ( ) { None } else { Some ( x) } ) ,
1416+ cache_clear : config. cache_clear ,
1417+ pip_local_dependencies : config
1418+ . pip_local_dependencies
1419+ . or_else ( || load_pip_local_dependencies_from_env ( ) ) ,
1420+ additional_python_paths : config
1421+ . additional_python_paths
1422+ . or_else ( || load_additional_python_paths_from_env ( ) ) ,
1423+ env_vars : resolved_env_vars,
1424+ } )
1425+ }
1426+
1427+ pub fn load_init_bash_from_env ( ) -> Option < String > {
1428+ std:: env:: var ( "INIT_SCRIPT" )
1429+ . ok ( )
1430+ . and_then ( |x| if x. is_empty ( ) { None } else { Some ( x) } )
1431+ }
1432+
1433+ pub fn load_pip_local_dependencies_from_env ( ) -> Option < Vec < String > > {
1434+ std:: env:: var ( "PIP_LOCAL_DEPENDENCIES" )
1435+ . ok ( )
1436+ . map ( |x| x. split ( ',' ) . map ( |x| x. to_string ( ) ) . collect_vec ( ) )
1437+ }
1438+
1439+ pub fn load_additional_python_paths_from_env ( ) -> Option < Vec < String > > {
1440+ std:: env:: var ( "ADDITIONAL_PYTHON_PATHS" )
1441+ . ok ( )
1442+ . map ( |x| x. split ( ':' ) . map ( |x| x. to_string ( ) ) . collect_vec ( ) )
1443+ }
1444+
1445+ pub fn load_whitelist_env_vars_from_env ( ) -> std:: vec:: IntoIter < String > {
1446+ std:: env:: var ( "WHITELIST_ENVS" )
1447+ . ok ( )
1448+ . map ( |x| x. split ( ',' ) . map ( |x| x. to_string ( ) ) . collect_vec ( ) )
1449+ . unwrap_or_default ( )
1450+ . into_iter ( )
1451+ }
1452+
1453+ pub fn load_env_vars (
1454+ iter : impl Iterator < Item = String > ,
1455+ env_vars_static : & HashMap < String , String > ,
1456+ ) -> HashMap < String , String > {
1457+ iter. sorted ( )
14131458 . unique ( )
14141459 . map ( |envvar_name| {
14151460 (
@@ -1422,34 +1467,7 @@ pub async fn load_worker_config(
14221467 } ) ,
14231468 )
14241469 } )
1425- . collect ( ) ;
1426-
1427- Ok ( WorkerConfig {
1428- worker_tags,
1429- priority_tags_sorted,
1430- dedicated_worker,
1431- init_bash : config
1432- . init_bash
1433- . or_else ( || std:: env:: var ( "INIT_SCRIPT" ) . ok ( ) )
1434- . and_then ( |x| if x. is_empty ( ) { None } else { Some ( x) } ) ,
1435- cache_clear : config. cache_clear ,
1436- pip_local_dependencies : config. pip_local_dependencies . or_else ( || {
1437- let pip_local_dependencies = std:: env:: var ( "PIP_LOCAL_DEPENDENCIES" )
1438- . ok ( )
1439- . map ( |x| x. split ( ',' ) . map ( |x| x. to_string ( ) ) . collect ( ) ) ;
1440- if pip_local_dependencies == Some ( vec ! [ "" . to_string( ) ] ) {
1441- None
1442- } else {
1443- pip_local_dependencies
1444- }
1445- } ) ,
1446- additional_python_paths : config. additional_python_paths . or_else ( || {
1447- std:: env:: var ( "ADDITIONAL_PYTHON_PATHS" )
1448- . ok ( )
1449- . map ( |x| x. split ( ':' ) . map ( |x| x. to_string ( ) ) . collect ( ) )
1450- } ) ,
1451- env_vars : resolved_env_vars,
1452- } )
1470+ . collect ( )
14531471}
14541472
14551473#[ derive( Clone , PartialEq , Debug ) ]
0 commit comments