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
4 changes: 3 additions & 1 deletion .github/build-setup.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
- name: Install Doppler CLI
uses: dopplerhq/cli-action@v4
- name: Generate .env from Doppler secrets
run: doppler secrets download --no-file --format env > .env
# 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
env:
DOPPLER_TOKEN: ${{ secrets.DOPPLER_TOKEN }}

3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ jobs:
- name: "Install Doppler CLI"
uses: "dopplerhq/cli-action@v4"
- name: "Generate .env from Doppler secrets"
run: "doppler secrets download --no-file --format env > .env"
run: "doppler secrets download --no-file --format env | grep -E '^(SITE_HOST|CONVEX_HTTP_URL|PLAYSITE_HOST)=' > .env"
shell: "bash"
env:
"DOPPLER_TOKEN": "${{ secrets.DOPPLER_TOKEN }}"
- name: Install dist
Expand Down
11 changes: 0 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,9 @@ 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: 1 addition & 29 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ 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 @@ -77,8 +75,6 @@ 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()),
})
}
}
Expand All @@ -103,38 +99,14 @@ 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 (always)
/// and Cloudflare Access headers (only on staging when creds are baked in).
/// Create an HTTP client configured with the CLI version header.
Comment thread
calvinstudebaker marked this conversation as resolved.
Resolved
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");

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)?,
);
}
}

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

Expand Down
Loading