Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
[package]
|
||||
name = "poster-fetcher"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
config = { workspace = true }
|
||||
domain = { workspace = true }
|
||||
async-trait = { workspace = true }
|
||||
reqwest = { workspace = true }
|
||||
rustls = { workspace = true, features = ["ring", "std"] }
|
||||
anyhow = { workspace = true }
|
||||
|
||||
@@ -3,11 +3,9 @@ pub struct PosterFetcherConfig {
|
||||
}
|
||||
|
||||
impl PosterFetcherConfig {
|
||||
pub fn from_env() -> Self {
|
||||
let timeout_seconds = std::env::var("POSTER_FETCH_TIMEOUT_SECONDS")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(30);
|
||||
Self { timeout_seconds }
|
||||
pub fn from_config(config: &::config::MetadataConfig) -> Self {
|
||||
Self {
|
||||
timeout_seconds: config.poster_fetch_timeout_seconds,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ pub struct ReqwestPosterFetcher {
|
||||
|
||||
impl ReqwestPosterFetcher {
|
||||
pub fn new(config: PosterFetcherConfig) -> anyhow::Result<Self> {
|
||||
let _ = rustls::crypto::ring::default_provider().install_default();
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(config.timeout_seconds))
|
||||
.build()?;
|
||||
@@ -59,14 +60,18 @@ impl ImageFetcher for ReqwestPosterFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create() -> anyhow::Result<std::sync::Arc<dyn domain::ports::PosterFetcherClient>> {
|
||||
pub fn create(
|
||||
config: &::config::MetadataConfig,
|
||||
) -> anyhow::Result<std::sync::Arc<dyn domain::ports::PosterFetcherClient>> {
|
||||
Ok(std::sync::Arc::new(ReqwestPosterFetcher::new(
|
||||
PosterFetcherConfig::from_env(),
|
||||
PosterFetcherConfig::from_config(config),
|
||||
)?))
|
||||
}
|
||||
|
||||
pub fn create_image_fetcher() -> anyhow::Result<std::sync::Arc<dyn domain::ports::ImageFetcher>> {
|
||||
pub fn create_image_fetcher(
|
||||
config: &::config::MetadataConfig,
|
||||
) -> anyhow::Result<std::sync::Arc<dyn domain::ports::ImageFetcher>> {
|
||||
Ok(std::sync::Arc::new(ReqwestPosterFetcher::new(
|
||||
PosterFetcherConfig::from_env(),
|
||||
PosterFetcherConfig::from_config(config),
|
||||
)?))
|
||||
}
|
||||
|
||||
6
crates/adapters/poster-fetcher/tests/client_tls.rs
Normal file
6
crates/adapters/poster-fetcher/tests/client_tls.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use poster_fetcher::{PosterFetcherConfig, ReqwestPosterFetcher};
|
||||
|
||||
#[test]
|
||||
fn poster_fetcher_builds_without_bootstrap() {
|
||||
ReqwestPosterFetcher::new(PosterFetcherConfig { timeout_seconds: 5 }).expect("client builds");
|
||||
}
|
||||
Reference in New Issue
Block a user