summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs37
1 files changed, 21 insertions, 16 deletions
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::<Vec<tinyjson::JsonValue>>().unwrap().iter() {
let candidate_str = it.get::<String>().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();
}