Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use secure websocket when https is used #273

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Changes from 1 commit
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
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 @@
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
Loading