1
0
Fork 0
mirror of https://github.com/zhaofengli/attic.git synced 2025-03-13 12:19:15 +00:00

server: Allow setting an alternative substituter endpoint

This commit is contained in:
Zhaofeng Li 2023-01-08 23:00:53 -07:00
parent 0b528b5417
commit 3d1961c0ab
3 changed files with 18 additions and 1 deletions

View file

@ -58,6 +58,15 @@ pub struct Config {
#[serde(rename = "api-endpoint")]
pub api_endpoint: Option<String>,
/// The canonical Nix Binary Cache endpoint of this server.
///
/// This is usually the same as `api_endpoint` but can be configured
/// to a different value.
///
/// If unconfigured, it's assumed to be the same as `api_endpoint`.
#[serde(rename = "substituter-endpoint")]
pub substituter_endpoint: Option<String>,
/// Whether to soft-delete caches.
///
/// If this is enabled, caches are soft-deleted instead of actually

View file

@ -75,6 +75,9 @@ struct RequestStateInner {
/// The canonical API endpoint.
api_endpoint: Option<String>,
/// The canonical substituter endpoint.
substituter_endpoint: Option<String>,
/// The potentially-invalid Host header supplied by the client.
host: String,
@ -172,7 +175,11 @@ impl RequestStateInner {
/// The binary cache endpoint may live on another host than
/// the canonical API endpoint.
fn substituter_endpoint(&self, cache: CacheName) -> ServerResult<String> {
Ok(format!("{}{}", self.api_endpoint()?, cache.as_str()))
if let Some(substituter_endpoint) = &self.substituter_endpoint {
Ok(format!("{}{}", substituter_endpoint, cache.as_str()))
} else {
Ok(format!("{}{}", self.api_endpoint()?, cache.as_str()))
}
}
/// Indicates whether the cache the client is interacting with is public.

View file

@ -31,6 +31,7 @@ pub async fn init_request_state<B>(
let req_state = Arc::new(RequestStateInner {
auth: AuthState::new(),
api_endpoint: state.config.api_endpoint.to_owned(),
substituter_endpoint: state.config.substituter_endpoint.to_owned(),
host,
client_claims_https,
public_cache: AtomicBool::new(false),