summaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 378686b..263a4fd 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -10,7 +10,8 @@ use axum::{
middleware,
response::{IntoResponse, Response},
};
-use clap::{CommandFactory, Parser};
+use chrono::Utc;
+use clap::{CommandFactory, Parser, Subcommand};
use sqlx::sqlite::SqlitePool;
use tokio::net;
@@ -65,6 +66,15 @@ pub struct Args {
/// upgrades
#[arg(short = 'D', long, env, default_value = "sqlite://pilcrow.db.backup")]
backup_database_url: String,
+
+ #[command(subcommand)]
+ command: Option<Command>,
+}
+
+#[derive(Subcommand)]
+enum Command {
+ /// Immediately rotate the server's VAPID (Web Push) application key.
+ RotateVapidKey,
}
impl Args {
@@ -89,6 +99,16 @@ impl Args {
let pool = self.pool().await?;
let app = App::from(pool);
+
+ match self.command {
+ None => self.serve(app).await?,
+ Some(Command::RotateVapidKey) => app.vapid().rotate_key(&Utc::now()).await?,
+ }
+
+ Result::<_, Error>::Ok(())
+ }
+
+ async fn serve(self, app: App) -> Result<(), Error> {
let app = routes::routes(&app)
.route_layer(middleware::from_fn(clock::middleware))
.route_layer(middleware::map_response(Self::server_info()))
@@ -101,7 +121,7 @@ impl Args {
println!("{started_msg}");
serve.await?;
- Result::<_, Error>::Ok(())
+ Ok(())
}
async fn listener(&self) -> io::Result<net::TcpListener> {
@@ -140,5 +160,6 @@ fn started_msg(listener: &net::TcpListener) -> io::Result<String> {
enum Error {
Io(#[from] io::Error),
Database(#[from] db::Error),
+ Sqlx(#[from] sqlx::Error),
Umask(#[from] umask::Error),
}