fix documentation + update http lib version
This commit is contained in:
parent
734ec7901d
commit
b07d4e7e0e
@ -17,7 +17,7 @@ log = "0.4.17"
|
|||||||
base64 = "0.13.1"
|
base64 = "0.13.1"
|
||||||
serde_json = "1.0"
|
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 ?)
|
# useful for tests (embedded files should be delete in release ?)
|
||||||
#rust-embed="6.4.1"
|
#rust-embed="6.4.1"
|
||||||
|
|||||||
@ -8,7 +8,6 @@ cargo build --release
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
### Store
|
### Store
|
||||||
The store represents the credentials. For now, this a `.txt` file with plain passwords. You have to create one like:
|
The store represents the credentials. For now, this a `.txt` file with plain passwords. You have to create one like:
|
||||||
```txt
|
```txt
|
||||||
@ -72,7 +71,7 @@ cargo test
|
|||||||
* set the following env variables:
|
* set the following env variables:
|
||||||
```bash
|
```bash
|
||||||
export SIMPLE_AUTH_URL="http://<url>:<port>"
|
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 the server (if no one is running remotly)
|
||||||
* run curl tests
|
* 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/
|
cd tests/bash/
|
||||||
./curling.bash && echo "passed"
|
./curling.bash && echo "passed"
|
||||||
```
|
```
|
||||||
* run python requests tests
|
* run python tests
|
||||||
```bash
|
```bash
|
||||||
# create a python venv
|
# create a python venv
|
||||||
cd tests/python
|
cd tests/python
|
||||||
python3 -m venv venv
|
python3 -m venv venv
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
|
|
||||||
# intall the requirements
|
# install the requirements
|
||||||
pip install -r requirements
|
pip install -r requirements
|
||||||
|
|
||||||
# launch the tests
|
# launch the tests
|
||||||
@ -97,5 +96,5 @@ python -m unittest
|
|||||||
## Documentation
|
## Documentation
|
||||||
```bash
|
```bash
|
||||||
# add the '--open' arg to open the doc on a browser
|
# add the '--open' arg to open the doc on a browser
|
||||||
cargo doc --no-deps
|
cargo doc -r --no-deps
|
||||||
```
|
```
|
||||||
|
|||||||
@ -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;
|
mod config;
|
||||||
|
|
||||||
pub use config::Config;
|
pub use config::Config;
|
||||||
|
|||||||
@ -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;
|
mod jwt;
|
||||||
|
|
||||||
pub use jwt::JWTSigner;
|
pub use jwt::JWTSigner;
|
||||||
|
|||||||
@ -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) {
|
async fn handle_connection(mut stream: TcpStream, addr: String, config: Config) {
|
||||||
log::info!("client connected: {}", addr);
|
log::info!("client connected: {}", addr);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(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 {
|
pub struct JWTMessage {
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
access_token: String,
|
access_token: String,
|
||||||
|
|||||||
@ -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;
|
mod message;
|
||||||
|
|
||||||
pub use message::{JWTMessage, ValidationMessage};
|
pub use message::{JWTMessage, ValidationMessage};
|
||||||
|
|||||||
@ -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;
|
mod router;
|
||||||
pub use router::ROUTER;
|
pub use router::ROUTER;
|
||||||
|
|||||||
@ -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 http::{HTTPRequest, HTTPResponse, JSONMessage};
|
||||||
use json::JsonValue;
|
use json::JsonValue;
|
||||||
|
|
||||||
@ -127,7 +124,7 @@ async fn handle_public_key(request: HTTPRequest<'_>, config: Config, method: &st
|
|||||||
pub struct Router;
|
pub struct Router;
|
||||||
|
|
||||||
impl 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 {
|
pub async fn route(&self, request_str: &str, config: Config) -> HTTPResponse {
|
||||||
let request = HTTPRequest::from(request_str);
|
let request = HTTPRequest::from(request_str);
|
||||||
match request.get_target() {
|
match request.get_target() {
|
||||||
@ -149,7 +146,7 @@ pub fn send_token(jwt_message: &str) -> HTTPResponse {
|
|||||||
HTTPResponse::as_200(Some(json::parse(message).unwrap()))
|
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 {};
|
pub const ROUTER: Router = Router {};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@ -18,7 +18,8 @@ impl FileStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// parse_contents loads and reads the file asynchonously
|
/// 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) {
|
async fn parse_contents(&mut self) {
|
||||||
let contents = tokio::fs::read_to_string(&self.path).await;
|
let contents = tokio::fs::read_to_string(&self.path).await;
|
||||||
let mut credentials: Vec<Credentials> = vec![];
|
let mut credentials: Vec<Credentials> = vec![];
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
//! store module lists interfaces available to check request credentials
|
//! **store** module lists interfaces available to check credentials. Each store must implement the trait `is_auth`.
|
||||||
//! each store must implement the trait `is_auth`
|
//!
|
||||||
//! two stores are available :
|
//! For now one store is available:
|
||||||
//! * `FileStore`: credentials stored in a text file (like **/etc/passwd**)
|
//! * `FileStore`: credentials stored in a text file (like **/etc/passwd**)
|
||||||
//! * `DBStore`: credentials stored in a database (TODO)
|
|
||||||
|
|
||||||
mod file;
|
mod file;
|
||||||
mod store;
|
mod store;
|
||||||
|
|||||||
@ -13,6 +13,7 @@ pub struct Credentials {
|
|||||||
password: String,
|
password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Credentials represents the incoming user credentials for authentication checking
|
||||||
impl Credentials {
|
impl Credentials {
|
||||||
pub fn new(email: String, password: String) -> Self {
|
pub fn new(email: String, password: String) -> Self {
|
||||||
Credentials { email, password }
|
Credentials { email, password }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user