Skip to content

Commit e88745b

Browse files
committed
merge: main -> feat/runners
2 parents f4f7a8c + cf1b50e commit e88745b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1366
-998
lines changed

Cargo.lock

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[workspace]
2-
members = ["backend", "backend/runner"]
2+
members = ["backend", "backend/runner", "frontend-wasm"]
33

44
[workspace.dependencies]
5+
bytecount = "0.6"
6+
operational-transform = { version = "0.6", features = ["serde"] }
7+
serde = { version = "1.0", features = ["derive", "rc"] }
8+
serde_json = "1.0"
59
thiserror = "1.0.63"
610
tokio = { version = "1", features = ["full"] }

backend/Cargo.toml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,37 @@ edition = "2021"
66
[dependencies]
77
rsground-runner = { path = "./runner" }
88

9-
actix = "0.13"
10-
actix-cors = "0.7.1"
11-
actix_error_proc = { version = "1.1.4", features = ["thiserror"] }
12-
actix-web = "4"
13-
actix-ws = "0.3.0"
149
chrono = "0.4"
1510
dotenv = "0.15.0"
1611
env_logger = "0.11.7"
1712
futures = "0.3"
18-
jsonwebtoken = "8"
1913
log = "0.4"
20-
oauth2 = { version = "4", features = ["reqwest"] }
21-
reqwest = { version = "0.12.15", features = ["json", "default-tls"] }
22-
serde = { version = "1.0", features = ["derive"] }
23-
serde_json = "1.0"
2414
thiserror.workspace = true
2515
tokio.workspace = true
16+
17+
# Auth
18+
jsonwebtoken = "8"
19+
oauth2 = { version = "4", features = ["reqwest"] }
20+
reqwest = { version = "0.12.15", features = ["json", "default-tls"] }
2621
uuid = { version = "1.3", features = ["serde", "v4"] }
2722

28-
# Para los tests de integracion
23+
# Http server
24+
actix = "0.13"
25+
actix-cors = "0.7.1"
26+
actix_error_proc = { version = "1.1.4", features = ["thiserror"] }
27+
actix-web = "4"
28+
actix-ws = "0.3.0"
29+
30+
# OT
31+
bytecount.workspace = true
32+
operational-transform.workspace = true
33+
34+
# Serialization
35+
serde.workspace = true
36+
serde_json.workspace = true
37+
2938
[dev-dependencies]
30-
awc = "3" # Cliente HTTP y WebSocket para Actix
39+
awc = "3" # Http & WebSocket Client for Actix
3140
actix-rt = { version = "2.10.0", features = ["macros"] }
3241
futures-util = "0.3"
3342
lazy_static = "1.4"

backend/runner/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
pub mod error;
22

3-
use std::future::Future;
4-
use std::io::Read;
5-
use std::path::{Path, PathBuf};
6-
use std::sync::Arc;
7-
83
use hakoniwa::{Child, Command, Container, ExitStatus, Output};
94
use nix::libc::pid_t;
105
use nix::sys::signal::{self, Signal};
116
use nix::unistd::Pid;
127
pub use os_pipe::{PipeReader, PipeWriter};
13-
use tokio::sync::{oneshot, Notify};
8+
use std::future::Future;
9+
use std::io::Read;
10+
use std::path::{Path, PathBuf};
11+
use tokio::sync::oneshot;
1412
use tokio::{fs, io};
1513

1614
pub const BASE_ENV: [(&str, &str); 3] = [
@@ -36,7 +34,7 @@ impl Runner {
3634
temp_home
3735
}
3836

39-
fn create_container(temp_home: &PathBuf) -> Container {
37+
fn create_container(temp_home: &str) -> Container {
4038
Container::new()
4139
.hostname("rsground")
4240
.rootfs(concat!(env!("CARGO_MANIFEST_DIR"), "/lxc_rootfs"))
@@ -45,15 +43,15 @@ impl Runner {
4543
.procfsmount("/proc")
4644
.uidmap(1001)
4745
.gidmap(100)
48-
.bindmount_rw(temp_home.to_str().unwrap(), "/home")
46+
.bindmount_rw(temp_home, "/home")
4947
// FIXME: This needs to set resource limit
5048
// .setrlimit(hakoniwa::Rlimit::*, soft_limit, hard_limit)
5149
.clone()
5250
}
5351

5452
pub async fn new() -> Result<Self, ()> {
5553
let temp_home = Self::create_home().await;
56-
let container = Self::create_container(&temp_home);
54+
let container = Self::create_container(temp_home.to_str().unwrap());
5755

5856
Ok(Self {
5957
container,

backend/src/auth/jwt.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ use serde::{Deserialize, Serialize};
66

77
use crate::expect_var;
88
use crate::http_errors::HttpErrors;
9+
use crate::utils::ArcStr;
910

1011
pub static JWT_SECRET: LazyLock<String> = LazyLock::new(|| expect_var!("JWT_SECRET"));
1112
const JWT_EXP: TimeDelta = Duration::hours(12);
1213

1314
#[derive(Debug, Serialize, Deserialize)]
1415
pub struct RgUserData {
15-
pub id: String,
16-
pub name: String,
16+
pub id: ArcStr,
17+
pub name: ArcStr,
1718
pub is_guest: bool,
1819
pub exp: i64,
1920
}
2021

2122
impl RgUserData {
22-
pub fn new(id: String, name: String, is_guest: bool) -> Self {
23+
pub fn new(id: ArcStr, name: ArcStr, is_guest: bool) -> Self {
2324
let exp = Utc::now() + JWT_EXP;
2425

2526
Self {
@@ -70,6 +71,6 @@ pub fn get_auth_token(req: &HttpRequest) -> Option<&str> {
7071
}
7172

7273
pub fn get_user_info(req: &HttpRequest) -> Result<RgUserData, HttpErrors> {
73-
let token = get_auth_token(&req).ok_or_else(|| HttpErrors::NoTokenProvided)?;
74+
let token = get_auth_token(req).ok_or_else(|| HttpErrors::NoTokenProvided)?;
7475
decode(token).ok_or(HttpErrors::InvalidJWT)
7576
}

backend/src/auth/routes.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::auth::jwt::RgUserData;
88
use crate::auth::{github, jwt};
99
use crate::http_errors::HttpErrors;
1010
use crate::state::AppState;
11+
use crate::utils::ArcStr;
1112

1213
pub struct OAuthData {
1314
pub client: oauth2::basic::BasicClient,
@@ -61,10 +62,17 @@ async fn callback(
6162
.map_err(HttpErrors::GithubUserFetch)
6263
.inspect_err(|err| log::error!("{err}"))?;
6364

64-
let jwt =
65-
RgUserData::new(github_user.login.clone(), github_user.login.clone(), false).encode()?;
65+
let user_data = RgUserData::new(
66+
github_user.login.as_str().into(),
67+
github_user.login.as_str().into(),
68+
false,
69+
);
6670

67-
state.add_username(github_user.login.clone(), github_user.login.clone());
71+
state
72+
.add_username(user_data.id.clone(), user_data.name.clone())
73+
.await;
74+
75+
let jwt = user_data.encode()?;
6876

6977
Ok(HttpResponse::Ok().json(serde_json::json!({
7078
"jwt": jwt,
@@ -87,9 +95,18 @@ async fn login_guest(
8795
) -> HttpResult<HttpErrors> {
8896
let guest_name = &body.guest_name;
8997
let guest_uuid = Uuid::new_v4().to_string();
90-
let jwt = RgUserData::new(guest_uuid.clone(), guest_name.clone(), true).encode()?;
9198

92-
state.add_username(guest_uuid.clone(), guest_name.clone());
99+
let user_data = RgUserData::new(
100+
guest_uuid.as_str().into(),
101+
guest_name.as_str().into(),
102+
false,
103+
);
104+
105+
state
106+
.add_username(user_data.id.clone(), user_data.name.clone())
107+
.await;
108+
109+
let jwt = user_data.encode()?;
93110

94111
Ok(HttpResponse::Ok().json(serde_json::json!({
95112
"jwt": jwt,
@@ -100,7 +117,7 @@ async fn login_guest(
100117
}
101118
#[derive(Deserialize)]
102119
struct UpdateNameRequest {
103-
new_name: String,
120+
new_name: ArcStr,
104121
}
105122

106123
#[proof_route(post("/auth/update"))]
@@ -118,9 +135,13 @@ async fn update_name(
118135
let uuid = token_data.id;
119136
let new_name = body.into_inner().new_name;
120137

121-
let jwt = RgUserData::new(uuid.clone(), new_name.clone(), true).encode()?;
138+
let user_data = RgUserData::new(uuid.clone(), new_name.clone(), false);
139+
140+
state
141+
.add_username(user_data.id.clone(), user_data.name.clone())
142+
.await;
122143

123-
state.add_username(uuid.clone(), new_name.clone());
144+
let jwt = user_data.encode()?;
124145

125146
Ok(HttpResponse::Ok().json(serde_json::json!({
126147
"jwt": jwt,

backend/src/collab/action.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1+
use std::sync::Arc;
2+
3+
use operational_transform::OperationSeq;
14
use serde::{Deserialize, Serialize};
25

3-
#[derive(Serialize, Deserialize, Clone, Debug)]
4-
#[serde(tag = "kind", rename_all = "snake_case")]
5-
pub enum Action {
6-
Insertion {
7-
from: usize,
8-
text: String,
9-
owner: String,
10-
},
11-
Deletion {
12-
from: usize,
13-
to: usize,
14-
owner: String,
15-
},
6+
#[derive(Clone, Debug, Serialize, Deserialize)]
7+
pub struct UserOperation {
8+
pub user_id: Arc<str>,
9+
pub operation: OperationSeq,
1610
}

0 commit comments

Comments
 (0)