Skip to content

Commit

Permalink
add env variables to match other sdks
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Oct 25, 2024
1 parent 96d68a2 commit 419c168
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,22 @@ async fn new_context(units: UnitLength) -> Result<ExecutorContext> {
.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);
}

Expand Down

0 comments on commit 419c168

Please sign in to comment.