@@ -377,14 +377,14 @@ my-registry = {{ index = "{}" }}
377
377
}
378
378
379
379
// 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 > ) {
381
381
let url = sid. canonical_url ( ) ;
382
382
config. credential_cache ( ) . insert (
383
383
url. clone ( ) ,
384
384
CredentialCacheValue {
385
385
from_commandline : true ,
386
386
independent_of_endpoint : true ,
387
- token_value : Secret :: from ( token. to_string ( ) ) ,
387
+ token_value : token. owned ( ) ,
388
388
} ,
389
389
) ;
390
390
}
@@ -399,7 +399,7 @@ pub fn auth_token(
399
399
mutation : Option < Mutation < ' _ > > ,
400
400
) -> CargoResult < String > {
401
401
match auth_token_optional ( config, sid, mutation. as_ref ( ) ) ? {
402
- Some ( token) => Ok ( token) ,
402
+ Some ( token) => Ok ( token. expose ( ) ) ,
403
403
None => Err ( AuthorizationError {
404
404
sid : sid. clone ( ) ,
405
405
login_url : login_url. cloned ( ) ,
@@ -414,7 +414,7 @@ fn auth_token_optional(
414
414
config : & Config ,
415
415
sid : & SourceId ,
416
416
mutation : Option < & ' _ Mutation < ' _ > > ,
417
- ) -> CargoResult < Option < String > > {
417
+ ) -> CargoResult < Option < Secret < String > > > {
418
418
let mut cache = config. credential_cache ( ) ;
419
419
let url = sid. canonical_url ( ) ;
420
420
@@ -425,17 +425,19 @@ fn auth_token_optional(
425
425
|| cache_token_value. independent_of_endpoint
426
426
|| mutation. is_none ( )
427
427
{
428
- return Ok ( Some ( cache_token_value. token_value . clone ( ) . expose ( ) ) ) ;
428
+ return Ok ( Some ( cache_token_value. token_value . clone ( ) ) ) ;
429
429
}
430
430
}
431
431
432
432
let credential = registry_credential_config ( config, sid) ?;
433
433
let ( independent_of_endpoint, token) = match credential {
434
434
RegistryCredentialConfig :: None => return Ok ( None ) ,
435
- RegistryCredentialConfig :: Token ( config_token) => ( true , config_token. expose ( ) ) ,
435
+ RegistryCredentialConfig :: Token ( config_token) => ( true , config_token) ,
436
436
RegistryCredentialConfig :: Process ( process) => {
437
437
// 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) )
439
441
}
440
442
RegistryCredentialConfig :: AsymmetricKey ( ( secret_key, secret_key_subject) ) => {
441
443
let secret: Secret < AsymmetricSecretKey < pasetors:: version3:: V3 > > =
@@ -496,18 +498,22 @@ fn auth_token_optional(
496
498
497
499
(
498
500
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 ( ) ?,
511
517
)
512
518
}
513
519
} ;
@@ -518,7 +524,7 @@ fn auth_token_optional(
518
524
CredentialCacheValue {
519
525
from_commandline : false ,
520
526
independent_of_endpoint,
521
- token_value : Secret :: from ( token. to_string ( ) ) ,
527
+ token_value : token. clone ( ) ,
522
528
} ,
523
529
) ;
524
530
}
0 commit comments