mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-16 17:13:46 -05:00
Added metrics to JSON, switched from json to serde_json, extracted all JSON related functionality into a function in utils.rs
Some checks are pending
Nightly Release / build-binary (map[bin:cup command:build name:cup-linux-aarch64 os:ubuntu-latest release_for:linux-aarch64 target:aarch64-unknown-linux-musl]) (push) Waiting to run
Nightly Release / build-binary (map[bin:cup command:build name:cup-linux-x86_64 os:ubuntu-latest release_for:linux-x86_64 target:x86_64-unknown-linux-musl]) (push) Waiting to run
Nightly Release / build-image (push) Waiting to run
Some checks are pending
Nightly Release / build-binary (map[bin:cup command:build name:cup-linux-aarch64 os:ubuntu-latest release_for:linux-aarch64 target:aarch64-unknown-linux-musl]) (push) Waiting to run
Nightly Release / build-binary (map[bin:cup command:build name:cup-linux-x86_64 os:ubuntu-latest release_for:linux-x86_64 target:x86_64-unknown-linux-musl]) (push) Waiting to run
Nightly Release / build-image (push) Waiting to run
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::sync::Mutex;
|
||||
|
||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||
use serde_json::Value;
|
||||
use ureq::Error;
|
||||
|
||||
use http_auth::parse_challenges;
|
||||
@@ -34,7 +35,7 @@ pub fn get_latest_digest(image: &Image, token: Option<&String>) -> Image {
|
||||
Ok(response) => response,
|
||||
Err(Error::Status(401, response)) => {
|
||||
if token.is_some() {
|
||||
error!("Failed to authenticate with given token!\n{}", token.unwrap())
|
||||
error!("Failed to authenticate to registry {} with given token!\n{}", &image.registry, token.unwrap())
|
||||
} else {
|
||||
return get_latest_digest(
|
||||
image,
|
||||
@@ -94,13 +95,18 @@ pub fn get_token(images: Vec<&Image>, auth_url: &str) -> String {
|
||||
error!("Token request failed!\n{}", e)
|
||||
}
|
||||
};
|
||||
let parsed_token_response = match json::parse(&raw_response) {
|
||||
let parsed_token_response: Value = match serde_json::from_str(&raw_response) {
|
||||
Ok(parsed) => parsed,
|
||||
Err(e) => {
|
||||
error!("Failed to parse server response\n{}", e)
|
||||
}
|
||||
};
|
||||
parsed_token_response["token"].to_string()
|
||||
parsed_token_response
|
||||
.get("token")
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn parse_www_authenticate(www_auth: &str) -> String {
|
||||
|
||||
Reference in New Issue
Block a user