From 8f0eb3db4f2900f7ec6e4ba25f26bd56e43b0971 Mon Sep 17 00:00:00 2001 From: Thomas Eppers Date: Sat, 23 Jul 2022 17:20:34 +0200 Subject: [PATCH] removed faulty ghcr implementation --- src/repository/ghcr.rs | 72 ------------------------------------------ src/repository/mod.rs | 7 ++-- 2 files changed, 3 insertions(+), 76 deletions(-) delete mode 100644 src/repository/ghcr.rs diff --git a/src/repository/ghcr.rs b/src/repository/ghcr.rs deleted file mode 100644 index 3dac08f..0000000 --- a/src/repository/ghcr.rs +++ /dev/null @@ -1,72 +0,0 @@ -use serde::Deserialize; - -use crate::repository::Error; - -#[derive(Deserialize)] -struct Token { - token: String, -} - -#[derive(Deserialize)] -pub struct Ghcr { - tags: Vec, -} - -impl Ghcr { - /// fetches tag information with a repository name in the form of organization/repository or library/repository in the case of official images from docker - pub fn create_repo(repo: &str) -> Result { - let request_token = format!("https://ghcr.io/token?scope=repository:{}:pull", repo); - let response = match reqwest::blocking::get(request_token) { - Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))), - Ok(response) => response, - }; - - let token = match response.json::() { - Err(e) => return Err(Error::Converting(format!("invalid token json: {}", e))), - Ok(token) => token.token, - }; - - let request = format!("https://ghcr.io/v2/{}/tags/list?n=100", repo); - let client = reqwest::blocking::Client::new(); - let response = match client - .get(request) - .header(reqwest::header::AUTHORIZATION, format!("Bearer {}", token)) - .send() - { - Ok(result) => result, - Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))), - }; - - //convert it to json - let tags = match response.json::() { - Ok(result) => result, - Err(e) => return Err(Error::Converting(format!("invalid json: {}", e))), - }; - - if tags.tags.is_empty() { - return Err(Error::NoTagsFound); - } - - Ok(super::Repo { - tags: tags - .tags - .iter() - .map(|t| super::Tag { - name: t.clone(), - details: vec![], - last_updated: None, - }) - .collect(), - next_page: None, - }) - } -} - -#[cfg(test)] -mod tests { - use super::Ghcr; - #[test] - fn test_ghcr() { - Ghcr::create_repo("ghcr.io/linuxserver/beets").unwrap(); - } -} diff --git a/src/repository/mod.rs b/src/repository/mod.rs index 9abd790..3fb4218 100644 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -1,5 +1,4 @@ mod dockerhub; -mod ghcr; use std::fmt; @@ -83,10 +82,10 @@ impl Repo { Err(e) => return Err(Error::Converting(format!("{}", e))), }; - if registry.unwrap_or_default() == "ghcr.io" { - ghcr::Ghcr::create_repo(&repo) - } else { + if registry.unwrap_or_default().is_empty() { dockerhub::DockerHub::create_repo(&repo) + } else { + return Err(Error::Converting("This registry is not supported".into())); } }