@@ -229,7 +229,7 @@ lazy_static! {
229229#[ derive( Clone , Debug ) ]
230230pub struct ExistingTunnel {
231231 /// Name you'd like to assign preexisting tunnel to use to connect to the VS Code Server
232- pub tunnel_name : String ,
232+ pub tunnel_name : Option < String > ,
233233
234234 /// Token to authenticate and use preexisting tunnel
235235 pub host_token : String ,
@@ -393,7 +393,12 @@ impl DevTunnels {
393393 } ;
394394
395395 tunnel = self
396- . sync_tunnel_tags ( & persisted. name , tunnel, & HOST_TUNNEL_REQUEST_OPTIONS )
396+ . sync_tunnel_tags (
397+ & self . client ,
398+ & persisted. name ,
399+ tunnel,
400+ & HOST_TUNNEL_REQUEST_OPTIONS ,
401+ )
397402 . await ?;
398403
399404 let locator = TunnelLocator :: try_from ( & tunnel) . unwrap ( ) ;
@@ -532,6 +537,7 @@ impl DevTunnels {
532537 /// other version tags.
533538 async fn sync_tunnel_tags (
534539 & self ,
540+ client : & TunnelManagementClient ,
535541 name : & str ,
536542 tunnel : Tunnel ,
537543 options : & TunnelRequestOptions ,
@@ -558,7 +564,7 @@ impl DevTunnels {
558564 let result = spanf ! (
559565 self . log,
560566 self . log. span( "dev-tunnel.protocol-tag-update" ) ,
561- self . client. update_tunnel( & tunnel_update, options)
567+ client. update_tunnel( & tunnel_update, options)
562568 ) ;
563569
564570 result. map_err ( |e| wrap ( e, "tunnel tag update failed" ) . into ( ) )
@@ -639,6 +645,12 @@ impl DevTunnels {
639645 Ok ( ( ) )
640646 }
641647
648+ fn get_placeholder_name ( ) -> String {
649+ let mut n = clean_hostname_for_tunnel ( & gethostname:: gethostname ( ) . to_string_lossy ( ) ) ;
650+ n. make_ascii_lowercase ( ) ;
651+ n
652+ }
653+
642654 async fn get_name_for_tunnel (
643655 & mut self ,
644656 preferred_name : Option < & str > ,
@@ -670,10 +682,7 @@ impl DevTunnels {
670682 use_random_name = true ;
671683 }
672684
673- let mut placeholder_name =
674- clean_hostname_for_tunnel ( & gethostname:: gethostname ( ) . to_string_lossy ( ) ) ;
675- placeholder_name. make_ascii_lowercase ( ) ;
676-
685+ let mut placeholder_name = Self :: get_placeholder_name ( ) ;
677686 if !is_name_free ( & placeholder_name) {
678687 for i in 2 .. {
679688 let fixed_name = format ! ( "{}{}" , placeholder_name, i) ;
@@ -715,7 +724,10 @@ impl DevTunnels {
715724 tunnel : ExistingTunnel ,
716725 ) -> Result < ActiveTunnel , AnyError > {
717726 let tunnel_details = PersistedTunnel {
718- name : tunnel. tunnel_name ,
727+ name : match tunnel. tunnel_name {
728+ Some ( n) => n,
729+ None => Self :: get_placeholder_name ( ) ,
730+ } ,
719731 id : tunnel. tunnel_id ,
720732 cluster : tunnel. cluster ,
721733 } ;
@@ -725,10 +737,23 @@ impl DevTunnels {
725737 tunnel. host_token . clone ( ) ,
726738 ) ) ;
727739
740+ let client = mgmt. into ( ) ;
741+ self . sync_tunnel_tags (
742+ & client,
743+ & tunnel_details. name ,
744+ Tunnel {
745+ cluster_id : Some ( tunnel_details. cluster . clone ( ) ) ,
746+ tunnel_id : Some ( tunnel_details. id . clone ( ) ) ,
747+ ..Default :: default ( )
748+ } ,
749+ & HOST_TUNNEL_REQUEST_OPTIONS ,
750+ )
751+ . await ?;
752+
728753 self . start_tunnel (
729754 tunnel_details. locator ( ) ,
730755 & tunnel_details,
731- mgmt . into ( ) ,
756+ client ,
732757 StaticAccessTokenProvider :: new ( tunnel. host_token ) ,
733758 )
734759 . await
0 commit comments