From 82ab36a5a0c021210e60520040ce335b827a7dff Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Mon, 2 Feb 2026 22:53:08 +0100 Subject: Make it deployable --- Cargo.toml | 6 ++++++ src/main.rs | 37 +++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a54256..ab19366 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,12 @@ name = "version-bumper" version = "0.1.0" edition = "2024" +[profile.dev] +panic="abort" + +[profile.release] +panic="abort" + [dependencies] base64 = "0.22.1" chrono = "0.4.43" diff --git a/src/main.rs b/src/main.rs index 3fed758..be73c5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ use crate::parser::*; use base64::prelude::*; use rand::distr::{Alphanumeric, SampleString}; use rusqlite::Connection; -use rusqlite::OptionalExtension; use yaml_rust2::parser::Parser; use yaml_rust2::Event; use std::collections::HashMap; @@ -162,24 +161,30 @@ fn perform_registry_request(registry: &str, url: &str, accept: &'static str, aut let response = request.call().unwrap(); - if response.status() == 401 && !authentication_retry { - if let Some(ref mut state) = state { - state.authenticate(&response)?; - authentication_retry = true; - continue; + if response.status() == 401 { + if !authentication_retry { + if let Some(ref mut state) = state { + state.authenticate(&response)?; + authentication_retry = true; + continue; + } else { + return Err(format!("Server {} returned 401 but we have no credentials", registry)); + } } else { - return Err(format!("Server {} returned 401 but we have no credentials", registry)); + return Err(format!("Authentication failed")); } } + if response.status() == 429 { + panic!(); + } + if response.status() != 200 { return Err(format!("Unexpected status code: {}", response.status())) } return Ok(response); } - - return Err("Authorization failed".to_string()); } struct Repository { @@ -404,9 +409,9 @@ fn update_images(db: &Connection, file: &str, auth: &mut Auth, img: DockerRef, e for it in body["tags"].get::>().unwrap().iter() { let candidate_str = it.get::().unwrap(); - db.execute(" - INSERT INTO known_images(registry, image, tag, discovered) VALUES (?1, ?2, ?3, ?4) - ", (registry, &file[img.image.clone()], candidate_str, chrono::offset::Utc::now())).unwrap(); + // db.execute(" + // INSERT INTO known_images(registry, image, tag, discovered) VALUES (?1, ?2, ?3, ?4) + // ", (registry, &file[img.image.clone()], candidate_str, chrono::offset::Utc::now())).unwrap(); let candidate = VersionPattern::parse(candidate_str); match current.compare(&candidate) { @@ -829,10 +834,10 @@ fn main() { } if newest_migration < 4 { - db.execute(" - CREATE UNIQUE INDEX known_images__registry_image_tag - ON known_images(registry, image, tag) - ", ()).unwrap(); + // db.execute(" + // CREATE UNIQUE INDEX known_images__registry_image_tag + // ON known_images(registry, image, tag) + // ", ()).unwrap(); db.execute("INSERT INTO migrations(id) VALUES (?1)", (4, )).unwrap(); } -- cgit v1.2.3