Skip to content

Commit d7cfba7

Browse files
authored
cli: update dev tunnel sdk (microsoft#203763)
1 parent 01a85f2 commit d7cfba7

File tree

3 files changed

+78
-57
lines changed

3 files changed

+78
-57
lines changed

cli/Cargo.lock

Lines changed: 28 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ serde_bytes = "0.11.9"
3434
chrono = { version = "0.4.26", features = ["serde", "std", "clock"], default-features = false }
3535
gethostname = "0.4.3"
3636
libc = "0.2.144"
37-
tunnels = { git = "https://github.com/microsoft/dev-tunnels", rev = "97233d20448e1c3cb0e0fd9114acf68c7e5c0249", default-features = false, features = ["connections"] }
37+
tunnels = { git = "https://github.com/microsoft/dev-tunnels", rev = "c1bf1424846ce3a1297ed3be7b8401cef6904bee", default-features = false, features = ["connections"] }
3838
keyring = { version = "2.0.3", default-features = false, features = ["linux-secret-service-rt-tokio-crypto-openssl"] }
3939
dialoguer = "0.10.4"
4040
hyper = { version = "0.14.26", features = ["server", "http1", "runtime"] }

cli/src/tunnels/dev_tunnels.rs

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,14 @@ impl DevTunnels {
409409
}
410410
}?;
411411

412-
let desired_tags = self.get_tags(&name);
413-
if is_new || vec_eq_as_set(&full_tunnel.tags, &desired_tags) {
412+
let desired_tags = self.get_labels(&name);
413+
if is_new || vec_eq_as_set(&full_tunnel.labels, &desired_tags) {
414414
return Ok((full_tunnel, persisted));
415415
}
416416

417417
debug!(self.log, "Tunnel name changed, applying updates...");
418418

419-
full_tunnel.tags = desired_tags;
419+
full_tunnel.labels = desired_tags;
420420

421421
let updated_tunnel = spanf!(
422422
self.log,
@@ -531,7 +531,6 @@ impl DevTunnels {
531531
let fut = self.client.delete_tunnel_endpoints(
532532
&locator,
533533
&endpoint.host_id,
534-
None,
535534
NO_REQUEST_OPTIONS,
536535
);
537536

@@ -572,52 +571,51 @@ impl DevTunnels {
572571
)
573572
.map_err(|e| wrap(e, "failed to lookup tunnel"))?
574573
}
575-
None => {
576-
let new_tunnel = Tunnel {
577-
tags: self.get_tags(name),
578-
..Default::default()
579-
};
580-
581-
loop {
582-
let result = spanf!(
583-
self.log,
584-
self.log.span("dev-tunnel.create"),
585-
self.client.create_tunnel(&new_tunnel, options)
586-
);
587-
588-
match result {
589-
Err(HttpError::ResponseError(e))
590-
if e.status_code == StatusCode::TOO_MANY_REQUESTS =>
591-
{
592-
if let Some(d) = e.get_details() {
593-
let detail = d.detail.unwrap_or_else(|| "unknown".to_string());
594-
if detail.contains(TUNNEL_COUNT_LIMIT_NAME)
595-
&& self.try_recycle_tunnel().await?
596-
{
597-
continue;
598-
}
599-
600-
return Err(AnyError::from(TunnelCreationFailed(
601-
name.to_string(),
602-
detail,
603-
)));
574+
None => loop {
575+
let result = spanf!(
576+
self.log,
577+
self.log.span("dev-tunnel.create"),
578+
self.client.create_tunnel(
579+
Tunnel {
580+
labels: self.get_labels(name),
581+
..Default::default()
582+
},
583+
options
584+
)
585+
);
586+
587+
match result {
588+
Err(HttpError::ResponseError(e))
589+
if e.status_code == StatusCode::TOO_MANY_REQUESTS =>
590+
{
591+
if let Some(d) = e.get_details() {
592+
let detail = d.detail.unwrap_or_else(|| "unknown".to_string());
593+
if detail.contains(TUNNEL_COUNT_LIMIT_NAME)
594+
&& self.try_recycle_tunnel().await?
595+
{
596+
continue;
604597
}
605598

606599
return Err(AnyError::from(TunnelCreationFailed(
607600
name.to_string(),
608-
"You have exceeded a limit for the port fowarding service. Please remove other machines before trying to add this machine.".to_string(),
601+
detail,
609602
)));
610603
}
611-
Err(e) => {
612-
return Err(AnyError::from(TunnelCreationFailed(
604+
605+
return Err(AnyError::from(TunnelCreationFailed(
613606
name.to_string(),
614-
format!("{:?}", e),
615-
)))
616-
}
617-
Ok(t) => break t,
607+
"You have exceeded a limit for the port fowarding service. Please remove other machines before trying to add this machine.".to_string(),
608+
)));
618609
}
610+
Err(e) => {
611+
return Err(AnyError::from(TunnelCreationFailed(
612+
name.to_string(),
613+
format!("{:?}", e),
614+
)))
615+
}
616+
Ok(t) => break t,
619617
}
620-
}
618+
},
621619
};
622620

623621
let pt = PersistedTunnel {
@@ -631,7 +629,7 @@ impl DevTunnels {
631629
}
632630

633631
/// Gets the expected tunnel tags
634-
fn get_tags(&self, name: &str) -> Vec<String> {
632+
fn get_labels(&self, name: &str) -> Vec<String> {
635633
vec![
636634
name.to_string(),
637635
PROTOCOL_VERSION_TAG.to_string(),
@@ -649,20 +647,20 @@ impl DevTunnels {
649647
tunnel: Tunnel,
650648
options: &TunnelRequestOptions,
651649
) -> Result<Tunnel, AnyError> {
652-
let new_tags = self.get_tags(name);
653-
if vec_eq_as_set(&tunnel.tags, &new_tags) {
650+
let new_labels = self.get_labels(name);
651+
if vec_eq_as_set(&tunnel.labels, &new_labels) {
654652
return Ok(tunnel);
655653
}
656654

657655
debug!(
658656
self.log,
659657
"Updating tunnel tags {} -> {}",
660-
tunnel.tags.join(", "),
661-
new_tags.join(", ")
658+
tunnel.labels.join(", "),
659+
new_labels.join(", ")
662660
);
663661

664662
let tunnel_update = Tunnel {
665-
tags: new_tags,
663+
labels: new_labels,
666664
tunnel_id: tunnel.tunnel_id.clone(),
667665
cluster_id: tunnel.cluster_id.clone(),
668666
..Default::default()
@@ -725,7 +723,7 @@ impl DevTunnels {
725723
self.log,
726724
self.log.span("dev-tunnel.listall"),
727725
self.client.list_all_tunnels(&TunnelRequestOptions {
728-
tags: tags.iter().map(|t| t.to_string()).collect(),
726+
labels: tags.iter().map(|t| t.to_string()).collect(),
729727
..Default::default()
730728
})
731729
)
@@ -739,8 +737,8 @@ impl DevTunnels {
739737
self.log,
740738
self.log.span("dev-tunnel.rename.search"),
741739
self.client.list_all_tunnels(&TunnelRequestOptions {
742-
tags: vec![self.tag.to_string(), name.to_string()],
743-
require_all_tags: true,
740+
labels: vec![self.tag.to_string(), name.to_string()],
741+
require_all_labels: true,
744742
limit: 1,
745743
include_ports: true,
746744
token_scopes: vec!["host".to_string()],
@@ -770,7 +768,7 @@ impl DevTunnels {
770768
v.status
771769
.as_ref()
772770
.and_then(|s| s.host_connection_count.as_ref().map(|c| c.get_count()))
773-
.unwrap_or(0) > 0 && v.tags.iter().any(|t| t == n)
771+
.unwrap_or(0) > 0 && v.labels.iter().any(|t| t == n)
774772
})
775773
};
776774

0 commit comments

Comments
 (0)