Skip to content

Commit

Permalink
make rust build
Browse files Browse the repository at this point in the history
  • Loading branch information
jfullerton44 committed Oct 11, 2023
1 parent b08062d commit 50457f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
1 change: 1 addition & 0 deletions rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ tokio-tungstenite = { version = "0.20", optional = true, features = ["native-tls
futures = { version = "0.3", optional = true }
tungstenite = { version = "0.20", optional = true, features = ["native-tls"] }
uuid = { version = "1.4", features = ["v4"], optional = true }
rand = "0.8.5"
russh = { version = "0.37.1", default-features = false, features = ["openssl", "flate2"], optional = true }
russh-keys = { version = "0.37.1", default-features = false, features = ["openssl"], optional = true }
hyper = "0.14"
Expand Down
25 changes: 23 additions & 2 deletions rs/src/management/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use reqwest::{
use serde::{de::DeserializeOwned, Serialize};
use url::Url;

extern crate rand;
use rand::Rng;

use crate::contracts::{
env_production, Tunnel, TunnelConnectionMode, TunnelEndpoint, TunnelPort,
TunnelRelayTunnelEndpoint, TunnelServiceProperties, NamedRateStatus, TunnelPortListResponse, TunnelListByRegionResponse,
Expand Down Expand Up @@ -87,12 +90,12 @@ impl TunnelManagementClient {
/// Creates a new tunnel.
pub async fn create_tunnel(
&self,
tunnel: &Tunnel,
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(super::IdGeneration::generate_tunnel_id());
tunnel.tunnel_id = Some(TunnelManagementClient::generate_tunnel_id());
}
let url = self.build_uri(tunnel.cluster_id.as_deref(), TUNNELS_API_PATH);
let mut request = self.make_tunnel_request(Method::PUT, url, options).await?;
Expand Down Expand Up @@ -448,6 +451,24 @@ impl TunnelManagementClient {

Ok(request)
}

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 TUNNEL_ID_CHARS: &'static str = "bcdfghjklmnpqrstvwxz0123456789";

let mut rng = rand::thread_rng();
let mut tunnel_id = String::new();
tunnel_id.push_str(ADJECTIVES[rng.gen_range(0..ADJECTIVES.len())]);
tunnel_id.push('-');
tunnel_id.push_str(NOUNS[rng.gen_range(0..NOUNS.len())]);
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
}
}

fn json_body<T>(request: &mut Request, body: T)
Expand Down
24 changes: 0 additions & 24 deletions rs/src/management/id_generation.rs

This file was deleted.

0 comments on commit 50457f4

Please sign in to comment.