diff --git a/src/cli/args.rs b/src/cli/args.rs index 276641a..35f09d4 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -168,10 +168,6 @@ mod tests { Token::try_from_str("ghp_sSIL4kMdtzfbfDdm1MC1OU2q5DbRqA3eSszT").unwrap(), Token::ClassicPersonalAccess(Secret::new("ghp_sSIL4kMdtzfbfDdm1MC1OU2q5DbRqA3eSszT".to_string())) ); - assert_eq!( - Token::try_from_str("gho_sSIL4kMdtzfbfDdm1MC1OU2q5DbRqA3eSszT").unwrap(), - Token::Oauth(Secret::new("gho_sSIL4kMdtzfbfDdm1MC1OU2q5DbRqA3eSszT".to_string())) - ); } #[test] diff --git a/src/cli/models.rs b/src/cli/models.rs index f2a0f01..f73fe82 100644 --- a/src/cli/models.rs +++ b/src/cli/models.rs @@ -24,7 +24,6 @@ pub enum TagSelection { #[derive(Debug, Clone)] pub enum Token { ClassicPersonalAccess(Secret), - Oauth(Secret), Temporal(Secret), } @@ -45,13 +44,6 @@ impl PartialEq for Token { false } } - Self::Oauth(a) => { - if let Self::Oauth(b) = other { - a.expose_secret() == b.expose_secret() - } else { - false - } - } } } } @@ -63,22 +55,16 @@ impl Token { // Classic PAT if Regex::new(r"ghp_[a-zA-Z0-9]{36}$").unwrap().is_match(trimmed_value) { - debug!("Recognized tokens as personal access token"); + debug!("Recognized token as personal access token"); return Ok(Self::ClassicPersonalAccess(secret)); }; - // Temporal token - i.e., $GITHUB_TOKEN + // Temporal token - i.e., $GITHUB_TOKEN or token acquired for a GitHub app if Regex::new(r"ghs_[a-zA-Z0-9]{36}$").unwrap().is_match(trimmed_value) { - debug!("Recognized tokens as temporal token"); + debug!("Recognized token as temporal token"); return Ok(Self::Temporal(secret)); }; - // GitHub oauth token - // TODO: Verify whether a Github app token is an oauth token or not. - if Regex::new(r"gho_[a-zA-Z0-9]{36}$").unwrap().is_match(trimmed_value) { - debug!("Recognized tokens as oauth token"); - return Ok(Self::Oauth(secret)); - }; Err( "The `token` value is not valid. Must be $GITHUB_TOKEN, a classic personal access token (prefixed by 'ghp') or oauth token (prefixed by 'gho').".to_string() ) diff --git a/src/client/builder.rs b/src/client/builder.rs index 7f59972..8e44627 100644 --- a/src/client/builder.rs +++ b/src/client/builder.rs @@ -47,8 +47,7 @@ impl PackagesClientBuilder { let auth_header_value = format!( "Bearer {}", match &token { - Token::Temporal(token) | Token::Oauth(token) | Token::ClassicPersonalAccess(token) => - token.expose_secret(), + Token::Temporal(token) | Token::ClassicPersonalAccess(token) => token.expose_secret(), } ); let mut headers = HeaderMap::new(); diff --git a/src/client/client.rs b/src/client/client.rs index 004a872..6773ffd 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -454,7 +454,7 @@ impl PackagesClient { // auth check: Make sure we have the correct scopes match self.token { Token::Temporal(_) => (), - Token::Oauth(_) | Token::ClassicPersonalAccess(_) => { + Token::ClassicPersonalAccess(_) => { if response_headers.x_oauth_scopes.is_none() || !response_headers .x_oauth_scopes @@ -462,8 +462,6 @@ impl PackagesClient { .unwrap() .contains("write:packages") { - /// Check that the headers of a GitHub request indicate that the token used has the correct scopes for deleting packages. - /// See documentation at: https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28#delete-a-package-for-an-organization eprintln!("The token does not have the scopes needed. Tokens need `write:packages`. The scopes found were {}.", response_headers.x_oauth_scopes.unwrap_or("none".to_string())); exit(1); } diff --git a/src/client/headers.rs b/src/client/headers.rs index b271c28..6d7caab 100644 --- a/src/client/headers.rs +++ b/src/client/headers.rs @@ -1,4 +1,3 @@ -use crate::cli::models::Token; use chrono::{DateTime, Utc}; use color_eyre::Result; use reqwest::header::HeaderMap;