Fixed all warnings

This commit is contained in:
Jan Schermer 2025-06-16 20:05:01 -07:00
parent 623cc2bbaa
commit 69b741fe13
8 changed files with 82 additions and 38 deletions

View file

@ -23,7 +23,7 @@ impl FromRequestParts<DbPool> for AuthInfo {
) -> Result<Self, Self::Rejection> { ) -> Result<Self, Self::Rejection> {
let header = &parts.headers; let header = &parts.headers;
inspect_with_header(state, &header).await inspect_with_header(state, header).await
} }
} }

View file

@ -1,14 +1,13 @@
use crate::storage::DbPool; use crate::storage::DbPool;
use axum::extract::{Path, Query, State}; use axum::extract::State;
use axum::http::StatusCode; use axum::http::StatusCode;
use axum::response::{IntoResponse, NoContent, Response}; use axum::response::{IntoResponse, Response};
use axum::routing::post; use axum::routing::post;
use axum::{Json, Router}; use axum::{Json, Router};
use log::error; use log::error;
use rand::{Rng, distributions::Alphanumeric}; use rand::{Rng, distributions::Alphanumeric};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sqlx::Error; use sqlx::Error;
use std::ops::Index;
use uuid::Uuid; use uuid::Uuid;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -83,8 +82,8 @@ pub async fn create_root_token_if_none_exist(pool: &DbPool) -> bool {
if result.is_err() { if result.is_err() {
let error = result.err().unwrap(); let error = result.err().unwrap();
// Log the error and panic // Log the error and panic
error!("create_root_token failed: {:?}", error); error!("create_root_token failed: {error:?}");
panic!("create_root_token failed: {:?}", error); panic!("create_root_token failed: {error:?}");
} }
// If successful, print the root token. This will only happen once. // If successful, print the root token. This will only happen once.
println!("\n\nYour root token is: {}", result.unwrap()); println!("\n\nYour root token is: {}", result.unwrap());
@ -190,7 +189,7 @@ async fn post_lookup(
} }
// If the token is not found, return a 404 Not Found error // If the token is not found, return a 404 Not Found error
Err(e) => { Err(e) => {
error!("Failed to retrieve token: {:?}", e); error!("Failed to retrieve token: {e:?}");
let err = ErrorResponse { let err = ErrorResponse {
error: "Failed to retrieve token".to_string(), error: "Failed to retrieve token".to_string(),
}; };
@ -203,40 +202,79 @@ async fn post_lookup(
// The following functions are placeholders for the various token-related operations. // The following functions are placeholders for the various token-related operations.
// //
async fn get_accessors() {}
async fn post_create() {} async fn get_accessors() -> &'static str {
todo!("not implemented")
}
async fn post_create_orphan() {} async fn post_create() -> &'static str {
todo!("not implemented")
}
async fn post_create_role() {} async fn post_create_orphan() -> &'static str {
todo!("not implemented")
}
async fn get_lookup() {} async fn post_create_role() -> &'static str {
todo!("not implemented")
}
async fn get_lookup_self() {} async fn get_lookup() -> &'static str {
todo!("not implemented")
}
async fn post_lookup_self() {} async fn get_lookup_self() -> &'static str {
todo!("not implemented")
}
async fn post_renew() {} async fn post_lookup_self() -> &'static str {
todo!("not implemented")
}
async fn post_renew_accessor() {} async fn post_renew() -> &'static str {
todo!("not implemented")
}
async fn post_renew_self() {} async fn post_renew_accessor() -> &'static str {
todo!("not implemented")
}
async fn post_revoke() {} async fn post_renew_self() -> &'static str {
todo!("not implemented")
}
async fn post_revoke_accessor() {} async fn post_revoke() -> &'static str {
todo!("not implemented")
}
async fn post_revoke_orphan() {} async fn post_revoke_accessor() -> &'static str {
todo!("not implemented")
}
async fn post_revoke_self() {} async fn post_revoke_orphan() -> &'static str {
todo!("not implemented")
}
async fn get_roles() {} async fn post_revoke_self() -> &'static str {
todo!("not implemented")
}
async fn get_role_by_name() {} async fn get_roles() -> &'static str {
todo!("not implemented")
}
async fn post_role_by_name() {} async fn get_role_by_name() -> &'static str {
todo!("not implemented")
}
async fn delete_role_by_name() {} async fn post_role_by_name() -> &'static str {
todo!("not implemented")
}
async fn post_tidy() {} async fn delete_role_by_name() -> &'static str {
todo!("not implemented")
}
async fn post_tidy() -> &'static str {
todo!("not implemented")
}

View file

@ -13,12 +13,12 @@ pub struct HttpError {
} }
impl HttpError { impl HttpError {
pub fn new(status_code: StatusCode, errors: Vec<String>) -> Response<Body> { pub fn simple_with_status(status_code: StatusCode, errors: Vec<String>) -> Response<Body> {
(status_code, Json(HttpError { errors })).into_response() (status_code, Json(HttpError { errors })).into_response()
} }
pub fn simple(status_code: StatusCode, error: impl ToString) -> Response<Body> { pub fn simple(status_code: StatusCode, error: impl ToString) -> Response<Body> {
HttpError::new(status_code, vec![error.to_string(); 1]) HttpError::simple_with_status(status_code, vec![error.to_string(); 1])
} }
} }

View file

@ -42,7 +42,7 @@ async fn engine_handler(
req: Request, req: Request,
) -> Response<Body> { ) -> Response<Body> {
if let Some((mount_path, engine_type)) = map_mount_points(req.uri(), &engines.pool).await { if let Some((mount_path, engine_type)) = map_mount_points(req.uri(), &engines.pool).await {
info!("Found mount point {} of type {}", mount_path, engine_type); info!("Found mount point {mount_path} of type {engine_type}");
// Match the engine type to the appropriate router // Match the engine type to the appropriate router
match engine_type.as_str() { match engine_type.as_str() {
"kv_v2" => call_router(engines.kv_v2, mount_path, req).await, "kv_v2" => call_router(engines.kv_v2, mount_path, req).await,
@ -72,7 +72,7 @@ async fn call_router(engine: Router, mount_path: String, mut req: Request) -> Re
/// Occurs when the mount path is found in the database /// Occurs when the mount path is found in the database
/// but the registered is unknown /// but the registered is unknown
fn unknown_engine(engine_type: String) -> impl IntoResponse { fn unknown_engine(engine_type: String) -> impl IntoResponse {
error!("Engine type {} not implemented", engine_type); error!("Engine type {engine_type} not implemented");
HttpError::simple( HttpError::simple(
StatusCode::INTERNAL_SERVER_ERROR, StatusCode::INTERNAL_SERVER_ERROR,
format!("Engine type {engine_type} not implemented"), format!("Engine type {engine_type} not implemented"),

View file

@ -234,7 +234,6 @@ pub async fn patch_data(
Path(kv_path): Path<String>, Path(kv_path): Path<String>,
Extension(EnginePath(engine_path)): Extension<EnginePath>, Extension(EnginePath(engine_path)): Extension<EnginePath>,
Json(secret): Json<KvV2WriteRequest>, Json(secret): Json<KvV2WriteRequest>,
) -> Result<Response, ()> { ) -> &'static str {
// TODO: implement only application/merge-patch+json todo!("not implemented")
todo!("Not implemented")
} }

View file

@ -1,6 +1,11 @@
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
use crate::auth::auth_extractor::AuthInfo; // There are some placeholder functions, that will have to be implemented before the first release.
// They are marked with `todo!()` to indicate that they need to be implemented.
// We want to keep these functions in the codebase.
// That is why we choose to suppress unused warnings for now.
#![allow(unused)]
use crate::common::HttpError; use crate::common::HttpError;
use axum::{ use axum::{
extract::Request, extract::Request,

View file

@ -321,11 +321,11 @@ pub async fn init_default(pool: &DbPool) {
#[cfg(feature = "shamir")] #[cfg(feature = "shamir")]
{ {
shamir::init_shamir(&pool, 2, 5).await shamir::init_shamir(pool, 2, 5).await
} }
}; };
let success = prepare_unseal(&pool).await; let success = prepare_unseal(pool).await;
warn!("New sealing password generated: {user_key:?}"); warn!("New sealing password generated: {user_key:?}");
assert!( assert!(
success, success,

View file

@ -47,4 +47,6 @@ async fn unseal_post(State(pool): State<DbPool>, Json(req): Json<UnsealRequest>)
Ok(()) Ok(())
} }
async fn seal_status_get(State(pool): State<DbPool>) {} async fn seal_status_get(State(pool): State<DbPool>) -> &'static str {
todo!("not implemented")
}