@@ -6,13 +6,11 @@ use cloud_storage::{
66} ;
77use slog:: { info, Logger } ;
88use std:: { env, path:: Path } ;
9- use tokio_util:: { codec:: BytesCodec , codec :: FramedRead } ;
9+ use tokio_util:: codec:: { BytesCodec , FramedRead } ;
1010
11- use mithril_common:: logging:: LoggerExtensions ;
12- use mithril_common:: StdResult ;
11+ use mithril_common:: { logging:: LoggerExtensions , StdResult } ;
1312
14- use crate :: file_uploaders:: FileLocation ;
15- use crate :: FileUploader ;
13+ use crate :: { file_uploaders:: FileUri , FileUploader } ;
1614
1715/// GcpUploader represents a Google Cloud Platform file uploader interactor
1816pub struct GcpUploader {
@@ -31,21 +29,21 @@ impl GcpUploader {
3129 }
3230 }
3331
34- fn get_location ( & self , filename : & str ) -> String {
35- if self . use_cdn_domain {
36- format ! ( "https://{}/{}" , self . bucket, filename)
37- } else {
38- format ! (
39- "https://storage.googleapis.com/{}/{}" ,
40- self . bucket, filename
41- )
32+ fn get_location ( & self , filename : & str ) -> FileUri {
33+ let mut uri = vec ! [ ] ;
34+ if !self . use_cdn_domain {
35+ uri. push ( "storage.googleapis.com" ) ;
4236 }
37+ uri. push ( & self . bucket ) ;
38+ uri. push ( filename) ;
39+
40+ FileUri ( format ! ( "https://{}" , uri. join( "/" ) ) )
4341 }
4442}
4543
4644#[ async_trait]
4745impl FileUploader for GcpUploader {
48- async fn upload ( & self , filepath : & Path ) -> StdResult < FileLocation > {
46+ async fn upload ( & self , filepath : & Path ) -> StdResult < FileUri > {
4947 if env:: var ( "GOOGLE_APPLICATION_CREDENTIALS_JSON" ) . is_err ( ) {
5048 return Err ( anyhow ! (
5149 "Missing GOOGLE_APPLICATION_CREDENTIALS_JSON environment variable" . to_string( )
@@ -118,7 +116,7 @@ mod tests {
118116
119117 let location = file_uploader. get_location ( filename) ;
120118
121- assert_eq ! ( expected_location, location) ;
119+ assert_eq ! ( FileUri ( expected_location) , location) ;
122120 }
123121
124122 #[ tokio:: test]
@@ -135,6 +133,6 @@ mod tests {
135133
136134 let location = file_uploader. get_location ( filename) ;
137135
138- assert_eq ! ( expected_location, location) ;
136+ assert_eq ! ( FileUri ( expected_location) , location) ;
139137 }
140138}
0 commit comments