From 4a42025c286a987b5f962419ea14576bbdede356 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 23 Mar 2022 12:25:06 -0600 Subject: [PATCH] Authenticate on startup if ZED_IMPERSONATE is assigned Co-Authored-By: Max Brunsfeld --- crates/client/src/client.rs | 2 +- crates/zed/src/main.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index db4478f489..1bae6cd49e 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -45,7 +45,7 @@ pub use user::*; lazy_static! { static ref ZED_SERVER_URL: String = std::env::var("ZED_SERVER_URL").unwrap_or("https://zed.dev".to_string()); - static ref IMPERSONATE_LOGIN: Option = std::env::var("ZED_IMPERSONATE") + pub static ref IMPERSONATE_LOGIN: Option = std::env::var("ZED_IMPERSONATE") .ok() .and_then(|s| if s.is_empty() { None } else { Some(s) }); } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index af0c98506d..b79f7f1bb0 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -81,8 +81,14 @@ fn main() { cx.spawn({ let client = client.clone(); |cx| async move { - if !stdout_is_a_pty() && client.has_keychain_credentials(&cx) { - client.authenticate_and_connect(true, &cx).await?; + if stdout_is_a_pty() { + if client::IMPERSONATE_LOGIN.is_some() { + client.authenticate_and_connect(false, &cx).await?; + } + } else { + if client.has_keychain_credentials(&cx) { + client.authenticate_and_connect(true, &cx).await?; + } } Ok::<_, anyhow::Error>(()) }