Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/build-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- name: Generate .env from Doppler secrets
# Only the keys build.rs compiles into the binary
shell: bash
run: doppler secrets download --no-file --format env | grep -E '^(SITE_HOST|CONVEX_HTTP_URL|PLAYSITE_HOST)=' > .env
run: doppler secrets download --no-file --format env | grep -E '^(SITE_HOST|CONVEX_HTTP_URL|PLAYSITE_HOST|CF_ACCESS_CLIENT_ID|CF_ACCESS_CLIENT_SECRET)=' > .env
env:
DOPPLER_TOKEN: ${{ secrets.DOPPLER_TOKEN }}

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
- name: "Install Doppler CLI"
uses: "dopplerhq/cli-action@v4"
- name: "Generate .env from Doppler secrets"
run: "doppler secrets download --no-file --format env | grep -E '^(SITE_HOST|CONVEX_HTTP_URL|PLAYSITE_HOST)=' > .env"
run: "doppler secrets download --no-file --format env | grep -E '^(SITE_HOST|CONVEX_HTTP_URL|PLAYSITE_HOST|CF_ACCESS_CLIENT_ID|CF_ACCESS_CLIENT_SECRET)=' > .env"
shell: "bash"
env:
"DOPPLER_TOKEN": "${{ secrets.DOPPLER_TOKEN }}"
Expand Down
11 changes: 11 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,20 @@ fn main() {
};
println!("cargo:rustc-env=CONFIG_DIR={}", config_dir);

// Optional Cloudflare Access credentials (only needed for staging)
let optional = ["CF_ACCESS_CLIENT_ID", "CF_ACCESS_CLIENT_SECRET"];

for var in optional {
if let Ok(value) = std::env::var(var) {
println!("cargo:rustc-env={}={}", var, value);
}
}

println!("cargo:rerun-if-changed=.env");
println!("cargo:rerun-if-env-changed=SITE_HOST");
println!("cargo:rerun-if-env-changed=CONVEX_HTTP_URL");
println!("cargo:rerun-if-env-changed=PLAYSITE_HOST");
println!("cargo:rerun-if-env-changed=CF_ACCESS_CLIENT_ID");
println!("cargo:rerun-if-env-changed=CF_ACCESS_CLIENT_SECRET");
}

30 changes: 29 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct Config {
/// — serves the default-entrypoint scripts `wavedash dev` boots engine
/// builds with. https-prefixed here like site_host.
playsite_host: String,
cf_access_client_id: Option<String>,
cf_access_client_secret: Option<String>,
}

impl Config {
Expand All @@ -75,6 +77,8 @@ impl Config {
open_browser_website_host: site_host,
api_host: env!("CONVEX_HTTP_URL").to_string(),
playsite_host,
cf_access_client_id: option_env!("CF_ACCESS_CLIENT_ID").map(|s| s.to_string()),
cf_access_client_secret: option_env!("CF_ACCESS_CLIENT_SECRET").map(|s| s.to_string()),
Comment thread
calvinstudebaker marked this conversation as resolved.
Resolved
})
}
}
Expand All @@ -99,14 +103,38 @@ pub fn credentials_path() -> Result<PathBuf> {
/// "please upgrade" prompts without parsing User-Agent.
pub const CLI_VERSION_HEADER: &str = "X-Wavedash-CLI-Version";

/// Create an HTTP client configured with the CLI version header.
/// Create an HTTP client configured with the CLI version header (always)
/// and Cloudflare Access headers (only on staging when creds are baked in).
pub fn create_http_client() -> Result<reqwest::Client> {
let config = Config::load()?;

let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
CLI_VERSION_HEADER,
reqwest::header::HeaderValue::from_static(env!("CARGO_PKG_VERSION")),
);

let api_host = &config.api_host;
let needs_cf_headers = api_host
.trim_start_matches("https://")
.trim_start_matches("http://")
.ends_with("staging.wavedash.gg");
Comment thread
calvinstudebaker marked this conversation as resolved.
Resolved

if needs_cf_headers {
if let (Some(client_id), Some(client_secret)) =
(&config.cf_access_client_id, &config.cf_access_client_secret)
{
headers.insert(
"CF-Access-Client-Id",
reqwest::header::HeaderValue::from_str(client_id)?,
);
headers.insert(
"CF-Access-Client-Secret",
reqwest::header::HeaderValue::from_str(client_secret)?,
);
Comment thread
calvinstudebaker marked this conversation as resolved.
Resolved
}
}

Ok(reqwest::Client::builder().default_headers(headers).build()?)
}

Expand Down
Loading