@@ -377,14 +377,14 @@ my-registry = {{ index = "{}" }}
377377}
378378
379379// Store a token in the cache for future calls.
380- pub fn cache_token ( config : & Config , sid : & SourceId , token : & str ) {
380+ pub fn cache_token ( config : & Config , sid : & SourceId , token : Secret < & str > ) {
381381 let url = sid. canonical_url ( ) ;
382382 config. credential_cache ( ) . insert (
383383 url. clone ( ) ,
384384 CredentialCacheValue {
385385 from_commandline : true ,
386386 independent_of_endpoint : true ,
387- token_value : Secret :: from ( token. to_string ( ) ) ,
387+ token_value : token. owned ( ) ,
388388 } ,
389389 ) ;
390390}
@@ -399,7 +399,7 @@ pub fn auth_token(
399399 mutation : Option < Mutation < ' _ > > ,
400400) -> CargoResult < String > {
401401 match auth_token_optional ( config, sid, mutation. as_ref ( ) ) ? {
402- Some ( token) => Ok ( token) ,
402+ Some ( token) => Ok ( token. expose ( ) ) ,
403403 None => Err ( AuthorizationError {
404404 sid : sid. clone ( ) ,
405405 login_url : login_url. cloned ( ) ,
@@ -414,7 +414,7 @@ fn auth_token_optional(
414414 config : & Config ,
415415 sid : & SourceId ,
416416 mutation : Option < & ' _ Mutation < ' _ > > ,
417- ) -> CargoResult < Option < String > > {
417+ ) -> CargoResult < Option < Secret < String > > > {
418418 let mut cache = config. credential_cache ( ) ;
419419 let url = sid. canonical_url ( ) ;
420420
@@ -425,17 +425,19 @@ fn auth_token_optional(
425425 || cache_token_value. independent_of_endpoint
426426 || mutation. is_none ( )
427427 {
428- return Ok ( Some ( cache_token_value. token_value . clone ( ) . expose ( ) ) ) ;
428+ return Ok ( Some ( cache_token_value. token_value . clone ( ) ) ) ;
429429 }
430430 }
431431
432432 let credential = registry_credential_config ( config, sid) ?;
433433 let ( independent_of_endpoint, token) = match credential {
434434 RegistryCredentialConfig :: None => return Ok ( None ) ,
435- RegistryCredentialConfig :: Token ( config_token) => ( true , config_token. expose ( ) ) ,
435+ RegistryCredentialConfig :: Token ( config_token) => ( true , config_token) ,
436436 RegistryCredentialConfig :: Process ( process) => {
437437 // todo: PASETO with process
438- run_command ( config, & process, sid, Action :: Get ) ?. unwrap ( )
438+ let ( independent_of_endpoint, token) =
439+ run_command ( config, & process, sid, Action :: Get ) ?. unwrap ( ) ;
440+ ( independent_of_endpoint, Secret :: from ( token) )
439441 }
440442 RegistryCredentialConfig :: AsymmetricKey ( ( secret_key, secret_key_subject) ) => {
441443 let secret: Secret < AsymmetricSecretKey < pasetors:: version3:: V3 > > =
@@ -496,18 +498,22 @@ fn auth_token_optional(
496498
497499 (
498500 false ,
499- pasetors:: version3:: PublicToken :: sign (
500- & secret. expose ( ) ,
501- serde_json:: to_string ( & message)
502- . expect ( "cannot serialize" )
503- . as_bytes ( ) ,
504- Some (
505- serde_json:: to_string ( & footer)
506- . expect ( "cannot serialize" )
507- . as_bytes ( ) ,
508- ) ,
509- None ,
510- ) ?,
501+ secret
502+ . map ( |secret| {
503+ pasetors:: version3:: PublicToken :: sign (
504+ & secret,
505+ serde_json:: to_string ( & message)
506+ . expect ( "cannot serialize" )
507+ . as_bytes ( ) ,
508+ Some (
509+ serde_json:: to_string ( & footer)
510+ . expect ( "cannot serialize" )
511+ . as_bytes ( ) ,
512+ ) ,
513+ None ,
514+ )
515+ } )
516+ . transpose ( ) ?,
511517 )
512518 }
513519 } ;
@@ -518,7 +524,7 @@ fn auth_token_optional(
518524 CredentialCacheValue {
519525 from_commandline : false ,
520526 independent_of_endpoint,
521- token_value : Secret :: from ( token. to_string ( ) ) ,
527+ token_value : token. clone ( ) ,
522528 } ,
523529 ) ;
524530 }
0 commit comments