feat: use a logging library
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
gives us logs from actix and sqlx that otherwise arent exposed to us
This commit is contained in:
parent
80111af3de
commit
481c2c3648
11 changed files with 41 additions and 27 deletions
|
@ -13,11 +13,13 @@ actix-web = "4.10"
|
||||||
argon2 = { version = "0.5.3", features = ["std"] }
|
argon2 = { version = "0.5.3", features = ["std"] }
|
||||||
clap = { version = "4.5.37", features = ["derive"] }
|
clap = { version = "4.5.37", features = ["derive"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
getrandom = "0.3.2"
|
getrandom = "0.3"
|
||||||
hex = "0.4.3"
|
hex = "0.4"
|
||||||
|
log = "0.4"
|
||||||
regex = "1.11"
|
regex = "1.11"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
simple_logger = "5.0.0"
|
||||||
sqlx = { version = "0.8", features = ["runtime-tokio", "tls-native-tls", "postgres"] }
|
sqlx = { version = "0.8", features = ["runtime-tokio", "tls-native-tls", "postgres"] }
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
url = { version = "2.5", features = ["serde"] }
|
url = { version = "2.5", features = ["serde"] }
|
||||||
|
|
|
@ -21,6 +21,7 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- gorb-backend:/gorb
|
- gorb-backend:/gorb
|
||||||
environment:
|
environment:
|
||||||
|
#- RUST_LOG=debug
|
||||||
- DATABASE_USERNAME=gorb
|
- DATABASE_USERNAME=gorb
|
||||||
- DATABASE_PASSWORD=gorb
|
- DATABASE_PASSWORD=gorb
|
||||||
- DATABASE=gorb
|
- DATABASE=gorb
|
||||||
|
|
|
@ -15,6 +15,7 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- gorb-backend:/gorb
|
- gorb-backend:/gorb
|
||||||
environment:
|
environment:
|
||||||
|
#- RUST_LOG=debug
|
||||||
- DATABASE_USERNAME=gorb
|
- DATABASE_USERNAME=gorb
|
||||||
- DATABASE_PASSWORD=gorb
|
- DATABASE_PASSWORD=gorb
|
||||||
- DATABASE=gorb
|
- DATABASE=gorb
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use actix_web::{error, post, web, Error, HttpResponse};
|
use actix_web::{error, post, web, Error, HttpResponse};
|
||||||
use argon2::{PasswordHash, PasswordVerifier};
|
use argon2::{PasswordHash, PasswordVerifier};
|
||||||
|
use log::error;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
@ -75,14 +76,14 @@ async fn login(data: actix_web::web::Data<Data>, uuid: String, request_password:
|
||||||
let access_token = generate_access_token();
|
let access_token = generate_access_token();
|
||||||
|
|
||||||
if refresh_token.is_err() {
|
if refresh_token.is_err() {
|
||||||
eprintln!("{}", refresh_token.unwrap_err());
|
error!("{}", refresh_token.unwrap_err());
|
||||||
return HttpResponse::InternalServerError().finish()
|
return HttpResponse::InternalServerError().finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
let refresh_token = refresh_token.unwrap();
|
let refresh_token = refresh_token.unwrap();
|
||||||
|
|
||||||
if access_token.is_err() {
|
if access_token.is_err() {
|
||||||
eprintln!("{}", access_token.unwrap_err());
|
error!("{}", access_token.unwrap_err());
|
||||||
return HttpResponse::InternalServerError().finish()
|
return HttpResponse::InternalServerError().finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ async fn login(data: actix_web::web::Data<Data>, uuid: String, request_password:
|
||||||
.bind(device_name)
|
.bind(device_name)
|
||||||
.execute(&data.pool)
|
.execute(&data.pool)
|
||||||
.await {
|
.await {
|
||||||
eprintln!("{}", error);
|
error!("{}", error);
|
||||||
return HttpResponse::InternalServerError().finish()
|
return HttpResponse::InternalServerError().finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +107,7 @@ async fn login(data: actix_web::web::Data<Data>, uuid: String, request_password:
|
||||||
.bind(current_time)
|
.bind(current_time)
|
||||||
.execute(&data.pool)
|
.execute(&data.pool)
|
||||||
.await {
|
.await {
|
||||||
eprintln!("{}", error);
|
error!("{}", error);
|
||||||
return HttpResponse::InternalServerError().finish()
|
return HttpResponse::InternalServerError().finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{str::FromStr, time::{SystemTime, UNIX_EPOCH}};
|
use std::{str::FromStr, time::{SystemTime, UNIX_EPOCH}};
|
||||||
|
|
||||||
use actix_web::{web, HttpResponse, Scope};
|
use actix_web::{web, HttpResponse, Scope};
|
||||||
|
use log::error;
|
||||||
use sqlx::Postgres;
|
use sqlx::Postgres;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ pub async fn check_access_token<'a>(access_token: String, pool: &'a sqlx::Pool<P
|
||||||
Ok(Uuid::from_str(&uuid).unwrap())
|
Ok(Uuid::from_str(&uuid).unwrap())
|
||||||
},
|
},
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
eprintln!("{}", error);
|
error!("{}", error);
|
||||||
Err(HttpResponse::InternalServerError().finish())
|
Err(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use actix_web::{error, post, web, Error, HttpResponse};
|
use actix_web::{error, post, web, Error, HttpResponse};
|
||||||
|
use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
.bind(&refresh_request.refresh_token)
|
.bind(&refresh_request.refresh_token)
|
||||||
.execute(&data.pool)
|
.execute(&data.pool)
|
||||||
.await {
|
.await {
|
||||||
eprintln!("{}", error);
|
error!("{}", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
let lifetime = current_time - created;
|
let lifetime = current_time - created;
|
||||||
|
@ -51,7 +52,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
.bind(&refresh_request.refresh_token)
|
.bind(&refresh_request.refresh_token)
|
||||||
.execute(&data.pool)
|
.execute(&data.pool)
|
||||||
.await {
|
.await {
|
||||||
eprintln!("{}", error);
|
error!("{}", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(HttpResponse::Unauthorized().finish())
|
return Ok(HttpResponse::Unauthorized().finish())
|
||||||
|
@ -65,7 +66,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
let new_refresh_token = generate_refresh_token();
|
let new_refresh_token = generate_refresh_token();
|
||||||
|
|
||||||
if new_refresh_token.is_err() {
|
if new_refresh_token.is_err() {
|
||||||
eprintln!("{}", new_refresh_token.unwrap_err());
|
error!("{}", new_refresh_token.unwrap_err());
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
refresh_token = new_refresh_token;
|
refresh_token = new_refresh_token;
|
||||||
},
|
},
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
eprintln!("{}", error);
|
error!("{}", error);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +90,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
let access_token = generate_access_token();
|
let access_token = generate_access_token();
|
||||||
|
|
||||||
if access_token.is_err() {
|
if access_token.is_err() {
|
||||||
eprintln!("{}", access_token.unwrap_err());
|
error!("{}", access_token.unwrap_err());
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
.bind(current_time)
|
.bind(current_time)
|
||||||
.execute(&data.pool)
|
.execute(&data.pool)
|
||||||
.await {
|
.await {
|
||||||
eprintln!("{}", error);
|
error!("{}", error);
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use actix_web::{error, post, web, Error, HttpResponse};
|
use actix_web::{error, post, web, Error, HttpResponse};
|
||||||
|
use log::error;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
@ -117,14 +118,14 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
let access_token = generate_access_token();
|
let access_token = generate_access_token();
|
||||||
|
|
||||||
if refresh_token.is_err() {
|
if refresh_token.is_err() {
|
||||||
eprintln!("{}", refresh_token.unwrap_err());
|
error!("{}", refresh_token.unwrap_err());
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
let refresh_token = refresh_token.unwrap();
|
let refresh_token = refresh_token.unwrap();
|
||||||
|
|
||||||
if access_token.is_err() {
|
if access_token.is_err() {
|
||||||
eprintln!("{}", access_token.unwrap_err());
|
error!("{}", access_token.unwrap_err());
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +139,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
.bind(account_information.device_name)
|
.bind(account_information.device_name)
|
||||||
.execute(&data.pool)
|
.execute(&data.pool)
|
||||||
.await {
|
.await {
|
||||||
eprintln!("{}", error);
|
error!("{}", error);
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +149,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
.bind(current_time)
|
.bind(current_time)
|
||||||
.execute(&data.pool)
|
.execute(&data.pool)
|
||||||
.await {
|
.await {
|
||||||
eprintln!("{}", error);
|
error!("{}", error);
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +173,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!("{}", err_msg);
|
error!("{}", err_msg);
|
||||||
HttpResponse::InternalServerError().finish()
|
HttpResponse::InternalServerError().finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use actix_web::{error, post, web, Error, HttpResponse};
|
use actix_web::{error, post, web, Error, HttpResponse};
|
||||||
use argon2::{PasswordHash, PasswordVerifier};
|
use argon2::{PasswordHash, PasswordVerifier};
|
||||||
|
use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use futures::{future, StreamExt};
|
use futures::{future, StreamExt};
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if database_password_raw.is_err() {
|
if database_password_raw.is_err() {
|
||||||
eprintln!("{}", database_password_raw.unwrap_err());
|
error!("{}", database_password_raw.unwrap_err());
|
||||||
return Ok(HttpResponse::InternalServerError().json(Response::new(false)));
|
return Ok(HttpResponse::InternalServerError().json(Response::new(false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
let hashed_password_raw = PasswordHash::new(&database_password);
|
let hashed_password_raw = PasswordHash::new(&database_password);
|
||||||
|
|
||||||
if hashed_password_raw.is_err() {
|
if hashed_password_raw.is_err() {
|
||||||
eprintln!("{}", hashed_password_raw.unwrap_err());
|
error!("{}", hashed_password_raw.unwrap_err());
|
||||||
return Ok(HttpResponse::InternalServerError().json(Response::new(false)));
|
return Ok(HttpResponse::InternalServerError().json(Response::new(false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +80,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if tokens_raw.is_err() {
|
if tokens_raw.is_err() {
|
||||||
eprintln!("{:?}", tokens_raw);
|
error!("{:?}", tokens_raw);
|
||||||
return Ok(HttpResponse::InternalServerError().json(Response::new(false)))
|
return Ok(HttpResponse::InternalServerError().json(Response::new(false)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,14 +107,14 @@ pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<Htt
|
||||||
let refresh_tokens_errors: Vec<&Result<sqlx::postgres::PgQueryResult, sqlx::Error>> = results_refresh_tokens.iter().filter(|r| r.is_err()).collect();
|
let refresh_tokens_errors: Vec<&Result<sqlx::postgres::PgQueryResult, sqlx::Error>> = results_refresh_tokens.iter().filter(|r| r.is_err()).collect();
|
||||||
|
|
||||||
if !access_tokens_errors.is_empty() && !refresh_tokens_errors.is_empty() {
|
if !access_tokens_errors.is_empty() && !refresh_tokens_errors.is_empty() {
|
||||||
println!("{:?}", access_tokens_errors);
|
error!("{:?}", access_tokens_errors);
|
||||||
println!("{:?}", refresh_tokens_errors);
|
error!("{:?}", refresh_tokens_errors);
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
} else if !access_tokens_errors.is_empty() {
|
} else if !access_tokens_errors.is_empty() {
|
||||||
println!("{:?}", access_tokens_errors);
|
error!("{:?}", access_tokens_errors);
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
} else if !refresh_tokens_errors.is_empty() {
|
} else if !refresh_tokens_errors.is_empty() {
|
||||||
println!("{:?}", refresh_tokens_errors);
|
error!("{:?}", refresh_tokens_errors);
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use actix_web::{error, post, web, Error, HttpResponse};
|
use actix_web::{error, post, web, Error, HttpResponse};
|
||||||
|
use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -59,7 +60,7 @@ pub async fn res(mut payload: web::Payload, path: web::Path<(String,)>, data: we
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if row.is_err() {
|
if row.is_err() {
|
||||||
eprintln!("{}", row.unwrap_err());
|
error!("{}", row.unwrap_err());
|
||||||
return Ok(HttpResponse::InternalServerError().finish())
|
return Ok(HttpResponse::InternalServerError().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
use log::debug;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::postgres::PgConnectOptions;
|
use sqlx::postgres::PgConnectOptions;
|
||||||
use tokio::fs::read_to_string;
|
use tokio::fs::read_to_string;
|
||||||
|
@ -22,11 +23,12 @@ pub struct Database {
|
||||||
struct WebBuilder {
|
struct WebBuilder {
|
||||||
url: Option<String>,
|
url: Option<String>,
|
||||||
port: Option<u16>,
|
port: Option<u16>,
|
||||||
ssl: Option<bool>,
|
_ssl: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConfigBuilder {
|
impl ConfigBuilder {
|
||||||
pub async fn load(path: String) -> Result<Self, Error> {
|
pub async fn load(path: String) -> Result<Self, Error> {
|
||||||
|
debug!("loading config from: {}", path);
|
||||||
let raw = read_to_string(path).await?;
|
let raw = read_to_string(path).await?;
|
||||||
|
|
||||||
let config = toml::from_str(&raw)?;
|
let config = toml::from_str(&raw)?;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use actix_web::{App, HttpServer, web};
|
use actix_web::{App, HttpServer, web};
|
||||||
use argon2::Argon2;
|
use argon2::Argon2;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use simple_logger::SimpleLogger;
|
||||||
use sqlx::{PgPool, Pool, Postgres};
|
use sqlx::{PgPool, Pool, Postgres};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
mod config;
|
mod config;
|
||||||
|
@ -28,6 +29,7 @@ struct Data {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Error> {
|
async fn main() -> Result<(), Error> {
|
||||||
|
SimpleLogger::new().with_level(log::LevelFilter::Info).with_colors(true).env().init().unwrap();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let config = ConfigBuilder::load(args.config).await?.build();
|
let config = ConfigBuilder::load(args.config).await?.build();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue