Skip to content

allow authenticating to AWS with the EC2 instance role #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/db/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use error::Result;
use failure::err_msg;
use rusoto_s3::{S3, PutObjectRequest, GetObjectRequest, S3Client};
use rusoto_core::region::Region;
use rusoto_credential::EnvironmentProvider;
use rusoto_credential::DefaultCredentialsProvider;


fn get_file_list_from_dir<P: AsRef<Path>>(path: P,
Expand Down Expand Up @@ -115,12 +115,19 @@ pub fn get_path(conn: &Connection, path: &str) -> Option<Blob> {
fn s3_client() -> Option<S3Client> {
// If AWS keys aren't configured, then presume we should use the DB exclusively
// for file storage.
if std::env::var_os("AWS_ACCESS_KEY_ID").is_none() {
if std::env::var_os("AWS_ACCESS_KEY_ID").is_none() && std::env::var_os("FORCE_S3").is_none() {
return None;
}
let creds = match DefaultCredentialsProvider::new() {
Ok(creds) => creds,
Err(err) => {
warn!("failed to retrieve AWS credentials: {}", err);
return None;
}
};
Some(S3Client::new_with(
rusoto_core::request::HttpClient::new().unwrap(),
EnvironmentProvider::default(),
creds,
std::env::var("S3_ENDPOINT").ok().map(|e| Region::Custom {
name: "us-west-1".to_owned(),
endpoint: e,
Expand Down