Skip to content

Commit 7e39675

Browse files
committedJun 12, 2018
tokens: correctly handle S3 tokens
1 parent 41f3d8a commit 7e39675

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed
 

‎src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ error_chain! {
1616
ParseInt(::std::num::ParseIntError);
1717
Parse(::std::string::ParseError);
1818
RusotoTls(::rusoto_core::TlsError);
19+
RusotoParseRegion(::rusoto_core::ParseRegionError);
1920
Rusqlite(::rusqlite::Error);
2021
R2D2(::r2d2::Error);
2122
Base64Decode(::base64::DecodeError);

‎src/server/reports.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn generate_report(data: &Data, ex: &ExperimentData, results: &ResultsDB) -> Res
1818
let client = S3Client::new(
1919
default_tls_client()?,
2020
data.tokens.reports_bucket.clone(),
21-
data.tokens.reports_bucket.region.clone(),
21+
data.tokens.reports_bucket.region.to_region()?,
2222
);
2323
let dest = format!(
2424
"s3://{}/{}",
@@ -77,10 +77,11 @@ fn reports_thread(data: &Data, wakes: &mpsc::Receiver<()>) -> Result<()> {
7777
continue;
7878
}
7979

80-
let report_url = format!(
81-
"{}/{}/{}/index.html",
82-
data.tokens.reports_bucket.public_url, data.tokens.reports_bucket.bucket, name
83-
);
80+
let base_url = data.tokens
81+
.reports_bucket
82+
.public_url
83+
.replace("{bucket}", &data.tokens.reports_bucket.bucket);
84+
let report_url = format!("{}/{}/index.html", base_url, name);
8485

8586
ex.set_status(&data.db, Status::Completed)?;
8687
info!("report for the experiment {} generated successfully!", name);

‎src/server/tokens.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ use std::path::Path;
88

99
static TOKENS_PATH: &'static str = "tokens.toml";
1010

11+
#[derive(Debug, Clone, Deserialize)]
12+
#[serde(tag = "type", rename_all = "kebab-case")]
13+
pub enum BucketRegion {
14+
S3 { region: String },
15+
Custom { url: String },
16+
}
17+
18+
impl BucketRegion {
19+
pub fn to_region(&self) -> Result<Region> {
20+
match *self {
21+
BucketRegion::S3 { ref region } => Ok(region.parse()?),
22+
BucketRegion::Custom { ref url } => Ok(Region::Custom {
23+
name: "custom".to_string(),
24+
endpoint: url.clone(),
25+
}),
26+
}
27+
}
28+
}
29+
1130
#[derive(Debug, Clone, Deserialize)]
1231
#[serde(rename_all = "kebab-case")]
1332
pub struct BotTokens {
@@ -18,7 +37,7 @@ pub struct BotTokens {
1837
#[derive(Debug, Clone, Deserialize)]
1938
#[serde(rename_all = "kebab-case")]
2039
pub struct ReportsBucket {
21-
pub region: Region,
40+
pub region: BucketRegion,
2241
pub bucket: String,
2342
pub public_url: String,
2443
pub access_key: String,
@@ -57,7 +76,9 @@ impl Default for Tokens {
5776
api_token: String::new(),
5877
},
5978
reports_bucket: ReportsBucket {
60-
region: "us-east-1".parse().unwrap(),
79+
region: BucketRegion::S3 {
80+
region: "us-west-1".to_string(),
81+
},
6182
bucket: "crater-reports".into(),
6283
public_url: String::new(),
6384
access_key: String::new(),

‎tokens.example.toml

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ webhooks-secret = ""
33
api-token = ""
44

55
[reports-bucket]
6-
# This is configured by default to use the public minio playground
7-
# S3 can be changed by setting the region name (for example "us-east-1")
8-
region = ["custom", "https://play.minio.io:9000"]
96
bucket = "crater-reports"
10-
public-url = "https://play.minio.io:9000"
7+
8+
# Configuration for the minio playground
9+
# This requires no authentication (credentials are public) and it's great for
10+
# local testing, but it's purged every few days. You might have to recreate the
11+
# bucket manually if it was deleted.
12+
region = { type = "custom", url = "https://play.minio.io:9000" }
13+
public-url = "https://play.minio.io:9000/{bucket}"
1114
access-key = "Q3AM3UQ867SPQQA43P2F"
1215
secret-key = "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
1316

17+
# Configuration for production S3
18+
#region = { type = "s3", region = "us-west-1" }
19+
#public-url = "https://{bucket}.s3.amazonaws.com"
20+
#access-key = ""
21+
#secret-key = ""
22+
1423
[agents]
1524
# "TOKEN" = "agent-name"

0 commit comments

Comments
 (0)
Please sign in to comment.