From da3870ea316565a9152461a26551c9d2daf74090 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 2 May 2022 15:42:52 +0200 Subject: [PATCH] Pass secret token when uploading crashes --- crates/auto_update/src/auto_update.rs | 6 ++---- crates/client/src/client.rs | 2 ++ crates/zed/src/main.rs | 10 +++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index a74e08daca..f722167b6f 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -1,6 +1,5 @@ use anyhow::{anyhow, Context, Result}; -use client::http::HttpClient; - +use client::{http::HttpClient, ZED_SECRET_CLIENT_TOKEN}; use gpui::{ actions, elements::{Empty, MouseEventHandler, Text}, @@ -16,7 +15,6 @@ use std::{env, ffi::OsString, path::PathBuf, sync::Arc, time::Duration}; use workspace::{ItemHandle, StatusItemView}; const POLL_INTERVAL: Duration = Duration::from_secs(60 * 60); -const ACCESS_TOKEN: &'static str = "618033988749894"; lazy_static! { pub static ref ZED_APP_VERSION: Option = env::var("ZED_APP_VERSION") @@ -135,7 +133,7 @@ impl AutoUpdater { }); let mut response = client .get( - &format!("{server_url}/api/releases/latest?token={ACCESS_TOKEN}&asset=Zed.dmg"), + &format!("{server_url}/api/releases/latest?token={ZED_SECRET_CLIENT_TOKEN}&asset=Zed.dmg"), Default::default(), true, ) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 5bf07a956f..e6fc1bf19a 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -50,6 +50,8 @@ lazy_static! { .and_then(|s| if s.is_empty() { None } else { Some(s) }); } +pub const ZED_SECRET_CLIENT_TOKEN: &'static str = "618033988749894"; + actions!(client, [Authenticate]); pub fn init(rpc: Arc, cx: &mut MutableAppContext) { diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index ea38a1abde..94eeffbd9d 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -12,7 +12,7 @@ use cli::{ use client::{ self, http::{self, HttpClient}, - ChannelList, UserStore, + ChannelList, UserStore, ZED_SECRET_CLIENT_TOKEN, }; use fs::OpenOptions; use futures::{ @@ -296,7 +296,8 @@ fn init_crash_handler( .context("error reading crash file")?; let body = serde_json::to_string(&json!({ "text": text, - "version": version + "version": version, + "token": ZED_SECRET_CLIENT_TOKEN, })) .unwrap(); let request = Request::builder() @@ -311,7 +312,10 @@ fn init_crash_handler( .context("error removing crash after sending it successfully") .log_err(); } else { - log::error!("{:?}", response); + return Err(anyhow!( + "error uploading crash to server: {}", + response.status() + )); } } Ok::<_, anyhow::Error>(())