@@ -354,52 +354,55 @@ pub fn registry_configuration(
354
354
config : & Config ,
355
355
registry : Option < & str > ,
356
356
) -> CargoResult < RegistryConfig > {
357
+ let err_both = |token_key : & str , proc_key : & str | {
358
+ Err ( format_err ! (
359
+ "both `{TOKEN_KEY}` and `{PROC_KEY}` \
360
+ were specified in the config\n \
361
+ Only one of these values may be set, remove one or the other to proceed.",
362
+ TOKEN_KEY = token_key,
363
+ PROC_KEY = proc_key,
364
+ ) )
365
+ } ;
357
366
// `registry.default` is handled in command-line parsing.
358
- let ( index, token, process, token_key , proc_key ) = match registry {
367
+ let ( index, token, process) = match registry {
359
368
Some ( registry) => {
360
369
validate_package_name ( & registry, "registry name" , "" ) ?;
361
370
let index = Some ( config. get_registry_index ( & registry) ?. to_string ( ) ) ;
362
371
let token_key = format ! ( "registries.{}.token" , registry) ;
363
372
let token = config. get_string ( & token_key) ?. map ( |p| p. val ) ;
364
- let mut proc_key = format ! ( "registries.{}.credential-process" , registry) ;
365
- let mut process = config. get :: < Option < config:: PathAndArgs > > ( & proc_key) ?;
366
- if process. is_none ( ) {
367
- proc_key = String :: from ( "registry.credential-process" ) ;
368
- process = config. get :: < Option < config:: PathAndArgs > > ( & proc_key) ?;
369
- }
370
- ( index, token, process, token_key, proc_key)
373
+ let process = if config. cli_unstable ( ) . credential_process {
374
+ let mut proc_key = format ! ( "registries.{}.credential-process" , registry) ;
375
+ let mut process = config. get :: < Option < config:: PathAndArgs > > ( & proc_key) ?;
376
+ if process. is_none ( ) && token. is_none ( ) {
377
+ // This explicitly ignores the global credential-process if
378
+ // the token is set, as that is "more specific".
379
+ proc_key = String :: from ( "registry.credential-process" ) ;
380
+ process = config. get :: < Option < config:: PathAndArgs > > ( & proc_key) ?;
381
+ } else if process. is_some ( ) && token. is_some ( ) {
382
+ return err_both ( & token_key, & proc_key) ;
383
+ }
384
+ process
385
+ } else {
386
+ None
387
+ } ;
388
+ ( index, token, process)
371
389
}
372
390
None => {
373
391
// Use crates.io default.
374
392
config. check_registry_index_not_set ( ) ?;
375
393
let token = config. get_string ( "registry.token" ) ?. map ( |p| p. val ) ;
376
- let process =
377
- config. get :: < Option < config:: PathAndArgs > > ( "registry.credential-process" ) ?;
378
- (
379
- None ,
380
- token,
381
- process,
382
- String :: from ( "registry.token" ) ,
383
- String :: from ( "registry.credential-process" ) ,
384
- )
385
- }
386
- } ;
387
-
388
- let process = if config. cli_unstable ( ) . credential_process {
389
- if token. is_some ( ) && process. is_some ( ) {
390
- config. shell ( ) . warn ( format ! (
391
- "both `{TOKEN_KEY}` and `{PROC_KEY}` \
392
- were specified in the config, only `{TOKEN_KEY}` will be used\n \
393
- Specify only one value to silence this warning.",
394
- TOKEN_KEY = token_key,
395
- PROC_KEY = proc_key,
396
- ) ) ?;
397
- None
398
- } else {
399
- process
394
+ let process = if config. cli_unstable ( ) . credential_process {
395
+ let process =
396
+ config. get :: < Option < config:: PathAndArgs > > ( "registry.credential-process" ) ?;
397
+ if token. is_some ( ) && process. is_some ( ) {
398
+ return err_both ( "registry.token" , "registry.credential-process" ) ;
399
+ }
400
+ process
401
+ } else {
402
+ None
403
+ } ;
404
+ ( None , token, process)
400
405
}
401
- } else {
402
- None
403
406
} ;
404
407
405
408
let credential_process =
0 commit comments