@@ -163,11 +163,10 @@ impl Callback {
163
163
let resource = resource. to_string ( ) ;
164
164
let client_id = client_id. map ( |s| s. to_string ( ) ) ;
165
165
let mut url = format ! (
166
- "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource={}" ,
167
- resource
166
+ "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource={resource}"
168
167
) ;
169
168
if let Some ( ref client_id) = client_id {
170
- url. push_str ( & format ! ( "&client_id={}" , client_id ) ) ;
169
+ url. push_str ( & format ! ( "&client_id={client_id}" ) ) ;
171
170
}
172
171
Self :: new_function (
173
172
move |_| {
@@ -182,7 +181,7 @@ impl Callback {
182
181
. map_err ( |e| {
183
182
Error :: authentication_error (
184
183
MONGODB_OIDC_STR ,
185
- & format ! ( "Failed to get access token from Azure IDMS: {}" , e ) ,
184
+ & format ! ( "Failed to get access token from Azure IDMS: {e}" ) ,
186
185
)
187
186
} ) ;
188
187
let response = response?;
@@ -191,7 +190,7 @@ impl Callback {
191
190
. map_err ( |e| {
192
191
Error :: authentication_error (
193
192
MONGODB_OIDC_STR ,
194
- & format ! ( "Failed to get access token from Azure IDMS: {}" , e ) ,
193
+ & format ! ( "Failed to get access token from Azure IDMS: {e}" ) ,
195
194
)
196
195
} ) ?
197
196
. to_string ( ) ;
@@ -200,17 +199,14 @@ impl Callback {
200
199
. map_err ( |e| {
201
200
Error :: authentication_error (
202
201
MONGODB_OIDC_STR ,
203
- & format ! ( "Failed to get expires_in from Azure IDMS: {}" , e ) ,
202
+ & format ! ( "Failed to get expires_in from Azure IDMS: {e}" ) ,
204
203
)
205
204
} ) ?
206
205
. parse :: < u64 > ( )
207
206
. map_err ( |e| {
208
207
Error :: authentication_error (
209
208
MONGODB_OIDC_STR ,
210
- & format ! (
211
- "Failed to parse expires_in from Azure IDMS as u64: {}" ,
212
- e
213
- ) ,
209
+ & format ! ( "Failed to parse expires_in from Azure IDMS as u64: {e}" ) ,
214
210
)
215
211
} ) ?;
216
212
let expires = Some ( Instant :: now ( ) + Duration :: from_secs ( expires_in) ) ;
@@ -231,8 +227,7 @@ impl Callback {
231
227
fn gcp_callback ( resource : & str ) -> Function {
232
228
use futures_util:: FutureExt ;
233
229
let url = format ! (
234
- "http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience={}" ,
235
- resource
230
+ "http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience={resource}"
236
231
) ;
237
232
Self :: new_function (
238
233
move |_| {
@@ -247,7 +242,7 @@ impl Callback {
247
242
. map_err ( |e| {
248
243
Error :: authentication_error (
249
244
MONGODB_OIDC_STR ,
250
- & format ! ( "Failed to get access token from GCP IDMS: {}" , e ) ,
245
+ & format ! ( "Failed to get access token from GCP IDMS: {e}" ) ,
251
246
)
252
247
} ) ;
253
248
let access_token = response?;
@@ -732,8 +727,7 @@ fn get_allowed_hosts(mechanism_properties: Option<&Document>) -> Result<Vec<&str
732
727
. map ( |host| {
733
728
host. as_str ( ) . ok_or_else ( || {
734
729
auth_error ( format ! (
735
- "`{}` must contain only strings" ,
736
- ALLOWED_HOSTS_PROP_STR
730
+ "`{ALLOWED_HOSTS_PROP_STR}` must contain only strings"
737
731
) )
738
732
} )
739
733
} )
@@ -928,41 +922,34 @@ pub(super) fn validate_credential(credential: &Credential) -> Result<()> {
928
922
for k in properties. keys ( ) {
929
923
if VALID_PROPERTIES . iter ( ) . all ( |p| * p != k) {
930
924
return Err ( Error :: invalid_argument ( format ! (
931
- "'{}' is not a valid property for {} authentication" ,
932
- k, MONGODB_OIDC_STR ,
925
+ "'{k}' is not a valid property for {MONGODB_OIDC_STR} authentication" ,
933
926
) ) ) ;
934
927
}
935
928
}
936
929
let environment = properties. get_str ( ENVIRONMENT_PROP_STR ) ;
937
930
if environment. is_ok ( ) && credential. oidc_callback . is_user_provided ( ) {
938
931
return Err ( Error :: invalid_argument ( format ! (
939
- "OIDC callback cannot be set for {} authentication, if an `{}` is set" ,
940
- MONGODB_OIDC_STR , ENVIRONMENT_PROP_STR
932
+ "OIDC callback cannot be set for {MONGODB_OIDC_STR } authentication, if an \
933
+ `{ ENVIRONMENT_PROP_STR}` is set"
941
934
) ) ) ;
942
935
}
943
936
let has_token_resource = properties. contains_key ( TOKEN_RESOURCE_PROP_STR ) ;
944
937
match environment {
945
938
Ok ( AZURE_ENVIRONMENT_VALUE_STR ) | Ok ( GCP_ENVIRONMENT_VALUE_STR ) => {
946
939
if !has_token_resource {
947
940
return Err ( Error :: invalid_argument ( format ! (
948
- "`{}` must be set for {} authentication in the `{}` or `{}` `{}`" ,
949
- TOKEN_RESOURCE_PROP_STR ,
950
- MONGODB_OIDC_STR ,
951
- AZURE_ENVIRONMENT_VALUE_STR ,
952
- GCP_ENVIRONMENT_VALUE_STR ,
953
- ENVIRONMENT_PROP_STR ,
941
+ "`{TOKEN_RESOURCE_PROP_STR}` must be set for {MONGODB_OIDC_STR} \
942
+ authentication in the `{AZURE_ENVIRONMENT_VALUE_STR}` or \
943
+ `{GCP_ENVIRONMENT_VALUE_STR}` `{ENVIRONMENT_PROP_STR}`",
954
944
) ) ) ;
955
945
}
956
946
}
957
947
_ => {
958
948
if has_token_resource {
959
949
return Err ( Error :: invalid_argument ( format ! (
960
- "`{}` must not be set for {} authentication unless using the `{}` or `{}` `{}`" ,
961
- TOKEN_RESOURCE_PROP_STR ,
962
- MONGODB_OIDC_STR ,
963
- AZURE_ENVIRONMENT_VALUE_STR ,
964
- GCP_ENVIRONMENT_VALUE_STR ,
965
- ENVIRONMENT_PROP_STR ,
950
+ "`{TOKEN_RESOURCE_PROP_STR}` must not be set for {MONGODB_OIDC_STR} \
951
+ authentication unless using the `{AZURE_ENVIRONMENT_VALUE_STR}` or \
952
+ `{GCP_ENVIRONMENT_VALUE_STR}` `{ENVIRONMENT_PROP_STR}`",
966
953
) ) ) ;
967
954
}
968
955
}
@@ -983,27 +970,25 @@ pub(super) fn validate_credential(credential: &Credential) -> Result<()> {
983
970
&& credential. username . is_some ( )
984
971
{
985
972
return Err ( Error :: invalid_argument ( format ! (
986
- "username must not be set for {} authentication in the {} {}" ,
987
- MONGODB_OIDC_STR , TEST_ENVIRONMENT_VALUE_STR , ENVIRONMENT_PROP_STR ,
973
+ "username must not be set for {MONGODB_OIDC_STR } authentication in the \
974
+ { TEST_ENVIRONMENT_VALUE_STR} { ENVIRONMENT_PROP_STR}" ,
988
975
) ) ) ;
989
976
}
990
977
if credential. password . is_some ( ) {
991
978
return Err ( Error :: invalid_argument ( format ! (
992
- "password must not be set for {} authentication" ,
993
- MONGODB_OIDC_STR
979
+ "password must not be set for {MONGODB_OIDC_STR} authentication"
994
980
) ) ) ;
995
981
}
996
982
if let Ok ( env) = environment {
997
983
if VALID_ENVIRONMENTS . iter ( ) . all ( |e| * e != env) {
998
984
return Err ( Error :: invalid_argument ( format ! (
999
- "unsupported environment for {} authentication: {}" ,
1000
- MONGODB_OIDC_STR , env,
985
+ "unsupported environment for {MONGODB_OIDC_STR} authentication: {env}" ,
1001
986
) ) ) ;
1002
987
}
1003
988
}
1004
989
if let Some ( allowed_hosts) = properties. get ( ALLOWED_HOSTS_PROP_STR ) {
1005
990
allowed_hosts. as_array ( ) . ok_or_else ( || {
1006
- Error :: invalid_argument ( format ! ( "`{}` must be an array" , ALLOWED_HOSTS_PROP_STR ) )
991
+ Error :: invalid_argument ( format ! ( "`{ALLOWED_HOSTS_PROP_STR }` must be an array" ) )
1007
992
} ) ?;
1008
993
}
1009
994
Ok ( ( ) )
0 commit comments