rs_firebase_admin_sdk/credentials/emulator/
mod.rs1#[cfg(test)]
2mod test;
3
4use super::GoogleUserProject;
5use google_cloud_auth::{
6 credentials::{CacheableResource, CredentialsProvider, EntityTag},
7 errors::CredentialsError,
8};
9use headers::{Authorization, HeaderMapExt};
10use http::HeaderMap;
11
12#[derive(Debug, Clone)]
13pub struct EmulatorCredentials {
14 pub(crate) project_id: String,
15}
16
17impl Default for EmulatorCredentials {
18 fn default() -> Self {
19 Self {
20 project_id: std::env::var("GOOGLE_CLOUD_PROJECT").unwrap_or_else(|_| {
21 std::env::var("PROJECT_ID").unwrap_or("demo-firebase-project".into())
22 }),
23 }
24 }
25}
26
27impl CredentialsProvider for EmulatorCredentials {
28 async fn headers(
29 &self,
30 _extensions: http::Extensions,
31 ) -> Result<CacheableResource<HeaderMap>, CredentialsError> {
32 let mut headers = HeaderMap::with_capacity(2);
33 headers.typed_insert(Authorization::bearer("owner").expect("Should always be valid"));
34
35 headers.typed_insert(GoogleUserProject(self.project_id.clone()));
36
37 Ok(CacheableResource::New {
38 entity_tag: EntityTag::new(),
39 data: headers,
40 })
41 }
42
43 async fn universe_domain(&self) -> Option<String> {
44 unimplemented!("unimplemented")
45 }
46}