Skip to content

Commit

Permalink
Add logging for missing blob store env vars
Browse files Browse the repository at this point in the history
Co-authored-by: Marshall <marshall@zed.dev>
  • Loading branch information
maxbrunsfeld and maxdeviant committed Feb 15, 2024
1 parent 0482adc commit afe6045
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions crates/collab/src/api/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ const EXTENSION_DOWNLOAD_URL_LIFETIME: Duration = Duration::from_secs(3 * 60);

pub fn fetch_extensions_from_blob_store_periodically(app_state: Arc<AppState>, executor: Executor) {
let Some(blob_store_client) = app_state.blob_store_client.clone() else {
log::info!("no blob store client");
return;
};
let Some(blob_store_bucket) = app_state.config.blob_store_bucket.clone() else {
log::info!("no blob store bucket");
return;
};

Expand Down
32 changes: 25 additions & 7 deletions crates/collab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ pub mod rpc;
#[cfg(test)]
mod tests;

use anyhow::anyhow;
use aws_config::{BehaviorVersion, Region};
use axum::{http::StatusCode, response::IntoResponse};
use db::Database;
use executor::Executor;
use serde::Deserialize;
use std::{path::PathBuf, sync::Arc};
use util::ResultExt;

pub type Result<T, E = Error> = std::result::Result<T, E>;

Expand Down Expand Up @@ -153,28 +155,44 @@ impl AppState {
let this = Self {
db: Arc::new(db),
live_kit_client,
blob_store_client: build_blob_store_client(&config).await,
blob_store_client: build_blob_store_client(&config).await.log_err(),
config,
};
Ok(Arc::new(this))
}
}

async fn build_blob_store_client(config: &Config) -> Option<aws_sdk_s3::Client> {
async fn build_blob_store_client(config: &Config) -> anyhow::Result<aws_sdk_s3::Client> {
let keys = aws_sdk_s3::config::Credentials::new(
config.blob_store_access_key.clone()?,
config.blob_store_secret_key.clone()?,
config
.blob_store_access_key
.clone()
.ok_or_else(|| anyhow!("missing blob_store_access_key"))?,
config
.blob_store_secret_key
.clone()
.ok_or_else(|| anyhow!("missing blob_store_secret_key"))?,
None,
None,
"env",
);

let s3_config = aws_config::defaults(BehaviorVersion::latest())
.endpoint_url(config.blob_store_url.as_ref()?)
.region(Region::new(config.blob_store_region.clone()?))
.endpoint_url(
config
.blob_store_url
.as_ref()
.ok_or_else(|| anyhow!("missing blob_store_url"))?,
)
.region(Region::new(
config
.blob_store_region
.clone()
.ok_or_else(|| anyhow!("missing blob_store_region"))?,
))
.credentials_provider(keys)
.load()
.await;

Some(aws_sdk_s3::Client::new(&s3_config))
Ok(aws_sdk_s3::Client::new(&s3_config))
}

0 comments on commit afe6045

Please sign in to comment.