refactor: move path types into module

This commit is contained in:
shimun 2022-12-24 16:25:56 +01:00
parent ca40009f1a
commit e1da57a407
Signed by: shimun
GPG Key ID: E0420647856EA39E
5 changed files with 36 additions and 35 deletions

View File

@ -8,15 +8,13 @@ use std::time::{Duration, SystemTime};
use crate::certs::{load_cert_by_id, read_certs, read_pubkey, store_cert};
use crate::env_key;
use crate::routes::*;
use anyhow::Context;
use axum::body;
use axum::extract::{Query, State};
use axum::{http::StatusCode, response::IntoResponse, Json, Router};
use axum_extra::routing::{
RouterExt, // for `Router::typed_*`
TypedPath,
};
use axum_extra::routing::RouterExt;
use clap::{Args, Parser};
use jwt_compact::alg::{Hs256, Hs256Key};
use jwt_compact::{AlgorithmExt, Token, UntrustedToken};
@ -202,10 +200,6 @@ async fn fallback_404() -> ApiResult<()> {
Err(ApiError::CertificateNotFound)
}
#[derive(TypedPath, Deserialize)]
#[typed_path("/certs")]
pub struct CertList;
async fn list_certs(
_: CertList,
State(ApiState { certs, .. }): State<ApiState>,
@ -227,12 +221,6 @@ struct AuthClaims {
identifier: String,
}
#[derive(TypedPath, Deserialize)]
#[typed_path("/certs/:identifier")]
pub struct GetCert {
pub identifier: String,
}
/// Retrieve an certificate for identifier
/// TODO: add option to require auth
/// return Unauthorized with an challenge
@ -264,12 +252,6 @@ async fn get_certs_identifier(
Ok(cert.to_openssh().context("to openssh")?)
}
#[derive(TypedPath, Deserialize)]
#[typed_path("/certs/:identifier/info")]
pub struct GetCertInfo {
pub identifier: String,
}
#[cfg(feature = "info")]
#[derive(Debug, Serialize)]
struct CertInfo {
@ -312,12 +294,6 @@ async fn get_cert_info(
unimplemented!()
}
#[derive(TypedPath, Deserialize)]
#[typed_path("/certs/:identifier")]
pub struct PostCertInfo {
pub identifier: String,
}
#[derive(Debug, Deserialize)]
struct PostCertsQuery {
challenge: String,
@ -353,10 +329,6 @@ async fn post_certs_identifier(
Ok(cert.to_openssh().context("to openssh")?)
}
#[derive(TypedPath)]
#[typed_path("/cert")]
pub struct PutCert;
/// Upload an cert with an higher serial than the previous
async fn put_cert_update(
_: PutCert,

View File

@ -1,10 +1,10 @@
use super::ApiError;
use anyhow::Context;
use axum::{
async_trait, body::BoxBody, extract::FromRequest, http::Request, response::IntoResponse,
async_trait, body::BoxBody, extract::FromRequest, http::Request,
};
use ssh_key::{Certificate, SshSig};
use tracing::trace;
use super::ApiError;
#[derive(Debug, Clone)]
pub struct CertificateBody(pub Certificate);

View File

@ -3,7 +3,7 @@ use axum_extra::routing::TypedPath;
use clap::{Args, Parser, Subcommand};
use reqwest::{Client, StatusCode};
use ssh_key::Certificate;
use std::io::{stdin, stdout};
use std::io::{stdin};
use std::path::PathBuf;
use std::time::{Duration, SystemTime};
use tokio::fs;
@ -11,10 +11,10 @@ use tracing::{debug, error, info, instrument, trace};
use url::Url;
use crate::api::PutCert;
use crate::certs::load_cert;
use crate::certs::read_dir;
use crate::env_key;
use crate::{api::GetCert, certs::read_dir};
use crate::routes::*;
#[derive(Parser)]
pub struct ClientArgs {

View File

@ -7,6 +7,7 @@ mod api;
mod certs;
#[cfg(feature = "client")]
mod client;
mod routes;
#[macro_export]
macro_rules! env_key {

28
src/routes.rs Normal file
View File

@ -0,0 +1,28 @@
use axum_extra::routing::TypedPath;
use serde::Deserialize;
#[derive(TypedPath, Deserialize)]
#[typed_path("/certs")]
pub struct CertList;
#[derive(TypedPath, Deserialize)]
#[typed_path("/certs/:identifier")]
pub struct GetCert {
pub identifier: String,
}
#[derive(TypedPath, Deserialize)]
#[typed_path("/certs/:identifier/info")]
pub struct GetCertInfo {
pub identifier: String,
}
#[derive(TypedPath, Deserialize)]
#[typed_path("/certs/:identifier")]
pub struct PostCertInfo {
pub identifier: String,
}
#[derive(TypedPath)]
#[typed_path("/cert")]
pub struct PutCert;