@@ -4,25 +4,10 @@ use nodejs_semver::{Range, Version};
44
55use crate :: error:: OrchestrionError ;
66use crate :: function_query:: FunctionQuery ;
7+ use crate :: { get_arr, get_str} ;
78
89use yaml_rust2:: { Yaml , YamlLoader } ;
910
10- macro_rules! get_str {
11- ( $property: expr, $name: expr) => {
12- $property[ $name]
13- . as_str( )
14- . ok_or( format!( "Invalid config: '{}' must be a string" , $name) ) ?
15- } ;
16- }
17-
18- macro_rules! get_arr {
19- ( $property: expr, $name: expr) => {
20- $property[ $name]
21- . as_vec( )
22- . ok_or( format!( "Invalid config: '{}' must be a array" , $name) ) ?
23- } ;
24- }
25-
2611#[ derive( Clone , Debug ) ]
2712pub enum InstrumentationOperator {
2813 Callback ,
@@ -64,28 +49,27 @@ pub struct InstrumentationConfig {
6449
6550pub struct Config {
6651 pub instrumentations : Vec < InstrumentationConfig > ,
67- pub dc_module : String ,
52+ pub diagnostic_channel_module : String ,
6853}
6954
7055impl Config {
7156 pub fn from_yaml_data ( yaml_str : & str ) -> Result < Config , OrchestrionError > {
7257 let docs = YamlLoader :: load_from_str ( yaml_str) ?;
7358 let doc = & docs[ 0 ] ;
7459
75- let version = doc[ "version" ]
76- . as_i64 ( )
77- . ok_or ( "Invalid config: 'version' must be a number" ) ?;
78- if version != 1 {
79- return Err ( "Invalid config version" . into ( ) ) ;
80- }
60+ match doc[ "version" ] . as_i64 ( ) {
61+ Some ( 1 ) => 1 ,
62+ Some ( _) => return Err ( "Invalid config version" . into ( ) ) ,
63+ None => return Err ( "Invalid config: 'version' must be a number" . into ( ) ) ,
64+ } ;
8165
8266 let dc_module = doc[ "dc_module" ] . as_str ( ) . unwrap_or ( "diagnostics_channel" ) ;
8367
8468 let configs = InstrumentationConfig :: from_yaml ( doc) ?;
8569
8670 Ok ( Config {
8771 instrumentations : configs,
88- dc_module : dc_module. to_string ( ) ,
72+ diagnostic_channel_module : dc_module. to_string ( ) ,
8973 } )
9074 }
9175}
0 commit comments