Skip to content

Commit a11b72b

Browse files
committed
Rename token fields
1 parent a39a451 commit a11b72b

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

site/src/github.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ pub async fn create_ref(
336336
let timer_token = ctxt
337337
.config
338338
.keys
339-
.github
339+
.github_api_token
340340
.clone()
341-
.expect("needs rust-timer token");
341+
.expect("needs github API token");
342342
let url = format!("{}/git/refs", repository_url);
343343
let response = client
344344
.post(&url)
@@ -385,9 +385,9 @@ pub async fn create_pr(
385385
let timer_token = ctxt
386386
.config
387387
.keys
388-
.github
388+
.github_api_token
389389
.clone()
390-
.expect("needs rust-timer token");
390+
.expect("needs github API token");
391391
let url = format!("{}/pulls", repository_url);
392392
let response = client
393393
.post(&url)
@@ -432,9 +432,9 @@ pub async fn create_commit(
432432
let timer_token = ctxt
433433
.config
434434
.keys
435-
.github
435+
.github_api_token
436436
.clone()
437-
.expect("needs rust-timer token");
437+
.expect("needs github API token");
438438
let url = format!("{}/git/commits", repository_url);
439439
let commit_response = client
440440
.post(&url)
@@ -468,9 +468,9 @@ pub async fn get_commit(
468468
let timer_token = ctxt
469469
.config
470470
.keys
471-
.github
471+
.github_api_token
472472
.clone()
473-
.expect("needs rust-timer token");
473+
.expect("needs github API token");
474474
let url = format!("{}/commits/{}", repository_url, sha);
475475
let commit_response = client
476476
.get(&url)
@@ -574,7 +574,11 @@ where
574574
B: Into<String>,
575575
{
576576
let body = body.into();
577-
let timer_token = cfg.keys.github.clone().expect("needs rust-timer token");
577+
let timer_token = cfg
578+
.keys
579+
.github_api_token
580+
.clone()
581+
.expect("needs github API token");
578582
let client = reqwest::Client::new();
579583
let req = client
580584
.post(&format!(
@@ -595,7 +599,7 @@ where
595599
pub async fn post_finished(ctxt: &SiteCtxt) {
596600
// If the github token is not configured, do not run this -- we don't want
597601
// to mark things as complete without posting the comment.
598-
if ctxt.config.keys.github.is_none() {
602+
if ctxt.config.keys.github_api_token.is_none() {
599603
return;
600604
}
601605
let conn = ctxt.conn().await;

site/src/load.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ impl TryCommit {
6060
#[derive(Debug, Default, Deserialize)]
6161
pub struct Keys {
6262
/// GitHub API token from the `GITHUB_API_TOKEN` env variable
63-
pub github: Option<String>,
63+
#[serde(rename = "github")]
64+
pub github_api_token: Option<String>,
6465
/// GitHub webhook secret from the `GITHUB_WEBHOOK_SECRET` env variable
65-
pub secret: Option<String>,
66+
#[serde(rename = "secret")]
67+
pub github_webhook_secret: Option<String>,
6668
}
6769

6870
/// Site configuration
@@ -125,8 +127,8 @@ impl SiteCtxt {
125127
} else {
126128
Config {
127129
keys: Keys {
128-
github: std::env::var("GITHUB_API_TOKEN").ok(),
129-
secret: std::env::var("GITHUB_WEBHOOK_SECRET").ok(),
130+
github_api_token: std::env::var("GITHUB_API_TOKEN").ok(),
131+
github_webhook_secret: std::env::var("GITHUB_WEBHOOK_SECRET").ok(),
130132
},
131133
}
132134
};

site/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ impl Server {
13031303
&mut Some(auth).into_iter(),
13041304
)
13051305
.unwrap();
1306-
if auth.0.token() == *ctxt.config.keys.secret.as_ref().unwrap() {
1306+
if auth.0.token() == *ctxt.config.keys.github_webhook_secret.as_ref().unwrap() {
13071307
return true;
13081308
}
13091309
}
@@ -1701,7 +1701,7 @@ fn verify_gh(config: &Config, req: &http::request::Parts, body: &[u8]) -> bool {
17011701
fn verify_gh_sig(cfg: &Config, header: &str, body: &[u8]) -> Option<bool> {
17021702
let key = hmac::Key::new(
17031703
hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY,
1704-
cfg.keys.secret.as_ref().unwrap().as_bytes(),
1704+
cfg.keys.github_webhook_secret.as_ref().unwrap().as_bytes(),
17051705
);
17061706
let sha = header.get(5..)?; // strip sha1=
17071707
let sha = hex::decode(sha).ok()?;

0 commit comments

Comments
 (0)