Skip to content

Commit 963187b

Browse files
committed
config/Base: Remove unused uploader field
1 parent d005d8b commit 963187b

File tree

3 files changed

+5
-117
lines changed

3 files changed

+5
-117
lines changed

src/config/base.rs

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
//! Base configuration options
22
//!
33
//! - `HEROKU`: Is this instance of crates_io:: currently running on Heroku.
4-
//! - `S3_BUCKET`: The S3 bucket used to store crate files. If not present during development,
5-
//! crates_io:: will fall back to a local uploader.
6-
//! - `S3_REGION`: The region in which the bucket was created. Optional if US standard.
7-
//! - `AWS_ACCESS_KEY`: The access key to interact with S3.
8-
//! - `AWS_SECRET_KEY`: The secret key to interact with S3.
9-
//! - `S3_CDN`: Optional CDN configuration for building public facing URLs.
104
11-
use crate::{env, uploaders::Uploader, Env};
5+
use crate::Env;
126

137
pub struct Base {
148
pub env: Env,
15-
pub uploader: Uploader,
169
}
1710

1811
impl Base {
@@ -22,82 +15,6 @@ impl Base {
2215
_ => Env::Development,
2316
};
2417

25-
let uploader = if env == Env::Production {
26-
// `env` panics if these vars are not set, and in production for a primary instance,
27-
// that's what we want since we don't want to be able to start the server if the
28-
// server doesn't know where to upload crates.
29-
Self::s3_panic_if_missing_keys()
30-
} else if dotenvy::var("S3_BUCKET").is_ok() {
31-
// If we've set the `S3_BUCKET` variable to any value, use all of the values
32-
// for the related S3 environment variables and configure the app to upload to
33-
// and read from S3 like production does. All values except for bucket are
34-
// optional, like production read-only mirrors.
35-
info!("Using S3 uploader");
36-
Self::s3_maybe_read_only()
37-
} else {
38-
// If we don't set the `S3_BUCKET` variable, we'll use a development-only
39-
// uploader that makes it possible to run and publish to a locally-running
40-
// crates.io instance without needing to set up an account and a bucket in S3.
41-
info!("Using local uploader, crate files will be in the local_uploads directory");
42-
Uploader::Local
43-
};
44-
45-
Self { env, uploader }
46-
}
47-
48-
pub fn uploader(&self) -> &Uploader {
49-
&self.uploader
50-
}
51-
52-
fn s3_panic_if_missing_keys() -> Uploader {
53-
let index_bucket = match dotenvy::var("S3_INDEX_BUCKET") {
54-
Ok(name) => Some(Box::new(s3::Bucket::new(
55-
name,
56-
dotenvy::var("S3_INDEX_REGION")
57-
.map_or_else(|_err| s3::Region::Default, s3::Region::Region),
58-
env("AWS_ACCESS_KEY"),
59-
env("AWS_SECRET_KEY"),
60-
"https",
61-
))),
62-
Err(_) => None,
63-
};
64-
Uploader::S3 {
65-
bucket: Box::new(s3::Bucket::new(
66-
env("S3_BUCKET"),
67-
dotenvy::var("S3_REGION")
68-
.map_or_else(|_err| s3::Region::Default, s3::Region::Region),
69-
env("AWS_ACCESS_KEY"),
70-
env("AWS_SECRET_KEY"),
71-
"https",
72-
)),
73-
index_bucket,
74-
cdn: dotenvy::var("S3_CDN").ok(),
75-
}
76-
}
77-
78-
fn s3_maybe_read_only() -> Uploader {
79-
let index_bucket = match dotenvy::var("S3_INDEX_BUCKET") {
80-
Ok(name) => Some(Box::new(s3::Bucket::new(
81-
name,
82-
dotenvy::var("S3_INDEX_REGION")
83-
.map_or_else(|_err| s3::Region::Default, s3::Region::Region),
84-
dotenvy::var("AWS_ACCESS_KEY").unwrap_or_default(),
85-
dotenvy::var("AWS_SECRET_KEY").unwrap_or_default(),
86-
"https",
87-
))),
88-
Err(_) => None,
89-
};
90-
Uploader::S3 {
91-
bucket: Box::new(s3::Bucket::new(
92-
env("S3_BUCKET"),
93-
dotenvy::var("S3_REGION")
94-
.map_or_else(|_err| s3::Region::Default, s3::Region::Region),
95-
dotenvy::var("AWS_ACCESS_KEY").unwrap_or_default(),
96-
dotenvy::var("AWS_SECRET_KEY").unwrap_or_default(),
97-
"https",
98-
)),
99-
index_bucket,
100-
cdn: dotenvy::var("S3_CDN").ok(),
101-
}
18+
Self { env }
10219
}
10320
}

src/config/server.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ipnetwork::IpNetwork;
33
use oauth2::{ClientId, ClientSecret};
44

55
use crate::publish_rate_limit::PublishRateLimit;
6-
use crate::{env, env_optional, uploaders::Uploader, Env};
6+
use crate::{env, env_optional, Env};
77

88
use super::base::Base;
99
use super::database_pools::DatabasePools;
@@ -196,10 +196,6 @@ impl Server {
196196
pub fn env(&self) -> Env {
197197
self.base.env
198198
}
199-
200-
pub fn uploader(&self) -> &Uploader {
201-
self.base.uploader()
202-
}
203199
}
204200

205201
pub(crate) fn domain_name() -> String {

src/tests/util/test_app.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::record;
33
use crate::util::{chaosproxy::ChaosProxy, fresh_schema::FreshSchema};
44
use crates_io::config::{self, BalanceCapacityConfig, Base, DatabasePools, DbPoolConfig};
55
use crates_io::storage::StorageConfig;
6-
use crates_io::{background_jobs::Environment, env, App, Emails, Env, Uploader};
6+
use crates_io::{background_jobs::Environment, env, App, Emails, Env};
77
use crates_io_index::testing::UpstreamIndex;
88
use crates_io_index::{Credentials, Repository as WorkerRepository, RepositoryConfig};
99
use std::{rc::Rc, sync::Arc, time::Duration};
@@ -355,32 +355,7 @@ impl TestAppBuilder {
355355
}
356356

357357
fn simple_config() -> config::Server {
358-
let uploader = Uploader::S3 {
359-
bucket: Box::new(s3::Bucket::new(
360-
dotenvy::var("TEST_S3_BUCKET").unwrap_or_else(|_err| "crates-test".into()),
361-
parse_test_region(dotenvy::var("TEST_S3_REGION").ok()),
362-
dotenvy::var("TEST_AWS_ACCESS_KEY").unwrap_or_default(),
363-
dotenvy::var("TEST_AWS_SECRET_KEY").unwrap_or_default(),
364-
// When testing we route all API traffic over HTTP so we can
365-
// sniff/record it, but everywhere else we use https
366-
"http",
367-
)),
368-
index_bucket: Some(Box::new(s3::Bucket::new(
369-
dotenvy::var("TEST_S3_INDEX_BUCKET").unwrap_or_else(|_err| "crates-index-test".into()),
370-
parse_test_region(dotenvy::var("TEST_S3_INDEX_REGION").ok()),
371-
dotenvy::var("TEST_AWS_ACCESS_KEY").unwrap_or_default(),
372-
dotenvy::var("TEST_AWS_SECRET_KEY").unwrap_or_default(),
373-
// When testing we route all API traffic over HTTP so we can
374-
// sniff/record it, but everywhere else we use https
375-
"http",
376-
))),
377-
cdn: None,
378-
};
379-
380-
let base = Base {
381-
env: Env::Test,
382-
uploader,
383-
};
358+
let base = Base { env: Env::Test };
384359

385360
let db = DatabasePools {
386361
primary: DbPoolConfig {

0 commit comments

Comments
 (0)