From 419c1687a3405383a138c348150a75f052ab78d2 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Fri, 25 Oct 2024 15:44:55 -0700 Subject: [PATCH] add env variables to match other sdks Signed-off-by: Jess Frazelle --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f4d246..5f78a6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3746,7 +3746,7 @@ dependencies = [ [[package]] name = "zoo-kcl" -version = "0.1.42" +version = "0.1.43" dependencies = [ "anyhow", "kcl-lib", diff --git a/Cargo.toml b/Cargo.toml index 9b3b4e8..3e373dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zoo-kcl" -version = "0.1.42" +version = "0.1.43" edition = "2021" repository = "https://github.com/kittycad/kcl.py" diff --git a/src/lib.rs b/src/lib.rs index 9504954..7512e81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -198,12 +198,22 @@ async fn new_context(units: UnitLength) -> Result { .tcp_keepalive(std::time::Duration::from_secs(600)) .http1_only(); - let token = std::env::var("KITTYCAD_API_TOKEN").expect("KITTYCAD_API_TOKEN not set"); + let token = if let Ok(token) = std::env::var("KITTYCAD_API_TOKEN") { + token + } else if let Ok(token) = std::env::var("ZOO_API_TOKEN") { + token + } else { + return Err(anyhow::anyhow!( + "No API token found in environment variables. Use KITTYCAD_API_TOKEN or ZOO_API_TOKEN" + )); + }; // Create the client. let mut client = kittycad::Client::new_from_reqwest(token, http_client, ws_client); // Set a local engine address if it's set. - if let Ok(addr) = std::env::var("KITTYCAD_HOST") { + if let Ok(addr) = std::env::var("ZOO_HOST") { + client.set_base_url(addr); + } else if let Ok(addr) = std::env::var("KITTYCAD_HOST") { client.set_base_url(addr); }