fix: handle non-exist repository
This commit is contained in:
parent
2fa67bbcbc
commit
a25f67987c
@ -1,3 +1,4 @@
|
||||
use std::io::Write;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::{DockerTagsFetcher, QueryArgs};
|
||||
|
||||
@ -61,12 +62,18 @@ impl DockerTagsFetcher for DockerHubTagsFetcher {
|
||||
let mut url = format!("https://hub.docker.com/v2/namespaces/{namespace}/repositories/{repository}/tags?page={page}&page_size={page_size}");
|
||||
let mut results: Vec<DockerResult> = Vec::new();
|
||||
loop {
|
||||
let text = reqwest::blocking::get(url).unwrap().text().unwrap();
|
||||
let mut response: DockerResponse = serde_json::from_str(&text).unwrap();
|
||||
results.append(&mut response.results);
|
||||
url = match response.next {
|
||||
None => { break; }
|
||||
Some(next) => { next }
|
||||
let resp = reqwest::blocking::get(&url).unwrap();
|
||||
if resp.status().is_success() {
|
||||
let text = resp.text().unwrap();
|
||||
let mut response: DockerResponse = serde_json::from_str(&text).unwrap();
|
||||
results.append(&mut response.results);
|
||||
url = match response.next {
|
||||
None => { break; }
|
||||
Some(next) => { next }
|
||||
};
|
||||
} else {
|
||||
let _x = writeln!(std::io::stdout(), "Image not found: {}/{}", namespace, repository);
|
||||
break;
|
||||
};
|
||||
}
|
||||
let mut filtered = results.into_iter()
|
||||
|
@ -39,7 +39,10 @@ impl DockerTagsFetcher for RegistryTagsFetcher {
|
||||
let mut results = Vec::<String>::new();
|
||||
if let Ok(r) = response {
|
||||
let json: RegistryTagsResponse = serde_json::from_str(r.text().unwrap().as_str()).unwrap();
|
||||
results.append(&mut json.tags.unwrap());
|
||||
match json.tags {
|
||||
Some(mut x) => { results.append(&mut x); }
|
||||
None => { results.push(format!("Image not found: {}/{}", namespace, repository)); }
|
||||
}
|
||||
};
|
||||
results
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user