1use std::sync::Arc;
2
3use futures::future::BoxFuture;
4
5use crate::CredentialProvider;
6use crate::{ClientOptions, RequestSigner, Result, RetryConfig};
7
8pub use builder::*;
9pub use credential::GcpCredential;
10pub use token::*;
11
12mod builder;
13pub(crate) mod credential;
14mod token;
15
16pub type GcpCredentialProvider = Arc<dyn CredentialProvider<Credential = GcpCredential>>;
17
18#[derive(Debug, Clone)]
19pub struct GoogleConfig {
20 pub credentials: GcpCredentialProvider,
21
22 pub retry_config: RetryConfig,
23
24 pub client_options: ClientOptions,
25}
26
27impl GoogleConfig {
28 pub(crate) fn new(
29 credentials: GcpCredentialProvider,
30 retry_config: RetryConfig,
31 client_options: ClientOptions,
32 ) -> Self {
33 Self {
34 credentials,
35 retry_config,
36 client_options,
37 }
38 }
39
40 pub(crate) async fn get_credential(&self) -> Result<Arc<GcpCredential>> {
41 self.credentials.get_credential().await
42 }
43}
44
45impl RequestSigner for GoogleConfig {
46 fn sign<'a>(
47 &'a self,
48 req: reqwest::RequestBuilder,
49 ) -> BoxFuture<'a, Result<reqwest::RequestBuilder>> {
50 Box::pin(async move {
51 let credential = self.get_credential().await?;
52 Ok(req.bearer_auth(&credential.bearer))
53 })
54 }
55}