From b73c2532752b7b9708b03290a33f7ba278586f9a Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 27 Sep 2023 22:02:42 +1000 Subject: [PATCH] Fix `GhApiClient`: Accept any `auth_token` given (#1415) Fixed #1414 There are many different kinds of gh tokens and they can change the format at anytime, so we can't check it based on its formats. Signed-off-by: Jiahao XU --- .../binstalk-downloader/src/gh_api_client.rs | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/crates/binstalk-downloader/src/gh_api_client.rs b/crates/binstalk-downloader/src/gh_api_client.rs index 9c8f3f52..92dac5f8 100644 --- a/crates/binstalk-downloader/src/gh_api_client.rs +++ b/crates/binstalk-downloader/src/gh_api_client.rs @@ -13,7 +13,6 @@ use percent_encoding::{ percent_decode_str, utf8_percent_encode, AsciiSet, PercentEncode, CONTROLS, }; use tokio::sync::OnceCell; -use tracing::{debug, warn}; use crate::remote; @@ -132,33 +131,8 @@ struct Inner { #[derive(Clone, Debug)] pub struct GhApiClient(Arc); -fn is_ascii_alphanumeric(s: &[u8]) -> bool { - s.iter().all(|byte| byte.is_ascii_alphanumeric()) -} - -fn is_valid_gh_token(token: &str) -> bool { - let token = token.as_bytes(); - - token.len() >= 40 - && ((&token[0..2] == b"gh" - && token[2].is_ascii_alphanumeric() - && token[3] == b'_' - && is_ascii_alphanumeric(&token[4..])) - || (token.starts_with(b"github_") && is_ascii_alphanumeric(&token[7..]))) -} - impl GhApiClient { pub fn new(client: remote::Client, auth_token: Option) -> Self { - let auth_token = auth_token.and_then(|auth_token| { - if is_valid_gh_token(&auth_token) { - debug!("Using gh api token"); - Some(auth_token) - } else { - warn!("Invalid auth_token, expected 'gh*_' or `github_*` with [A-Za-z0-9], fallback to unauthorized mode"); - None - } - }); - Self(Arc::new(Inner { client, release_artifacts: Default::default(),