@@ -9,6 +9,7 @@ const CONFIG_PATH: &str = "/etc/sarus-suite";
99#[ derive( Serialize , Deserialize , Clone , Default ) ]
1010pub struct RawConfig {
1111 edf_system_search_path : Option < String > ,
12+ hooks : Option < RawConfigHooks > ,
1213 parallax_imagestore : Option < String > ,
1314 parallax_mount_program : Option < String > ,
1415 parallax_path : Option < String > ,
@@ -26,10 +27,17 @@ pub struct RawConfig {
2627 tracking_tool : Option < String > ,
2728}
2829
30+ #[ derive( Serialize , Deserialize , Clone , Default ) ]
31+ pub struct RawConfigHooks {
32+ parallax_imagestore_create : Option < String > ,
33+ }
34+
2935#[ derive( Serialize , Deserialize , Clone , Default ) ]
3036pub struct Config {
3137 #[ serde( default = "get_default_edf_system_search_path" ) ]
3238 pub edf_system_search_path : String ,
39+ #[ serde( default = "get_default_hooks" ) ]
40+ pub hooks : ConfigHooks ,
3341 #[ serde( default = "get_default_parallax_imagestore" ) ]
3442 pub parallax_imagestore : String ,
3543 #[ serde( default = "get_default_parallax_mount_program" ) ]
@@ -62,6 +70,12 @@ pub struct Config {
6270 pub tracking_tool : String ,
6371}
6472
73+ #[ derive( Serialize , Deserialize , Clone , Default ) ]
74+ pub struct ConfigHooks {
75+ #[ serde( default = "get_default_hook_parallax_imagestore_create" ) ]
76+ pub parallax_imagestore_create : String ,
77+ }
78+
6579#[ derive( Clone , Copy ) ]
6680pub enum VarExpand {
6781 Never , // Do not expand variables.
@@ -134,13 +148,27 @@ fn get_default_tracking_tool() -> String {
134148 return String :: from ( "" ) ;
135149}
136150
151+ fn get_default_hook_parallax_imagestore_create ( ) -> String {
152+ return String :: from ( "" ) ;
153+ }
154+
155+ fn get_default_hooks ( ) -> ConfigHooks {
156+ return ConfigHooks {
157+ parallax_imagestore_create : get_default_hook_parallax_imagestore_create ( ) ,
158+ }
159+ }
160+
137161impl From < RawConfig > for Config {
138162 fn from ( r : RawConfig ) -> Self {
139163 Config {
140164 edf_system_search_path : match r. edf_system_search_path {
141165 Some ( s) => s,
142166 None => get_default_edf_system_search_path ( ) ,
143167 } ,
168+ hooks : match r. hooks {
169+ Some ( s) => ConfigHooks :: from ( s) ,
170+ None => get_default_hooks ( ) ,
171+ } ,
144172 parallax_imagestore : match r. parallax_imagestore {
145173 Some ( s) => s,
146174 None => get_default_parallax_imagestore ( ) ,
@@ -211,6 +239,9 @@ impl RawConfig {
211239 if i. edf_system_search_path . is_some ( ) {
212240 self . edf_system_search_path = i. edf_system_search_path ;
213241 }
242+ if i. hooks . is_some ( ) {
243+ self . hooks = i. hooks ;
244+ }
214245 if i. parallax_imagestore . is_some ( ) {
215246 self . parallax_imagestore = i. parallax_imagestore ;
216247 }
@@ -259,6 +290,17 @@ impl RawConfig {
259290 }
260291}
261292
293+ impl From < RawConfigHooks > for ConfigHooks {
294+ fn from ( r : RawConfigHooks ) -> Self {
295+ ConfigHooks {
296+ parallax_imagestore_create : match r. parallax_imagestore_create {
297+ Some ( s) => s,
298+ None => get_default_hook_parallax_imagestore_create ( ) ,
299+ } ,
300+ }
301+ }
302+ }
303+
262304fn validate_configfile ( path : String ) -> SarusResult < ( ) > {
263305 // Embedding schema file
264306 let schema_content = include_str ! ( "schema/config.json" ) ;
@@ -303,6 +345,7 @@ fn load_raw_config_from_file(
303345 } ;
304346
305347 let mut r: RawConfig = toml_value;
348+
306349 //let mut r: RawConfig = toml_read(path_str)?;
307350
308351 // Expand variables in the fields
@@ -427,6 +470,14 @@ fn load_raw_config_from_dir(
427470}
428471
429472pub fn update_config_by_user ( config : & mut Config , edf : EDF ) -> SarusResult < ( ) > {
473+ let parallax_imagestore_create = edf. annotations . get ( "com.sarus.hooks.parallax_imagestore_create" ) ;
474+ if parallax_imagestore_create. is_some ( ) {
475+ match parallax_imagestore_create. unwrap ( ) . as_str ( ) {
476+ "false" => { config. hooks . parallax_imagestore_create = String :: from ( "" ) } ,
477+ _ => { } ,
478+ }
479+ }
480+
430481 let parallax_imagestore = edf. annotations . get ( "com.sarus.parallax_imagestore" ) ;
431482 if parallax_imagestore. is_some ( ) {
432483 config. parallax_imagestore = parallax_imagestore. unwrap ( ) . to_string ( ) ;
0 commit comments