From b07d4e7e0e0f18be03353558bdc180361e12a353 Mon Sep 17 00:00:00 2001 From: rmanach Date: Thu, 16 Feb 2023 15:43:11 +0100 Subject: [PATCH] fix documentation + update http lib version --- Cargo.toml | 2 +- README.md | 9 ++++----- src/config/mod.rs | 3 ++- src/jwt/mod.rs | 3 ++- src/main.rs | 2 +- src/message/message.rs | 2 +- src/message/mod.rs | 3 ++- src/router/mod.rs | 2 +- src/router/router.rs | 7 ++----- src/stores/file.rs | 3 ++- src/stores/mod.rs | 7 +++---- src/stores/store.rs | 1 + 12 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ad33220..f327306 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ log = "0.4.17" base64 = "0.13.1" serde_json = "1.0" -http = { git = "https://gitea.thegux.fr/rmanach/http", version = "0.1.5" } +http = { git = "https://gitea.thegux.fr/rmanach/http", version = "0.1.6" } # useful for tests (embedded files should be delete in release ?) #rust-embed="6.4.1" diff --git a/README.md b/README.md index b5e57fc..a0238c6 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ cargo build --release ``` ## Configuration - ### Store The store represents the credentials. For now, this a `.txt` file with plain passwords. You have to create one like: ```txt @@ -72,7 +71,7 @@ cargo test * set the following env variables: ```bash export SIMPLE_AUTH_URL="http://:" -export SIMPLE_AUTH_PUB_KEY="" # DO NOT USE THE ONE IN PRODUCTION ! +export SIMPLE_AUTH_PUB_KEY="" # DO NOT USE THIS ONE IN PRODUCTION ! ``` * run the server (if no one is running remotly) * run curl tests @@ -80,14 +79,14 @@ export SIMPLE_AUTH_PUB_KEY="" # DO NOT USE THE ONE IN PRODU cd tests/bash/ ./curling.bash && echo "passed" ``` -* run python requests tests +* run python tests ```bash # create a python venv cd tests/python python3 -m venv venv source venv/bin/activate -# intall the requirements +# install the requirements pip install -r requirements # launch the tests @@ -97,5 +96,5 @@ python -m unittest ## Documentation ```bash # add the '--open' arg to open the doc on a browser -cargo doc --no-deps +cargo doc -r --no-deps ``` diff --git a/src/config/mod.rs b/src/config/mod.rs index b82b271..bd20f7d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,4 +1,5 @@ -//! provides `Config` struct to load and validate `.ini` file +//! **config** module provides `Config` struct to load and validate `.ini` file. + mod config; pub use config::Config; diff --git a/src/jwt/mod.rs b/src/jwt/mod.rs index ae4d8f4..7eb999b 100644 --- a/src/jwt/mod.rs +++ b/src/jwt/mod.rs @@ -1,4 +1,5 @@ -//! jwt module aims to read `.pem` files, sign/validate the token +//! **jwt** module aims to read `.pem` files and sign/validate the token. + mod jwt; pub use jwt::JWTSigner; diff --git a/src/main.rs b/src/main.rs index d103358..90f47ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,7 +67,7 @@ async fn main() { } } -/// parses the incoming request (partial spec implementation) and build an HTTP response +/// handle_connection parses the incoming request and builds an HTTP response async fn handle_connection(mut stream: TcpStream, addr: String, config: Config) { log::info!("client connected: {}", addr); diff --git a/src/message/message.rs b/src/message/message.rs index 3dc0cb7..8b365c8 100644 --- a/src/message/message.rs +++ b/src/message/message.rs @@ -1,7 +1,7 @@ use serde::Serialize; #[derive(Serialize)] -/// JWTMessage aims to have a generic struct to build HTTP response message with JWT +/// JWTMessage aims to have a generic struct to build JSON HTTP response message with JWT informations pub struct JWTMessage { #[serde(skip_serializing_if = "String::is_empty")] access_token: String, diff --git a/src/message/mod.rs b/src/message/mod.rs index 5da0789..072badf 100644 --- a/src/message/mod.rs +++ b/src/message/mod.rs @@ -1,4 +1,5 @@ -//! message lib holds all structs to manager auth JSON response body +//! **message** module holds all structs to manage JSON response body for the authentication. + mod message; pub use message::{JWTMessage, ValidationMessage}; diff --git a/src/router/mod.rs b/src/router/mod.rs index 16b5ebb..343295a 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -1,4 +1,4 @@ -//! router module includes all the handlers to get and validate JWT +//! **router** module includes all the handlers to get and validate JWT. mod router; pub use router::ROUTER; diff --git a/src/router/router.rs b/src/router/router.rs index d284234..63dcd00 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -1,6 +1,3 @@ -//! router aims to handle correctly the request corresponding to the target -//! it implements all the logic to build an `HTTPResponse` - use http::{HTTPRequest, HTTPResponse, JSONMessage}; use json::JsonValue; @@ -127,7 +124,7 @@ async fn handle_public_key(request: HTTPRequest<'_>, config: Config, method: &st pub struct Router; impl Router { - /// route routes the request to the corresponding handling method + /// route routes the request to the corresponding handler pub async fn route(&self, request_str: &str, config: Config) -> HTTPResponse { let request = HTTPRequest::from(request_str); match request.get_target() { @@ -149,7 +146,7 @@ pub fn send_token(jwt_message: &str) -> HTTPResponse { HTTPResponse::as_200(Some(json::parse(message).unwrap())) } -// this MUST be used like a Singleton +// this **MUST** be used like a Singleton pub const ROUTER: Router = Router {}; #[tokio::test] diff --git a/src/stores/file.rs b/src/stores/file.rs index 6526cac..5783320 100644 --- a/src/stores/file.rs +++ b/src/stores/file.rs @@ -18,7 +18,8 @@ impl FileStore { } /// parse_contents loads and reads the file asynchonously - /// parses the file line by line to retrieve the credentials + /// + /// It parses the file line by line to retrieve the credentials async fn parse_contents(&mut self) { let contents = tokio::fs::read_to_string(&self.path).await; let mut credentials: Vec = vec![]; diff --git a/src/stores/mod.rs b/src/stores/mod.rs index 2a768fc..ae56d8e 100644 --- a/src/stores/mod.rs +++ b/src/stores/mod.rs @@ -1,8 +1,7 @@ -//! store module lists interfaces available to check request credentials -//! each store must implement the trait `is_auth` -//! two stores are available : +//! **store** module lists interfaces available to check credentials. Each store must implement the trait `is_auth`. +//! +//! For now one store is available: //! * `FileStore`: credentials stored in a text file (like **/etc/passwd**) -//! * `DBStore`: credentials stored in a database (TODO) mod file; mod store; diff --git a/src/stores/store.rs b/src/stores/store.rs index 9cf23ef..e5fa8fb 100644 --- a/src/stores/store.rs +++ b/src/stores/store.rs @@ -13,6 +13,7 @@ pub struct Credentials { password: String, } +/// Credentials represents the incoming user credentials for authentication checking impl Credentials { pub fn new(email: String, password: String) -> Self { Credentials { email, password }