mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-13 23:53:48 -05:00
Updated image regex to support any image. Removed dependency on fancy_regex in favour of the regex crate
This commit is contained in:
19
src/utils.rs
19
src/utils.rs
@@ -1,4 +1,4 @@
|
||||
use fancy_regex::Regex;
|
||||
use regex::Regex;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
#[macro_export]
|
||||
@@ -9,27 +9,20 @@ macro_rules! error {
|
||||
})
|
||||
}
|
||||
|
||||
// Takes an image and splits it into registry, repository and tag. For example ghcr.io/sergi0g/cup:latest becomes ['ghcr.io', 'sergi0g/cup', 'latest']. ONLY REGISTRIES THAT USE A / IN THE REPOSITORY ARE SUPPORTED CURRENTLY. THAT MEANS AZURE WILL NOT WORK.
|
||||
// Takes an image and splits it into registry, repository and tag. For example ghcr.io/sergi0g/cup:latest becomes ['ghcr.io', 'sergi0g/cup', 'latest'].
|
||||
pub fn split_image(image: &str) -> (String, String, String) {
|
||||
static RE: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(
|
||||
r#"^(?P<registry>[\w.\-_]+((?::\d+|)(?=/[a-z0-9._-]+/[a-z0-9._-]+))|)(?:/|)(?P<repository>[a-z0-9.\-_]+(?:/[a-z0-9.\-_]+|))(:(?P<tag>[\w.\-_]{1,127})|)$"#, // From https://regex101.com/r/a98UqN/1
|
||||
r#"^(?P<name>(?:(?P<registry>(?:(?:localhost|[\w-]+(?:\.[\w-]+)+)(?::\d+)?)|[\w]+:\d+)/)?(?P<repository>[a-z0-9_.-]+(?:/[a-z0-9_.-]+)*))(?::(?P<tag>[\w][\w.-]{0,127}))?$"#, // From https://regex101.com/r/nmSDPA/1
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
match RE.captures(image).unwrap() {
|
||||
match RE.captures(image) {
|
||||
Some(c) => {
|
||||
return (
|
||||
match c.name("registry") {
|
||||
Some(registry) => {
|
||||
let reg = registry.as_str().to_owned();
|
||||
if reg.is_empty() {
|
||||
String::from("registry-1.docker.io")
|
||||
} else {
|
||||
reg
|
||||
}
|
||||
}
|
||||
None => error!("Failed to parse image {}", image),
|
||||
Some(registry) => registry.as_str().to_owned(),
|
||||
None => String::from("registry-1.docker.io"),
|
||||
},
|
||||
match c.name("repository") {
|
||||
Some(repository) => {
|
||||
|
||||
Reference in New Issue
Block a user