Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #604 from cgwalters/format-image-alternate
Browse files Browse the repository at this point in the history
container: Allow alternative formatting to drop `ostree-unverified-registry`
  • Loading branch information
jmarrero authored Feb 17, 2024
2 parents bf56661 + 399b7b7 commit 4549445
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/src/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use ostree::glib;

use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Debug;
use std::ops::Deref;
use std::str::FromStr;

Expand Down Expand Up @@ -277,7 +278,14 @@ impl std::fmt::Display for OstreeImageReference {
(SignatureSource::ContainerPolicyAllowInsecure, imgref)
if imgref.transport == Transport::Registry =>
{
write!(f, "ostree-unverified-registry:{}", self.imgref.name)
// Because allow-insecure is the effective default, allow formatting
// without it. Note this formatting is asymmetric and cannot be
// re-parsed.
if f.alternate() {
write!(f, "{}", self.imgref)
} else {
write!(f, "ostree-unverified-registry:{}", self.imgref.name)
}
}
(sigverify, imgref) => {
write!(f, "{}:{}", sigverify, imgref)
Expand Down Expand Up @@ -584,10 +592,8 @@ mod tests {
assert_eq!(ir.sigverify, SignatureSource::ContainerPolicy);
assert_eq!(ir.imgref.transport, Transport::Registry);
assert_eq!(ir.imgref.name, "quay.io/exampleos/blah");
assert_eq!(
ir.to_string(),
"ostree-image-signed:docker://quay.io/exampleos/blah"
);
assert_eq!(ir.to_string(), ir_s);
assert_eq!(format!("{:#}", &ir), ir_s);

let ir_s = "ostree-unverified-image:docker://quay.io/exampleos/blah";
let ir: OstreeImageReference = ir_s.try_into().unwrap();
Expand All @@ -602,6 +608,7 @@ mod tests {
OstreeImageReference::try_from("ostree-unverified-registry:quay.io/exampleos/blah")
.unwrap();
assert_eq!(&ir_shorthand, &ir);
assert_eq!(format!("{:#}", &ir), "docker://quay.io/exampleos/blah");
}

#[test]
Expand Down

0 comments on commit 4549445

Please sign in to comment.