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

Commit

Permalink
container: Allow alternative formatting to drop `ostree-unverified-re…
Browse files Browse the repository at this point in the history
…gistry`

Since
34fea14
we are backing off the signature verification bits.  Let's make
it easier to not put those bits in the user's face by
adding an alternative formatting that drops it if it's the default.
  • Loading branch information
cgwalters committed Feb 13, 2024
1 parent bf56661 commit 399b7b7
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 399b7b7

Please sign in to comment.