aboutsummaryrefslogtreecommitdiffstats
path: root/crates/rocie-server/src/main.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-12-09 13:07:14 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-12-09 13:07:14 +0100
commitc91dce4f77ae12453203f0a28b91efb6533cc095 (patch)
tree4f50e755dff7f717d45309b08f9fe2c8c87f88bd /crates/rocie-server/src/main.rs
parentchore(rocie-client): Regenerate (diff)
downloadserver-c91dce4f77ae12453203f0a28b91efb6533cc095.zip
feat(rocie-server): Implement basic user handling and authentication
Diffstat (limited to '')
-rw-r--r--crates/rocie-server/src/main.rs77
1 files changed, 42 insertions, 35 deletions
diff --git a/crates/rocie-server/src/main.rs b/crates/rocie-server/src/main.rs
index dc5be0b..caa210d 100644
--- a/crates/rocie-server/src/main.rs
+++ b/crates/rocie-server/src/main.rs
@@ -26,39 +26,42 @@ use actix_session::{SessionMiddleware, storage::CookieSessionStore};
async fn main() -> Result<(), std::io::Error> {
#[derive(OpenApi)]
#[openapi(
- paths(
- api::get::product::product_by_id,
- api::get::product::product_by_name,
- api::get::product::product_suggestion_by_name,
- api::get::product::products_registered,
- api::get::product::products_in_storage,
- api::get::product::products_by_product_parent_id_indirect,
- api::get::product::products_by_product_parent_id_direct,
- api::get::product_parent::product_parents,
- api::get::product_parent::product_parents_toplevel,
- api::get::product_parent::product_parents_under,
- api::get::recipe::recipe_by_id,
- api::get::recipe::recipes,
- api::get::unit::units,
- api::get::unit::units_by_property_id,
- api::get::unit::unit_by_id,
- api::get::unit_property::unit_property_by_id,
- api::get::unit_property::unit_properties,
- api::get::inventory::amount_by_id,
- api::set::product::register_product,
- api::set::product::associate_barcode,
- api::set::product_parent::register_product_parent,
- api::set::recipe::add_recipe,
- api::set::unit::register_unit,
- api::set::unit_property::register_unit_property,
- api::set::barcode::buy_barcode,
- api::set::barcode::consume_barcode,
+ paths(
+ api::get::auth::product::product_by_id,
+ api::get::auth::product::product_by_name,
+ api::get::auth::product::product_suggestion_by_name,
+ api::get::auth::product::products_registered,
+ api::get::auth::product::products_in_storage,
+ api::get::auth::product::products_by_product_parent_id_indirect,
+ api::get::auth::product::products_by_product_parent_id_direct,
+ api::get::auth::product_parent::product_parents,
+ api::get::auth::product_parent::product_parents_toplevel,
+ api::get::auth::product_parent::product_parents_under,
+ api::get::auth::recipe::recipe_by_id,
+ api::get::auth::recipe::recipes,
+ api::get::auth::unit::units,
+ api::get::auth::unit::units_by_property_id,
+ api::get::auth::unit::unit_by_id,
+ api::get::auth::unit_property::unit_property_by_id,
+ api::get::auth::unit_property::unit_properties,
+ api::get::auth::inventory::amount_by_id,
+ api::get::auth::user::users,
+ api::get::auth::user::user_by_id,
+ //
+ api::set::auth::product::register_product,
+ api::set::auth::product::associate_barcode,
+ api::set::auth::product_parent::register_product_parent,
+ api::set::auth::recipe::add_recipe,
+ api::set::auth::unit::register_unit,
+ api::set::auth::unit_property::register_unit_property,
+ api::set::auth::barcode::buy_barcode,
+ api::set::auth::barcode::consume_barcode,
+ api::set::auth::user::register_user,
+ //
+ api::set::no_auth::user::login,
+ api::set::no_auth::user::logout,
+ api::set::no_auth::user::provision,
),
- // security(
- // (),
- // ("my_auth" = ["read:items", "edit:items"]),
- // ("token_jwt" = [])
- // ),
)]
struct ApiDoc;
@@ -67,6 +70,7 @@ async fn main() -> Result<(), std::io::Error> {
// When using `Key::generate()` it is important to initialize outside of the
// `HttpServer::new` closure. When deployed the secret key should be read from a
// configuration file or environment variables.
+ // TODO: Load from a config file. <2025-12-07>
let secret_key = Key::generate();
let args = CliArgs::parse();
@@ -91,7 +95,7 @@ async fn main() -> Result<(), std::io::Error> {
.wrap(Logger::new(
r#"%a "%r" -> %s %b ("%{Referer}i" "%{User-Agent}i" %T s)"#,
))
- // Install the identity framework before middle-ware (as actix is filo).
+ // Install the identity framework before middleware (as actix uses FILO).
.wrap(IdentityMiddleware::default())
.wrap(
SessionMiddleware::builder(
@@ -104,8 +108,10 @@ async fn main() -> Result<(), std::io::Error> {
.build(),
)
.app_data(Data::clone(&data))
- .configure(api::get::register_paths)
- .configure(api::set::register_paths)
+ .configure(api::get::auth::register_paths)
+ .configure(api::get::no_auth::register_paths)
+ .configure(api::set::auth::register_paths)
+ .configure(api::set::no_auth::register_paths)
})
.bind((host, port.unwrap_or(0)))?;
@@ -121,6 +127,7 @@ async fn main() -> Result<(), std::io::Error> {
}
Command::OpenApi => {
let openapi = ApiDoc::openapi();
+
println!("{}", openapi.to_pretty_json().expect("Comp-time constant"));
Ok(())
}