Class ContainerRegistryContentAsyncClient

java.lang.Object
com.azure.containers.containerregistry.ContainerRegistryContentAsyncClient

public final class ContainerRegistryContentAsyncClient extends Object
This class provides a client that exposes operations to push and pull images into container registry. It exposes methods that upload, download and delete artifacts from the registry i.e. images and manifests.

View this for additional ways to construct the client.

See Also:
  • Method Details

    • getRepositoryName

      public String getRepositoryName()
      This method returns the registry's repository on which operations are being performed.
      Returns:
      The name of the repository
    • getEndpoint

      public String getEndpoint()
      This method returns the complete registry endpoint.
      Returns:
      The registry endpoint including the authority.
    • setManifest

      public Mono<SetManifestResult> setManifest(OciImageManifest manifest, String tag)
      Upload the Oci manifest to the repository.

      Code Samples:

       OciImageManifest manifest = new OciImageManifest()
               .setConfiguration(configDescriptor)
               .setSchemaVersion(2)
               .setLayers(Collections.singletonList(layerDescriptor));
       Mono<SetManifestResult> result = contentClient.setManifest(manifest, "latest");
       
      Parameters:
      manifest - The OciImageManifest that needs to be uploaded.
      tag - Tag to apply on uploaded manifest. If null is passed, no tags will be applied.
      Returns:
      upload result.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the manifest is null.
      See Also:
    • setManifestWithResponse

      public Mono<com.azure.core.http.rest.Response<SetManifestResult>> setManifestWithResponse(SetManifestOptions options)
      Uploads a manifest to the repository.

      Code Samples:

       SetManifestOptions options = new SetManifestOptions(manifestList, DOCKER_MANIFEST_LIST_TYPE)
           .setTag("v2");
      
       contentClient.setManifestWithResponse(options)
           .subscribe(response ->
               System.out.println("Manifest uploaded, digest - " + response.getValue().getDigest()));
       
      Parameters:
      options - The options for the upload manifest operation.
      Returns:
      The rest response containing the upload result.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the data is null.
      See Also:
    • uploadBlob

      public Mono<UploadRegistryBlobResult> uploadBlob(com.azure.core.util.BinaryData content)
      Uploads a blob to the repository.

      Code Samples:

       BinaryData configContent = BinaryData.fromObject(Collections.singletonMap("hello", "world"));
      
       contentClient
           .uploadBlob(configContent)
           .subscribe(uploadResult -> System.out.printf("Uploaded blob: digest - '%s', size - %s\n",
                   uploadResult.getDigest(), uploadResult.getSizeInBytes()));
       
       contentClient.uploadBlob(BinaryData.fromFile(Paths.get("artifact.tar.gz"), CHUNK_SIZE))
           .subscribe(uploadResult ->
               System.out.printf("Uploaded blob: digest - '%s', size - %s\n",
                   uploadResult.getDigest(), uploadResult.getSizeInBytes()));
       
       layerContent
           .flatMap(content -> contentClient.uploadBlob(content))
           .doOnError(HttpResponseException.class, (ex) -> {
               if (ex.getCause() instanceof AcrErrorsException) {
                   AcrErrorsException acrErrors = (AcrErrorsException) ex.getCause();
                   for (AcrErrorInfo info : acrErrors.getValue().getErrors()) {
                       System.out.printf("Uploaded blob failed: code '%s'\n", info.getCode());
                   }
               }
           });
       

      Note:

      Content may be uploaded in chunks of up to 4MB size. Chunk size depends on the passed BinaryData content. When BinaryData is created using BinaryData.fromFlux(Flux, Long, boolean), it may be uploaded in chunks matching individual ByteBuffer in the Flux and up to 4MB size. Buffers that are bigger than 4MB can be broken down into smaller chunks, but small buffers are not aggregated. To decrease number of chunks for big content, use buffers of 4MB size.
      Parameters:
      content - The blob content that needs to be uploaded.
      Returns:
      The operation result.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the data is null.
    • getManifest

      public Mono<GetManifestResult> getManifest(String tagOrDigest)
      Download the manifest identified by the given tag or digest.

      Code Samples:

       contentClient.getManifest("latest")
           .doOnNext(downloadResult -> {
               if (ManifestMediaType.OCI_IMAGE_MANIFEST.equals(downloadResult.getManifestMediaType())
                   || ManifestMediaType.DOCKER_MANIFEST.equals(downloadResult.getManifestMediaType())) {
                   OciImageManifest manifest = downloadResult.getManifest().toObject(OciImageManifest.class);
                   System.out.println("Got OCI manifest");
               } else {
                   throw new IllegalArgumentException("Unexpected manifest type: " + downloadResult.getManifestMediaType());
               }
           })
           .block();
       
      Parameters:
      tagOrDigest - Manifest reference which can be tag or digest.
      Returns:
      The manifest identified by the given tag or digest.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the tagOrDigest is null.
      See Also:
    • getManifestWithResponse

      public Mono<com.azure.core.http.rest.Response<GetManifestResult>> getManifestWithResponse(String tagOrDigest)
      Download the manifest identified by the given tag or digest.

      Code Samples:

       contentClient.getManifestWithResponse("latest")
           .doOnNext(response -> {
               GetManifestResult manifestResult = response.getValue();
               if (ManifestMediaType.OCI_IMAGE_MANIFEST.equals(manifestResult.getManifestMediaType())
                   || ManifestMediaType.DOCKER_MANIFEST.equals(manifestResult.getManifestMediaType())) {
                   OciImageManifest manifest = manifestResult.getManifest().toObject(OciImageManifest.class);
                   System.out.println("Got OCI manifest");
               } else {
                   throw new IllegalArgumentException("Unexpected manifest type: " + manifestResult.getManifestMediaType());
               }
           })
           .block();
       
      Parameters:
      tagOrDigest - Manifest reference which can be tag or digest.
      Returns:
      The response for the manifest identified by the given tag or digest.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the tagOrDigest is null.
    • downloadStream

      public Mono<com.azure.core.util.BinaryData> downloadStream(String digest)
      Download the blob identified by the given digest. Content is downloaded in chunks of 4MB size each.

      Code Samples:

      Write content to synchronous channel, for example FileChannel:
       contentClient
           .downloadStream(digest)
           .flatMap(downloadResult ->
               Mono.using(() -> new FileOutputStream(trimSha(digest)),
                   fileStream -> FluxUtil.writeToWritableByteChannel(
                       downloadResult.toFluxByteBuffer(), fileStream.getChannel()),
                   fileStream -> closeStream(fileStream)))
           .block();
       
      Write content to asynchronous byte channel, for example AsynchronousSocketChannel:
       contentClient
           .downloadStream(digest)
           .flatMap(downloadResult ->
               Mono.using(
                   () -> openSocket(),
                   socket -> FluxUtil.writeToAsynchronousByteChannel(downloadResult.toFluxByteBuffer(), socket),
                   socket -> closeStream(socket)))
           .block();
       
      Parameters:
      digest - The digest for the given image layer.
      Returns:
      The image identified by the given digest.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the digest is null.
    • deleteBlob

      public Mono<Void> deleteBlob(String digest)
      Delete the image identified by the given digest

      Code Samples:

       contentClient.getManifest("latest")
           .flatMap(manifest -> contentClient.deleteBlob(manifest.getDigest()))
           .block();
       
      Parameters:
      digest - The digest for the given image layer.
      Returns:
      The completion signal.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the digest is null.
    • deleteBlobWithResponse

      public Mono<com.azure.core.http.rest.Response<Void>> deleteBlobWithResponse(String digest)
      Delete the image identified by the given digest
      Parameters:
      digest - The digest for the given image layer.
      Returns:
      The REST response for the completion.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the digest is null.
    • deleteManifest

      public Mono<Void> deleteManifest(String digest)
      Delete the manifest identified by the given digest.

      Code Samples:

       contentClient.getManifest("latest")
           .flatMap(manifest -> contentClient.deleteManifest(manifest.getDigest()))
           .block();
       
      Parameters:
      digest - The digest of the manifest.
      Returns:
      The completion.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the digest is null.
    • deleteManifestWithResponse

      public Mono<com.azure.core.http.rest.Response<Void>> deleteManifestWithResponse(String digest)
      Delete the manifest identified by the given digest.
      Parameters:
      digest - The digest of the manifest.
      Returns:
      The REST response for completion.
      Throws:
      com.azure.core.exception.ClientAuthenticationException - thrown if the client's credentials do not have access to modify the namespace.
      NullPointerException - thrown if the digest is null.