Skip to content

Commit

Permalink
worker/environment: Add team_repo field
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Jan 3, 2024
1 parent 1eefd82 commit 7247bae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/bin/background-worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crates_io::cloudfront::CloudFront;
use crates_io::db::DieselPool;
use crates_io::fastly::Fastly;
use crates_io::storage::Storage;
use crates_io::team_repo::TeamRepoImpl;
use crates_io::worker::{Environment, RunnerExt};
use crates_io::{config, Emails};
use crates_io::{db, ssh};
Expand Down Expand Up @@ -76,7 +77,8 @@ fn main() -> anyhow::Result<()> {
.expect("Couldn't build client");

let emails = Emails::from_environment(&config);
let fastly = Fastly::from_environment(client);
let fastly = Fastly::from_environment(client.clone());
let team_repo = TeamRepoImpl::new(client);

let connection_pool = r2d2::Pool::builder()
.max_size(10)
Expand All @@ -90,6 +92,7 @@ fn main() -> anyhow::Result<()> {
.storage(storage)
.connection_pool(DieselPool::new_background_worker(connection_pool.clone()))
.emails(emails)
.team_repo(Box::new(team_repo))
.build()?;

let environment = Arc::new(environment);
Expand Down
10 changes: 10 additions & 0 deletions src/tests/util/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crates_io::middleware::cargo_compat::StatusCodeConfig;
use crates_io::models::token::{CrateScope, EndpointScope};
use crates_io::rate_limiter::{LimitedAction, RateLimiterConfig};
use crates_io::storage::StorageConfig;
use crates_io::team_repo::MockTeamRepo;
use crates_io::worker::{Environment, RunnerExt};
use crates_io::{App, Emails, Env};
use crates_io_index::testing::UpstreamIndex;
Expand Down Expand Up @@ -80,6 +81,7 @@ impl TestApp {
index: None,
build_job_runner: false,
use_chaos_proxy: false,
team_repo: MockTeamRepo::new(),
}
}

Expand Down Expand Up @@ -204,6 +206,7 @@ pub struct TestAppBuilder {
index: Option<UpstreamIndex>,
build_job_runner: bool,
use_chaos_proxy: bool,
team_repo: MockTeamRepo,
}

impl TestAppBuilder {
Expand Down Expand Up @@ -259,11 +262,13 @@ impl TestAppBuilder {
index_location: index.url(),
credentials: Credentials::Missing,
};

let environment = Environment::builder()
.repository_config(repository_config)
.storage(app.storage.clone())
.connection_pool(app.primary_database.clone())
.emails(app.emails.clone())
.team_repo(Box::new(self.team_repo))
.build()
.unwrap();

Expand Down Expand Up @@ -351,6 +356,11 @@ impl TestAppBuilder {
self
}

pub fn with_team_repo(mut self, team_repo: MockTeamRepo) -> Self {
self.team_repo = team_repo;
self
}

pub fn with_replica(mut self) -> Self {
let primary = &self.config.db.primary;

Expand Down
2 changes: 2 additions & 0 deletions src/worker/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::cloudfront::CloudFront;
use crate::db::DieselPool;
use crate::fastly::Fastly;
use crate::storage::Storage;
use crate::team_repo::TeamRepo;
use crate::typosquat;
use crate::Emails;
use crates_io_index::{Repository, RepositoryConfig};
Expand All @@ -25,6 +26,7 @@ pub struct Environment {
pub storage: Arc<Storage>,
pub connection_pool: DieselPool,
pub emails: Emails,
pub team_repo: Box<dyn TeamRepo + Send + Sync>,

/// A lazily initialised cache of the most popular crates ready to use in typosquatting checks.
#[builder(default, setter(skip))]
Expand Down

0 comments on commit 7247bae

Please sign in to comment.