feat(config): read secrets from NAME_FILE variables (#1421)

Co-authored-by: Hampus <[email protected]>
This commit is contained in:
Kai Compton
2026-10-06 21:43:08 +02:00
committed by GitHub
co-authored by Hampus
parent cc5545c333
commit 0c4f016ba2
17 changed files with 534 additions and 31 deletions
+1 -6
View File
@@ -4,7 +4,6 @@ use super::{ResolveContext, Resolver, ResolverResult};
use crate::http_fetch;
use crate::media_proxy::{MediaMetadata, embed_media_flags};
use crate::types::{EmbedMedia, EmbedProvider, MessageEmbed};
use fluxer_svc::config::optional_env;
use std::future::Future;
use std::pin::Pin;
use std::time::Duration;
@@ -49,7 +48,7 @@ impl Resolver for KlipyResolver {
ctx: &'a ResolveContext<'_>,
) -> Pin<Box<dyn Future<Output = anyhow::Result<ResolverResult>> + Send + 'a>> {
Box::pin(async move {
let Some(api_key) = ctx.klipy_api_key.clone().or_else(klipy_api_key) else {
let Some(api_key) = ctx.klipy_api_key.clone() else {
return Ok(ResolverResult { embeds: vec![] });
};
let formats = match resolve_media_via_api(ctx, &api_key).await {
@@ -136,10 +135,6 @@ fn klipy_resource(kind: &str) -> &'static str {
}
}
fn klipy_api_key() -> Option<String> {
optional_env("FLUXER_KLIPY_API_KEY").or_else(|| optional_env("KLIPY_API_KEY"))
}
async fn resolve_media_via_api(
ctx: &ResolveContext<'_>,
api_key: &str,
+1 -6
View File
@@ -5,7 +5,6 @@ use crate::http_fetch;
use crate::media_proxy::embed_media_flags;
use crate::text_limits;
use crate::types::{EmbedAuthor, EmbedMedia, EmbedProvider, MessageEmbed};
use fluxer_svc::config::optional_env;
use serde::Deserialize;
use std::future::Future;
use std::pin::Pin;
@@ -61,7 +60,7 @@ impl Resolver for YouTubeResolver {
}
};
let Some(api_key) = ctx.youtube_api_key.clone().or_else(youtube_api_key) else {
let Some(api_key) = ctx.youtube_api_key.clone() else {
tracing::debug!("No YouTube API key configured");
return Ok(ResolverResult { embeds: vec![] });
};
@@ -251,10 +250,6 @@ struct YouTubeThumbnail {
height: Option<u32>,
}
fn youtube_api_key() -> Option<String> {
optional_env("FLUXER_YOUTUBE_API_KEY").or_else(|| optional_env("YOUTUBE_API_KEY"))
}
fn build_youtube_api_url(video_id: &str, api_key: &str) -> anyhow::Result<Url> {
let mut url = Url::parse(YOUTUBE_API_BASE)?;
url.query_pairs_mut()
+14 -2
View File
@@ -24,6 +24,8 @@ pub struct UnfurlShard {
resolvers: Vec<Box<dyn crate::resolvers::Resolver>>,
media_proxy: MediaProxyClient,
self_hosted: bool,
youtube_api_key: Option<String>,
klipy_api_key: Option<String>,
}
impl UnfurlShard {
@@ -78,6 +80,10 @@ impl UnfurlShard {
resolvers,
media_proxy,
self_hosted,
youtube_api_key: optional_env("FLUXER_YOUTUBE_API_KEY")
.or_else(|| optional_env("YOUTUBE_API_KEY")),
klipy_api_key: optional_env("FLUXER_KLIPY_API_KEY")
.or_else(|| optional_env("KLIPY_API_KEY")),
}
}
@@ -100,6 +106,8 @@ impl UnfurlShard {
internal_http_client(),
),
self_hosted: false,
youtube_api_key: None,
klipy_api_key: None,
}
}
@@ -125,8 +133,12 @@ impl UnfurlShard {
nsfw_mode,
media_proxy: &self.media_proxy,
self_hosted: self.self_hosted,
youtube_api_key: youtube_api_key.map(str::to_owned),
klipy_api_key: klipy_api_key.map(str::to_owned),
youtube_api_key: youtube_api_key
.map(str::to_owned)
.or_else(|| self.youtube_api_key.clone()),
klipy_api_key: klipy_api_key
.map(str::to_owned)
.or_else(|| self.klipy_api_key.clone()),
};
if let Some(idx) = matched_resolver_idx {