Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use crate::{
http::Client,
registry::{check_auth, get_token},
structs::{image::Image, update::Update},
utils::request::{get_response_body, parse_json},
utils::{
reference::split,
request::{get_response_body, parse_json},
},
Context,
};

Expand Down Expand Up @@ -79,6 +82,21 @@ async fn get_remote_updates(ctx: &Context, client: &Client, refresh: bool) -> Ve
remote_images
}

/// Returns a list of excluded tag prefixes for the given image.
fn get_excluded_tags(image: &Image, ctx: &Context) -> Vec<String> {
let image_name = image.reference.split(':').next().unwrap();
ctx.config
.images
.exclude
.iter()
.filter(|item| item.starts_with(image_name))
.filter_map(|excluded| {
let tag = split(excluded).2;
(tag != "latest").then_some(tag)
})
.collect()
}

/// Returns a list of updates for all images passed in.
pub async fn get_updates(
references: &Option<Vec<String>>, // If a user requested _specific_ references to be checked, this will have a value
Expand Down Expand Up @@ -200,8 +218,9 @@ pub async fn get_updates(
.iter()
.any(|item| image.reference.starts_with(item));
if !is_ignored {
let excluded_tags = get_excluded_tags(image, ctx);
let token = tokens.get(image.parts.registry.as_str()).unwrap();
let future = image.check(token.as_deref(), ctx, &client);
let future = image.check(token.as_deref(), ctx, &client, excluded_tags);
handles.push(future);
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub async fn get_latest_tag(
token: Option<&str>,
ctx: &Context,
client: &Client,
excluded_tags: Vec<String>,
) -> Image {
ctx.logger
.debug(format!("Checking for tag update to {}", image.reference));
Expand Down Expand Up @@ -153,6 +154,7 @@ pub async fn get_latest_tag(
&image.version_info.as_ref().unwrap().format_str,
ctx,
client,
&excluded_tags,
)
.await
{
Expand Down Expand Up @@ -211,13 +213,28 @@ pub async fn get_latest_tag(
}
}

/// Checks if a tag matches any of the excluded tag prefixes.
fn is_excluded_tag(tag: &str, excluded_tags: &[String], ctx: &Context) -> bool {
for excluded in excluded_tags {
if tag.starts_with(excluded) {
ctx.logger.debug(format!(
"Ignoring tag \"{}\" as it matches excluded prefix \"{}\"",
tag, excluded
));
Comment thread
danroc marked this conversation as resolved.
return true;
}
}
false
}

pub async fn get_extra_tags(
url: &str,
headers: &[(&str, Option<&str>)],
base: &Version,
format_str: &str,
ctx: &Context,
client: &Client,
excluded_tags: &[String],
) -> Result<(Vec<Version>, Option<String>), String> {
let response = client.get(url, headers, false).await;

Expand All @@ -232,6 +249,7 @@ pub async fn get_extra_tags(
.as_array()
.unwrap()
.iter()
.filter(|tag| !is_excluded_tag(tag.as_str().unwrap(), excluded_tags, ctx))
.filter_map(|tag| Version::from_tag(tag.as_str().unwrap()))
.filter(|(tag, format_string)| match (base.minor, tag.minor) {
(Some(_), Some(_)) | (None, None) => {
Expand Down
12 changes: 10 additions & 2 deletions src/structs/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,17 @@ impl Image {
}

/// Checks if the image has an update
pub async fn check(&self, token: Option<&str>, ctx: &Context, client: &Client) -> Self {
pub async fn check(
&self,
token: Option<&str>,
ctx: &Context,
client: &Client,
excluded_tags: Vec<String>,
) -> Self {
match &self.version_info {
Some(data) => get_latest_tag(self, &data.current_tag, token, ctx, client).await,
Some(data) => {
get_latest_tag(self, &data.current_tag, token, ctx, client, excluded_tags).await
}
None => match self.digest_info {
Some(_) => get_latest_digest(self, token, ctx, client).await,
None => unreachable!(),
Expand Down