@@ -565,11 +565,26 @@ fn config_translate_keywords(
565
565
s => s. to_string ( ) ,
566
566
} ;
567
567
568
- let ip = parse_ip ( config. agent . ip . as_ref ( ) ) ?. to_string ( ) ;
569
- let contact_ip = parse_ip ( config. agent . contact_ip . as_ref ( ) ) ?. to_string ( ) ;
568
+ let ip = match parse_ip ( config. agent . ip . as_ref ( ) ) {
569
+ Ok ( ip) => ip. to_string ( ) ,
570
+ Err ( _) => {
571
+ debug ! ( "Parsing configured IP as hostname" ) ;
572
+ parse_hostname ( config. agent . ip . as_ref ( ) ) ?. to_string ( )
573
+ }
574
+ } ;
575
+
576
+ let contact_ip = match parse_ip ( config. agent . contact_ip . as_ref ( ) ) {
577
+ Ok ( ip) => ip. to_string ( ) ,
578
+ Err ( _) => {
579
+ debug ! ( "Parsing configured contact IP as hostname" ) ;
580
+ parse_hostname ( config. agent . contact_ip . as_ref ( ) ) ?. to_string ( )
581
+ }
582
+ } ;
583
+
570
584
let registrar_ip = match parse_ip ( config. agent . registrar_ip . as_ref ( ) ) {
571
585
Ok ( ip) => ip. to_string ( ) ,
572
586
Err ( _) => {
587
+ debug ! ( "Parsing configured registrar IP as hostname" ) ;
573
588
parse_hostname ( config. agent . registrar_ip . as_ref ( ) ) ?. to_string ( )
574
589
}
575
590
} ;
@@ -711,6 +726,30 @@ mod tests {
711
726
assert_eq ! ( expected, default ) ;
712
727
}
713
728
729
+ #[ test]
730
+ fn test_hostname_support ( ) {
731
+ let default = AgentConfig :: default ( ) ;
732
+
733
+ let modified = AgentConfig {
734
+ ip : "localhost" . to_string ( ) ,
735
+ contact_ip : "contact.ip" . to_string ( ) ,
736
+ registrar_ip : "registrar.ip" . to_string ( ) ,
737
+ ..default
738
+ } ;
739
+
740
+ let c = KeylimeConfig { agent : modified } ;
741
+
742
+ let result = config_translate_keywords ( & c) ;
743
+ assert ! ( result. is_ok( ) ) ;
744
+ let result = result. unwrap ( ) ; //#[allow_ci]
745
+ let resulting_ip = result. agent . ip ;
746
+ let resulting_contact_ip = result. agent . contact_ip ;
747
+ let resulting_registrar_ip = result. agent . registrar_ip ;
748
+ assert_eq ! ( resulting_ip, "localhost" ) ;
749
+ assert_eq ! ( resulting_contact_ip, "contact.ip" ) ;
750
+ assert_eq ! ( resulting_registrar_ip, "registrar.ip" ) ;
751
+ }
752
+
714
753
#[ test]
715
754
fn get_revocation_cert_path_default ( ) {
716
755
let test_config = KeylimeConfig :: default ( ) ;
0 commit comments