pub const PACKAGE_FORMAT: &[&str] = &[
"npm", "pypi", "maven", "nuget", "generic", "ruby", "swift", "cargo",
];
pub const PACKAGE_VERSION_STATUS: &[&str] = &[
"Published",
"Unfinished",
"Unlisted",
"Archived",
"Disposed",
"Deleted",
];
pub const PACKAGE_VERSION_SORT: &[&str] = &["PUBLISHED_TIME"];
pub const PACKAGE_VERSION_ORIGIN_TYPE: &[&str] = &["INTERNAL", "EXTERNAL", "UNKNOWN"];
pub const ENDPOINT_TYPE: &[&str] = &["dualstack", "ipv4"];
pub const ALLOW_BLOCK: &[&str] = &["ALLOW", "BLOCK"];
pub const ORIGIN_RESTRICTION_TYPE: &[&str] = &["EXTERNAL_UPSTREAM", "INTERNAL_UPSTREAM", "PUBLISH"];
pub const ORIGIN_RESTRICTION_MODE: &[&str] =
&["ALLOW", "ALLOW_SPECIFIC_REPOSITORIES", "BLOCK", "INHERIT"];
pub fn is_enum(set: &[&str], value: &str) -> bool {
set.contains(&value)
}
pub fn is_domain_name(name: &str) -> bool {
let len = name.chars().count();
if !(2..=50).contains(&len) {
return false;
}
let bytes = name.as_bytes();
let first = bytes[0];
let last = bytes[len - 1];
if !first.is_ascii_lowercase() {
return false;
}
if !(last.is_ascii_lowercase() || last.is_ascii_digit()) {
return false;
}
name.bytes()
.all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-')
}
pub fn is_repository_name(name: &str) -> bool {
let len = name.chars().count();
if !(2..=100).contains(&len) {
return false;
}
let first = name.as_bytes()[0];
if !(first.is_ascii_alphanumeric()) {
return false;
}
name.bytes()
.all(|b| b.is_ascii_alphanumeric() || b == b'.' || b == b'_' || b == b'-')
}
pub fn is_account_id(id: &str) -> bool {
id.len() == 12 && id.bytes().all(|b| b.is_ascii_digit())
}