Skip to content

Commit 35a41c3

Browse files
committed
cli/trust: check for Digested, Tagged reference instead of Canonical
The [Canonical] interface defines images that are both [Named] and [Digested], but in all places where it was used, we were only interested whether the reference contained a digest. Similarly [NamedTagged] is a superset of [Tagged], so checking for [Tagged] is sufficient if we're already dealing with a [Named] reference. This patch changes those checks to check for [Digested] and [Tagged] references, as that's what's relevant for these checks. [Named]: https://pkg.go.dev/github.com/distribution/reference#Named [NamedTagged]: https://pkg.go.dev/github.com/distribution/reference#NamedTagged [Canonical]: https://pkg.go.dev/github.com/distribution/reference#Canonical [Digested]: https://pkg.go.dev/github.com/distribution/reference#Digested Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent abe4aa7 commit 35a41c3

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

cli/trust/trust.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ func GetImageReferencesAndAuth(ctx context.Context,
346346

347347
func getTag(ref reference.Named) string {
348348
switch x := ref.(type) {
349-
case reference.Canonical, reference.Digested:
350-
return ""
351-
case reference.NamedTagged:
349+
case reference.Digested:
350+
return "" // TODO(thaJeztah): is it intentional to discard the tag when "Tagged+Digested"?
351+
case reference.Tagged:
352352
return x.Tag()
353353
default:
354354
return ""
@@ -357,12 +357,10 @@ func getTag(ref reference.Named) string {
357357

358358
func getDigest(ref reference.Named) digest.Digest {
359359
switch x := ref.(type) {
360-
case reference.Canonical:
361-
return x.Digest()
362360
case reference.Digested:
363361
return x.Digest()
364362
default:
365-
return digest.Digest("")
363+
return ""
366364
}
367365
}
368366

cli/trust/trust_push.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func PushTrustedReference(ctx context.Context, ioStreams Streams, repoInfo *Repo
6363

6464
var tag string
6565
switch x := ref.(type) {
66-
case reference.Canonical:
66+
case reference.Digested:
6767
return errors.New("cannot push a digest reference")
68-
case reference.NamedTagged:
68+
case reference.Tagged:
6969
tag = x.Tag()
7070
default:
7171
// We want trust signatures to always take an explicit tag,

0 commit comments

Comments
 (0)