refactor: move path types into module
This commit is contained in:
parent
ca40009f1a
commit
e1da57a407
32
src/api.rs
32
src/api.rs
@ -8,15 +8,13 @@ use std::time::{Duration, SystemTime};
|
|||||||
|
|
||||||
use crate::certs::{load_cert_by_id, read_certs, read_pubkey, store_cert};
|
use crate::certs::{load_cert_by_id, read_certs, read_pubkey, store_cert};
|
||||||
use crate::env_key;
|
use crate::env_key;
|
||||||
|
use crate::routes::*;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use axum::body;
|
use axum::body;
|
||||||
use axum::extract::{Query, State};
|
use axum::extract::{Query, State};
|
||||||
|
|
||||||
use axum::{http::StatusCode, response::IntoResponse, Json, Router};
|
use axum::{http::StatusCode, response::IntoResponse, Json, Router};
|
||||||
use axum_extra::routing::{
|
use axum_extra::routing::RouterExt;
|
||||||
RouterExt, // for `Router::typed_*`
|
|
||||||
TypedPath,
|
|
||||||
};
|
|
||||||
use clap::{Args, Parser};
|
use clap::{Args, Parser};
|
||||||
use jwt_compact::alg::{Hs256, Hs256Key};
|
use jwt_compact::alg::{Hs256, Hs256Key};
|
||||||
use jwt_compact::{AlgorithmExt, Token, UntrustedToken};
|
use jwt_compact::{AlgorithmExt, Token, UntrustedToken};
|
||||||
@ -202,10 +200,6 @@ async fn fallback_404() -> ApiResult<()> {
|
|||||||
Err(ApiError::CertificateNotFound)
|
Err(ApiError::CertificateNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(TypedPath, Deserialize)]
|
|
||||||
#[typed_path("/certs")]
|
|
||||||
pub struct CertList;
|
|
||||||
|
|
||||||
async fn list_certs(
|
async fn list_certs(
|
||||||
_: CertList,
|
_: CertList,
|
||||||
State(ApiState { certs, .. }): State<ApiState>,
|
State(ApiState { certs, .. }): State<ApiState>,
|
||||||
@ -227,12 +221,6 @@ struct AuthClaims {
|
|||||||
identifier: String,
|
identifier: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(TypedPath, Deserialize)]
|
|
||||||
#[typed_path("/certs/:identifier")]
|
|
||||||
pub struct GetCert {
|
|
||||||
pub identifier: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieve an certificate for identifier
|
/// Retrieve an certificate for identifier
|
||||||
/// TODO: add option to require auth
|
/// TODO: add option to require auth
|
||||||
/// return Unauthorized with an challenge
|
/// return Unauthorized with an challenge
|
||||||
@ -264,12 +252,6 @@ async fn get_certs_identifier(
|
|||||||
Ok(cert.to_openssh().context("to openssh")?)
|
Ok(cert.to_openssh().context("to openssh")?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(TypedPath, Deserialize)]
|
|
||||||
#[typed_path("/certs/:identifier/info")]
|
|
||||||
pub struct GetCertInfo {
|
|
||||||
pub identifier: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "info")]
|
#[cfg(feature = "info")]
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct CertInfo {
|
struct CertInfo {
|
||||||
@ -312,12 +294,6 @@ async fn get_cert_info(
|
|||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(TypedPath, Deserialize)]
|
|
||||||
#[typed_path("/certs/:identifier")]
|
|
||||||
pub struct PostCertInfo {
|
|
||||||
pub identifier: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct PostCertsQuery {
|
struct PostCertsQuery {
|
||||||
challenge: String,
|
challenge: String,
|
||||||
@ -353,10 +329,6 @@ async fn post_certs_identifier(
|
|||||||
Ok(cert.to_openssh().context("to openssh")?)
|
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
|
/// Upload an cert with an higher serial than the previous
|
||||||
async fn put_cert_update(
|
async fn put_cert_update(
|
||||||
_: PutCert,
|
_: PutCert,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
use super::ApiError;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use axum::{
|
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 ssh_key::{Certificate, SshSig};
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
use super::ApiError;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CertificateBody(pub Certificate);
|
pub struct CertificateBody(pub Certificate);
|
||||||
|
@ -3,7 +3,7 @@ use axum_extra::routing::TypedPath;
|
|||||||
use clap::{Args, Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand};
|
||||||
use reqwest::{Client, StatusCode};
|
use reqwest::{Client, StatusCode};
|
||||||
use ssh_key::Certificate;
|
use ssh_key::Certificate;
|
||||||
use std::io::{stdin, stdout};
|
use std::io::{stdin};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
@ -11,10 +11,10 @@ use tracing::{debug, error, info, instrument, trace};
|
|||||||
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::api::PutCert;
|
|
||||||
use crate::certs::load_cert;
|
use crate::certs::load_cert;
|
||||||
|
use crate::certs::read_dir;
|
||||||
use crate::env_key;
|
use crate::env_key;
|
||||||
use crate::{api::GetCert, certs::read_dir};
|
use crate::routes::*;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct ClientArgs {
|
pub struct ClientArgs {
|
||||||
|
@ -7,6 +7,7 @@ mod api;
|
|||||||
mod certs;
|
mod certs;
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
mod client;
|
mod client;
|
||||||
|
mod routes;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! env_key {
|
macro_rules! env_key {
|
||||||
|
28
src/routes.rs
Normal file
28
src/routes.rs
Normal 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;
|
Loading…
x
Reference in New Issue
Block a user