@@ -4,16 +4,19 @@ use std::path::Path;
44use anyhow:: { Context as _, Result } ;
55use clap:: { Arg , ArgMatches , Command } ;
66use console:: style;
7+ use http:: header:: AUTHORIZATION ;
78use log:: { debug, info} ;
8- use objectstore_client:: { Client , Usecase } ;
9+ use objectstore_client:: { Client , ClientBuilder , Usecase } ;
10+ use secrecy:: ExposeSecret as _;
911use sha2:: { Digest as _, Sha256 } ;
1012use walkdir:: WalkDir ;
1113
1214use crate :: api:: Api ;
13- use crate :: config:: Config ;
15+ use crate :: config:: { Auth , Config } ;
1416use crate :: utils:: api:: get_org_project_id;
1517use crate :: utils:: args:: ArgExt as _;
1618use crate :: utils:: objectstore:: get_objectstore_url;
19+ use http:: { self , HeaderValue } ;
1720
1821const EXPERIMENTAL_WARNING : & str =
1922 "[EXPERIMENTAL] The \" build snapshots\" command is experimental. \
@@ -135,8 +138,26 @@ fn upload_files(
135138 project : & str ,
136139 snapshot_id : & str ,
137140) -> Result < ( ) > {
141+ let config = Config :: current ( ) ;
142+ let auth = config
143+ . get_auth ( )
144+ . ok_or_else ( || anyhow:: anyhow!( "Authentication required" ) ) ?;
145+ let token = match auth {
146+ Auth :: Token ( token) => token. raw ( ) . expose_secret ( ) ,
147+ } ;
148+
138149 let url = get_objectstore_url ( Api :: current ( ) , org) ?;
139- let client = Client :: new ( url) ?;
150+ let client = ClientBuilder :: new ( url. clone ( ) )
151+ . configure_reqwest ( move |r| {
152+ let mut headers = http:: HeaderMap :: new ( ) ;
153+ headers. insert (
154+ AUTHORIZATION ,
155+ HeaderValue :: from_str ( & format ! ( "Bearer {token}" ) )
156+ . expect ( "always a valid header value" ) ,
157+ ) ;
158+ r. default_headers ( headers)
159+ } )
160+ . build ( ) ?;
140161
141162 let ( org, project) = get_org_project_id ( Api :: current ( ) , org, project) ?;
142163 let session = Usecase :: new ( "preprod" )
0 commit comments