use std::{
num::{NonZeroU64, NonZeroUsize},
path::PathBuf,
};
use shardline_cache::RedisTlsConfig;
use shardline_protocol::{SecretBytes, SecretString};
use super::error::ServerConfigError;
use crate::reconstruction_cache::ReconstructionCacheAdapter;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AuthProviderKind {
Local,
Oidc,
Jwks,
Passthrough,
}
impl AuthProviderKind {
pub fn parse(value: &str) -> Result<Self, ServerConfigError> {
match value {
"local" => Ok(Self::Local),
"oidc" => Ok(Self::Oidc),
"jwks" => Ok(Self::Jwks),
"passthrough" => Ok(Self::Passthrough),
_other => Err(ServerConfigError::InvalidAuthProvider),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ObjectStorageAdapter {
Local,
S3,
}
impl ObjectStorageAdapter {
pub fn parse(value: &str) -> Result<Self, ServerConfigError> {
match value {
"local" => Ok(Self::Local),
"s3" => Ok(Self::S3),
_other => Err(ServerConfigError::InvalidObjectStorageAdapter),
}
}
}
#[derive(Clone, PartialEq, Eq)]
pub struct AuthConfig {
pub token_signing_key: Option<SecretBytes>,
pub auth_provider: AuthProviderKind,
pub auth_oidc_issuer: Option<String>,
pub auth_jwks_url: Option<String>,
pub auth_jwks_issuer: Option<String>,
}
#[derive(Clone, PartialEq, Eq)]
pub struct OciConfig {
pub upload_session_ttl_seconds: NonZeroU64,
pub upload_max_active_sessions: NonZeroUsize,
pub registry_token_ttl_seconds: NonZeroU64,
pub registry_token_max_in_flight_requests: NonZeroUsize,
}
#[derive(Clone, PartialEq, Eq)]
pub struct CacheConfig {
pub adapter: ReconstructionCacheAdapter,
pub ttl_seconds: NonZeroU64,
pub memory_max_entries: NonZeroUsize,
pub redis_url: Option<SecretString>,
pub redis_tls: Option<RedisTlsConfig>,
}
#[derive(Clone, PartialEq, Eq)]
pub struct ProviderConfig {
pub config_path: Option<PathBuf>,
pub api_key: Option<SecretBytes>,
pub token_issuer: Option<String>,
pub token_ttl_seconds: Option<NonZeroU64>,
}