cli: fix tunnel names are case sensitive but remoteAuthorities are not (#181347)

Fixes #177222
This commit is contained in:
Connor Peet 2023-05-02 09:55:11 -07:00 committed by GitHub
parent 3b6633daa7
commit 5a139d4ffc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -274,47 +274,14 @@ impl DevTunnels {
/// Renames the current tunnel to the new name. /// Renames the current tunnel to the new name.
pub async fn rename_tunnel(&mut self, name: &str) -> Result<(), AnyError> { pub async fn rename_tunnel(&mut self, name: &str) -> Result<(), AnyError> {
is_valid_name(name)?; self.update_tunnel_name(None, name).await.map(|_| ())
self.check_is_name_free(name).await?;
let mut tunnel = match self.launcher_tunnel.load() {
Some(t) => t,
None => {
debug!(self.log, "No code server tunnel found, creating new one");
let (persisted, _) = self.create_tunnel(name, NO_REQUEST_OPTIONS).await?;
self.launcher_tunnel.save(Some(persisted))?;
return Ok(());
}
};
let locator = tunnel.locator();
let mut full_tunnel = spanf!(
self.log,
self.log.span("dev-tunnel.tag.get"),
self.client.get_tunnel(&locator, NO_REQUEST_OPTIONS)
)
.map_err(|e| wrap(e, "failed to lookup original tunnel"))?;
full_tunnel.tags = vec![name.to_string(), VSCODE_CLI_TUNNEL_TAG.to_string()];
spanf!(
self.log,
self.log.span("dev-tunnel.tag.update"),
self.client.update_tunnel(&full_tunnel, NO_REQUEST_OPTIONS)
)
.map_err(|e| wrap(e, "failed to update tunnel tags"))?;
tunnel.name = name.to_string();
self.launcher_tunnel.save(Some(tunnel.clone()))?;
Ok(())
} }
/// Updates the name of the existing persisted tunnel to the new name. /// Updates the name of the existing persisted tunnel to the new name.
/// Gracefully creates a new tunnel if the previous one was deleted. /// Gracefully creates a new tunnel if the previous one was deleted.
async fn update_tunnel_name( async fn update_tunnel_name(
&mut self, &mut self,
persisted: PersistedTunnel, persisted: Option<PersistedTunnel>,
name: &str, name: &str,
) -> Result<(Tunnel, PersistedTunnel), AnyError> { ) -> Result<(Tunnel, PersistedTunnel), AnyError> {
let name = name.to_ascii_lowercase(); let name = name.to_ascii_lowercase();
@ -322,9 +289,17 @@ impl DevTunnels {
debug!(self.log, "Tunnel name changed, applying updates..."); debug!(self.log, "Tunnel name changed, applying updates...");
let (mut full_tunnel, mut persisted, is_new) = self let (mut full_tunnel, mut persisted, is_new) = match persisted {
.get_or_create_tunnel(persisted, Some(&name), NO_REQUEST_OPTIONS) Some(persisted) => {
.await?; self.get_or_create_tunnel(persisted, Some(&name), NO_REQUEST_OPTIONS)
.await
}
None => self
.create_tunnel(&name, NO_REQUEST_OPTIONS)
.await
.map(|(pt, t)| (t, pt, true)),
}?;
if is_new { if is_new {
return Ok((full_tunnel, persisted)); return Ok((full_tunnel, persisted));
} }
@ -368,7 +343,6 @@ impl DevTunnels {
let (persisted, tunnel) = self let (persisted, tunnel) = self
.create_tunnel(create_with_new_name.unwrap_or(&persisted.name), options) .create_tunnel(create_with_new_name.unwrap_or(&persisted.name), options)
.await?; .await?;
self.launcher_tunnel.save(Some(persisted.clone()))?;
Ok((tunnel, persisted, true)) Ok((tunnel, persisted, true))
} }
Err(e) => Err(wrap(e, "failed to lookup tunnel").into()), Err(e) => Err(wrap(e, "failed to lookup tunnel").into()),
@ -386,8 +360,9 @@ impl DevTunnels {
Some(mut persisted) => { Some(mut persisted) => {
if let Some(preferred_name) = preferred_name.map(|n| n.to_ascii_lowercase()) { if let Some(preferred_name) = preferred_name.map(|n| n.to_ascii_lowercase()) {
if persisted.name.to_ascii_lowercase() != preferred_name { if persisted.name.to_ascii_lowercase() != preferred_name {
(_, persisted) = (_, persisted) = self
self.update_tunnel_name(persisted, &preferred_name).await?; .update_tunnel_name(Some(persisted), &preferred_name)
.await?;
} }
} }
@ -404,7 +379,6 @@ impl DevTunnels {
let (persisted, full_tunnel) = self let (persisted, full_tunnel) = self
.create_tunnel(&name, &HOST_TUNNEL_REQUEST_OPTIONS) .create_tunnel(&name, &HOST_TUNNEL_REQUEST_OPTIONS)
.await?; .await?;
self.launcher_tunnel.save(Some(persisted.clone()))?;
(full_tunnel, persisted) (full_tunnel, persisted)
} }
}; };
@ -509,14 +483,14 @@ impl DevTunnels {
))) )))
} }
Ok(t) => { Ok(t) => {
return Ok(( let pt = PersistedTunnel {
PersistedTunnel { cluster: t.cluster_id.clone().unwrap(),
cluster: t.cluster_id.clone().unwrap(), id: t.tunnel_id.clone().unwrap(),
id: t.tunnel_id.clone().unwrap(), name: name.to_string(),
name: name.to_string(), };
},
t, self.launcher_tunnel.save(Some(pt.clone()))?;
)) return Ok((pt, t));
} }
} }
} }