@@ -479,7 +479,7 @@ impl Configurator {
479479 Ok ( result)
480480 }
481481
482- /// Set the parameters context for the configuration.
482+ /// Set the parameters and variables context for the configuration.
483483 ///
484484 /// # Arguments
485485 ///
@@ -488,12 +488,18 @@ impl Configurator {
488488 /// # Errors
489489 ///
490490 /// This function will return an error if the parameters are invalid.
491- pub fn set_parameters ( & mut self , parameters_input : & Option < Value > ) -> Result < ( ) , DscError > {
492- // set default parameters first
491+ pub fn set_context ( & mut self , parameters_input : & Option < Value > ) -> Result < ( ) , DscError > {
493492 let config = serde_json:: from_str :: < Configuration > ( self . json . as_str ( ) ) ?;
493+ self . set_parameters ( parameters_input, & config) ?;
494+ self . set_variables ( & config) ?;
495+ Ok ( ( ) )
496+ }
497+
498+ fn set_parameters ( & mut self , parameters_input : & Option < Value > , config : & Configuration ) -> Result < ( ) , DscError > {
499+ // set default parameters first
494500 let Some ( parameters) = & config. parameters else {
495501 if parameters_input. is_none ( ) {
496- debug ! ( "No parameters defined in configuration and no parameters input" ) ;
502+ info ! ( "No parameters defined in configuration and no parameters input" ) ;
497503 return Ok ( ( ) ) ;
498504 }
499505 return Err ( DscError :: Validation ( "No parameters defined in configuration" . to_string ( ) ) ) ;
@@ -543,6 +549,7 @@ impl Configurator {
543549 } else {
544550 info ! ( "Set parameter '{name}' to '{value}'" ) ;
545551 }
552+
546553 self . context . parameters . insert ( name. clone ( ) , ( value. clone ( ) , constraint. parameter_type . clone ( ) ) ) ;
547554 // also update the configuration with the parameter value
548555 if let Some ( parameters) = & mut self . config . parameters {
@@ -558,6 +565,25 @@ impl Configurator {
558565 Ok ( ( ) )
559566 }
560567
568+ fn set_variables ( & mut self , config : & Configuration ) -> Result < ( ) , DscError > {
569+ let Some ( variables) = & config. variables else {
570+ debug ! ( "No variables defined in configuration" ) ;
571+ return Ok ( ( ) ) ;
572+ } ;
573+
574+ for ( name, value) in variables {
575+ let new_value = if let Some ( string) = value. as_str ( ) {
576+ self . statement_parser . parse_and_execute ( string, & self . context ) ?
577+ }
578+ else {
579+ value. clone ( )
580+ } ;
581+ info ! ( "Set variable '{name}' to '{new_value}'" ) ;
582+ self . context . variables . insert ( name. to_string ( ) , new_value) ;
583+ }
584+ Ok ( ( ) )
585+ }
586+
561587 fn get_result_metadata ( & self , operation : Operation ) -> Metadata {
562588 let end_datetime = chrono:: Local :: now ( ) ;
563589 Metadata {
0 commit comments