From d3d3771d22b8a0faaa01a5dbf817b2ca18b036e8 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 23 Nov 2021 20:31:54 +0100 Subject: [PATCH 1/2] Added working "infinite" jwt token for testing --- src/main.rs | 8 ++------ test.py | 7 +++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index a484c1b..70287c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use figment::{ providers::{Env, Format, Yaml}, Figment, }; -use rb::{auth::JwtConf, guards}; +use rb::auth::JwtConf; use rocket::{ fairing::AdHoc, http::Status, @@ -49,9 +49,6 @@ pub struct RbConfig jwt: JwtConf, } -#[get("/test")] -async fn test(_yeet: guards::Jwt) {} - #[launch] fn rocket() -> _ { @@ -87,8 +84,7 @@ fn rocket() -> _ posts::patch, posts::delete ], - ) - .mount("/", routes![test]); + ); let new_figment = rocket.figment(); let jwt_conf: JwtConf = new_figment.extract_inner("jwt").expect("jwt config"); diff --git a/test.py b/test.py index a1e7a1f..2493a41 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,7 @@ import requests -token = "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjVjMjM2OTI0NjY4ZDQzZWFiNGNmNDczYjk1YWZiNzgzIiwidXNlcm5hbWUiOiJKb2huIERvZSIsImFkbWluIjp0cnVlLCJleHAiOjE1MTYyMzkwMjIwfQ.3AzUBe08lcnC3fUIMqPZ8kG51PNPS4MAMpoh_v5HSKM" +# Token specifically used for testing. It's signed with secret "secret" & expires in 2034 or something +token = "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjVjMjM2OTI0NjY4ZDQzZWFiNGNmNDczYjk1YWZiNzgzIiwidXNlcm5hbWUiOiJKb2huIERvZSIsImFkbWluIjp0cnVlLCJleHAiOjE1MTYyMzkwMjIwfQ.if939L9le8LP-dtXnQs-mHPkb-VieRAvAfSu20755jY" headers = { "Authorization": f"Bearer {token}" @@ -11,6 +12,8 @@ data = { "shortname": "short", } -r = requests.get("http://localhost:8000/test", headers=headers) +r = requests.post("http://localhost:8000/sections", headers=headers, json=data) print(r.content) print(r.status_code) +r = requests.get("http://localhost:8000/sections?offset=0&limit=100") +print(r.json()) From 7aee0282b2271fbc9e313efc9b924246badd6875 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 24 Nov 2021 17:51:52 +0100 Subject: [PATCH 2/2] Moved routes to versioned prefix --- src/main.rs | 27 +++++++++++++-------------- src/v1/mod.rs | 2 ++ src/{ => v1}/posts.rs | 0 src/{ => v1}/sections.rs | 0 4 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 src/v1/mod.rs rename src/{ => v1}/posts.rs (100%) rename src/{ => v1}/sections.rs (100%) diff --git a/src/main.rs b/src/main.rs index 70287c0..683c0b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,8 +17,7 @@ use rocket::{ use rocket_sync_db_pools::database; use serde::{Deserialize, Serialize}; -pub mod posts; -pub mod sections; +pub mod v1; #[database("postgres_rb")] pub struct RbDbConn(diesel::PgConnection); @@ -66,23 +65,23 @@ fn rocket() -> _ // .attach(AdHoc::config::()) .register("/", catchers![default_catcher]) .mount( - "/sections", + "/v1/sections", routes![ - sections::get, - sections::create, - sections::find, - sections::patch, - sections::delete + v1::sections::get, + v1::sections::create, + v1::sections::find, + v1::sections::patch, + v1::sections::delete ], ) .mount( - "/posts", + "/v1/posts", routes![ - posts::get, - posts::create, - posts::find, - posts::patch, - posts::delete + v1::posts::get, + v1::posts::create, + v1::posts::find, + v1::posts::patch, + v1::posts::delete ], ); diff --git a/src/v1/mod.rs b/src/v1/mod.rs new file mode 100644 index 0000000..ac3e36c --- /dev/null +++ b/src/v1/mod.rs @@ -0,0 +1,2 @@ +pub mod posts; +pub mod sections; diff --git a/src/posts.rs b/src/v1/posts.rs similarity index 100% rename from src/posts.rs rename to src/v1/posts.rs diff --git a/src/sections.rs b/src/v1/sections.rs similarity index 100% rename from src/sections.rs rename to src/v1/sections.rs