@@ -3,7 +3,7 @@ mod trusted_publishing;
3
3
use std:: path:: { Path , PathBuf } ;
4
4
use std:: sync:: Arc ;
5
5
use std:: time:: { Duration , SystemTime } ;
6
- use std:: { env , fmt, io} ;
6
+ use std:: { fmt, io} ;
7
7
8
8
use fs_err:: tokio:: File ;
9
9
use futures:: TryStreamExt ;
@@ -21,7 +21,6 @@ use tokio::io::{AsyncReadExt, BufReader};
21
21
use tokio:: sync:: Semaphore ;
22
22
use tokio_util:: io:: ReaderStream ;
23
23
use tracing:: { Level , debug, enabled, trace, warn} ;
24
- use trusted_publishing:: TrustedPublishingToken ;
25
24
use url:: Url ;
26
25
27
26
use uv_auth:: { Credentials , PyxTokenStore } ;
@@ -38,10 +37,9 @@ use uv_fs::{ProgressReader, Simplified};
38
37
use uv_metadata:: read_metadata_async_seek;
39
38
use uv_pypi_types:: { HashAlgorithm , HashDigest , Metadata23 , MetadataError } ;
40
39
use uv_redacted:: DisplaySafeUrl ;
41
- use uv_static:: EnvVars ;
42
- use uv_warnings:: { warn_user, warn_user_once} ;
40
+ use uv_warnings:: warn_user;
43
41
44
- use crate :: trusted_publishing:: TrustedPublishingError ;
42
+ use crate :: trusted_publishing:: { TrustedPublishingError , TrustedPublishingToken } ;
45
43
46
44
#[ derive( Error , Debug ) ]
47
45
pub enum PublishError {
@@ -324,26 +322,20 @@ pub async fn check_trusted_publishing(
324
322
{
325
323
return Ok ( TrustedPublishResult :: Skipped ) ;
326
324
}
327
- // If we aren't in GitHub Actions, we can't use trusted publishing.
328
- if env:: var ( EnvVars :: GITHUB_ACTIONS ) != Ok ( "true" . to_string ( ) ) {
329
- return Ok ( TrustedPublishResult :: Skipped ) ;
330
- }
331
- // We could check for credentials from the keyring or netrc the auth middleware first, but
332
- // given that we are in GitHub Actions we check for trusted publishing first.
333
- debug ! (
334
- "Running on GitHub Actions without explicit credentials, checking for trusted publishing"
335
- ) ;
325
+
326
+ debug ! ( "Attempting to get a token for trusted publishing" ) ;
327
+ // Attempt to get a token for trusted publishing.
336
328
match trusted_publishing:: get_token ( registry, client. for_host ( registry) . raw_client ( ) )
337
329
. await
338
330
{
339
- Ok ( token ) => Ok ( TrustedPublishResult :: Configured ( token) ) ,
340
- Err ( err ) => {
341
- // TODO(konsti): It would be useful if we could differentiate between actual errors
342
- // such as connection errors and warn for them while ignoring errors from trusted
343
- // publishing not being configured.
344
- debug ! ( "Could not obtain trusted publishing credentials, skipping: {err}" ) ;
345
- Ok ( TrustedPublishResult :: Ignored ( err ) )
346
- }
331
+ // Success: we have a token for trusted publishing.
332
+ Ok ( Some ( token ) ) => Ok ( TrustedPublishResult :: Configured ( token ) ) ,
333
+ // Failed to discover an ambient OIDC token.
334
+ Ok ( None ) => Ok ( TrustedPublishResult :: Ignored (
335
+ TrustedPublishingError :: NoToken ,
336
+ ) ) ,
337
+ // Hard failure during OIDC discovery or token exchange.
338
+ Err ( err ) => Ok ( TrustedPublishResult :: Ignored ( err ) ) ,
347
339
}
348
340
}
349
341
TrustedPublishing :: Always => {
@@ -363,15 +355,15 @@ pub async fn check_trusted_publishing(
363
355
return Err ( PublishError :: MixedCredentials ( conflicts. join ( " and " ) ) ) ;
364
356
}
365
357
366
- if env:: var ( EnvVars :: GITHUB_ACTIONS ) != Ok ( "true" . to_string ( ) ) {
367
- warn_user_once ! (
368
- "Trusted publishing was requested, but you're not in GitHub Actions."
369
- ) ;
370
- }
371
-
372
- let token =
358
+ let Some ( token) =
373
359
trusted_publishing:: get_token ( registry, client. for_host ( registry) . raw_client ( ) )
374
- . await ?;
360
+ . await ?
361
+ else {
362
+ return Err ( PublishError :: TrustedPublishing (
363
+ TrustedPublishingError :: NoToken ,
364
+ ) ) ;
365
+ } ;
366
+
375
367
Ok ( TrustedPublishResult :: Configured ( token) )
376
368
}
377
369
TrustedPublishing :: Never => Ok ( TrustedPublishResult :: Skipped ) ,
0 commit comments