Pass secret token when uploading crashes

Antonio Scandurra created

Change summary

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(-)

Detailed changes

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<AppVersion> = 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,
             )

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<Client>, cx: &mut MutableAppContext) {

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>(())