Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
jfullerton44 committed Oct 12, 2023
1 parent 50457f4 commit 74f4744
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rs/src/connections/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ pub enum TunnelError {
ProxyHandshakeFailed(hyper::Error),

#[error("proxy connect request failed: {0}")]
ProxyConnectRequestFailed(hyper::Error)
ProxyConnectRequestFailed(hyper::Error),
}
2 changes: 1 addition & 1 deletion rs/src/contracts/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion rs/src/contracts/tunnel_access_control_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion rs/src/contracts/tunnel_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 39 additions & 11 deletions rs/src/management/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -93,7 +94,6 @@ impl TunnelManagementClient {
mut tunnel: Tunnel,
options: &TunnelRequestOptions,
) -> HttpResult<Tunnel> {

if tunnel.tunnel_id.is_none() || tunnel.tunnel_id.as_ref().unwrap().is_empty() {
tunnel.tunnel_id = Some(TunnelManagementClient::generate_tunnel_id());
}
Expand Down Expand Up @@ -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();
Expand All @@ -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
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 74f4744

Please sign in to comment.