Skip to content

Commit

Permalink
explicit args for denyliststate
Browse files Browse the repository at this point in the history
  • Loading branch information
r-birkner committed Jul 30, 2024
1 parent 80548f7 commit 1ad62e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/routing/middleware/denylist.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{path::PathBuf, sync::Arc, time::Duration};

use anyhow::{Context, Error};
use axum::{
Expand All @@ -7,6 +7,7 @@ use axum::{
response::Response,
};
use prometheus::Registry;
use reqwest::Url;

use crate::{
cli::Cli,
Expand All @@ -22,19 +23,21 @@ pub struct DenylistState(Arc<Denylist>);
#[allow(clippy::type_complexity)]
impl DenylistState {
pub fn new(
cli: &Cli,
denylist_url: Option<Url>,
denylist_seed: Option<PathBuf>,
allowlist: Option<PathBuf>,
poll_interval: Duration,
tasks: &mut TaskManager,
http_client: Arc<dyn Client>,
registry: &Registry,
) -> Result<Self, Error> {
let denylist_url = cli.policy.policy_denylist_url.clone();
let denylist = Arc::new(
Denylist::init(
denylist_url.clone(),
cli.policy.policy_denylist_allowlist.clone(),
cli.policy.policy_denylist_seed.clone(),
allowlist,
denylist_seed,
http_client,
cli.policy.policy_denylist_poll_interval,
poll_interval,
registry,
)
.context("unable to init denylist")?,
Expand Down
10 changes: 9 additions & 1 deletion src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,15 @@ pub fn setup_router(
let denylist_mw =
if cli.policy.policy_denylist_seed.is_some() || cli.policy.policy_denylist_url.is_some() {
Some(from_fn_with_state(
denylist::DenylistState::new(cli, tasks, http_client.clone(), registry)?,
denylist::DenylistState::new(
cli.policy.policy_denylist_url.clone(),
cli.policy.policy_denylist_seed.clone(),
cli.policy.policy_denylist_allowlist.clone(),
cli.policy.policy_denylist_poll_interval,
tasks,
http_client.clone(),
registry,
)?,
denylist::middleware,
))
} else {
Expand Down

0 comments on commit 1ad62e7

Please sign in to comment.