make namespace naming better
continuous-integration/drone/push Build is passing Details

- replace acc_create with account::create on server & client
- replace acc_auth with account::authorize on server & client
- to use the account module (non-common), just import
  crate::server/client::account;
- remove redundant use namings
This commit is contained in:
ayham 2021-08-20 10:11:06 +03:00
parent 888b2cbe80
commit ca6f0677ed
Signed by: ayham
GPG Key ID: EAB7F5A9DF503678
28 changed files with 51 additions and 50 deletions

View File

@ -2,7 +2,6 @@ use std::io;
use argon2::password_hash::PasswordHash;
use crate::common::command::*;
use crate::common::message::*;
use crate::client::account::hash::*;
@ -34,7 +33,7 @@ use tokio_rustls::client::TlsStream;
/// Err(err) => panic!("panik! {}", err), /* unauth OR invalid JWT token */
/// }
/// ```
pub async fn acc_auth(
pub async fn authorize(
socket: &mut TlsStream<TcpStream>,
username: &str,
email: &str,

View File

@ -1,6 +1,5 @@
use std::io;
use crate::common::command::*;
use crate::common::message::*;
use crate::client::account::hash::*;
@ -33,7 +32,7 @@ use tokio_rustls::client::TlsStream;
/// Err(err) => panic!("panik {}", err),
/// }
/// ```
pub async fn acc_create(
pub async fn create(
socket: &mut TlsStream<TcpStream>,
username: &str,
email: &str,

View File

@ -1,3 +1,7 @@
pub mod authorization;
pub mod creation;
pub mod hash;
pub use crate::client::account::creation::create;
pub use crate::client::account::authorization::authorize;
pub use crate::client::account::hash::hash;

View File

@ -5,13 +5,15 @@ use tokio::net::TcpStream;
use tokio_rustls::webpki::DNSNameRef;
use tokio_rustls::TlsConnector;
use crate::client::network::gen_tls_client_config::gen_tls_client_config;
use crate::client::network::tls::*;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use argh::FromArgs;
use crate::client::account;
/// Client Options
#[derive(FromArgs)]
struct Options {
@ -140,17 +142,15 @@ pub async fn libtrader_init_client() -> std::io::Result<()> {
.map(char::from)
.collect();
use crate::client::account::creation::acc_create;
match acc_create(&mut socket, &username, &email, &password).await {
match account::create(&mut socket, &username, &email, &password).await {
Ok(_) => println!("we created it"),
Err(err) => panic!("panik! {}", err),
}
use crate::client::account::authorization::acc_auth;
let mut jwt: String = String::new();
println!("{}", jwt); // this is for removing pisky warnings,
// this is fine as long as this code is sandbox
match acc_auth(&mut socket, &username, &email, &password).await {
match account::authorize(&mut socket, &username, &email, &password).await {
Ok(auth) => {
jwt = auth;
println!("we accessed it, the token: {}", jwt);

View File

@ -2,7 +2,6 @@ use std::io;
use argon2::password_hash::SaltString;
use crate::common::command::*;
use crate::common::message::*;
use tokio::net::TcpStream;

View File

@ -2,7 +2,6 @@ use std::io;
use argon2::password_hash::SaltString;
use crate::common::command::*;
use crate::common::message::*;
use tokio::net::TcpStream;

View File

@ -1,3 +1,3 @@
pub mod cmd;
pub mod gen_tls_client_config;
pub mod tls;
pub mod handle_data;

View File

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
pub use crate::common::account::position::Position;
pub use crate::common::account::position::*;
#[derive(Serialize, Deserialize, PartialEq, Debug, Default)]
pub struct Portfolio {

View File

@ -1,7 +1,7 @@
use log::warn;
use serde::{Deserialize, Serialize};
pub use crate::common::command::Command;
pub use crate::common::command::*;
use tokio::io::AsyncReadExt;
use tokio::io::AsyncWriteExt;

View File

@ -5,19 +5,18 @@ use argon2::{
Argon2,
};
use crate::common::command::*;
use crate::common::message::*;
use crate::server::db::cmd::get_user_hash::get_user_hash;
use crate::server::db::cmd::get_user_id::get_user_id;
use crate::server::db::cmd::get_user_hash::*;
use crate::server::db::cmd::get_user_id::*;
use crate::server::network::jwt_wrapper::create_jwt_token;
use crate::server::network::jwt::*;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpStream;
use tokio_rustls::server::TlsStream;
pub async fn acc_auth(
pub async fn authorize(
sql_conn: &tokio_postgres::Client,
socket: &mut TlsStream<TcpStream>,
message: &Message,

View File

@ -1,19 +1,19 @@
use argon2::password_hash::PasswordHash;
use log::warn;
use crate::common::account::portfolio::Portfolio;
use crate::common::account::portfolio::*;
use crate::common::message::*;
use crate::server::account::hash::*;
use crate::server::db::cmd::user_exists::*;
use crate::server::ds::account::Account;
use crate::server::ds::account::*;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpStream;
use tokio_rustls::server::TlsStream;
pub async fn acc_create(
pub async fn create(
sql_conn: &tokio_postgres::Client,
socket: &mut TlsStream<TcpStream>,
message: &Message,

View File

@ -1,3 +1,7 @@
pub mod authorization;
pub mod creation;
pub mod hash;
pub use crate::server::account::authorization::authorize;
pub use crate::server::account::creation::create;
pub use crate::server::account::hash::hash;

View File

@ -1,4 +1,4 @@
//use crate::common::generic::company::Company;
//use crate::common::generic::company::*;
//
///// Creates a company on the postgres SQL database.
/////

View File

@ -1,4 +1,4 @@
use crate::common::account::position::Position;
use crate::common::account::position::*;
/// Creates a position on the postgre SQL database
///

View File

@ -1,4 +1,4 @@
use crate::common::account::transaction::Transaction;
use crate::common::account::transaction::*;
/// Creates a transaction on the postgre SQL database
///

View File

@ -1,5 +1,5 @@
use crate::common::command::*;
use crate::server::db::cmd::user_exists::user_exists;
use crate::server::db::cmd::user_exists::*;
pub async fn get_client_salt(
sql_conn: &tokio_postgres::Client,

View File

@ -1,4 +1,4 @@
//use crate::common::generic::company::Company;
//use crate::common::generic::company::*;
//
///// Returns a company from the postgres SQL database.
/////

View File

@ -1,7 +1,7 @@
use argon2::password_hash::PasswordHash;
use crate::common::command::*;
use crate::server::db::cmd::user_exists::user_exists;
use crate::server::db::cmd::user_exists::*;
pub async fn get_server_salt(
sql_conn: &tokio_postgres::Client,

View File

@ -1,4 +1,4 @@
//use crate::common::generic::stock_val::StockVal;
//use crate::common::generic::stock_val::*;
//
///// Returns the whole stock data from the postgres SQL database.
/////

View File

@ -1,4 +1,4 @@
use crate::server::db::cmd::user_exists::user_exists;
use crate::server::db::cmd::user_exists::*;
pub async fn get_user_hash(
sql_conn: &tokio_postgres::Client,

View File

@ -1,4 +1,4 @@
use crate::server::db::cmd::user_exists::user_exists;
use crate::server::db::cmd::user_exists::*;
pub async fn get_user_id(sql_conn: &tokio_postgres::Client, username: &str) -> Result<i64, String> {
/* check that user exists */

View File

@ -10,10 +10,10 @@ use tokio::io::AsyncReadExt;
use tokio::net::TcpListener;
use tokio_rustls::TlsAcceptor;
use crate::server::network::gen_tls_server_config::gen_tls_server_config;
use crate::server::network::tls::*;
use crate::server::db::initializer::db_connect;
use crate::server::network::handle_data::handle_data;
use crate::server::db::initializer::*;
use crate::server::network::handle_data::*;
/// Server Options
#[derive(FromArgs)]

View File

@ -1,11 +1,9 @@
use argon2::password_hash::SaltString;
use rand_core::OsRng;
use crate::common::command::*;
use crate::common::message::*;
use crate::server::account::authorization::acc_auth;
use crate::server::account::creation::acc_create;
use crate::server::account;
use crate::server::db::cmd::get_client_salt::*;
use tokio::net::TcpStream;
@ -44,8 +42,8 @@ pub async fn handle_data(
response.command(Command::Failure).send(socket).await
}
}
Command::Register => acc_create(sql_conn, socket, &client_msg).await,
Command::LoginMethod1 => acc_auth(sql_conn, socket, &client_msg).await,
Command::Register => account::create(sql_conn, socket, &client_msg).await,
Command::LoginMethod1 => account::authorize(sql_conn, socket, &client_msg).await,
_ => {
Message::new()
.command(Command::Failure)

View File

@ -1,3 +1,3 @@
pub mod gen_tls_server_config;
pub mod tls;
pub mod handle_data;
pub mod jwt_wrapper;
pub mod jwt;

View File

@ -1,5 +1,9 @@
## To do
- add testing suite
* [ ] configure ci to run those tests
* [ ] add tests for all server functions
* [ ] add tests for all client functions
- create correct modules
* [ ] fix weird file naming
* [ ] fix namespace naming
@ -12,18 +16,9 @@
* [ ] ret data on server
* [ ] transaction data retrieval
* [ ] split data into multiple writes
- add testing suite
* [ ] configure ci to run those tests
* [ ] add tests for all server functions
* [ ] add tests for all client functions
## In progress
- create correct modules
* [x] fix weird file naming
* [ ] fix namespace naming
* [x] remove unneeded MessageType
* [ ] make server return coded
## Done
@ -163,3 +158,8 @@
* [ ] configure ci to run those tests
* [ ] add tests for all server functions
* [ ] add tests for all client functions
- create correct modules
* [x] fix weird file naming
* [x] fix namespace naming
* [x] remove unneeded MessageType
* [x] make server return coded