Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

allow insecyre ws #20

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ golem-examples = "0.1.5"
http = "0.2.9"
indoc = "2.0.3"
itertools = "0.11.0"
native-tls = "0.2.11"
reqwest = "0.11.20"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.105"
Expand Down
19 changes: 17 additions & 2 deletions src/clients/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use futures_util::{future, pin_mut, SinkExt, StreamExt};
use golem_client::model::{
ComponentInstance, InstanceMetadata, InvokeParameters, InvokeResult, WorkerCreationRequest,
};
use native_tls::TlsConnector;
use reqwest::Url;
use serde::Deserialize;
use std::fmt::{Display, Formatter};
use std::time::Duration;
use tokio::{task, time};
use tokio_tungstenite::{
connect_async, tungstenite::client::IntoClientRequest, tungstenite::protocol::Message,
connect_async_tls_with_config, tungstenite::client::IntoClientRequest,
tungstenite::protocol::Message, Connector,
};
use tracing::{debug, info};

Expand Down Expand Up @@ -89,6 +91,7 @@ pub trait WorkerClient {
pub struct WorkerClientLive<C: golem_client::instance::Instance + Send + Sync> {
pub client: C,
pub base_url: Url,
pub allow_insecure: bool,
}

#[async_trait]
Expand Down Expand Up @@ -279,7 +282,19 @@ impl<C: golem_client::instance::Instance + Send + Sync> WorkerClient for WorkerC
let headers = request.headers_mut();
headers.insert("Authorization", auth.header().parse().unwrap());

let (ws_stream, _) = connect_async(request)
let connector = if self.allow_insecure {
Some(Connector::NativeTls(
TlsConnector::builder()
.danger_accept_invalid_certs(true)
.danger_accept_invalid_hostnames(true)
.build()
.unwrap(),
))
} else {
None
};

let (ws_stream, _) = connect_async_tls_with_config(request, None, false, connector)
.await
.map_err(|e| GolemError(format!("Failed websocket: {e}")))?;

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ async fn async_main(cmd: GolemCommand) -> Result<(), Box<dyn std::error::Error>>
allow_insecure,
},
base_url: url.clone(),
allow_insecure,
};
let worker_srv = WorkerHandlerLive {
client: worker_client.clone(),
Expand Down
Loading