Skip to content

Commit 5aafa78

Browse files
authored
Fastly: Mark API token as secret/sensitive information (#6810)
1 parent 7e56c97 commit 5aafa78

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/worker/fastly.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
use anyhow::{anyhow, Context};
2+
use http::HeaderValue;
23
use reqwest::blocking::Client;
4+
use secrecy::{ExposeSecret, SecretString};
35

46
#[derive(Clone, Debug)]
57
pub struct Fastly {
6-
api_token: String,
8+
api_token: SecretString,
79
static_domain_name: String,
810
}
911

1012
impl Fastly {
1113
pub fn from_environment() -> Option<Self> {
12-
let api_token = dotenvy::var("FASTLY_API_TOKEN").ok()?;
14+
let api_token = dotenvy::var("FASTLY_API_TOKEN").ok()?.into();
1315
let static_domain_name = dotenvy::var("S3_CDN").expect("missing S3_CDN");
1416

1517
Some(Self {
@@ -43,8 +45,12 @@ impl Fastly {
4345
);
4446
trace!(?url);
4547

48+
let api_token = self.api_token.expose_secret();
49+
let mut api_token = HeaderValue::try_from(api_token)?;
50+
api_token.set_sensitive(true);
51+
4652
let mut headers = reqwest::header::HeaderMap::new();
47-
headers.append("Fastly-Key", self.api_token.parse()?);
53+
headers.append("Fastly-Key", api_token);
4854

4955
debug!("sending invalidation request to Fastly");
5056
let response = client

0 commit comments

Comments
 (0)