Skip to content

Commit 7247bae

Browse files
committed
worker/environment: Add team_repo field
1 parent 1eefd82 commit 7247bae

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/bin/background-worker.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crates_io::cloudfront::CloudFront;
1818
use crates_io::db::DieselPool;
1919
use crates_io::fastly::Fastly;
2020
use crates_io::storage::Storage;
21+
use crates_io::team_repo::TeamRepoImpl;
2122
use crates_io::worker::{Environment, RunnerExt};
2223
use crates_io::{config, Emails};
2324
use crates_io::{db, ssh};
@@ -76,7 +77,8 @@ fn main() -> anyhow::Result<()> {
7677
.expect("Couldn't build client");
7778

7879
let emails = Emails::from_environment(&config);
79-
let fastly = Fastly::from_environment(client);
80+
let fastly = Fastly::from_environment(client.clone());
81+
let team_repo = TeamRepoImpl::new(client);
8082

8183
let connection_pool = r2d2::Pool::builder()
8284
.max_size(10)
@@ -90,6 +92,7 @@ fn main() -> anyhow::Result<()> {
9092
.storage(storage)
9193
.connection_pool(DieselPool::new_background_worker(connection_pool.clone()))
9294
.emails(emails)
95+
.team_repo(Box::new(team_repo))
9396
.build()?;
9497

9598
let environment = Arc::new(environment);

src/tests/util/test_app.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crates_io::middleware::cargo_compat::StatusCodeConfig;
77
use crates_io::models::token::{CrateScope, EndpointScope};
88
use crates_io::rate_limiter::{LimitedAction, RateLimiterConfig};
99
use crates_io::storage::StorageConfig;
10+
use crates_io::team_repo::MockTeamRepo;
1011
use crates_io::worker::{Environment, RunnerExt};
1112
use crates_io::{App, Emails, Env};
1213
use crates_io_index::testing::UpstreamIndex;
@@ -80,6 +81,7 @@ impl TestApp {
8081
index: None,
8182
build_job_runner: false,
8283
use_chaos_proxy: false,
84+
team_repo: MockTeamRepo::new(),
8385
}
8486
}
8587

@@ -204,6 +206,7 @@ pub struct TestAppBuilder {
204206
index: Option<UpstreamIndex>,
205207
build_job_runner: bool,
206208
use_chaos_proxy: bool,
209+
team_repo: MockTeamRepo,
207210
}
208211

209212
impl TestAppBuilder {
@@ -259,11 +262,13 @@ impl TestAppBuilder {
259262
index_location: index.url(),
260263
credentials: Credentials::Missing,
261264
};
265+
262266
let environment = Environment::builder()
263267
.repository_config(repository_config)
264268
.storage(app.storage.clone())
265269
.connection_pool(app.primary_database.clone())
266270
.emails(app.emails.clone())
271+
.team_repo(Box::new(self.team_repo))
267272
.build()
268273
.unwrap();
269274

@@ -351,6 +356,11 @@ impl TestAppBuilder {
351356
self
352357
}
353358

359+
pub fn with_team_repo(mut self, team_repo: MockTeamRepo) -> Self {
360+
self.team_repo = team_repo;
361+
self
362+
}
363+
354364
pub fn with_replica(mut self) -> Self {
355365
let primary = &self.config.db.primary;
356366

src/worker/environment.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::cloudfront::CloudFront;
22
use crate::db::DieselPool;
33
use crate::fastly::Fastly;
44
use crate::storage::Storage;
5+
use crate::team_repo::TeamRepo;
56
use crate::typosquat;
67
use crate::Emails;
78
use crates_io_index::{Repository, RepositoryConfig};
@@ -25,6 +26,7 @@ pub struct Environment {
2526
pub storage: Arc<Storage>,
2627
pub connection_pool: DieselPool,
2728
pub emails: Emails,
29+
pub team_repo: Box<dyn TeamRepo + Send + Sync>,
2830

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

0 commit comments

Comments
 (0)