m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-18 09:53:43 -05:00

Change config, add schema

This commit is contained in:
Sergio
2024-12-07 16:21:01 +02:00
parent e544ef6ca5
commit 33a72c8c0d
5 changed files with 132 additions and 25 deletions

View File

@@ -1,8 +1,9 @@
use http_auth::parse_challenges;
use json::JsonValue;
use reqwest::Response;
use rustc_hash::FxHashMap;
use crate::error;
use crate::{config::RegistryConfig, error};
/// Parses the www-authenticate header the registry sends into a challenge URL
pub fn parse_www_authenticate(www_auth: &str) -> String {
@@ -23,13 +24,20 @@ pub fn parse_www_authenticate(www_auth: &str) -> String {
}
}
pub fn get_protocol(registry: &String, insecure_registries: &[String]) -> String {
if insecure_registries.contains(registry) {
"http"
} else {
"https"
pub fn get_protocol(
registry: &str,
registry_config: &FxHashMap<String, RegistryConfig>,
) -> &'static str {
match registry_config.get(registry) {
Some(config) => {
if config.insecure {
"http"
} else {
"https"
}
},
None => "https"
}
.to_string()
}
pub fn to_bearer_string(token: &Option<&String>) -> Option<String> {