Skip to content

Commit

Permalink
use secure websocket when https is used
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht committed Nov 21, 2023
1 parent f20bb83 commit 5646c69
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/cloudagent-python/src/cloudagent/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use tungstenite::connect;
impl WebhookModule for CloudAgentPython {
/// Listen to all incoming webhook
async fn listen(&self, on_event: fn(serde_json::Value)) -> Result<()> {
let stripped_agent_url = match &self.endpoint {
s if s.starts_with("http://") => &s[7..],
s if s.starts_with("https://") => &s[8..],
let (uses_tls, stripped_agent_url) = match &self.endpoint {
s if s.starts_with("http://") => (false, &s[7..]),
s if s.starts_with("https://") => (true, &s[8..]),

Check warning on line 13 in crates/cloudagent-python/src/cloudagent/webhook.rs

View check run for this annotation

Codecov / codecov/patch

crates/cloudagent-python/src/cloudagent/webhook.rs#L11-L13

Added lines #L11 - L13 were not covered by tests
s => return Err(Error::InvalidAgentUrl(s.clone()).into()),
};

let listen_url = format!("wss://{stripped_agent_url}/ws");
let scheme = if uses_tls { "wss" } else { "ws" };

Check warning on line 17 in crates/cloudagent-python/src/cloudagent/webhook.rs

View check run for this annotation

Codecov / codecov/patch

crates/cloudagent-python/src/cloudagent/webhook.rs#L17

Added line #L17 was not covered by tests

let listen_url = format!("{scheme}://{stripped_agent_url}/ws");

Check warning on line 19 in crates/cloudagent-python/src/cloudagent/webhook.rs

View check run for this annotation

Codecov / codecov/patch

crates/cloudagent-python/src/cloudagent/webhook.rs#L19

Added line #L19 was not covered by tests
info!({ "message": format!("Listening on {listen_url}") });

let (mut socket, _response) = connect(listen_url)?;
Expand Down

0 comments on commit 5646c69

Please sign in to comment.