Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support <reference> as the digest of manifest #128

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ocipkg/src/distribution/reference.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::Digest;
use anyhow::{bail, Result};
use regex::Regex;
use std::fmt;

/// Reference of container image stored in the repository
///
/// In [OCI distribution spec](https://github.com/opencontainers/distribution-spec/blob/main/spec.md):
/// > `<reference>` MUST be either (a) the digest of the manifest or (b) a tag
/// > `<reference>` as a tag MUST be at most 128 characters
/// > in length and MUST match the following regular expression:
/// > ```text
Expand Down Expand Up @@ -39,6 +41,9 @@ impl Reference {
pub fn new(name: &str) -> Result<Self> {
if REF_RE.is_match(name) {
Ok(Reference(name.to_string()))
} else if name.contains(':') {
_ = Digest::new(name)?;
Ok(Reference(name.to_string()))
} else {
bail!("Invalid reference {name}");
}
Expand All @@ -52,6 +57,10 @@ mod tests {
#[test]
fn reference() {
assert_eq!(Reference::new("latest").unwrap().as_str(), "latest");
assert_eq!(
Reference::new("sha256:a1b2c3").unwrap().as_str(),
"sha256:a1b2c3"
);
// @ is not allowed
assert!(Reference::new("my_super_tag@2").is_err());
}
Expand Down
Loading