m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-16 17:13:46 -05:00

Move usage of get_images_from_docker_daemon to get_updates

This commit is contained in:
Sergio
2024-11-16 12:38:00 +02:00
parent 6b83f51749
commit 4519c534a1
4 changed files with 10 additions and 39 deletions

View File

@@ -4,13 +4,17 @@ use rustc_hash::FxHashMap;
use crate::{
config::Config,
docker::get_images_from_docker_daemon,
http::Client,
registry::{check_auth, get_token},
structs::image::Image,
};
/// Returns a list of updates for all images passed in.
pub async fn get_updates(images: &[Image], config: &Config) -> Vec<Image> {
pub async fn get_updates(references: &Option<Vec<String>>, config: &Config) -> Vec<Image> {
// Get images
let images = get_images_from_docker_daemon(config, references).await;
// Get a list of unique registries our images belong to. We are unwrapping the registry because it's guaranteed to be there.
let registries: Vec<&String> = images
.iter()
@@ -25,7 +29,7 @@ pub async fn get_updates(images: &[Image], config: &Config) -> Vec<Image> {
// Create a map of images indexed by registry. This solution seems quite inefficient, since each iteration causes a key to be looked up. I can't find anything better at the moment.
let mut image_map: FxHashMap<&String, Vec<&Image>> = FxHashMap::default();
for image in images {
for image in &images {
image_map.entry(&image.registry).or_default().push(image);
}
@@ -53,7 +57,7 @@ pub async fn get_updates(images: &[Image], config: &Config) -> Vec<Image> {
// Create a Vec to store futures so we can await them all at once.
let mut handles = Vec::new();
// Loop through images and get the latest digest for each
for image in images {
for image in &images {
let token = tokens.get(image.registry.as_str()).unwrap();
let future = image.check(token.as_ref(), config, &client);
handles.push(future);