@@ -354,52 +354,55 @@ pub fn registry_configuration(
354354 config : & Config ,
355355 registry : Option < & str > ,
356356) -> 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+ } ;
357366 // `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 {
359368 Some ( registry) => {
360369 validate_package_name ( & registry, "registry name" , "" ) ?;
361370 let index = Some ( config. get_registry_index ( & registry) ?. to_string ( ) ) ;
362371 let token_key = format ! ( "registries.{}.token" , registry) ;
363372 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)
371389 }
372390 None => {
373391 // Use crates.io default.
374392 config. check_registry_index_not_set ( ) ?;
375393 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)
400405 }
401- } else {
402- None
403406 } ;
404407
405408 let credential_process =
0 commit comments