1- use crate :: MAuthInfo ;
2- use mauth_core:: { signer:: Signer , verifier:: Verifier } ;
1+ use crate :: { MAuthInfo , CLIENT } ;
2+ use mauth_core:: signer:: Signer ;
3+ use reqwest:: Client ;
34use reqwest:: Url ;
5+ use reqwest_middleware:: ClientBuilder ;
46use serde:: Deserialize ;
5- use std:: collections:: HashMap ;
67use std:: io;
7- use std:: sync:: { Arc , RwLock } ;
88use thiserror:: Error ;
99use uuid:: Uuid ;
1010
@@ -15,7 +15,7 @@ impl MAuthInfo {
1515 /// present in the current user's home directory. Returns an enum error type that includes the
1616 /// error types of all crates used.
1717 pub fn from_default_file ( ) -> Result < MAuthInfo , ConfigReadError > {
18- Self :: from_config_section ( & Self :: config_section_from_default_file ( ) ?, None )
18+ Self :: from_config_section ( & Self :: config_section_from_default_file ( ) ?)
1919 }
2020
2121 pub ( crate ) fn config_section_from_default_file ( ) -> Result < ConfigFileSection , ConfigReadError > {
@@ -35,10 +35,7 @@ impl MAuthInfo {
3535 /// Construct the MAuthInfo struct based on a passed-in ConfigFileSection instance. The
3636 /// optional input_keystore is present to support internal cloning and need not be provided
3737 /// if being used outside of the crate.
38- pub fn from_config_section (
39- section : & ConfigFileSection ,
40- input_keystore : Option < Arc < RwLock < HashMap < Uuid , Verifier > > > > ,
41- ) -> Result < MAuthInfo , ConfigReadError > {
38+ pub fn from_config_section ( section : & ConfigFileSection ) -> Result < MAuthInfo , ConfigReadError > {
4239 let full_uri: Url = format ! (
4340 "{}/mauth/{}/security_tokens/" ,
4441 & section. mauth_baseurl, & section. mauth_api_version
@@ -55,15 +52,22 @@ impl MAuthInfo {
5552 return Err ( ConfigReadError :: NoPrivateKey ) ;
5653 }
5754
58- Ok ( MAuthInfo {
55+ let mauth_info = MAuthInfo {
5956 app_id : Uuid :: parse_str ( & section. app_uuid ) ?,
6057 mauth_uri_base : full_uri,
61- remote_key_store : input_keystore
62- . unwrap_or_else ( || Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ) ,
6358 sign_with_v1_also : !section. v2_only_sign_requests . unwrap_or ( false ) ,
6459 allow_v1_auth : !section. v2_only_authenticate . unwrap_or ( false ) ,
6560 signer : Signer :: new ( section. app_uuid . clone ( ) , pk_data. unwrap ( ) ) ?,
66- } )
61+ } ;
62+
63+ CLIENT . get_or_init ( || {
64+ let builder = ClientBuilder :: new ( Client :: new ( ) ) . with ( mauth_info. clone ( ) ) ;
65+ #[ cfg( any( feature = "tracing-otel-26" , feature = "tracing-otel-27" ) ) ]
66+ let builder = builder. with ( reqwest_tracing:: TracingMiddleware :: default ( ) ) ;
67+ builder. build ( )
68+ } ) ;
69+
70+ Ok ( mauth_info)
6771 }
6872}
6973
@@ -145,7 +149,7 @@ mod test {
145149 v2_only_sign_requests : None ,
146150 v2_only_authenticate : None ,
147151 } ;
148- let load_result = MAuthInfo :: from_config_section ( & bad_config, None ) ;
152+ let load_result = MAuthInfo :: from_config_section ( & bad_config) ;
149153 assert ! ( matches!( load_result, Err ( ConfigReadError :: InvalidUri ( _) ) ) ) ;
150154 }
151155
@@ -160,7 +164,7 @@ mod test {
160164 v2_only_sign_requests : None ,
161165 v2_only_authenticate : None ,
162166 } ;
163- let load_result = MAuthInfo :: from_config_section ( & bad_config, None ) ;
167+ let load_result = MAuthInfo :: from_config_section ( & bad_config) ;
164168 assert ! ( matches!(
165169 load_result,
166170 Err ( ConfigReadError :: FileReadError ( _) )
@@ -180,7 +184,7 @@ mod test {
180184 v2_only_sign_requests : None ,
181185 v2_only_authenticate : None ,
182186 } ;
183- let load_result = MAuthInfo :: from_config_section ( & bad_config, None ) ;
187+ let load_result = MAuthInfo :: from_config_section ( & bad_config) ;
184188 fs:: remove_file ( & filename) . await . unwrap ( ) ;
185189 assert ! ( matches!(
186190 load_result,
@@ -201,7 +205,7 @@ mod test {
201205 v2_only_sign_requests : None ,
202206 v2_only_authenticate : None ,
203207 } ;
204- let load_result = MAuthInfo :: from_config_section ( & bad_config, None ) ;
208+ let load_result = MAuthInfo :: from_config_section ( & bad_config) ;
205209 fs:: remove_file ( & filename) . await . unwrap ( ) ;
206210 assert ! ( matches!(
207211 load_result,
0 commit comments