Commit
+22 -29 +/-1 browse
1 | diff --git a/src/storage/s3.rs b/src/storage/s3.rs |
2 | index bcafa75..668b468 100644 |
3 | --- a/src/storage/s3.rs |
4 | +++ b/src/storage/s3.rs |
5 | @@ -39,6 +39,9 @@ use super::{LFSObject, Storage, StorageKey, StorageStream}; |
6 | use rusoto_s3::util::{PreSignedRequest, PreSignedRequestOption}; |
7 | use std::time::Duration; |
8 | |
9 | + type BoxedCredentialProvider = |
10 | + Box<dyn ProvideAwsCredentials + Send + Sync + 'static>; |
11 | + |
12 | #[derive(Debug, From, Display)] |
13 | pub enum Error { |
14 | Get(RusotoError<GetObjectError>), |
15 | @@ -113,8 +116,8 @@ pub struct Backend<C = S3Client> { |
16 | /// S3 client. |
17 | client: C, |
18 | |
19 | - // Aws Credentials. Used for signing URLs. |
20 | - credential_provider: Box<dyn ProvideAwsCredentials + Send + Sync + 'static>, |
21 | + // AWS Credentials. Used for signing URLs. |
22 | + credential_provider: BoxedCredentialProvider, |
23 | |
24 | /// Name of the bucket to use. |
25 | bucket: String, |
26 | @@ -168,23 +171,21 @@ impl Backend { |
27 | // Check if there is any k8s credential provider. If there is, use it. |
28 | let k8s_provider = WebIdentityProvider::from_k8s_env(); |
29 | |
30 | - let (client, credential_provider): ( |
31 | - S3Client, |
32 | - Box<dyn ProvideAwsCredentials + Send + Sync + 'static>, |
33 | - ) = if k8s_provider.credentials().await.is_ok() { |
34 | - log::info!("Using credentials from Kubernetes"); |
35 | - let provider = AutoRefreshingProvider::new(k8s_provider)?; |
36 | - let client = S3Client::new_with( |
37 | - HttpClient::new()?, |
38 | - provider.clone(), |
39 | - region.clone(), |
40 | - ); |
41 | - (client, Box::new(provider)) |
42 | - } else { |
43 | - let client = S3Client::new(region.clone()); |
44 | - let provider = DefaultCredentialsProvider::new()?; |
45 | - (client, Box::new(provider)) |
46 | - }; |
47 | + let (client, credential_provider): (_, BoxedCredentialProvider) = |
48 | + if k8s_provider.credentials().await.is_ok() { |
49 | + log::info!("Using credentials from Kubernetes"); |
50 | + let provider = AutoRefreshingProvider::new(k8s_provider)?; |
51 | + let client = S3Client::new_with( |
52 | + HttpClient::new()?, |
53 | + provider.clone(), |
54 | + region.clone(), |
55 | + ); |
56 | + (client, Box::new(provider)) |
57 | + } else { |
58 | + let client = S3Client::new(region.clone()); |
59 | + let provider = DefaultCredentialsProvider::new()?; |
60 | + (client, Box::new(provider)) |
61 | + }; |
62 | |
63 | Backend::with_client( |
64 | client, |
65 | @@ -205,9 +206,7 @@ impl<C> Backend<C> { |
66 | prefix: String, |
67 | cdn: Option<String>, |
68 | region: Region, |
69 | - credential_provider: Box< |
70 | - dyn ProvideAwsCredentials + Send + Sync + 'static, |
71 | - >, |
72 | + credential_provider: BoxedCredentialProvider, |
73 | ) -> Result<Self, Error> |
74 | where |
75 | C: S3 + Clone, |
76 | @@ -353,13 +352,7 @@ where |
77 | key: self.key_to_path(&key), |
78 | ..Default::default() |
79 | }; |
80 | - let credentials = self.credential_provider.credentials().await; |
81 | - let credentials = match credentials { |
82 | - Ok(credentials) => credentials, |
83 | - Err(_) => { |
84 | - return None; |
85 | - } |
86 | - }; |
87 | + let credentials = self.credential_provider.credentials().await.ok()?; |
88 | let presigned_url = request.get_presigned_url( |
89 | &self.region, |
90 | &credentials, |