fix documentation + update http lib version

This commit is contained in:
rmanach 2023-02-16 15:43:11 +01:00
parent 734ec7901d
commit b07d4e7e0e
12 changed files with 22 additions and 22 deletions

View File

@ -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"

View File

@ -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://<url>:<port>"
export SIMPLE_AUTH_PUB_KEY="<path_to_pem_pub_key>" # DO NOT USE THE ONE IN PRODUCTION !
export SIMPLE_AUTH_PUB_KEY="<path_to_pem_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="<path_to_pem_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
```

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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,

View File

@ -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};

View File

@ -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;

View File

@ -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]

View File

@ -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<Credentials> = vec![];

View File

@ -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;

View File

@ -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 }