Skip to content

Commit

Permalink
FIX proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
synoet committed May 10, 2024
1 parent b684bef commit 9c5dda4
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 89 deletions.
104 changes: 104 additions & 0 deletions theia/proxy-rs/Cargo.lock

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

4 changes: 3 additions & 1 deletion theia/proxy-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ edition = "2021"
anyhow = "1.0.82"
axum = { version = "0.7.5", features = ["ws"] }
axum-extra = { version = "0.9.3", features = ["cookie"] }
chrono = "0.4.38"
futures-util = "0.3.30"
hyper = "1.3.1"
hyper-util = { version = "0.1.3", features = ["tokio"] }
hyper-tungstenite = "0.13.0"
hyper-util = { version = "0.1.3", features = ["client", "client-legacy"] }
jsonwebtoken = "9.3.0"
lazy_static = "1.4.0"
serde = "1.0.200"
Expand Down
47 changes: 47 additions & 0 deletions theia/proxy-rs/src/db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};
use sqlx::{prelude::FromRow, MySqlPool};

#[derive(Deserialize, Serialize, FromRow)]
struct TheiaSession {
cluster_address: Option<String>,
}

pub async fn get_cluster_address(pool: &MySqlPool, session_id: &str) -> Result<String> {
let row: Option<TheiaSession> = sqlx::query_as(
r#"
SELECT cluster_address
FROM theia_session
WHERE id = ? AND active = 1
"#,
)
.bind(session_id)
.fetch_optional(pool)
.await?;

match row {
Some(session) => {
if let Some(cluster_address) = session.cluster_address {
Ok(cluster_address)
} else {
Err(anyhow::anyhow!("cluster address not found"))
}
}
None => Err(anyhow::anyhow!("session not found")),
}
}

pub async fn update_last_proxy_time(session_id: &str, pool: &MySqlPool) -> Result<()> {
sqlx::query(
r#"
UPDATE theia_session
SET last_proxy = NOW()
WHERE id = ?
"#,
)
.bind(session_id)
.execute(pool)
.await?;

Ok(())
}
Loading

0 comments on commit 9c5dda4

Please sign in to comment.