Skip to content

Commit aa3f28b

Browse files
committed
cache certs
1 parent 8e74aec commit aa3f28b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

slingshot/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ struct Args {
3131
/// - TODO: a rate-limiter will be installed
3232
#[arg(long)]
3333
host: Option<String>,
34+
/// a location to cache acme https certs
35+
///
36+
/// only used if --host is specified. omitting requires re-requesting certs
37+
/// on every restart, and letsencrypt has rate limits that are easy to hit.
38+
///
39+
/// recommended in production, but mind the file permissions.
40+
#[arg(long)]
41+
certs: Option<PathBuf>,
3442
}
3543

3644
#[tokio::main]
@@ -91,6 +99,7 @@ async fn main() -> Result<(), String> {
9199
identity,
92100
repo,
93101
args.host,
102+
args.certs,
94103
server_shutdown,
95104
)
96105
.await?;

slingshot/src/server.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{CachedRecord, Identity, Repo, error::ServerError};
22
use atrium_api::types::string::{Cid, Did, Handle, Nsid, RecordKey};
33
use foyer::HybridCache;
44
use serde::Serialize;
5+
use std::path::PathBuf;
56
use std::str::FromStr;
67
use std::sync::Arc;
78
use tokio_util::sync::CancellationToken;
@@ -293,6 +294,7 @@ pub async fn serve(
293294
identity: Identity,
294295
repo: Repo,
295296
host: Option<String>,
297+
certs: Option<PathBuf>,
296298
_shutdown: CancellationToken,
297299
) -> Result<(), ServerError> {
298300
let repo = Arc::new(repo);
@@ -320,11 +322,13 @@ pub async fn serve(
320322

321323
app = app.at("/.well-known/did.json", get_did_doc(&host));
322324

323-
let auto_cert = AutoCert::builder()
325+
let mut auto_cert = AutoCert::builder()
324326
.directory_url(LETS_ENCRYPT_PRODUCTION)
325-
.domain(&host)
326-
.build()
327-
.map_err(ServerError::AcmeBuildError)?;
327+
.domain(&host);
328+
if let Some(certs) = certs {
329+
auto_cert = auto_cert.cache_path(certs)
330+
}
331+
let auto_cert = auto_cert.build().map_err(ServerError::AcmeBuildError)?;
328332

329333
run(TcpListener::bind("0.0.0.0:443").acme(auto_cert), app).await
330334
} else {

0 commit comments

Comments
 (0)