fixed problem with official images

This commit is contained in:
Thomas Eppers 2021-09-02 01:00:09 +02:00
parent 7b1501f4d8
commit db5216b100
2 changed files with 19 additions and 18 deletions

View File

@ -29,6 +29,7 @@ pub struct Tags {
pub results: Vec<Images>, pub results: Vec<Images>,
} }
#[derive(Debug)]
pub enum Error { pub enum Error {
InvalidCharacter(char), InvalidCharacter(char),
Fetching(String), Fetching(String),
@ -37,13 +38,9 @@ pub enum Error {
impl Tags { impl Tags {
pub fn new(repo: String) -> Result<Self, Error> { pub fn new(repo: String) -> Result<Self, Error> {
// let repo = Self::check_repo(repo)?;
let request = format!("https://hub.docker.com/v2/repositories/{}/tags", repo); let request = format!("https://hub.docker.com/v2/repositories/{}/tags", repo);
//check for right set of characters
if request.bytes().any(|c| !c.is_ascii()) {
return Err(Error::InvalidCharacter('a'));
}
//get response //get response
let res = match reqwest::blocking::get(request) { let res = match reqwest::blocking::get(request) {
Ok(result) => result, Ok(result) => result,
@ -60,14 +57,18 @@ impl Tags {
Ok(tags) Ok(tags)
} }
pub fn get_images(&self) -> &Vec<Images> { pub fn check_repo(mut name: String) -> Result<String, Error> {
&self.results //check for right set of characters
} if name.bytes().any(|c| !c.is_ascii()) {
} return Err(Error::InvalidCharacter('a'));
}
impl Images { //check if need to inject "library" of given repo
pub fn get_name(&self) -> &str { let regex = regex::Regex::new(r".*/.*").unwrap();
&self.tag_name if !regex.is_match(&name) {
name.insert_str(0, "library/");
}
Ok(name)
} }
} }

View File

@ -93,10 +93,7 @@ impl Ui {
ui.tags = tag_list::TagList::with_repo(ui.repo.get()); ui.tags = tag_list::TagList::with_repo(ui.repo.get());
} }
State::SelectTag => { State::SelectTag => {
let mut repo = match ui.services.extract_repo() { let mut repo = ui.repo.get();
Err(_) => continue,
Ok(s) => s,
};
let tag = match ui.tags.get_selected() { let tag = match ui.tags.get_selected() {
Err(_) => continue, Err(_) => continue,
Ok(tag) => tag, Ok(tag) => tag,
@ -136,8 +133,11 @@ impl Ui {
match ui.services.extract_repo() { match ui.services.extract_repo() {
Err(_) => ui.tags = tag_list::TagList::with_status("No image found"), Err(_) => ui.tags = tag_list::TagList::with_status("No image found"),
Ok(s) => { Ok(s) => {
ui.repo.set(s); let repo = match crate::tags::Tags::check_repo(s) {
ui.tags = tag_list::TagList::with_repo(ui.repo.get()); Err(_) => continue,
Ok(s) => s,
};
ui.repo.set(repo);
} }
} }
} }