Skip to content

Commit 4549445

Browse files
authored
Merge pull request bootc-dev#604 from cgwalters/format-image-alternate
container: Allow alternative formatting to drop `ostree-unverified-registry`
2 parents bf56661 + 399b7b7 commit 4549445

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/src/container/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use ostree::glib;
3131

3232
use std::borrow::Cow;
3333
use std::collections::HashMap;
34+
use std::fmt::Debug;
3435
use std::ops::Deref;
3536
use std::str::FromStr;
3637

@@ -277,7 +278,14 @@ impl std::fmt::Display for OstreeImageReference {
277278
(SignatureSource::ContainerPolicyAllowInsecure, imgref)
278279
if imgref.transport == Transport::Registry =>
279280
{
280-
write!(f, "ostree-unverified-registry:{}", self.imgref.name)
281+
// Because allow-insecure is the effective default, allow formatting
282+
// without it. Note this formatting is asymmetric and cannot be
283+
// re-parsed.
284+
if f.alternate() {
285+
write!(f, "{}", self.imgref)
286+
} else {
287+
write!(f, "ostree-unverified-registry:{}", self.imgref.name)
288+
}
281289
}
282290
(sigverify, imgref) => {
283291
write!(f, "{}:{}", sigverify, imgref)
@@ -584,10 +592,8 @@ mod tests {
584592
assert_eq!(ir.sigverify, SignatureSource::ContainerPolicy);
585593
assert_eq!(ir.imgref.transport, Transport::Registry);
586594
assert_eq!(ir.imgref.name, "quay.io/exampleos/blah");
587-
assert_eq!(
588-
ir.to_string(),
589-
"ostree-image-signed:docker://quay.io/exampleos/blah"
590-
);
595+
assert_eq!(ir.to_string(), ir_s);
596+
assert_eq!(format!("{:#}", &ir), ir_s);
591597

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

607614
#[test]

0 commit comments

Comments
 (0)