diff --git a/rs/src/connections/errors.rs b/rs/src/connections/errors.rs index c9b51e04..65047a33 100644 --- a/rs/src/connections/errors.rs +++ b/rs/src/connections/errors.rs @@ -34,5 +34,5 @@ pub enum TunnelError { ProxyHandshakeFailed(hyper::Error), #[error("proxy connect request failed: {0}")] - ProxyConnectRequestFailed(hyper::Error) + ProxyConnectRequestFailed(hyper::Error), } diff --git a/rs/src/contracts/tunnel.rs b/rs/src/contracts/tunnel.rs index 16a78133..3e71632f 100644 --- a/rs/src/contracts/tunnel.rs +++ b/rs/src/contracts/tunnel.rs @@ -2,12 +2,12 @@ // Licensed under the MIT license. // Generated from ../../../cs/src/Contracts/Tunnel.cs -use chrono::{DateTime, Utc}; use crate::contracts::TunnelAccessControl; use crate::contracts::TunnelEndpoint; use crate::contracts::TunnelOptions; use crate::contracts::TunnelPort; use crate::contracts::TunnelStatus; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; diff --git a/rs/src/contracts/tunnel_access_control_entry.rs b/rs/src/contracts/tunnel_access_control_entry.rs index b36863a9..fa7f985a 100644 --- a/rs/src/contracts/tunnel_access_control_entry.rs +++ b/rs/src/contracts/tunnel_access_control_entry.rs @@ -2,8 +2,8 @@ // Licensed under the MIT license. // Generated from ../../../cs/src/Contracts/TunnelAccessControlEntry.cs -use chrono::{DateTime, Utc}; use crate::contracts::TunnelAccessControlEntryType; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; // Data contract for an access control entry on a `Tunnel` or `TunnelPort`. diff --git a/rs/src/contracts/tunnel_port.rs b/rs/src/contracts/tunnel_port.rs index 1fd3e41a..89611508 100644 --- a/rs/src/contracts/tunnel_port.rs +++ b/rs/src/contracts/tunnel_port.rs @@ -43,7 +43,7 @@ pub struct TunnelPort { // A client that connects to a tunnel (by ID or name) without specifying a port number // will connect to the default port for the tunnel, if a default is configured. Or if // the tunnel has only one port then the single port is the implicit default. - // + // // Selection of a default port for a connection also depends on matching the // connection to the port `TunnelPort.Protocol`, so it is possible to configure // separate defaults for distinct protocols like `TunnelProtocol.Http` and diff --git a/rs/src/management/http_client.rs b/rs/src/management/http_client.rs index 8c8f1f8c..31864d45 100644 --- a/rs/src/management/http_client.rs +++ b/rs/src/management/http_client.rs @@ -14,8 +14,9 @@ extern crate rand; use rand::Rng; use crate::contracts::{ - env_production, Tunnel, TunnelConnectionMode, TunnelEndpoint, TunnelPort, - TunnelRelayTunnelEndpoint, TunnelServiceProperties, NamedRateStatus, TunnelPortListResponse, TunnelListByRegionResponse, + env_production, NamedRateStatus, Tunnel, TunnelConnectionMode, TunnelEndpoint, + TunnelListByRegionResponse, TunnelPort, TunnelPortListResponse, TunnelRelayTunnelEndpoint, + TunnelServiceProperties, }; use super::{ @@ -93,7 +94,6 @@ impl TunnelManagementClient { mut tunnel: Tunnel, options: &TunnelRequestOptions, ) -> HttpResult { - if tunnel.tunnel_id.is_none() || tunnel.tunnel_id.as_ref().unwrap().is_empty() { tunnel.tunnel_id = Some(TunnelManagementClient::generate_tunnel_id()); } @@ -453,8 +453,32 @@ impl TunnelManagementClient { } fn generate_tunnel_id() -> String { - const NOUNS: [&'static str; 16] = [ "pond", "hill", "mountain", "field", "fog", "ant", "dog", "cat", "shoe", "plane", "chair", "book", "ocean", "lake", "river" , "horse"]; - const ADJECTIVES: [&'static str; 20] = ["fun", "happy", "interesting", "neat", "peaceful", "puzzled", "kind", "joyful", "new", "giant", "sneaky", "quick", "majestic", "jolly" , "fancy", "tidy", "swift", "silent", "amusing", "spiffy"]; + const NOUNS: [&'static str; 16] = [ + "pond", "hill", "mountain", "field", "fog", "ant", "dog", "cat", "shoe", "plane", + "chair", "book", "ocean", "lake", "river", "horse", + ]; + const ADJECTIVES: [&'static str; 20] = [ + "fun", + "happy", + "interesting", + "neat", + "peaceful", + "puzzled", + "kind", + "joyful", + "new", + "giant", + "sneaky", + "quick", + "majestic", + "jolly", + "fancy", + "tidy", + "swift", + "silent", + "amusing", + "spiffy", + ]; const TUNNEL_ID_CHARS: &'static str = "bcdfghjklmnpqrstvwxz0123456789"; let mut rng = rand::thread_rng(); @@ -465,7 +489,12 @@ impl TunnelManagementClient { tunnel_id.push('-'); for _ in 0..7 { - tunnel_id.push(TUNNEL_ID_CHARS.chars().nth(rng.gen_range(0..TUNNEL_ID_CHARS.len())).unwrap()); + tunnel_id.push( + TUNNEL_ID_CHARS + .chars() + .nth(rng.gen_range(0..TUNNEL_ID_CHARS.len())) + .unwrap(), + ); } tunnel_id } @@ -567,7 +596,8 @@ fn add_query(url: &mut Url, tunnel_opts: &TunnelRequestOptions, api_version: &st url.query_pairs_mut().append_pair("allLabels", "true"); } } - url.query_pairs_mut().append_pair("api-version", api_version); + url.query_pairs_mut() + .append_pair("api-version", api_version); if tunnel_opts.limit > 0 { url.query_pairs_mut() .append_pair("limit", &tunnel_opts.limit.to_string()); @@ -715,10 +745,8 @@ mod tests { let builder = super::new_tunnel_management("test-caller"); // verify - let re = Regex::new( - r"^test-caller Dev-Tunnels-Service-Rust-SDK/[0-9]+\.[0-9]+\.[0-9]+$", - ) - .unwrap(); + let re = Regex::new(r"^test-caller Dev-Tunnels-Service-Rust-SDK/[0-9]+\.[0-9]+\.[0-9]+$") + .unwrap(); let full_agent = builder.user_agent.to_str().unwrap(); assert!(re.is_match(full_agent)); }