@@ -6,7 +6,6 @@ use std::str::FromStr as _;
66use anyhow:: { Context as _, Result } ;
77use clap:: { Arg , ArgMatches , Command } ;
88use console:: style;
9- use http:: header:: AUTHORIZATION ;
109use log:: { debug, info, warn} ;
1110use objectstore_client:: { ClientBuilder , ExpirationPolicy , Usecase } ;
1211use serde:: { Deserialize , Serialize } ;
@@ -18,7 +17,6 @@ use secrecy::ExposeSecret as _;
1817use crate :: api:: Api ;
1918use crate :: config:: { Auth , Config } ;
2019use crate :: utils:: args:: ArgExt as _;
21- use http:: { self , HeaderValue } ;
2220
2321const EXPERIMENTAL_WARNING : & str =
2422 "[EXPERIMENTAL] The \" build snapshots\" command is experimental. \
@@ -229,19 +227,13 @@ fn upload_images(
229227 let expiration = ExpirationPolicy :: from_str ( & options. objectstore . expiration_policy )
230228 . context ( "Failed to parse expiration policy from upload options" ) ?;
231229
232- // TODO: replace with auth from `ObjectstoreUploadOptions` when available
233- let auth = match * authenticated_api. get_auth ( ) {
234- Auth :: Token ( ref token) => {
235- format ! ( "Bearer {}" , token. raw( ) . expose_secret( ) )
236- }
237- } ;
238- let auth = HeaderValue :: from_str ( & auth) . context ( "Invalid auth token" ) ?;
239-
240230 let client = ClientBuilder :: new ( options. objectstore . url )
241- . configure_reqwest ( move |r| {
242- let mut headers = http:: HeaderMap :: new ( ) ;
243- headers. insert ( AUTHORIZATION , auth) ;
244- r. default_headers ( headers)
231+ . token ( {
232+ // TODO: replace with auth from `ObjectstoreUploadOptions` when appropriate
233+ let auth = match authenticated_api. get_auth ( ) {
234+ Auth :: Token ( token) => token. raw ( ) . expose_secret ( ) . to_owned ( ) ,
235+ } ;
236+ auth
245237 } )
246238 . build ( ) ?;
247239
@@ -291,11 +283,9 @@ fn upload_images(
291283 ) ;
292284 }
293285
294- let upload = runtime
295- . block_on ( async { many_builder. send ( ) . await } )
296- . context ( "Failed to upload image files" ) ?;
286+ let result = runtime. block_on ( async { many_builder. send ( ) . error_for_failures ( ) . await } ) ;
297287
298- match upload . error_for_failures ( ) {
288+ match result {
299289 Ok ( ( ) ) => {
300290 println ! (
301291 "{} Uploaded {} image {}" ,
@@ -307,10 +297,11 @@ fn upload_images(
307297 }
308298 Err ( errors) => {
309299 eprintln ! ( "There were errors uploading images:" ) ;
310- for error in & errors {
300+ let mut error_count = 0 ;
301+ for error in errors {
311302 eprintln ! ( " {}" , style( error) . red( ) ) ;
303+ error_count += 1 ;
312304 }
313- let error_count = errors. len ( ) ;
314305 anyhow:: bail!( "Failed to upload {error_count} out of {image_count} images" )
315306 }
316307 }
0 commit comments