Remove loop as it is handled by library
This commit is contained in:
@@ -28,42 +28,24 @@ fn extract_version(tag: &str) -> Option<Version> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Filter a tag list using exclude and include parameters
|
||||||
fn tag_matches_filters(tag: &str, include: Option<&[String]>, exclude: Option<&[String]>) -> bool {
|
fn tag_matches_filters(tag: &str, include: Option<&[String]>, exclude: Option<&[String]>) -> bool {
|
||||||
let includes = include.map_or(true, |incs| incs.iter().all(|inc| tag.contains(inc)));
|
let includes = include.map_or(true, |incs| incs.iter().all(|inc| tag.contains(inc)));
|
||||||
let excludes = exclude.map_or(true, |excs| excs.iter().all(|exc| !tag.contains(exc)));
|
let excludes = exclude.map_or(true, |excs| excs.iter().all(|exc| !tag.contains(exc)));
|
||||||
includes && excludes
|
includes && excludes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieve all tags using the list_tags method on the Client object
|
||||||
async fn fetch_all_tags(
|
async fn fetch_all_tags(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
image_ref: &Reference,
|
image_ref: &Reference,
|
||||||
auth: &RegistryAuth,
|
auth: &RegistryAuth,
|
||||||
) -> Result<Vec<String>, Box<dyn Error>> {
|
) -> Result<Vec<String>, Box<dyn Error>> {
|
||||||
let mut all_tags = Vec::new();
|
let response = client.list_tags(image_ref, auth, Some(1000), None).await?;
|
||||||
let mut last_tag: Option<String> = None;
|
Ok(response.tags)
|
||||||
|
|
||||||
loop {
|
|
||||||
let response = client
|
|
||||||
.list_tags(image_ref, auth, Some(100), last_tag.as_deref())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let tags = response.tags;
|
|
||||||
if tags.is_empty() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
let is_last_page = tags.len() < 100;
|
|
||||||
last_tag = tags.last().cloned();
|
|
||||||
all_tags.extend(tags);
|
|
||||||
|
|
||||||
if is_last_page {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(all_tags)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The core function that make all other functions working together
|
||||||
async fn get_sorted_tags(
|
async fn get_sorted_tags(
|
||||||
image: &str,
|
image: &str,
|
||||||
include: Option<&[String]>,
|
include: Option<&[String]>,
|
||||||
@@ -90,6 +72,7 @@ async fn get_sorted_tags(
|
|||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The public entrypoint that outputs results as JSON
|
||||||
pub async fn get_tags(
|
pub async fn get_tags(
|
||||||
image: &str,
|
image: &str,
|
||||||
include: Option<&[String]>,
|
include: Option<&[String]>,
|
||||||
|
|||||||
Reference in New Issue
Block a user