Add application routes

This commit is contained in:
Savanni D'Gerinel 2021-12-29 12:53:04 -05:00
parent b685057346
commit 50807077a6
7 changed files with 2991 additions and 29 deletions

1826
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

6
Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[workspace]
members = [
"common",
"gtk",
"server",
]

84
common/Cargo.lock generated Normal file
View File

@ -0,0 +1,84 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "common"
version = "0.1.0"
dependencies = [
"serde",
"serde_derive",
"thiserror",
]
[[package]]
name = "proc-macro2"
version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [
"proc-macro2",
]
[[package]]
name = "serde"
version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008"
[[package]]
name = "serde_derive"
version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "1.0.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "thiserror"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

1016
server/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -6,5 +6,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
orizentic = { path = "../../orizentic/" }
tokio = { version = "1", features = ["full"] }
warp = { version = "0.3.1" }

View File

@ -1,42 +1,64 @@
use orizentic::{OrizenticCtx, Secret, Username};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use warp::Filter;
use std::sync::{Arc, RwLock};
use warp::{reject, Filter, Rejection};
fn gm_paths() -> impl Filter {
let base = warp::path("gm").and(warp::header("authentication"));
let character_sheet = base
.clone()
.and(warp::path!("character" / String))
.map(|auth: String, name| format!("name: {}", name));
let send_item = base
.clone()
.and(warp::path("send_item"))
.map(|auth| format!("send_item"));
let send_resource = base
.clone()
.and(warp::path("send_resource"))
.map(|auth| format!("send_resource"));
character_sheet.or(send_item).or(send_resource)
fn with_auth(
auth_ctx: Arc<RwLock<OrizenticCtx>>,
) -> impl Filter<Extract = (Username,), Error = Rejection> + Clone {
let auth_ctx = auth_ctx.clone();
warp::header("authentication").and_then({
let auth_ctx = auth_ctx.clone();
move |text| {
let auth_ctx = auth_ctx.clone();
async move {
match auth_ctx.read().unwrap().decode_and_validate_text(text) {
Ok(token) => Ok(token.claims.audience),
Err(_) => Err(reject()),
}
}
}
})
}
fn player_paths() -> impl Filter {
let base = warp::path("player").and(warp::header("authentication"));
let character_sheet = base
.and(warp::path!("character" / String))
.map(|authentication: String, name: String| format!("name: {}", name));
fn gm_routes(
auth_ctx: Arc<RwLock<OrizenticCtx>>,
) -> impl Filter<Extract = (), Error = Rejection> + Clone {
let base_route = with_auth(auth_ctx).and(warp::path("gm"));
character_sheet
let character_sheet = {
let auth_ctx = auth_ctx.clone();
with_auth(auth_ctx)
.and(warp::path!("gm" / "character" / String))
.map(|auth: Username, name| format!("name: {} {}", String::from(auth), name))
};
}
#[tokio::main]
pub async fn main() {
let hi = warp::path!("hello" / String)
.and(warp::header("user-agent"))
.map(|param: String, agent: String| format!("Saluton! {}, {}", param, agent));
let bye = warp::path!("goodbye").map(|| "Goodbye!");
let auth_ctx = Arc::new(RwLock::new(OrizenticCtx::new(
Secret(Vec::from("abcdefg".as_bytes())),
vec![],
)));
let server = warp::serve(hi.or(bye));
let send_item = {
let auth_ctx = auth_ctx.clone();
with_auth(auth_ctx)
.and(warp::path!("gm" / "send_item"))
.map(|auth: Username| format!("send_item: {}", String::from(auth)))
};
let send_resource = warp::header("authentication")
.and(warp::path!("gm" / "send_resource"))
.map(|auth: String| format!("send_resource"));
let pc_sheet = warp::header("authentication")
.and(warp::path!("player" / "character" / String))
.map(|authentication: String, name: String| format!("name: {}", name));
let filter = character_sheet.or(send_item).or(send_resource).or(pc_sheet);
let server = warp::serve(filter);
server
.run(SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),

View File

@ -10,6 +10,13 @@ in pkgs.mkShell {
name = "datasphere";
nativeBuildInputs = [
pkgs.gnome.webkitgtk
pkgs.glib
pkgs.gtk3
pkgs.libpng
pkgs.openssl
pkgs.pkg-config
pkgs.wrapGAppsHook
rust
unstable.rust-analyzer
pkgs.nodejs