private static async Task <Stream> ProcessManifest(BicepRegistryBlobClient client, OciManifest manifest) { ProcessConfig(manifest.Config); if (manifest.Layers.Length != 1) { throw new InvalidModuleException("Expected a single layer in the OCI artifact."); } var layer = manifest.Layers.Single(); return(await ProcessLayer(client, layer)); }
private static async Task <Stream> ProcessLayer(BicepRegistryBlobClient client, OciDescriptor layer) { if (!string.Equals(layer.MediaType, BicepMediaTypes.BicepModuleLayerV1Json, MediaTypeComparison)) { throw new InvalidModuleException($"Did not expect layer media type \"{layer.MediaType}\"."); } Response <DownloadBlobResult> blobResult; try { blobResult = await client.DownloadBlobAsync(layer.Digest); } catch (RequestFailedException exception) when(exception.Status == 404) { throw new InvalidModuleException($"Module manifest refers to a non-existent blob with digest \"{layer.Digest}\".", exception); } ValidateBlobResponse(blobResult, layer); return(blobResult.Value.Content); }
private static async Task <(OciManifest, Stream, string)> DownloadManifestAsync(OciArtifactModuleReference moduleReference, BicepRegistryBlobClient client) { Response <DownloadManifestResult> manifestResponse; try { manifestResponse = await client.DownloadManifestAsync(moduleReference.Tag, new DownloadManifestOptions(ContentType.ApplicationVndOciImageManifestV1Json)); } catch (RequestFailedException exception) when(exception.Status == 404) { // manifest does not exist throw new OciModuleRegistryException("The module does not exist in the registry.", exception); } ValidateManifestResponse(manifestResponse); // the SDK doesn't expose all the manifest properties we need // so we need to deserialize the manifest ourselves to get everything var stream = manifestResponse.Value.Content; stream.Position = 0; var deserialized = DeserializeManifest(stream); stream.Position = 0; return(deserialized, stream, manifestResponse.Value.Digest); }