Skip to content

Commit

Permalink
feat: default project id (#191)
Browse files Browse the repository at this point in the history
* feat: default project id

* fix: clippy

* fix: use match
  • Loading branch information
ilteoood authored Sep 13, 2024
1 parent 84f999f commit c28d147
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ impl FirestoreDb {
.await
}

pub async fn for_default_project_id() -> FirestoreResult<Self> {
match FirestoreDbOptions::for_default_project_id().await {
Some(options) => Self::with_options(options).await,
_ => Err(FirestoreError::InvalidParametersError(
FirestoreInvalidParametersError::new(FirestoreInvalidParametersPublicDetails::new(
"google_project_id".to_string(),
"Unable to retrieve google_project_id".to_string(),
)),
)),
}
}

pub async fn with_options_service_account_key_file(
options: FirestoreDbOptions,
service_account_key_path: std::path::PathBuf,
Expand Down
9 changes: 9 additions & 0 deletions src/db/options.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use gcloud_sdk::GoogleEnvironment;
use rsb_derive::Builder;

#[derive(Debug, Eq, PartialEq, Clone, Builder)]
Expand All @@ -13,4 +14,12 @@ pub struct FirestoreDbOptions {
pub firebase_api_url: Option<String>,
}

impl FirestoreDbOptions {
pub async fn for_default_project_id() -> Option<FirestoreDbOptions> {
let google_project_id = GoogleEnvironment::detect_google_project_id().await;

google_project_id.map(FirestoreDbOptions::new)
}
}

pub const FIREBASE_DEFAULT_DATABASE_ID: &str = "(default)";

0 comments on commit c28d147

Please sign in to comment.