Omit hash scheme from image.id. (#1658)

- Closes #1657.
- Also reduces `trimDigest()` output to 12 characters and gets rid of
the trailing ellipsis.
This commit is contained in:
J Logan
2026-06-05 14:43:20 -07:00
committed by GitHub
parent 1f4b47061e
commit 90cc3c15af
4 changed files with 37 additions and 9 deletions
@@ -69,8 +69,14 @@ public struct ImageResource: ManagedResource {
// MARK: ManagedResource
/// The unique identifier for this image. Identical to the image's index digest.
public var id: String { configuration.descriptor.digest }
/// The scheme-specific value of `configuration.descriptor.digest` (the hex portion
/// after the algorithm prefix). The fully-qualified digest — needed for content-store
/// lookups and XPC transport — is always recoverable as `configuration.descriptor.digest`.
public var id: String {
let digest = configuration.descriptor.digest
guard let colonIndex = digest.firstIndex(of: ":") else { return digest }
return String(digest[digest.index(after: colonIndex)...])
}
/// The user-facing reference (`name:tag`) for this image.
public var name: String { configuration.name }
@@ -44,12 +44,11 @@ public struct Utility {
}
public static func trimDigest(digest: String) -> String {
var digest = digest
digest.trimPrefix("sha256:")
if digest.count > 24 {
digest = String(digest.prefix(24)) + "..."
var hex = digest
if let colonIndex = digest.firstIndex(of: ":") {
hex = String(digest[digest.index(after: colonIndex)...])
}
return digest
return String(hex.prefix(12))
}
public static func validEntityName(_ name: String) throws {