From 8ae71001256e9cbb2b370f56b27eff5300402619 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Wed, 27 Mar 2024 16:10:36 -1000 Subject: [PATCH 1/6] Fix cluster ID logic for tunnels.local.api... hostname --- cs/src/Management/TunnelManagementClient.cs | 4 ++-- go/tunnels/manager.go | 6 ++++-- .../tunnels/management/TunnelManagementClient.java | 1 + ts/src/management/tunnelManagementHttpClient.ts | 5 ++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cs/src/Management/TunnelManagementClient.cs b/cs/src/Management/TunnelManagementClient.cs index 54d6454e..b5d21325 100644 --- a/cs/src/Management/TunnelManagementClient.cs +++ b/cs/src/Management/TunnelManagementClient.cs @@ -649,7 +649,7 @@ private string UserLimitsPath errorMessage = "Tunnel service error: " + problemDetails!.Title + " " + problemDetails.Detail; } - + if (problemDetails.Errors != null) { foreach (var error in problemDetails.Errors) @@ -785,7 +785,7 @@ private Uri BuildUri( if (!string.IsNullOrEmpty(clusterId) && baseAddress.HostNameType == UriHostNameType.Dns) { - if (baseAddress.Host != "localhost" && + if (baseAddress.Host != "localhost" && !baseAddress.Host.Contains(".local") && !baseAddress.Host.StartsWith($"{clusterId}.")) { // A specific cluster ID was specified (while not running on localhost). diff --git a/go/tunnels/manager.go b/go/tunnels/manager.go index 0cfdc3b7..24702342 100644 --- a/go/tunnels/manager.go +++ b/go/tunnels/manager.go @@ -108,7 +108,7 @@ func NewManager(userAgents []UserAgent, tp tokenProviderfn, tunnelServiceUrl *ur var client *http.Client if httpHandler == nil { - if strings.Contains(tunnelServiceUrl.Host, "localhost") { + if strings.Contains(tunnelServiceUrl.Host, "localhost" || strings.Contains(".local")) { client = &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}} } else { client = &http.Client{} @@ -825,7 +825,9 @@ func (m *Manager) getAccessToken(tunnel *Tunnel, tunnelRequestOptions *TunnelReq func (m *Manager) buildUri(clusterId string, path string, options *TunnelRequestOptions, query string) *url.URL { baseAddress := m.uri if clusterId != "" { - if !strings.HasPrefix(baseAddress.Host, "localhost") && !strings.HasPrefix(baseAddress.Host, clusterId) { + if !strings.HasPrefix(baseAddress.Host, "localhost") && + !strings.Contains(baseAddress.Host, ".local") && + !strings.HasPrefix(baseAddress.Host, clusterId) { // A specific cluster ID was specified (while not running on localhost). // Prepend the cluster ID to the hostname, and optionally strip a global prefix. baseAddress.Host = fmt.Sprintf("%s.%s", clusterId, baseAddress.Host) diff --git a/java/src/main/java/com/microsoft/tunnels/management/TunnelManagementClient.java b/java/src/main/java/com/microsoft/tunnels/management/TunnelManagementClient.java index 8402311d..fc4f5ffb 100644 --- a/java/src/main/java/com/microsoft/tunnels/management/TunnelManagementClient.java +++ b/java/src/main/java/com/microsoft/tunnels/management/TunnelManagementClient.java @@ -302,6 +302,7 @@ private URI buildUri(String clusterId, if (StringUtils.isNotBlank(clusterId)) { if (!baseAddress.getHost().equals("localhost") + && !baseAddress.getHost().contains(".local") && !baseAddress.getHost().startsWith(clusterId + ".")) { host = (clusterId + "." + baseAddress.getHost()).replace("global.", ""); } else if (baseAddress.getScheme().equals("https") diff --git a/ts/src/management/tunnelManagementHttpClient.ts b/ts/src/management/tunnelManagementHttpClient.ts index 19aa7885..b41abccd 100644 --- a/ts/src/management/tunnelManagementHttpClient.ts +++ b/ts/src/management/tunnelManagementHttpClient.ts @@ -875,7 +875,10 @@ export class TunnelManagementHttpClient implements TunnelManagementClient { if (clusterId) { const url = new URL(baseAddress); const portNumber = parseInt(url.port, 10); - if (url.hostname !== 'localhost' && !url.hostname.startsWith(`${clusterId}.`)) { + if (url.hostname !== 'localhost' && + !url.hostname.includes('.local') && + !url.hostname.startsWith(`${clusterId}.`) + ) { // A specific cluster ID was specified (while not running on localhost). // Prepend the cluster ID to the hostname, and optionally strip a global prefix. url.hostname = `${clusterId}.${url.hostname}`.replace('global.', ''); From 45e6fd465f76032566bf5e9c3856d6d19b5ff069 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Wed, 27 Mar 2024 16:18:13 -1000 Subject: [PATCH 2/6] Fix go parentheses --- go/tunnels/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/tunnels/manager.go b/go/tunnels/manager.go index 24702342..a3c50247 100644 --- a/go/tunnels/manager.go +++ b/go/tunnels/manager.go @@ -108,7 +108,7 @@ func NewManager(userAgents []UserAgent, tp tokenProviderfn, tunnelServiceUrl *ur var client *http.Client if httpHandler == nil { - if strings.Contains(tunnelServiceUrl.Host, "localhost" || strings.Contains(".local")) { + if strings.Contains(tunnelServiceUrl.Host, "localhost") || strings.Contains(".local") { client = &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}} } else { client = &http.Client{} From 9ef4bcf951b7c6b16a1bc7c5b28bb6175bee08c1 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Thu, 28 Mar 2024 08:59:31 -1000 Subject: [PATCH 3/6] Fix go Contains call --- go/tunnels/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/tunnels/manager.go b/go/tunnels/manager.go index a3c50247..52546097 100644 --- a/go/tunnels/manager.go +++ b/go/tunnels/manager.go @@ -108,7 +108,7 @@ func NewManager(userAgents []UserAgent, tp tokenProviderfn, tunnelServiceUrl *ur var client *http.Client if httpHandler == nil { - if strings.Contains(tunnelServiceUrl.Host, "localhost") || strings.Contains(".local") { + if strings.Contains(tunnelServiceUrl.Host, "localhost") || strings.Contains(tunnelServiceUrl.Host, ".local") { client = &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}} } else { client = &http.Client{} From 9be7286fe54f79b31e30f45e8cde75b88943d217 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Thu, 28 Mar 2024 09:04:58 -1000 Subject: [PATCH 4/6] Update package versions --- go/tunnels/tunnels.go | 2 +- rs/src/contracts/tunnel_endpoint.rs | 2 +- ts/src/connections/package.json | 4 ++-- ts/src/management/package.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go/tunnels/tunnels.go b/go/tunnels/tunnels.go index 1fd4e93d..46953168 100644 --- a/go/tunnels/tunnels.go +++ b/go/tunnels/tunnels.go @@ -10,7 +10,7 @@ import ( "github.com/rodaine/table" ) -const PackageVersion = "0.1.9" +const PackageVersion = "0.1.10" func (tunnel *Tunnel) requestObject() (*Tunnel, error) { convertedTunnel := &Tunnel{ diff --git a/rs/src/contracts/tunnel_endpoint.rs b/rs/src/contracts/tunnel_endpoint.rs index a0f8ee02..aef96832 100644 --- a/rs/src/contracts/tunnel_endpoint.rs +++ b/rs/src/contracts/tunnel_endpoint.rs @@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize}; #[serde(rename_all(serialize = "camelCase", deserialize = "camelCase"))] pub struct TunnelEndpoint { // Gets or sets the ID of this endpoint. - pub id: String, + pub id: Option, // Gets or sets the connection mode of the endpoint. // diff --git a/ts/src/connections/package.json b/ts/src/connections/package.json index 85d57dc1..a2a83472 100644 --- a/ts/src/connections/package.json +++ b/ts/src/connections/package.json @@ -18,8 +18,8 @@ "buffer": "^5.2.1", "debug": "^4.1.1", "vscode-jsonrpc": "^4.0.0", - "@microsoft/dev-tunnels-contracts": ">1.1.26", - "@microsoft/dev-tunnels-management": ">1.1.26", + "@microsoft/dev-tunnels-contracts": ">1.1.32", + "@microsoft/dev-tunnels-management": ">1.1.32", "@microsoft/dev-tunnels-ssh": "^3.11.36", "@microsoft/dev-tunnels-ssh-tcp": "^3.11.36", "uuid": "^3.3.3", diff --git a/ts/src/management/package.json b/ts/src/management/package.json index 758d67b3..d1bff272 100644 --- a/ts/src/management/package.json +++ b/ts/src/management/package.json @@ -18,7 +18,7 @@ "buffer": "^5.2.1", "debug": "^4.1.1", "vscode-jsonrpc": "^4.0.0", - "@microsoft/dev-tunnels-contracts": ">1.1.26", + "@microsoft/dev-tunnels-contracts": ">1.1.32", "axios": "^1.6.6" } } From bb0ad39d5be9241343815f059a97c3b93ae7ee9e Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Thu, 28 Mar 2024 09:17:35 -1000 Subject: [PATCH 5/6] Fix rust errors --- rs/src/connections/relay_tunnel_host.rs | 2 +- rs/src/management/http_client.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rs/src/connections/relay_tunnel_host.rs b/rs/src/connections/relay_tunnel_host.rs index e52e27fe..b800164a 100644 --- a/rs/src/connections/relay_tunnel_host.rs +++ b/rs/src/connections/relay_tunnel_host.rs @@ -389,7 +389,7 @@ impl RelayTunnelHost { &self.locator, &TunnelRelayTunnelEndpoint { base: TunnelEndpoint { - id: format!("{}-relay", self.host_id), + id: Some(format!("{}-relay", self.host_id)), connection_mode: TunnelConnectionMode::TunnelRelay, host_id: self.host_id.to_string(), host_public_keys: vec![], diff --git a/rs/src/management/http_client.rs b/rs/src/management/http_client.rs index 0ad685c9..94bbd84b 100644 --- a/rs/src/management/http_client.rs +++ b/rs/src/management/http_client.rs @@ -162,7 +162,7 @@ impl TunnelManagementClient { ) -> HttpResult { let mut url = self.build_tunnel_uri( locator, - Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.id)), + Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.id.unwrap())), ); url.query_pairs_mut() .append_pair("connectionMode", &endpoint.connection_mode.to_string()); @@ -180,7 +180,7 @@ impl TunnelManagementClient { ) -> HttpResult { let mut url = self.build_tunnel_uri( locator, - Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.base.id)), + Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.base.id.unwrap())), ); url.query_pairs_mut() .append_pair("connectionMode", &endpoint.base.connection_mode.to_string()); From 28a416f28a34a63c0b3914cca7e6944769756324 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Thu, 28 Mar 2024 09:24:54 -1000 Subject: [PATCH 6/6] Fix rust errors (2) --- rs/src/management/http_client.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rs/src/management/http_client.rs b/rs/src/management/http_client.rs index 94bbd84b..20986bf7 100644 --- a/rs/src/management/http_client.rs +++ b/rs/src/management/http_client.rs @@ -162,7 +162,7 @@ impl TunnelManagementClient { ) -> HttpResult { let mut url = self.build_tunnel_uri( locator, - Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.id.unwrap())), + Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.id.as_deref().unwrap())), ); url.query_pairs_mut() .append_pair("connectionMode", &endpoint.connection_mode.to_string()); @@ -180,7 +180,7 @@ impl TunnelManagementClient { ) -> HttpResult { let mut url = self.build_tunnel_uri( locator, - Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.base.id.unwrap())), + Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.base.id.as_deref().unwrap())), ); url.query_pairs_mut() .append_pair("connectionMode", &endpoint.base.connection_mode.to_string());