@@ -114,15 +114,20 @@ fn global_defaults_to_variables(global_defaults: HashMap<String, serde_yaml::Val
114114 global_defaults
115115 . into_iter ( )
116116 . map ( |( key, value) | {
117- // Convert the YAML value to a string representation
118- let string_value = match value {
119- serde_yaml:: Value :: String ( s) => s,
120- other => serde_yaml:: to_string ( & other)
121- . unwrap_or_else ( |_| String :: new ( ) )
122- . trim ( )
123- . to_string ( ) ,
117+ // Create the appropriate Variable type based on the YAML value type
118+ let var = match value {
119+ serde_yaml:: Value :: String ( s) => Variable :: new_final_string_variable ( s) ,
120+ serde_yaml:: Value :: Bool ( b) => Variable :: new_final_bool_variable ( b) ,
121+ serde_yaml:: Value :: Number ( n) => Variable :: new_final_number_variable ( n) ,
122+ serde_yaml:: Value :: Mapping ( m) => {
123+ let map: HashMap < String , serde_yaml:: Value > = m
124+ . into_iter ( )
125+ . filter_map ( |( k, v) | k. as_str ( ) . map ( |s| ( s. to_string ( ) , v) ) )
126+ . collect ( ) ;
127+ Variable :: new_final_mapping_variable ( map)
128+ }
129+ other => Variable :: new_final_yaml_variable ( other) ,
124130 } ;
125- let var = Variable :: new_final_string_variable ( string_value) ;
126131 ( Namespace :: Default . namespaced_name ( & key) , var)
127132 } )
128133 . collect ( )
@@ -673,15 +678,22 @@ variables:
673678 description: "registry url"
674679 type: string
675680 required: false
676- default: "${nr-default:registry_url}"
681+ default: "${nr-default:registry_url}/test-repository"
682+ enable_file_logging:
683+ description: "enable file logging"
684+ type: bool
685+ required: false
686+ default: ${nr-default:enable_file_logging}
677687deployment:
678688 linux:
689+ enable_file_logging: ${nr-var:enable_file_logging}
679690 executables:
680691 - id: first
681692 path: /opt/first
682693 args:
683694 - "${nr-var:registry}"
684695 windows:
696+ enable_file_logging: ${nr-var:enable_file_logging}
685697 executables:
686698 - id: first
687699 path: /opt/first
@@ -693,10 +705,16 @@ deployment:
693705 let values = testing_values ( "" ) ;
694706 let attributes = testing_agent_attributes ( & agent_id) ;
695707
696- let global_defaults = HashMap :: from ( [ (
697- "registry_url" . to_string ( ) ,
698- serde_yaml:: to_value ( "random-registry-url" ) . unwrap ( ) ,
699- ) ] ) ;
708+ let global_defaults = HashMap :: from ( [
709+ (
710+ "registry_url" . to_string ( ) ,
711+ serde_yaml:: to_value ( "test-registry-url" ) . unwrap ( ) ,
712+ ) ,
713+ (
714+ "enable_file_logging" . to_string ( ) ,
715+ serde_yaml:: to_value ( true ) . unwrap ( ) ,
716+ ) ,
717+ ] ) ;
700718
701719 let renderer =
702720 TemplateRenderer :: default ( ) . with_agent_control_variables ( HashMap :: new ( ) . into_iter ( ) ) ;
@@ -711,14 +729,15 @@ deployment:
711729 )
712730 . unwrap ( ) ;
713731 assert_eq ! (
714- rendered:: Args ( vec!( "random -registry-url" . to_string( ) ) ) ,
715- extract_runtime_by_environment( runtime_config)
732+ rendered:: Args ( vec!( "test -registry-url/test-repository " . to_string( ) ) ) ,
733+ extract_runtime_by_environment( runtime_config. clone ( ) )
716734 . executables
717735 . first( )
718736 . unwrap( )
719737 . args
720738 . clone( )
721739 ) ;
740+ assert ! ( extract_runtime_by_environment( runtime_config. clone( ) ) . enable_file_logging) ;
722741 }
723742
724743 #[ test]
@@ -736,15 +755,22 @@ variables:
736755 description: "registry url"
737756 type: string
738757 required: false
739- default: "${nr-default:registry_url}"
758+ default: "${nr-default:registry_url}/test-repository"
759+ enable_file_logging:
760+ description: "enable file logging"
761+ type: bool
762+ required: false
763+ default: ${nr-default:enable_file_logging}
740764deployment:
741765 linux:
766+ enable_file_logging: ${nr-var:enable_file_logging}
742767 executables:
743768 - id: first
744769 path: /opt/first
745770 args:
746771 - "${nr-var:registry}"
747772 windows:
773+ enable_file_logging: ${nr-var:enable_file_logging}
748774 executables:
749775 - id: first
750776 path: /opt/first
@@ -756,15 +782,27 @@ deployment:
756782 let values = testing_values ( "" ) ;
757783 let attributes = testing_agent_attributes ( & agent_id) ;
758784
759- let global_defaults = HashMap :: from ( [ (
760- "registry_url" . to_string ( ) ,
761- serde_yaml:: to_value ( "${nr-env:REGISTRY_URL}" ) . unwrap ( ) ,
762- ) ] ) ;
785+ let global_defaults = HashMap :: from ( [
786+ (
787+ "registry_url" . to_string ( ) ,
788+ serde_yaml:: to_value ( "${nr-env:REGISTRY_URL}" ) . unwrap ( ) ,
789+ ) ,
790+ (
791+ "enable_file_logging" . to_string ( ) ,
792+ serde_yaml:: to_value ( "${nr-env:ENABLE_FILE_LOGGING}" ) . unwrap ( ) ,
793+ ) ,
794+ ] ) ;
763795
764- let secrets = HashMap :: from ( [ (
765- Namespace :: EnvironmentVariable . namespaced_name ( "REGISTRY_URL" ) ,
766- Variable :: new_final_string_variable ( "random-registry-url" . to_string ( ) ) ,
767- ) ] ) ;
796+ let secrets = HashMap :: from ( [
797+ (
798+ Namespace :: EnvironmentVariable . namespaced_name ( "REGISTRY_URL" ) ,
799+ Variable :: new_final_string_variable ( "test-registry-url" . to_string ( ) ) ,
800+ ) ,
801+ (
802+ Namespace :: EnvironmentVariable . namespaced_name ( "ENABLE_FILE_LOGGING" ) ,
803+ Variable :: new_final_bool_variable ( true ) ,
804+ ) ,
805+ ] ) ;
768806
769807 let renderer =
770808 TemplateRenderer :: default ( ) . with_agent_control_variables ( HashMap :: new ( ) . into_iter ( ) ) ;
@@ -779,14 +817,15 @@ deployment:
779817 )
780818 . unwrap ( ) ;
781819 assert_eq ! (
782- rendered:: Args ( vec!( "random -registry-url" . to_string( ) ) ) ,
783- extract_runtime_by_environment( runtime_config)
820+ rendered:: Args ( vec!( "test -registry-url/test-repository " . to_string( ) ) ) ,
821+ extract_runtime_by_environment( runtime_config. clone ( ) )
784822 . executables
785823 . first( )
786824 . unwrap( )
787825 . args
788826 . clone( )
789827 ) ;
828+ assert ! ( extract_runtime_by_environment( runtime_config. clone( ) ) . enable_file_logging) ;
790829 }
791830
792831 // Agent Type and Values definitions
0 commit comments