Add application routes
This commit is contained in:
parent
b685057346
commit
50807077a6
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,6 @@
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"common",
|
||||||
|
"gtk",
|
||||||
|
"server",
|
||||||
|
]
|
|
@ -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"
|
File diff suppressed because it is too large
Load Diff
|
@ -6,5 +6,6 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
orizentic = { path = "../../orizentic/" }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
warp = { version = "0.3.1" }
|
warp = { version = "0.3.1" }
|
||||||
|
|
|
@ -1,42 +1,64 @@
|
||||||
|
use orizentic::{OrizenticCtx, Secret, Username};
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
use warp::Filter;
|
use std::sync::{Arc, RwLock};
|
||||||
|
use warp::{reject, Filter, Rejection};
|
||||||
|
|
||||||
fn gm_paths() -> impl Filter {
|
fn with_auth(
|
||||||
let base = warp::path("gm").and(warp::header("authentication"));
|
auth_ctx: Arc<RwLock<OrizenticCtx>>,
|
||||||
|
) -> impl Filter<Extract = (Username,), Error = Rejection> + Clone {
|
||||||
let character_sheet = base
|
let auth_ctx = auth_ctx.clone();
|
||||||
.clone()
|
warp::header("authentication").and_then({
|
||||||
.and(warp::path!("character" / String))
|
let auth_ctx = auth_ctx.clone();
|
||||||
.map(|auth: String, name| format!("name: {}", name));
|
move |text| {
|
||||||
let send_item = base
|
let auth_ctx = auth_ctx.clone();
|
||||||
.clone()
|
async move {
|
||||||
.and(warp::path("send_item"))
|
match auth_ctx.read().unwrap().decode_and_validate_text(text) {
|
||||||
.map(|auth| format!("send_item"));
|
Ok(token) => Ok(token.claims.audience),
|
||||||
let send_resource = base
|
Err(_) => Err(reject()),
|
||||||
.clone()
|
}
|
||||||
.and(warp::path("send_resource"))
|
}
|
||||||
.map(|auth| format!("send_resource"));
|
}
|
||||||
|
})
|
||||||
character_sheet.or(send_item).or(send_resource)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn player_paths() -> impl Filter {
|
fn gm_routes(
|
||||||
let base = warp::path("player").and(warp::header("authentication"));
|
auth_ctx: Arc<RwLock<OrizenticCtx>>,
|
||||||
let character_sheet = base
|
) -> impl Filter<Extract = (), Error = Rejection> + Clone {
|
||||||
.and(warp::path!("character" / String))
|
let base_route = with_auth(auth_ctx).and(warp::path("gm"));
|
||||||
.map(|authentication: String, name: String| format!("name: {}", name));
|
|
||||||
|
|
||||||
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]
|
#[tokio::main]
|
||||||
pub async fn main() {
|
pub async fn main() {
|
||||||
let hi = warp::path!("hello" / String)
|
let auth_ctx = Arc::new(RwLock::new(OrizenticCtx::new(
|
||||||
.and(warp::header("user-agent"))
|
Secret(Vec::from("abcdefg".as_bytes())),
|
||||||
.map(|param: String, agent: String| format!("Saluton! {}, {}", param, agent));
|
vec![],
|
||||||
let bye = warp::path!("goodbye").map(|| "Goodbye!");
|
)));
|
||||||
|
|
||||||
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
|
server
|
||||||
.run(SocketAddr::new(
|
.run(SocketAddr::new(
|
||||||
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||||
|
|
|
@ -10,6 +10,13 @@ in pkgs.mkShell {
|
||||||
name = "datasphere";
|
name = "datasphere";
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
|
pkgs.gnome.webkitgtk
|
||||||
|
pkgs.glib
|
||||||
|
pkgs.gtk3
|
||||||
|
pkgs.libpng
|
||||||
|
pkgs.openssl
|
||||||
|
pkgs.pkg-config
|
||||||
|
pkgs.wrapGAppsHook
|
||||||
rust
|
rust
|
||||||
unstable.rust-analyzer
|
unstable.rust-analyzer
|
||||||
pkgs.nodejs
|
pkgs.nodejs
|
||||||
|
|
Loading…
Reference in New Issue