pub struct ServerConfig {
pub storage_root: PathBuf,
pub bearer_token: Option<String>,
pub public_base_url: Option<String>,
pub signed_url_key_id: Option<String>,
pub signed_url_secret: Option<String>,
pub allow_insecure_url_sources: bool,
pub cache_root: Option<PathBuf>,
pub log_handler: Option<LogHandler>,
}Fields§
§storage_root: PathBufThe storage root used for source.kind=path lookups.
bearer_token: Option<String>The expected Bearer token for private endpoints.
public_base_url: Option<String>The externally visible base URL used for public signed-URL authority.
When this value is set, public signed GET requests use its authority component when
reconstructing the canonical signature payload. This is primarily useful when the server
runs behind a reverse proxy and the incoming Host header is not the externally visible
authority that clients sign.
signed_url_key_id: Option<String>The expected key identifier for public signed GET requests.
signed_url_secret: Option<String>The shared secret used to verify public signed GET requests.
allow_insecure_url_sources: boolWhether server-side URL sources may bypass private-network and port restrictions.
This flag is intended for local development and automated tests where fixture servers commonly run on loopback addresses and non-standard ports. Production-like configurations should keep this disabled.
cache_root: Option<PathBuf>Optional directory for the on-disk transform cache.
When set, transformed image bytes are cached on disk using a sharded directory layout
(ab/cd/ef/<sha256_hex>). Repeated requests with the same source and transform options
are served from the cache instead of re-transforming. When None, caching is disabled
and every request performs a fresh transform.
log_handler: Option<LogHandler>Optional logging callback for diagnostic messages.
When set, the server routes all diagnostic messages (cache errors, connection
failures, transform warnings) through this handler. When None, messages are
written to stderr via eprintln!.
Implementations§
Source§impl ServerConfig
impl ServerConfig
Sourcepub fn new(storage_root: PathBuf, bearer_token: Option<String>) -> Self
pub fn new(storage_root: PathBuf, bearer_token: Option<String>) -> Self
Creates a server configuration from explicit values.
This constructor does not canonicalize the storage root. It is primarily intended for tests and embedding scenarios where the caller already controls the filesystem layout.
§Examples
use truss::adapters::server::ServerConfig;
let config = ServerConfig::new(std::env::temp_dir(), Some("secret".to_string()));
assert_eq!(config.bearer_token.as_deref(), Some("secret"));Sourcepub fn with_signed_url_credentials(
self,
key_id: impl Into<String>,
secret: impl Into<String>,
) -> Self
pub fn with_signed_url_credentials( self, key_id: impl Into<String>, secret: impl Into<String>, ) -> Self
Returns a copy of the configuration with signed-URL verification credentials attached.
Public GET endpoints require both a key identifier and a shared secret. Tests and local development setups can use this helper to attach those values directly without going through environment variables.
§Examples
use truss::adapters::server::ServerConfig;
let config = ServerConfig::new(std::env::temp_dir(), None)
.with_signed_url_credentials("public-dev", "top-secret");
assert_eq!(config.signed_url_key_id.as_deref(), Some("public-dev"));
assert_eq!(config.signed_url_secret.as_deref(), Some("top-secret"));Sourcepub fn with_insecure_url_sources(self, allow_insecure_url_sources: bool) -> Self
pub fn with_insecure_url_sources(self, allow_insecure_url_sources: bool) -> Self
Returns a copy of the configuration with insecure URL source allowances toggled.
Enabling this flag allows URL sources that target loopback or private-network addresses and permits non-standard ports. This is useful for local integration tests but weakens the default SSRF protections of the server adapter.
§Examples
use truss::adapters::server::ServerConfig;
let config = ServerConfig::new(std::env::temp_dir(), Some("secret".to_string()))
.with_insecure_url_sources(true);
assert!(config.allow_insecure_url_sources);Sourcepub fn with_cache_root(self, cache_root: impl Into<PathBuf>) -> Self
pub fn with_cache_root(self, cache_root: impl Into<PathBuf>) -> Self
Returns a copy of the configuration with a transform cache directory set.
When a cache root is configured, the server stores transformed images on disk using a sharded directory layout and serves subsequent identical requests from the cache.
§Examples
use truss::adapters::server::ServerConfig;
let config = ServerConfig::new(std::env::temp_dir(), None)
.with_cache_root(std::env::temp_dir().join("truss-cache"));
assert!(config.cache_root.is_some());Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Loads server configuration from environment variables.
The adapter currently reads:
TRUSS_STORAGE_ROOT: filesystem root forsource.kind=pathinputs. Defaults to the current directory and is canonicalized before use.TRUSS_BEARER_TOKEN: private API Bearer token. When this value is missing, private endpoints remain unavailable and return503 Service Unavailable.TRUSS_PUBLIC_BASE_URL: externally visible base URL reserved for future public endpoint signing. When set, it must parse as an absolutehttporhttpsURL.TRUSS_SIGNED_URL_KEY_ID: key identifier accepted by public signed GET endpoints.TRUSS_SIGNED_URL_SECRET: shared secret used to verify public signed GET signatures.TRUSS_ALLOW_INSECURE_URL_SOURCES: when set to1,true,yes, oron, URL sources may target loopback or private-network addresses and non-standard ports.TRUSS_CACHE_ROOT: directory for the on-disk transform cache. When set, transformed images are cached using a shardedab/cd/ef/<sha256>layout. When absent, caching is disabled.
§Errors
Returns an io::Error when the configured storage root does not exist or cannot be
canonicalized.
§Examples
// SAFETY: This example runs single-threaded; no concurrent env access.
unsafe {
std::env::set_var("TRUSS_STORAGE_ROOT", ".");
std::env::set_var("TRUSS_ALLOW_INSECURE_URL_SOURCES", "true");
}
let config = truss::adapters::server::ServerConfig::from_env().unwrap();
assert!(config.storage_root.is_absolute());
assert!(config.allow_insecure_url_sources);Trait Implementations§
Source§impl Clone for ServerConfig
impl Clone for ServerConfig
Source§impl Debug for ServerConfig
impl Debug for ServerConfig
Source§impl PartialEq for ServerConfig
impl PartialEq for ServerConfig
impl Eq for ServerConfig
Auto Trait Implementations§
impl Freeze for ServerConfig
impl !RefUnwindSafe for ServerConfig
impl Send for ServerConfig
impl Sync for ServerConfig
impl Unpin for ServerConfig
impl UnsafeUnpin for ServerConfig
impl !UnwindSafe for ServerConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more