@@ -229,7 +229,7 @@ lazy_static! {
229
229
#[ derive( Clone , Debug ) ]
230
230
pub struct ExistingTunnel {
231
231
/// 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 > ,
233
233
234
234
/// Token to authenticate and use preexisting tunnel
235
235
pub host_token : String ,
@@ -393,7 +393,12 @@ impl DevTunnels {
393
393
} ;
394
394
395
395
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
+ )
397
402
. await ?;
398
403
399
404
let locator = TunnelLocator :: try_from ( & tunnel) . unwrap ( ) ;
@@ -532,6 +537,7 @@ impl DevTunnels {
532
537
/// other version tags.
533
538
async fn sync_tunnel_tags (
534
539
& self ,
540
+ client : & TunnelManagementClient ,
535
541
name : & str ,
536
542
tunnel : Tunnel ,
537
543
options : & TunnelRequestOptions ,
@@ -558,7 +564,7 @@ impl DevTunnels {
558
564
let result = spanf ! (
559
565
self . log,
560
566
self . log. span( "dev-tunnel.protocol-tag-update" ) ,
561
- self . client. update_tunnel( & tunnel_update, options)
567
+ client. update_tunnel( & tunnel_update, options)
562
568
) ;
563
569
564
570
result. map_err ( |e| wrap ( e, "tunnel tag update failed" ) . into ( ) )
@@ -639,6 +645,12 @@ impl DevTunnels {
639
645
Ok ( ( ) )
640
646
}
641
647
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
+
642
654
async fn get_name_for_tunnel (
643
655
& mut self ,
644
656
preferred_name : Option < & str > ,
@@ -670,10 +682,7 @@ impl DevTunnels {
670
682
use_random_name = true ;
671
683
}
672
684
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 ( ) ;
677
686
if !is_name_free ( & placeholder_name) {
678
687
for i in 2 .. {
679
688
let fixed_name = format ! ( "{}{}" , placeholder_name, i) ;
@@ -715,7 +724,10 @@ impl DevTunnels {
715
724
tunnel : ExistingTunnel ,
716
725
) -> Result < ActiveTunnel , AnyError > {
717
726
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
+ } ,
719
731
id : tunnel. tunnel_id ,
720
732
cluster : tunnel. cluster ,
721
733
} ;
@@ -725,10 +737,23 @@ impl DevTunnels {
725
737
tunnel. host_token . clone ( ) ,
726
738
) ) ;
727
739
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
+
728
753
self . start_tunnel (
729
754
tunnel_details. locator ( ) ,
730
755
& tunnel_details,
731
- mgmt . into ( ) ,
756
+ client ,
732
757
StaticAccessTokenProvider :: new ( tunnel. host_token ) ,
733
758
)
734
759
. await
0 commit comments