feat: add tracing log identifier to each HTTP route handler
This commit is contained in:
parent
0b2db58483
commit
3a961bc524
11 changed files with 38 additions and 4 deletions
|
@ -58,6 +58,7 @@ pub struct Username {
|
|||
path = "crate::V1_API_ROUTES.account.update_username",
|
||||
wrap = "super::get_auth_middleware()"
|
||||
)]
|
||||
#[tracing::instrument(name = "Update username", skip(ctx, payload, id))]
|
||||
async fn set_username(
|
||||
id: Identity,
|
||||
payload: web::Json<Username>,
|
||||
|
@ -74,6 +75,7 @@ async fn set_username(
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::post(path = "crate::V1_API_ROUTES.account.username_exists")]
|
||||
#[tracing::instrument(name = "Check if username exists", skip(ctx, payload))]
|
||||
async fn username_exists(
|
||||
payload: web::Json<AccountCheckPayload>,
|
||||
ctx: AppCtx,
|
||||
|
@ -82,6 +84,7 @@ async fn username_exists(
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::post(path = "crate::V1_API_ROUTES.account.email_exists")]
|
||||
#[tracing::instrument(name = "Check if email exists", skip(ctx, payload))]
|
||||
pub async fn email_exists(
|
||||
payload: web::Json<AccountCheckPayload>,
|
||||
ctx: AppCtx,
|
||||
|
@ -94,6 +97,7 @@ pub async fn email_exists(
|
|||
path = "crate::V1_API_ROUTES.account.update_email",
|
||||
wrap = "super::get_auth_middleware()"
|
||||
)]
|
||||
#[tracing::instrument(name = "Update email", skip(ctx, payload, id))]
|
||||
async fn set_email(
|
||||
id: Identity,
|
||||
payload: web::Json<Email>,
|
||||
|
@ -108,6 +112,7 @@ async fn set_email(
|
|||
path = "crate::V1_API_ROUTES.account.delete",
|
||||
wrap = "super::get_auth_middleware()"
|
||||
)]
|
||||
#[tracing::instrument(name = "Delete account", skip(ctx, payload, id))]
|
||||
async fn delete_account(
|
||||
id: Identity,
|
||||
payload: web::Json<Password>,
|
||||
|
@ -124,6 +129,7 @@ async fn delete_account(
|
|||
path = "crate::V1_API_ROUTES.account.update_password",
|
||||
wrap = "super::get_auth_middleware()"
|
||||
)]
|
||||
#[tracing::instrument(name = "Update user password", skip(ctx, payload, id))]
|
||||
async fn update_user_password(
|
||||
id: Identity,
|
||||
ctx: AppCtx,
|
||||
|
|
|
@ -30,12 +30,14 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||
cfg.service(signout);
|
||||
}
|
||||
#[actix_web_codegen_const_routes::post(path = "crate::V1_API_ROUTES.auth.register")]
|
||||
#[tracing::instrument(name = "Register new user", skip(ctx, payload))]
|
||||
async fn register(payload: web::Json<Register>, ctx: AppCtx) -> ServiceResult<impl Responder> {
|
||||
ctx.register(&payload).await?;
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::post(path = "crate::V1_API_ROUTES.auth.login")]
|
||||
#[tracing::instrument(name = "Login", skip(ctx, payload, id, query))]
|
||||
async fn login(
|
||||
id: Identity,
|
||||
payload: web::Json<Login>,
|
||||
|
@ -59,6 +61,7 @@ async fn login(
|
|||
path = "crate::V1_API_ROUTES.auth.logout",
|
||||
wrap = "super::get_auth_middleware()"
|
||||
)]
|
||||
#[tracing::instrument(name = "Sign out", skip(id))]
|
||||
async fn signout(id: Identity) -> impl Responder {
|
||||
use actix_auth_middleware::GetLoginRoute;
|
||||
|
||||
|
|
17
src/api/v1/pages.rs
Normal file
17
src/api/v1/pages.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
|
@ -45,6 +45,7 @@ pub struct DeployEvent {
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::post(path = "crate::V1_API_ROUTES.deploy.update")]
|
||||
#[tracing::instrument(name = "Update webpages", skip(payload, ctx))]
|
||||
async fn update(payload: web::Json<DeployEvent>, ctx: AppCtx) -> ServiceResult<impl Responder> {
|
||||
let payload = payload.into_inner();
|
||||
ctx.update_site(&payload.secret, Some(payload.branch))
|
||||
|
@ -81,12 +82,12 @@ impl DeployInfo {
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::post(path = "crate::V1_API_ROUTES.deploy.info")]
|
||||
#[tracing::instrument(name = "Get webpage deploy info", skip(payload, ctx))]
|
||||
async fn deploy_info(
|
||||
payload: web::Json<DeploySecret>,
|
||||
ctx: AppCtx,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
if let Ok(page) = ctx.db.get_site_from_secret(&payload.secret).await {
|
||||
// if let Some(page) = find_page(&payload.secret, &ctx) {
|
||||
let resp = DeployInfo::from_page(&Page::from_site(&ctx.settings, page))?;
|
||||
Ok(HttpResponse::Ok().json(resp))
|
||||
} else {
|
||||
|
|
|
@ -44,6 +44,7 @@ pub mod routes {
|
|||
|
||||
/// emits build details of the binary
|
||||
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.meta.build_details")]
|
||||
#[tracing::instrument(name = "Fetch Build Details", skip(ctx))]
|
||||
async fn build_details(ctx: AppCtx) -> impl Responder {
|
||||
let build = BuildDetails {
|
||||
version: VERSION,
|
||||
|
@ -61,6 +62,7 @@ pub struct Health {
|
|||
|
||||
/// checks all components of the system
|
||||
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.meta.health")]
|
||||
#[tracing::instrument(name = "Fetch health", skip(ctx))]
|
||||
async fn health(ctx: crate::AppCtx) -> impl Responder {
|
||||
let res = Health {
|
||||
db: ctx.db.ping().await,
|
||||
|
|
|
@ -61,6 +61,7 @@ impl Login {
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::get(path = "PAGES.auth.login")]
|
||||
#[tracing::instrument(name = "Serve login page", skip(ctx))]
|
||||
pub async fn get_login(ctx: AppCtx) -> impl Responder {
|
||||
let login = Login::page(&ctx.settings);
|
||||
let html = ContentType::html();
|
||||
|
@ -73,6 +74,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::post(path = "PAGES.auth.login")]
|
||||
#[tracing::instrument(name = "Web UI Login", skip(id, payload, query, ctx))]
|
||||
pub async fn login_submit(
|
||||
id: Identity,
|
||||
payload: web::Form<LoginPayload>,
|
||||
|
|
|
@ -42,13 +42,13 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||
path = "PAGES.auth.logout",
|
||||
wrap = "super::get_auth_middleware()"
|
||||
)]
|
||||
#[tracing::instrument(name = "Sign out", skip(id))]
|
||||
async fn signout(id: Identity) -> impl Responder {
|
||||
use actix_auth_middleware::GetLoginRoute;
|
||||
|
||||
if id.identity().is_some() {
|
||||
id.forget();
|
||||
}
|
||||
println!("received signout");
|
||||
HttpResponse::Found()
|
||||
.append_header((http::header::LOCATION, PAGES.get_login_route(None)))
|
||||
.finish()
|
||||
|
|
|
@ -58,6 +58,7 @@ impl Register {
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::get(path = "PAGES.auth.register")]
|
||||
#[tracing::instrument(name = "Serve registration page", skip(ctx))]
|
||||
pub async fn get_register(ctx: AppCtx) -> impl Responder {
|
||||
let login = Register::page(&ctx.settings);
|
||||
let html = ContentType::html();
|
||||
|
@ -70,6 +71,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::post(path = "PAGES.auth.register")]
|
||||
#[tracing::instrument(name = "Process web UI registration", skip(ctx))]
|
||||
pub async fn register_submit(
|
||||
payload: web::Form<RegisterPayload>,
|
||||
ctx: AppCtx,
|
||||
|
|
|
@ -16,11 +16,9 @@
|
|||
*/
|
||||
use std::cell::RefCell;
|
||||
|
||||
use actix_identity::Identity;
|
||||
use actix_web::http::header::ContentType;
|
||||
use tera::Context;
|
||||
|
||||
use crate::api::v1::RedirectQuery;
|
||||
use crate::ctx::api::v1::auth::Login as LoginPayload;
|
||||
use crate::pages::errors::*;
|
||||
use crate::settings::Settings;
|
||||
|
@ -63,6 +61,7 @@ impl Home {
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::get(path = "PAGES.dash.home")]
|
||||
#[tracing::instrument(name = "Dashboard homepage", skip(ctx))]
|
||||
pub async fn get_home(ctx: AppCtx) -> impl Responder {
|
||||
let home = Home::page(&ctx.settings);
|
||||
let html = ContentType::html();
|
||||
|
|
|
@ -165,6 +165,7 @@ impl Home {
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::get(path = "PAGES.home")]
|
||||
#[tracing::instrument(name = "Dashboard homepage", skip(id, ctx))]
|
||||
pub async fn home(ctx: AppCtx, id: Identity) -> impl Responder {
|
||||
if id.identity().is_none() {
|
||||
let home = Home::page(&ctx.settings);
|
||||
|
|
|
@ -34,6 +34,7 @@ pub mod routes {
|
|||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.serve.catch_all")]
|
||||
#[tracing::instrument(name = "Serve webpages", skip(req, ctx))]
|
||||
async fn index(req: HttpRequest, ctx: AppCtx) -> ServiceResult<impl Responder> {
|
||||
let c = req.connection_info();
|
||||
let mut host = c.host();
|
||||
|
|
Loading…
Add table
Reference in a new issue