@@ -10,6 +10,8 @@ use std::io::Read;
10
10
use time:: Timespec ;
11
11
use tokio:: runtime:: Runtime ;
12
12
13
+ pub ( crate ) static S3_BUCKET_NAME : & str = "rust-docs-rs" ;
14
+
13
15
pub ( crate ) struct S3Backend < ' a > {
14
16
client : S3Client ,
15
17
bucket : & ' a str ,
@@ -100,6 +102,32 @@ fn parse_timespec(raw: &str) -> Result<Timespec, Error> {
100
102
Ok ( time:: strptime ( raw, TIME_FMT ) ?. to_timespec ( ) )
101
103
}
102
104
105
+ pub ( crate ) fn s3_client ( ) -> Option < S3Client > {
106
+ // If AWS keys aren't configured, then presume we should use the DB exclusively
107
+ // for file storage.
108
+ if std:: env:: var_os ( "AWS_ACCESS_KEY_ID" ) . is_none ( ) && std:: env:: var_os ( "FORCE_S3" ) . is_none ( ) {
109
+ return None ;
110
+ }
111
+ let creds = match DefaultCredentialsProvider :: new ( ) {
112
+ Ok ( creds) => creds,
113
+ Err ( err) => {
114
+ warn ! ( "failed to retrieve AWS credentials: {}" , err) ;
115
+ return None ;
116
+ }
117
+ } ;
118
+ Some ( S3Client :: new_with (
119
+ rusoto_core:: request:: HttpClient :: new ( ) . unwrap ( ) ,
120
+ creds,
121
+ std:: env:: var ( "S3_ENDPOINT" )
122
+ . ok ( )
123
+ . map ( |e| Region :: Custom {
124
+ name : std:: env:: var ( "S3_REGION" ) . unwrap_or_else ( |_| "us-west-1" . to_owned ( ) ) ,
125
+ endpoint : e,
126
+ } )
127
+ . unwrap_or ( Region :: UsWest1 ) ,
128
+ ) )
129
+ }
130
+
103
131
#[ cfg( test) ]
104
132
pub ( crate ) mod tests {
105
133
use super :: * ;
@@ -259,31 +287,3 @@ pub(crate) mod tests {
259
287
// NOTE: On s3, it will succeed and create a file called `/`.
260
288
// NOTE: On min.io, it will fail with 'Object name contains unsupported characters.'
261
289
}
262
-
263
- pub ( crate ) static S3_BUCKET_NAME : & str = "rust-docs-rs" ;
264
-
265
- pub ( crate ) fn s3_client ( ) -> Option < S3Client > {
266
- // If AWS keys aren't configured, then presume we should use the DB exclusively
267
- // for file storage.
268
- if std:: env:: var_os ( "AWS_ACCESS_KEY_ID" ) . is_none ( ) && std:: env:: var_os ( "FORCE_S3" ) . is_none ( ) {
269
- return None ;
270
- }
271
- let creds = match DefaultCredentialsProvider :: new ( ) {
272
- Ok ( creds) => creds,
273
- Err ( err) => {
274
- warn ! ( "failed to retrieve AWS credentials: {}" , err) ;
275
- return None ;
276
- }
277
- } ;
278
- Some ( S3Client :: new_with (
279
- rusoto_core:: request:: HttpClient :: new ( ) . unwrap ( ) ,
280
- creds,
281
- std:: env:: var ( "S3_ENDPOINT" )
282
- . ok ( )
283
- . map ( |e| Region :: Custom {
284
- name : std:: env:: var ( "S3_REGION" ) . unwrap_or_else ( |_| "us-west-1" . to_owned ( ) ) ,
285
- endpoint : e,
286
- } )
287
- . unwrap_or ( Region :: UsWest1 ) ,
288
- ) )
289
- }
0 commit comments