refactor: split
This commit is contained in:
parent
e1da57a407
commit
1b8b304ebc
50
Cargo.lock
generated
50
Cargo.lock
generated
@ -1607,7 +1607,46 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ssh-cert-dist"
|
||||
name = "ssh-cert-dist-client"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"axum-extra",
|
||||
"chrono",
|
||||
"clap",
|
||||
"rand 0.8.5",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"ssh-cert-dist-common",
|
||||
"ssh-key",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ssh-cert-dist-common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"axum",
|
||||
"axum-extra",
|
||||
"serde",
|
||||
"ssh-key",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ssh-cert-dist-server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
@ -1618,8 +1657,8 @@ dependencies = [
|
||||
"clap",
|
||||
"jwt-compact",
|
||||
"rand 0.8.5",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"ssh-cert-dist-common",
|
||||
"ssh-key",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
@ -1628,13 +1667,13 @@ dependencies = [
|
||||
"tower-http",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ssh-encoding"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/a-dma/SSH.git?branch=u2f_signatures#ce0c34c935acd2caf7174d33039ec1c4557119de"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19cfdc32e0199062113edf41f344fbf784b8205a94600233c84eb838f45191e1"
|
||||
dependencies = [
|
||||
"base64ct",
|
||||
"pem-rfc7468",
|
||||
@ -1644,7 +1683,8 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ssh-key"
|
||||
version = "0.5.1"
|
||||
source = "git+https://github.com/a-dma/SSH.git?branch=u2f_signatures#ce0c34c935acd2caf7174d33039ec1c4557119de"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "288d8f5562af5a3be4bda308dd374b2c807b940ac370b5efa1c99311da91d9a1"
|
||||
dependencies = [
|
||||
"ed25519-dalek",
|
||||
"num-bigint-dig",
|
||||
|
47
Cargo.toml
47
Cargo.toml
@ -1,43 +1,8 @@
|
||||
[package]
|
||||
name = "ssh-cert-dist"
|
||||
version = "0.1.0"
|
||||
authors = ["shimun <shimun@shimun.net>"]
|
||||
edition = "2021"
|
||||
[workspace]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = [ "client", "reload", "info", "authorized" ]
|
||||
reload = []
|
||||
authorized =[ "dep:jwt-compact" ]
|
||||
index = []
|
||||
info = [ "axum/json", "ssh-key/serde" ]
|
||||
client = [ "dep:url", "dep:reqwest" ]
|
||||
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.66"
|
||||
async-trait = "0.1.59"
|
||||
axum = { version = "0.6.1", features = ["http2"] }
|
||||
axum-extra = { version = "0.4.1", features = ["typed-routing"] }
|
||||
chrono = "0.4.23"
|
||||
clap = { version = "4.0.29", features = ["env", "derive"] }
|
||||
jwt-compact = { version = "0.6.0", features = ["serde_cbor", "std", "clock"], optional = true }
|
||||
rand = "0.8.5"
|
||||
reqwest = { version = "0.11.13", optional = true }
|
||||
serde = { version = "1.0.148", features = ["derive"] }
|
||||
ssh-key = { version = "0.5.1", features = ["ed25519", "p256", "p384", "rsa", "signature"] }
|
||||
thiserror = "1.0.37"
|
||||
tokio = { version = "1.22.0", features = ["io-std", "test-util", "tracing", "macros", "fs"] }
|
||||
tower = { version = "0.4.13", features = ["util"] }
|
||||
tower-http = { version = "0.3.4", features = ["map-request-body", "trace"] }
|
||||
tracing = { version = "0.1.37", features = ["release_max_level_debug"] }
|
||||
tracing-subscriber = "0.3.16"
|
||||
url = { version = "2.3.1", optional = true }
|
||||
|
||||
[patch.crates-io]
|
||||
ssh-key = { git = "https://github.com/a-dma/SSH.git", branch = "u2f_signatures" }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.3.0"
|
||||
members = [
|
||||
"common",
|
||||
"server",
|
||||
"client",
|
||||
]
|
||||
|
||||
|
31
client/Cargo.toml
Normal file
31
client/Cargo.toml
Normal file
@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "ssh-cert-dist-client"
|
||||
version = "0.1.0"
|
||||
authors = ["shimun <shimun@shimun.net>"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.66"
|
||||
async-trait = "0.1.59"
|
||||
axum-extra = { version = "0.4.1", features = ["typed-routing"] }
|
||||
chrono = "0.4.23"
|
||||
clap = { version = "4.0.29", features = ["env", "derive"] }
|
||||
rand = "0.8.5"
|
||||
reqwest = { version = "0.11.13", optional = true }
|
||||
serde = { version = "1.0.148", features = ["derive"] }
|
||||
ssh-key = { version = "0.5.1", features = ["ed25519", "p256", "p384", "rsa", "signature"] }
|
||||
thiserror = "1.0.37"
|
||||
tokio = { version = "1.22.0", features = ["io-std", "test-util", "tracing", "macros", "fs"] }
|
||||
tracing = { version = "0.1.37", features = ["release_max_level_debug"] }
|
||||
tracing-subscriber = "0.3.16"
|
||||
url = { version = "2.3.1" }
|
||||
ssh-cert-dist-common = { path = "../common" }
|
||||
|
||||
[patch.crates-io]
|
||||
ssh-key = { git = "https://github.com/a-dma/SSH.git", branch = "u2f_signatures" }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.3.0"
|
||||
|
@ -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};
|
||||
use std::io::stdin;
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, SystemTime};
|
||||
use tokio::fs;
|
||||
@ -11,10 +11,7 @@ use tracing::{debug, error, info, instrument, trace};
|
||||
|
||||
use url::Url;
|
||||
|
||||
use crate::certs::load_cert;
|
||||
use crate::certs::read_dir;
|
||||
use crate::env_key;
|
||||
use crate::routes::*;
|
||||
use ssh_cert_dist_common::*;
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct ClientArgs {
|
||||
@ -46,7 +43,7 @@ pub struct UploadArgs {
|
||||
files: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
#[derive(Parser)]
|
||||
pub struct ClientCommand {
|
||||
#[clap(subcommand)]
|
||||
cmd: ClientCommands,
|
10
client/src/main.rs
Normal file
10
client/src/main.rs
Normal file
@ -0,0 +1,10 @@
|
||||
use clap::Parser;
|
||||
|
||||
mod client;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
client::run(client::ClientCommand::parse()).await
|
||||
}
|
26
common/Cargo.toml
Normal file
26
common/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "ssh-cert-dist-common"
|
||||
version = "0.1.0"
|
||||
authors = ["shimun <shimun@shimun.net>"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.66"
|
||||
async-trait = "0.1.59"
|
||||
axum = { version = "0.6.1" }
|
||||
axum-extra = { version = "0.4.1", features = ["typed-routing"] }
|
||||
serde = { version = "1.0.148", features = ["derive"] }
|
||||
ssh-key = { version = "0.5.1", features = ["ed25519", "p256", "p384", "rsa", "signature"] }
|
||||
thiserror = "1.0.37"
|
||||
tokio = { version = "1.22.0", features = ["io-std", "test-util", "tracing", "macros", "fs"] }
|
||||
tracing = { version = "0.1.37", features = ["release_max_level_debug"] }
|
||||
tracing-subscriber = "0.3.16"
|
||||
|
||||
[patch.crates-io]
|
||||
ssh-key = { git = "https://github.com/a-dma/SSH.git", branch = "u2f_signatures" }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.3.0"
|
||||
|
6
common/src/lib.rs
Normal file
6
common/src/lib.rs
Normal file
@ -0,0 +1,6 @@
|
||||
mod certs;
|
||||
mod routes;
|
||||
mod util;
|
||||
|
||||
pub use certs::*;
|
||||
pub use routes::*;
|
@ -1,3 +1,4 @@
|
||||
use async_trait::async_trait;
|
||||
use axum_extra::routing::TypedPath;
|
||||
use serde::Deserialize;
|
||||
|
6
common/src/util.rs
Normal file
6
common/src/util.rs
Normal file
@ -0,0 +1,6 @@
|
||||
#[macro_export]
|
||||
macro_rules! env_key {
|
||||
( $var:expr ) => {
|
||||
concat!("SSH_CD_", $var)
|
||||
};
|
||||
}
|
41
server/Cargo.toml
Normal file
41
server/Cargo.toml
Normal file
@ -0,0 +1,41 @@
|
||||
[package]
|
||||
name = "ssh-cert-dist-server"
|
||||
version = "0.1.0"
|
||||
authors = ["shimun <shimun@shimun.net>"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = [ "reload", "info", "authorized" ]
|
||||
reload = []
|
||||
authorized =[ "dep:jwt-compact" ]
|
||||
index = []
|
||||
info = [ "axum/json", "ssh-key/serde" ]
|
||||
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.66"
|
||||
async-trait = "0.1.59"
|
||||
axum = { version = "0.6.1", features = ["http2"] }
|
||||
axum-extra = { version = "0.4.1", features = ["typed-routing"] }
|
||||
chrono = "0.4.23"
|
||||
clap = { version = "4.0.29", features = ["env", "derive"] }
|
||||
jwt-compact = { version = "0.6.0", features = ["serde_cbor", "std", "clock"], optional = true }
|
||||
rand = "0.8.5"
|
||||
serde = { version = "1.0.148", features = ["derive"] }
|
||||
ssh-key = { version = "0.5.1", features = ["ed25519", "p256", "p384", "rsa", "signature"] }
|
||||
thiserror = "1.0.37"
|
||||
tokio = { version = "1.22.0", features = ["io-std", "test-util", "tracing", "macros", "fs"] }
|
||||
tower = { version = "0.4.13", features = ["util"] }
|
||||
tower-http = { version = "0.3.4", features = ["map-request-body", "trace"] }
|
||||
tracing = { version = "0.1.37", features = ["release_max_level_debug"] }
|
||||
tracing-subscriber = "0.3.16"
|
||||
ssh-cert-dist-common = { path = "../common" }
|
||||
|
||||
[patch.crates-io]
|
||||
ssh-key = { git = "https://github.com/a-dma/SSH.git", branch = "u2f_signatures" }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.3.0"
|
||||
|
@ -6,12 +6,10 @@ use std::path::{self, PathBuf};
|
||||
use std::sync::Arc;
|
||||
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 ssh_cert_dist_common::*;
|
||||
|
||||
use axum::{http::StatusCode, response::IntoResponse, Json, Router};
|
||||
use axum_extra::routing::RouterExt;
|
@ -1,8 +1,6 @@
|
||||
use super::ApiError;
|
||||
use anyhow::Context;
|
||||
use axum::{
|
||||
async_trait, body::BoxBody, extract::FromRequest, http::Request,
|
||||
};
|
||||
use axum::{async_trait, body::BoxBody, extract::FromRequest, http::Request};
|
||||
use ssh_key::{Certificate, SshSig};
|
||||
use tracing::trace;
|
||||
|
10
server/src/main.rs
Normal file
10
server/src/main.rs
Normal file
@ -0,0 +1,10 @@
|
||||
use clap::Parser;
|
||||
|
||||
mod api;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
api::run(api::ApiArgs::parse()).await
|
||||
}
|
36
src/main.rs
36
src/main.rs
@ -1,36 +0,0 @@
|
||||
use api::ApiArgs;
|
||||
use clap::Parser;
|
||||
#[cfg(feature = "client")]
|
||||
use client::ClientCommand;
|
||||
|
||||
mod api;
|
||||
mod certs;
|
||||
#[cfg(feature = "client")]
|
||||
mod client;
|
||||
mod routes;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! env_key {
|
||||
( $var:expr ) => {
|
||||
concat!("SSH_CD_", $var)
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
enum Command {
|
||||
Server(ApiArgs),
|
||||
#[cfg(feature = "client")]
|
||||
Client(ClientCommand),
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
match Command::parse() {
|
||||
Command::Server(args) => api::run(args).await?,
|
||||
#[cfg(feature = "client")]
|
||||
Command::Client(args) => client::run(args).await?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user