Skip to content

Commit

Permalink
Add endpoint connection mode query param (#392)
Browse files Browse the repository at this point in the history
* add endpoint query param

* Revert "add endpoint query param"

This reverts commit 76b489c.

* use tostring

* update types

* fix delete

* fix build

* update port request

* fix syntax

* fix build again

* fix build

* compilation error, build connections in ci

* run clippy and cargo fmt

---------

Co-authored-by: Connor Peet <[email protected]>
  • Loading branch information
jfullerton44 and connor4312 authored Jan 30, 2024
1 parent 1122326 commit c1bf142
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose --manifest-path=rs/Cargo.toml
run: cargo build --features connections --verbose --manifest-path=rs/Cargo.toml
- name: Run tests
run: cargo test --verbose --manifest-path=rs/Cargo.toml
run: cargo test --features connections --verbose --manifest-path=rs/Cargo.toml

7 changes: 3 additions & 4 deletions rs/src/connections/relay_tunnel_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ impl RelayTunnelHost {
self.mgmt
.delete_tunnel_endpoints(
&self.locator,
&self.host_id.to_string(),
None,
&format!("{}-relay", &self.host_id.to_string()),
NO_REQUEST_OPTIONS,
)
.await
Expand Down Expand Up @@ -326,7 +325,7 @@ impl RelayTunnelHost {
connection_timeout: None,
auth_rejection_time: std::time::Duration::from_secs(5),
keys: vec![keypair],
window_size: 1024 * 1024 * 1,
window_size: 1024 * 1024,
preferred: russh::Preferred::COMPRESSED,
limits: russh::Limits {
rekey_read_limit: usize::MAX,
Expand Down Expand Up @@ -390,7 +389,7 @@ impl RelayTunnelHost {
&self.locator,
&TunnelRelayTunnelEndpoint {
base: TunnelEndpoint {
id: Some(uuid::Uuid::new_v4().to_string()),
id: format!("{}-relay", self.host_id),
connection_mode: TunnelConnectionMode::TunnelRelay,
host_id: self.host_id.to_string(),
host_public_keys: vec![],
Expand Down
3 changes: 1 addition & 2 deletions rs/src/connections/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ mod test {
}
});

let mut output = Vec::new();
output.resize(input_len, 0);
let mut output = vec![0; input_len];
read.read_exact(&mut output)
.await
.expect("expected to read");
Expand Down
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_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub const TUNNEL_ALIAS_PATTERN: &str = r#"[0123456789bcdfghjklmnpqrstvwxz]{3,60}
pub const TUNNEL_NAME_PATTERN: &str = r#"([a-z0-9][a-z0-9-]{1,58}[a-z0-9])|(^$)"#;

// Regular expression that can match or validate tunnel or port labels.
pub const LABEL_PATTERN: &str = r#"[\w-=]{1,50}"#;
pub const LABEL_PATTERN: &str = r"[\w-=]{1,50}";

// Regular expression that can match or validate tunnel domains.
//
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
37 changes: 16 additions & 21 deletions rs/src/management/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use url::Url;
use rand::Rng;

use crate::contracts::{
env_production, NamedRateStatus, Tunnel, TunnelConnectionMode, TunnelEndpoint,
TunnelListByRegionResponse, TunnelPort, TunnelPortListResponse, TunnelRelayTunnelEndpoint,
TunnelServiceProperties,
env_production, NamedRateStatus, Tunnel, TunnelEndpoint, TunnelListByRegionResponse,
TunnelPort, TunnelPortListResponse, TunnelRelayTunnelEndpoint, TunnelServiceProperties,
};

use super::{
Expand Down Expand Up @@ -161,13 +160,12 @@ impl TunnelManagementClient {
endpoint: &TunnelEndpoint,
options: &TunnelRequestOptions,
) -> HttpResult<TunnelEndpoint> {
let url = self.build_tunnel_uri(
let mut url = self.build_tunnel_uri(
locator,
Some(&format!(
"{}/{}/{}",
ENDPOINTS_API_SUB_PATH, endpoint.host_id, endpoint.connection_mode
)),
Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.id)),
);
url.query_pairs_mut()
.append_pair("connectionMode", &endpoint.connection_mode.to_string());
let mut request = self.make_tunnel_request(Method::PUT, url, options).await?;
json_body(&mut request, endpoint);
self.execute_json("update_tunnel_endpoints", request).await
Expand All @@ -180,13 +178,12 @@ impl TunnelManagementClient {
endpoint: &TunnelRelayTunnelEndpoint,
options: &TunnelRequestOptions,
) -> HttpResult<TunnelRelayTunnelEndpoint> {
let url = self.build_tunnel_uri(
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)),
);
url.query_pairs_mut()
.append_pair("connectionMode", &endpoint.base.connection_mode.to_string());
let mut request = self.make_tunnel_request(Method::PUT, url, options).await?;
json_body(&mut request, endpoint);
self.execute_json("update_tunnel_relay_endpoints", request)
Expand All @@ -197,15 +194,10 @@ impl TunnelManagementClient {
pub async fn delete_tunnel_endpoints(
&self,
locator: &TunnelLocator,
host_id: &str,
connection_mode: Option<TunnelConnectionMode>,
id: &str,
options: &TunnelRequestOptions,
) -> HttpResult<bool> {
let path = if let Some(cm) = connection_mode {
format!("{}/{}/{}", ENDPOINTS_API_SUB_PATH, host_id, cm)
} else {
format!("{}/{}", ENDPOINTS_API_SUB_PATH, host_id)
};
let path = format!("{}/{}", ENDPOINTS_API_SUB_PATH, id);

let url = self.build_tunnel_uri(locator, Some(&path));
let request = self
Expand Down Expand Up @@ -250,7 +242,10 @@ impl TunnelManagementClient {
port: &TunnelPort,
options: &TunnelRequestOptions,
) -> HttpResult<TunnelPort> {
let url = self.build_tunnel_uri(locator, Some(PORTS_API_SUB_PATH));
let url = self.build_tunnel_uri(
locator,
Some(&format!("{}/{}", PORTS_API_SUB_PATH, port.port_number)),
);
let mut request = self.make_tunnel_request(Method::PUT, url, options).await?;
json_body(&mut request, port);
self.execute_json("create_tunnel_port", request).await
Expand Down

0 comments on commit c1bf142

Please sign in to comment.