|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the SwiftContainerPlugin open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +import struct Foundation.Data |
| 16 | + |
| 17 | +/// A source, such as a registry, from which container images can be fetched. |
| 18 | +public protocol ImageSource { |
| 19 | + /// Fetches a blob of unstructured data. |
| 20 | + /// |
| 21 | + /// - Parameters: |
| 22 | + /// - repository: Name of the source repository. |
| 23 | + /// - digest: Digest of the blob. |
| 24 | + /// - Returns: The downloaded data. |
| 25 | + /// - Throws: If the blob download fails. |
| 26 | + func getBlob( |
| 27 | + repository: ImageReference.Repository, |
| 28 | + digest: ImageReference.Digest |
| 29 | + ) async throws -> Data |
| 30 | + |
| 31 | + /// Fetches an image manifest. |
| 32 | + /// |
| 33 | + /// - Parameters: |
| 34 | + /// - repository: Name of the source repository. |
| 35 | + /// - reference: Tag or digest of the manifest to fetch. |
| 36 | + /// - Returns: The downloaded manifest. |
| 37 | + /// - Throws: If the download fails or the manifest cannot be decoded. |
| 38 | + func getManifest( |
| 39 | + repository: ImageReference.Repository, |
| 40 | + reference: any ImageReference.Reference |
| 41 | + ) async throws -> (ImageManifest, ContentDescriptor) |
| 42 | + |
| 43 | + /// Fetches an image index. |
| 44 | + /// |
| 45 | + /// - Parameters: |
| 46 | + /// - repository: Name of the source repository. |
| 47 | + /// - reference: Tag or digest of the index to fetch. |
| 48 | + /// - Returns: The downloaded index. |
| 49 | + /// - Throws: If the download fails or the index cannot be decoded. |
| 50 | + func getIndex( |
| 51 | + repository: ImageReference.Repository, |
| 52 | + reference: any ImageReference.Reference |
| 53 | + ) async throws -> ImageIndex |
| 54 | + |
| 55 | + /// Fetches an image configuration from the registry. |
| 56 | + /// |
| 57 | + /// - Parameters: |
| 58 | + /// - image: Reference to the image containing the record. |
| 59 | + /// - digest: Digest of the configuration object to fetch. |
| 60 | + /// - Returns: The image confguration record. |
| 61 | + /// - Throws: If the download fails or the configuration record cannot be decoded. |
| 62 | + /// |
| 63 | + /// Image configuration records are stored as blobs in the registry. This function retrieves |
| 64 | + /// the requested blob and tries to decode it as a configuration record. |
| 65 | + func getImageConfiguration( |
| 66 | + forImage image: ImageReference, |
| 67 | + digest: ImageReference.Digest |
| 68 | + ) async throws -> ImageConfiguration |
| 69 | +} |
0 commit comments