From 2eb37b0928ea91ec553dddb4b37e4d170c8d5ee0 Mon Sep 17 00:00:00 2001 From: Pallavi Taneja Date: Fri, 12 Nov 2021 11:40:49 -0800 Subject: [PATCH 1/2] Move ACR to use the new code snippet generation. --- .../pom.xml | 3 + .../ContainerRegistryAsyncClient.java | 71 ++++++++- .../ContainerRegistryClient.java | 69 +++++++-- .../ContainerRegistryClientBuilder.java | 50 ++++++- .../ContainerRepository.java | 83 +++++++++-- .../ContainerRepositoryAsync.java | 82 +++++++++-- .../containerregistry/RegistryArtifact.java | 135 +++++++++++++++--- .../RegistryArtifactAsync.java | 128 +++++++++++++++-- .../containerregistry/ReadmeSamples.java | 26 +++- 9 files changed, 574 insertions(+), 73 deletions(-) diff --git a/sdk/containerregistry/azure-containers-containerregistry/pom.xml b/sdk/containerregistry/azure-containers-containerregistry/pom.xml index 6fa9810630af3..8ee4acee4173e 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/pom.xml +++ b/sdk/containerregistry/azure-containers-containerregistry/pom.xml @@ -28,6 +28,9 @@ + false + + --add-exports com.azure.core/com.azure.core.implementation.http=ALL-UNNAMED diff --git a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryAsyncClient.java b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryAsyncClient.java index c4ee4f53ddb87..93533f549908e 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryAsyncClient.java +++ b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryAsyncClient.java @@ -30,10 +30,31 @@ * *

Instantiating an asynchronous Container Registry client

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryAsyncClient.instantiation} + * + *
+ * ContainerRegistryAsyncClient registryAsyncClient = new ContainerRegistryClientBuilder()
+ *     .endpoint(endpoint)
+ *     .credential(credential)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .buildAsyncClient();
+ * 
+ * * *

Instantiating an asynchronous Container Registry client using a custom pipeline

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryAsyncClient.pipeline.instantiation} + * + *
+ * HttpPipeline pipeline = new HttpPipelineBuilder()
+ *     .policies(/* add policies */)
+ *     .build();
+ *
+ * ContainerRegistryAsyncClient registryAsyncClient = new ContainerRegistryClientBuilder()
+ *     .pipeline(pipeline)
+ *     .endpoint(endpoint)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .credential(credential)
+ *     .buildAsyncClient();
+ * 
+ * * *

View {@link ContainerRegistryClientBuilder this} for additional ways to construct the client.

* @@ -74,7 +95,13 @@ public String getEndpoint() { * *

List repository names in the registry.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryAsyncClient.listRepositoryNames} + * + *
+     * client.listRepositoryNames().subscribe(name -> {
+     *     System.out.printf("Repository Name:%s,", name);
+     * });
+     * 
+ * * * @return list of repository names. * @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the namespace. @@ -122,7 +149,15 @@ Mono> listRepositoryNamesNextSinglePageAsync(String nextLi * *

Delete a repository in the registry.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryAsyncClient.deleteRepositoryWithResponse#String} + * + *
+     * client.deleteRepositoryWithResponse(repositoryName).subscribe(response -> {
+     *     System.out.printf("Successfully initiated delete of the repository.");
+     * }, error -> {
+     *     System.out.println("Failed to initiate a delete of the repository.");
+     * });
+     * 
+ * * * @param repositoryName Name of the repository (including the namespace). * @return the completion. @@ -157,7 +192,15 @@ Mono> deleteRepositoryWithResponse(String repositoryName, Context * Delete the repository identified by {@code repositoryName}. * *

Delete a repository in the registry.

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryAsyncClient.deleteRepository#String} + * + *
+     * client.deleteRepository(repositoryName).subscribe(response -> {
+     *     System.out.printf("Successfully initiated delete of the repository.");
+     * }, error -> {
+     *     System.out.println("Failed to initiate a delete of the repository.");
+     * });
+     * 
+ * * * @param repositoryName Name of the image (including the namespace). * @return the completion stream. @@ -178,7 +221,14 @@ Mono deleteRepository(String repositoryName, Context context) { * Creates a new instance of {@link ContainerRepositoryAsync} object for the specified repository. * *

Create an instance of ContainerRepositoryAsync helper type

- * {@codesnippet com.azure.containers.containerregistry.containeregistryasyncclient.getRepository} + * + *
+     * ContainerRepositoryAsync repositoryAsync = client.getRepository(repositoryName);
+     * repositoryAsync.getProperties().subscribe(properties -> {
+     *     System.out.println(properties.getName());
+     * });
+     * 
+ * * * @param repositoryName Name of the repository to reference. * @return A new {@link ContainerRepositoryAsync} for the desired repository. @@ -193,7 +243,14 @@ public ContainerRepositoryAsync getRepository(String repositoryName) { * Creates a new instance of {@link RegistryArtifactAsync} object for the specified artifact. * *

Create an instance of RegistryArtifactAsync helper type

- * {@codesnippet com.azure.containers.containerregistry.containeregistryasyncclient.getArtifact} + * + *
+     * RegistryArtifactAsync registryArtifactAsync = client.getArtifact(repositoryName, tagOrDigest);
+     * registryArtifactAsync.getManifestProperties().subscribe(properties -> {
+     *     System.out.println(properties.getDigest());
+     * });
+     * 
+ * * * @param repositoryName Name of the repository to reference. * @param digest Either a tag or digest that uniquely identifies the artifact. diff --git a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryClient.java b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryClient.java index a980ea0504bff..f381eca0a65d8 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryClient.java +++ b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryClient.java @@ -18,10 +18,31 @@ * that can be used to perform operations on repository and artifacts. * *

Instantiating a synchronous Container Registry client

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.instantiation} + * + *
+ * ContainerRegistryClient registryAsyncClient = new ContainerRegistryClientBuilder()
+ *     .endpoint(endpoint)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .credential(credential)
+ *     .buildClient();
+ * 
+ * * *

Instantiating a synchronous Container Registry client with custom pipeline

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.pipeline.instantiation} + * + *
+ * HttpPipeline pipeline = new HttpPipelineBuilder()
+ *     .policies(/* add policies */)
+ *     .build();
+ *
+ * ContainerRegistryClient registryAsyncClient = new ContainerRegistryClientBuilder()
+ *     .pipeline(pipeline)
+ *     .endpoint(endpoint)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .credential(credential)
+ *     .buildClient();
+ * 
+ * * *

View {@link ContainerRegistryClientBuilder this} for additional ways to construct the client.

* @@ -48,7 +69,13 @@ public String getEndpoint() { * *

List the repository names in the registry.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.listRepositoryNames} + * + *
+     * client.listRepositoryNames().stream().forEach(name -> {
+     *     System.out.printf("Repository Name:%s,", name);
+     * });
+     * 
+ * * * @return list of repository names. * @throws ClientAuthenticationException thrown if the client credentials do not have access to perform this operation. @@ -62,7 +89,13 @@ public PagedIterable listRepositoryNames() { * List all the repository names in this registry. * *

List the repository names in the registry.

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.listRepositoryNames#Context} + * + *
+     * client.listRepositoryNames(Context.NONE).stream().forEach(name -> {
+     *     System.out.printf("Repository Name:%s,", name);
+     * });
+     * 
+ * * * @param context The context to associate with this operation. * @return list of repositories. @@ -77,7 +110,11 @@ public PagedIterable listRepositoryNames(Context context) { * Delete the repository identified by {@code repositoryName}. * *

Delete a repository in the registry.

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.deleteRepository#String} + * + *
+     * client.deleteRepository(repositoryName);
+     * 
+ * * * @param repositoryName Name of the repository (including the namespace). * @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the namespace. @@ -93,7 +130,11 @@ public void deleteRepository(String repositoryName) { * Delete the repository identified by {@code repositoryName}. * *

Delete a repository in the registry.

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.deleteRepositoryWithResponse#String-Context} + * + *
+     * client.deleteRepositoryWithResponse(repositoryName, Context.NONE);
+     * 
+ * * * @param repositoryName Name of the repository (including the namespace). * @param context The context to associate with this operation. @@ -111,7 +152,13 @@ public Response deleteRepositoryWithResponse(String repositoryName, Contex * Creates a new instance of {@link ContainerRepository} object for the specified repository. * *

Create a ContainerRegistry helper instance.

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.getRepository} + * + *
+     * ContainerRepository repository = client.getRepository(repositoryName);
+     * ContainerRepositoryProperties properties = repository.getProperties();
+     * System.out.println(properties.getName());
+     * 
+ * * * @param repositoryName Name of the repository to reference. * @return A new {@link ContainerRepository} for the desired repository. @@ -126,7 +173,13 @@ public ContainerRepository getRepository(String repositoryName) { * Creates a new instance of {@link RegistryArtifact} object for the specified artifact. * *

Create a RegistryArtifact helper instance.

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.getArtifact} + * + *
+     * RegistryArtifact registryArtifact = client.getArtifact(repositoryName, tagOrDigest);
+     * ArtifactManifestProperties properties = registryArtifact.getManifestProperties();
+     * System.out.println(properties.getDigest());
+     * 
+ * * * * @param repositoryName Name of the repository to reference. diff --git a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryClientBuilder.java b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryClientBuilder.java index 455d0124b805d..f4dbef5f5ca26 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryClientBuilder.java +++ b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRegistryClientBuilder.java @@ -32,10 +32,26 @@ * *

The client needs the service endpoint of the Azure Container Registry, Audience for ACR that you want to target and Azure access credentials to use for authentication. *

Instantiating an asynchronous Container Registry client

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryAsyncClient.instantiation} + * + *
+ * ContainerRegistryAsyncClient registryAsyncClient = new ContainerRegistryClientBuilder()
+ *     .endpoint(endpoint)
+ *     .credential(credential)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .buildAsyncClient();
+ * 
+ * * *

Instantiating a synchronous Container Registry client

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.instantiation} + * + *
+ * ContainerRegistryClient registryAsyncClient = new ContainerRegistryClientBuilder()
+ *     .endpoint(endpoint)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .credential(credential)
+ *     .buildClient();
+ * 
+ * * *

Another way to construct the client is using a {@link HttpPipeline}. The pipeline gives the client an * authenticated way to communicate with the service but it doesn't contain the service endpoint. Set the pipeline with @@ -48,10 +64,36 @@ * For more information please see Azure Container Registry Authentication .

* *

Instantiating an asynchronous Container Registry client using a custom pipeline

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryAsyncClient.pipeline.instantiation} + * + *
+ * HttpPipeline pipeline = new HttpPipelineBuilder()
+ *     .policies(/* add policies */)
+ *     .build();
+ *
+ * ContainerRegistryAsyncClient registryAsyncClient = new ContainerRegistryClientBuilder()
+ *     .pipeline(pipeline)
+ *     .endpoint(endpoint)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .credential(credential)
+ *     .buildAsyncClient();
+ * 
+ * * *

Instantiating a synchronous Container Registry client with custom pipeline

- * {@codesnippet com.azure.containers.containerregistry.ContainerRegistryClient.pipeline.instantiation} + * + *
+ * HttpPipeline pipeline = new HttpPipelineBuilder()
+ *     .policies(/* add policies */)
+ *     .build();
+ *
+ * ContainerRegistryClient registryAsyncClient = new ContainerRegistryClientBuilder()
+ *     .pipeline(pipeline)
+ *     .endpoint(endpoint)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .credential(credential)
+ *     .buildClient();
+ * 
+ * * * * @see ContainerRegistryAsyncClient diff --git a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRepository.java b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRepository.java index 96bf2c464cb9a..11291733362d5 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRepository.java +++ b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRepository.java @@ -22,7 +22,15 @@ * *

Instantiating Container Repository helper type.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.instantiation} + * + *
+ * ContainerRepository repositoryClient = new ContainerRegistryClientBuilder()
+ *     .endpoint(endpoint)
+ *     .credential(credential)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .buildClient().getRepository(repository);
+ * 
+ * * *

View {@link ContainerRegistryClientBuilder this} for additional ways to construct the client.

* @@ -67,7 +75,12 @@ public String getRegistryEndpoint() { * *

Delete the repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.deleteRepositoryWithResponse} + * + *
+     * Response<Void> response = client.deleteWithResponse(Context.NONE);
+     * System.out.printf("Successfully initiated delete.");
+     * 
+ * * * @param context Additional context that is passed through the Http pipeline during the service call. artifacts * that are deleted as part of the repository delete. @@ -87,7 +100,12 @@ public Response deleteWithResponse(Context context) { * *

Delete the repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.deleteRepository} + * + *
+     * client.delete();
+     * System.out.printf("Successfully initiated delete.");
+     * 
+ * * * @throws ClientAuthenticationException thrown if the client does not have access to the repository. * @throws HttpResponseException thrown if any other unexpected exception is returned by the service. @@ -105,7 +123,13 @@ public void delete() { * *

Get the properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.getPropertiesWithResponse} + * + *
+     * Response<ContainerRepositoryProperties> response = client.getPropertiesWithResponse(Context.NONE);
+     * final ContainerRepositoryProperties properties = response.getValue();
+     * System.out.printf("Name:%s,", properties.getName());
+     * 
+ * * * @param context Additional context that is passed through the Http pipeline during the service call. * @return A REST response with the {@link ContainerRepositoryProperties properties} associated with the given @@ -127,7 +151,12 @@ public Response getPropertiesWithResponse(Context * *

Get the properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.getProperties} + * + *
+     * ContainerRepositoryProperties properties = client.getProperties();
+     * System.out.printf("Name:%s,", properties.getName());
+     * 
+ * * * @return The {@link ContainerRepositoryProperties properties} associated with the given {@link #getName() * repository}. @@ -165,7 +194,15 @@ public RegistryArtifact getArtifact(String digest) { * *

Retrieve all artifacts associated with the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.listManifestProperties}. + * + *
+     * client.listManifestProperties().iterableByPage(10)
+     *     .forEach(pagedResponse -> {
+     *         pagedResponse.getValue().stream().forEach(
+     *             ManifestProperties -> System.out.println(ManifestProperties.getDigest()));
+     *     });
+     * 
+ * * * @return {@link PagedIterable} of the artifacts for the given repository in the order specified by the options. * @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the @@ -189,7 +226,15 @@ public PagedIterable listManifestProperties() { * *

Retrieve all artifacts associated with the given repository from the most recently updated to the last.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.listManifestPropertiesWithOptionsNoContext}. + * + *
+     * client.listManifestProperties(ArtifactManifestOrderBy.LAST_UPDATED_ON_DESCENDING).iterableByPage(10)
+     *     .forEach(pagedResponse -> {
+     *         pagedResponse.getValue().stream().forEach(
+     *             ManifestProperties -> System.out.println(ManifestProperties.getDigest()));
+     *     });
+     * 
+ * * * @param orderBy the order in which the artifacts are returned by the service. * @return {@link PagedIterable} of the artifacts for the given repository in the order specified by the options. @@ -214,7 +259,15 @@ public PagedIterable listManifestProperties(Artifact * *

Retrieve all artifacts associated with the given repository from the most recently updated to the last.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.listManifestPropertiesWithOptions}. + * + *
+     * client.listManifestProperties(ArtifactManifestOrderBy.LAST_UPDATED_ON_DESCENDING, Context.NONE).iterableByPage(10)
+     *     .forEach(pagedResponse -> {
+     *         pagedResponse.getValue().stream().forEach(
+     *             ManifestProperties -> System.out.println(ManifestProperties.getDigest()));
+     *     });
+     * 
+ * * * @param orderBy the order in which the artifacts are returned by the service. * @param context Additional context that is passed through the Http pipeline during the service call. @@ -236,7 +289,12 @@ public PagedIterable listManifestProperties(Artifact * *

Update the writeable properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.updatePropertiesWithResponse}. + * + *
+     * ContainerRepositoryProperties properties = getRepositoryProperties();
+     * client.updatePropertiesWithResponse(properties, Context.NONE);
+     * 
+ * * * @param repositoryProperties {@link ContainerRepositoryProperties repository properties} that need to be updated * for the repository. @@ -260,7 +318,12 @@ public Response updatePropertiesWithResponse(Cont * *

Update the writeable properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepository.updateProperties}. + * + *
+     * ContainerRepositoryProperties properties = getRepositoryProperties();
+     * client.updateProperties(properties);
+     * 
+ * * * @param repositoryProperties {@link ContainerRepositoryProperties repository properties} that need to be updated * for the repository. diff --git a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRepositoryAsync.java b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRepositoryAsync.java index 6453e516f03fb..f5439b47bfca5 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRepositoryAsync.java +++ b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/ContainerRepositoryAsync.java @@ -40,7 +40,16 @@ * *

Instantiating an asynchronous Container Repository Helper class

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepositoryAsync.instantiation} + * + *
+ * ContainerRepositoryAsync repositoryAsyncClient = new ContainerRegistryClientBuilder()
+ *     .endpoint(endpoint)
+ *     .credential(credential)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .buildAsyncClient()
+ *     .getRepository(repository);
+ * 
+ * * */ public final class ContainerRepositoryAsync { @@ -114,7 +123,15 @@ public String getRegistryEndpoint() { * *

Delete the repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepositoryAsync.deleteRepositoryWithResponse} + * + *
+     * client.deleteWithResponse().subscribe(response -> {
+     *     System.out.printf("Successfully initiated delete of the repository.");
+     * }, error -> {
+     *     System.out.println("Failed to initiate a delete of the repository.");
+     * });
+     * 
+ * * * @return A REST response containing the result of the repository delete operation. It returns the count of the tags and * artifacts that are deleted as part of the repository delete. @@ -143,7 +160,15 @@ Mono> deleteWithResponse(Context context) { * *

Delete the repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepositoryAsync.deleteRepository} + * + *
+     * client.delete().subscribe(response -> {
+     *     System.out.printf("Successfully initiated delete of the repository.");
+     * }, error -> {
+     *     System.out.println("Failed to initiate a delete of the repository.");
+     * });
+     * 
+ * * * @return It returns the count of the tags and artifacts that are deleted as part of the repository delete. * @throws ClientAuthenticationException thrown if the client does not have access to the repository. @@ -178,7 +203,15 @@ public RegistryArtifactAsync getArtifact(String digest) { * *

Retrieve all artifacts associated with the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepositoryAsync.listManifestProperties}. + * + *
+     * client.listManifestProperties().byPage(10)
+     *     .subscribe(ManifestPropertiesPagedResponse -> {
+     *         ManifestPropertiesPagedResponse.getValue().stream().forEach(
+     *             ManifestProperties -> System.out.println(ManifestProperties.getDigest()));
+     *     });
+     * 
+ * * * @return {@link PagedFlux} of ManifestProperties for all the artifacts in the given repository. * @throws ClientAuthenticationException thrown if the client does not have access to the repository. @@ -200,7 +233,15 @@ public PagedFlux listManifestProperties() { * *

Retrieve all artifacts associated with the given repository from the most recently updated to the last.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepositoryAsync.listManifestPropertiesWithOptions}. + * + *
+     * client.listManifestProperties(ArtifactManifestOrderBy.LAST_UPDATED_ON_DESCENDING).byPage(10)
+     *     .subscribe(ManifestPropertiesPagedResponse -> {
+     *         ManifestPropertiesPagedResponse.getValue().stream().forEach(
+     *             ManifestProperties -> System.out.println(ManifestProperties.getDigest()));
+     *     });
+     * 
+ * * * @param orderBy The order in which the artifacts are returned by the service. * @return {@link PagedFlux} of the artifacts for the given repository in the order specified by the options. @@ -278,7 +319,14 @@ private List mapManifestsProperties(ListGet the properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepositoryAsync.getPropertiesWithResponse} + * + *
+     * client.getPropertiesWithResponse().subscribe(response -> {
+     *     final ContainerRepositoryProperties properties = response.getValue();
+     *     System.out.printf("Name:%s,", properties.getName());
+     * });
+     * 
+ * * * @return A REST response with the {@link ContainerRepositoryProperties properties} associated with the given {@link #getName() repository}. * @throws ClientAuthenticationException thrown if the client have access to the repository. @@ -306,7 +354,13 @@ Mono> getPropertiesWithResponse(Context * *

Get the properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepositoryAsync.getProperties} + * + *
+     * client.getProperties().subscribe(response -> {
+     *     System.out.printf("Name:%s,", response.getName());
+     * });
+     * 
+ * * * @return The {@link ContainerRepositoryProperties properties} associated with the given {@link #getName() repository}. * @throws ClientAuthenticationException thrown if the client does not have access to the repository. @@ -326,7 +380,12 @@ public Mono getProperties() { * *

Update the writeable properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepositoryAsync.updatePropertiesWithResponse}. + * + *
+     * ContainerRepositoryProperties properties = getRepositoryProperties();
+     * client.updatePropertiesWithResponse(properties).subscribe();
+     * 
+ * * * @param repositoryProperties {@link ContainerRepositoryProperties repository properties} that need to be updated for the repository. * @return The updated {@link ContainerRepositoryProperties repository properties }. @@ -368,7 +427,12 @@ Mono> updatePropertiesWithResponse(Conta * *

Update the writeable properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.ContainerRepositoryAsync.updateProperties}. + * + *
+     * ContainerRepositoryProperties properties = getRepositoryProperties();
+     * client.updateProperties(properties).subscribe();
+     * 
+ * * * @param repositoryProperties {@link ContainerRepositoryProperties writeable properties} that need to be updated for the repository. * @return The completion. diff --git a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/RegistryArtifact.java b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/RegistryArtifact.java index e46bcb217a129..888e4127d8924 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/RegistryArtifact.java +++ b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/RegistryArtifact.java @@ -21,7 +21,15 @@ * *

Instantiating Registry Artifact

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.instantiation} + * + *
+ * RegistryArtifact registryArtifact = new ContainerRegistryClientBuilder()
+ *     .endpoint(endpoint)
+ *     .credential(credential)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .buildClient().getArtifact(repository, digest);
+ * 
+ * */ public final class RegistryArtifact { private final RegistryArtifactAsync asyncClient; @@ -67,7 +75,11 @@ public String getFullyQualifiedReference() { * *

Delete the registry artifact.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.deleteWithResponse#Context} + * + *
+     * client.deleteWithResponse(Context.NONE);
+     * 
+ * * * @param context Additional context that is passed through the Http pipeline during the service call. * @return A REST response containing the result of the service call. @@ -86,7 +98,11 @@ public Response deleteWithResponse(Context context) { * *

Delete the registry artifact.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.delete} + * + *
+     * client.delete();
+     * 
+ * * * @throws ClientAuthenticationException thrown if the client does not have access to modify the namespace. * @throws HttpResponseException thrown if any other unexpected exception is returned by the service. @@ -103,7 +119,12 @@ public void delete() { * *

Delete the tag for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.deleteTagWithResponse} + * + *
+     * String tag = getTag();
+     * client.deleteTagWithResponse(tag, Context.NONE);
+     * 
+ * * * @param tag The name of the tag that needs to be deleted. * @param context Additional context that is passed through the Http pipeline during the service call. @@ -125,7 +146,12 @@ public Response deleteTagWithResponse(String tag, Context context) { * *

Delete the tag for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.deleteTag} + * + *
+     * String tag = getTag();
+     * client.deleteTag(tag);
+     * 
+ * * * @param tag The name of the tag that needs to be deleted. * @throws ClientAuthenticationException thrown if the client does not have access to modify the namespace. @@ -149,7 +175,14 @@ public void deleteTag(String tag) { * *

Get the properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.getManifestPropertiesWithResponse} + * + *
+     * Response<ArtifactManifestProperties> response = client.getManifestPropertiesWithResponse(
+     *     Context.NONE);
+     * final ArtifactManifestProperties properties = response.getValue();
+     * System.out.printf("Digest:%s,", properties.getDigest());
+     * 
+ * * * @param context Additional context that is passed through the Http pipeline during the service call. * @return A REST response containing {@link ArtifactManifestProperties properties} associated with the given {@code Digest}. @@ -172,7 +205,12 @@ public Response getManifestPropertiesWithResponse(Co * *

Get the registry artifact properties for a given tag or digest.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.getManifestProperties}. + * + *
+     * ArtifactManifestProperties properties = client.getManifestProperties();
+     * System.out.printf("Digest:%s,", properties.getDigest());
+     * 
+ * * * @return The {@link ArtifactManifestProperties properties} associated with the given {@code Digest}. * @throws ClientAuthenticationException thrown if the client's credentials do not have access to modify the namespace. @@ -191,7 +229,14 @@ public ArtifactManifestProperties getManifestProperties() { * *

Retrieve the properties associated with the given tag.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.getTagPropertiesWithResponse}. + * + *
+     * String tag = getTag();
+     * Response<ArtifactTagProperties> response = client.getTagPropertiesWithResponse(tag, Context.NONE);
+     * final ArtifactTagProperties properties = response.getValue();
+     * System.out.printf("Digest:%s,", properties.getDigest());
+     * 
+ * * * @param tag name of the tag. * @param context Additional context that is passed through the Http pipeline during the service call. @@ -215,7 +260,13 @@ public Response getTagPropertiesWithResponse(String tag, * *

Retrieve the properties associated with the given tag.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.getTagProperties}. + * + *
+     * String tag = getTag();
+     * ArtifactTagProperties properties = client.getTagProperties(tag);
+     * System.out.printf("Digest:%s,", properties.getDigest());
+     * 
+ * * * @param tag name of the tag. * @return The {@link ArtifactTagProperties properties} associated with the given tag. @@ -242,7 +293,17 @@ public ArtifactTagProperties getTagProperties(String tag) { * *

Retrieve all the tags associated with the given repository from the most recently updated to the last.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.listTagPropertiesWithOptions}. + * + *
+     * client.listTagProperties(ArtifactTagOrderBy.LAST_UPDATED_ON_DESCENDING, Context.NONE)
+     *     .iterableByPage(10)
+     *     .forEach(pagedResponse -> {
+     *         pagedResponse.getValue()
+     *             .stream()
+     *             .forEach(tagProperties -> System.out.println(tagProperties.getDigest()));
+     *     });
+     * 
+ * * * @return {@link PagedIterable} of the artifacts for the given repository in the order specified by the options. * @throws ClientAuthenticationException thrown if the client does not have access to the repository. @@ -265,7 +326,17 @@ public PagedIterable listTagProperties() { * *

Retrieve all the tags associated with the given repository from the most recently updated to the last.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.listTagPropertiesWithOptionsNoContext}. + * + *
+     * client.listTagProperties(ArtifactTagOrderBy.LAST_UPDATED_ON_DESCENDING)
+     *     .iterableByPage(10)
+     *     .forEach(pagedResponse -> {
+     *         pagedResponse.getValue()
+     *             .stream()
+     *             .forEach(tagProperties -> System.out.println(tagProperties.getDigest()));
+     *     });
+     * 
+ * * * @param orderBy The order in which the tags should be returned by the service. * @return {@link PagedIterable} of the artifacts for the given repository in the order specified by the options. @@ -289,7 +360,17 @@ public PagedIterable listTagProperties(ArtifactTagOrderBy * *

Retrieve all the tags associated with the given repository from the most recently updated to the last.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.listTagPropertiesWithOptions}. + * + *
+     * client.listTagProperties(ArtifactTagOrderBy.LAST_UPDATED_ON_DESCENDING, Context.NONE)
+     *     .iterableByPage(10)
+     *     .forEach(pagedResponse -> {
+     *         pagedResponse.getValue()
+     *             .stream()
+     *             .forEach(tagProperties -> System.out.println(tagProperties.getDigest()));
+     *     });
+     * 
+ * * * @param orderBy The order in which the tags should be returned by the service. * @param context Additional context that is passed through the Http pipeline during the service call. @@ -310,7 +391,13 @@ public PagedIterable listTagProperties(ArtifactTagOrderBy * *

Update the writeable properties of a given tag.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.updateTagPropertiesWithResponse}. + * + *
+     * ArtifactTagProperties properties = getArtifactTagProperties();
+     * String tag = getTag();
+     * client.updateTagPropertiesWithResponse(tag, properties, Context.NONE);
+     * 
+ * * * @param tag Name of the tag. * @param tagProperties {@link ArtifactTagProperties tagProperties} to be set. @@ -335,7 +422,13 @@ public Response updateTagPropertiesWithResponse(String ta * *

Update the writeable properties of a given tag.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.updateTagProperties}. + * + *
+     * ArtifactTagProperties properties = getArtifactTagProperties();
+     * String tag = getTag();
+     * client.updateTagProperties(tag, properties);
+     * 
+ * * * @param tag Name of the tag. * @param tagProperties {@link ArtifactTagProperties tagProperties} to be set. @@ -359,7 +452,12 @@ public ArtifactTagProperties updateTagProperties(String tag, ArtifactTagProperti * *

Update the writeable properties of a given artifact.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.updateManifestPropertiesWithResponse}. + * + *
+     * ArtifactManifestProperties properties = getArtifactManifestProperties();
+     * client.updateManifestPropertiesWithResponse(properties, Context.NONE);
+     * 
+ * * * @param manifestProperties {@link ArtifactManifestProperties tagProperties} to be set. * @param context Additional context that is passed through the Http pipeline during the service call. @@ -380,7 +478,12 @@ public Response updateManifestPropertiesWithResponse * *

Update the writeable properties of a given manifest.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifact.updateManifestProperties}. + * + *
+     * ArtifactManifestProperties properties = getArtifactManifestProperties();
+     * client.updateManifestProperties(properties);
+     * 
+ * * * @param manifestProperties {@link ArtifactManifestProperties manifestProperties} to be set. * @return The updated {@link ArtifactManifestProperties properties } diff --git a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/RegistryArtifactAsync.java b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/RegistryArtifactAsync.java index 1367c87d54b2c..e5e979a5ba367 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/RegistryArtifactAsync.java +++ b/sdk/containerregistry/azure-containers-containerregistry/src/main/java/com/azure/containers/containerregistry/RegistryArtifactAsync.java @@ -42,7 +42,15 @@ * *

Instantiating an asynchronous RegistryArtifact helper.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.instantiation} + * + *
+ * RegistryArtifactAsync registryArtifactAsync = new ContainerRegistryClientBuilder()
+ *     .endpoint(endpoint)
+ *     .credential(credential)
+ *     .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD)
+ *     .buildAsyncClient().getArtifact(repository, digest);
+ * 
+ * * *

View {@link ContainerRegistryClientBuilder this} for additional ways to construct the client.

* @@ -162,7 +170,11 @@ private Mono getDigestMono() { * *

Delete the registry artifact.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.deleteWithResponse} + * + *
+     * client.deleteWithResponse().subscribe();
+     * 
+ * * * @return A REST response with completion signal. * @throws ClientAuthenticationException thrown if the client does not have access to the repository. @@ -191,7 +203,11 @@ Mono> deleteWithResponse(Context context) { * *

Delete the registry artifact.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.delete} + * + *
+     * client.delete().subscribe();
+     * 
+ * * * @return the completion. * @throws ClientAuthenticationException thrown if the client does not have access to the repository. @@ -209,7 +225,12 @@ public Mono delete() { * *

Delete the tag for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.deleteTagWithResponse} + * + *
+     * String tag = getTag();
+     * client.deleteTagWithResponse(tag).subscribe();
+     * 
+ * * * @param tag The name of the 'tag' that uniquely identifies the 'tag' that needs to be deleted. * @return A REST response with completion signal. @@ -246,7 +267,12 @@ Mono> deleteTagWithResponse(String tag, Context context) { * *

Delete the tag for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.deleteTag} + * + *
+     * String tag = getTag();
+     * client.deleteTag(tag).subscribe();
+     * 
+ * * * @param tag The name of the tag that uniquely identifies the tag that needs to be deleted. * @return The completion. @@ -270,7 +296,15 @@ public Mono deleteTag(String tag) { * *

Get the properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.getManifestPropertiesWithResponse} + * + *
+     * client.getManifestPropertiesWithResponse()
+     *     .subscribe(response -> {
+     *         final ArtifactManifestProperties properties = response.getValue();
+     *         System.out.printf("Digest:%s,", properties.getDigest());
+     *     });
+     * 
+ * * * @return A REST response containing {@link ArtifactManifestProperties properties} associated with the given {@code Digest}. * @throws ClientAuthenticationException thrown if the client does not have access to the repository. @@ -302,7 +336,14 @@ Mono> getManifestPropertiesWithResponse(Con * *

Get the properties for the given repository.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.getManifestProperties}. + * + *
+     * client.getManifestProperties()
+     *     .subscribe(properties -> {
+     *         System.out.printf("Digest:%s,", properties.getDigest());
+     *     });
+     * 
+ * * * @return The {@link ArtifactManifestProperties properties} associated with the given {@code Digest}. * @throws ClientAuthenticationException thrown if the client does not have access to the repository. @@ -321,7 +362,15 @@ public Mono getManifestProperties() { * *

Retrieve the properties associated with the given tag.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.getTagPropertiesWithResponse}. + * + *
+     * String tag = getTag();
+     * client.getTagPropertiesWithResponse(tag).subscribe(response -> {
+     *     final ArtifactTagProperties properties = response.getValue();
+     *     System.out.printf("Digest:%s,", properties.getDigest());
+     * });
+     * 
+ * * * @param tag name of the tag that uniquely identifies a given tag. * @return A REST response with the {@link ArtifactTagProperties properties} associated with the given tag. @@ -359,7 +408,14 @@ Mono> getTagPropertiesWithResponse(String tag, C * *

Retrieve the properties associated with the given tag.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.getTagProperties}. + * + *
+     * String tag = getTag();
+     * client.getTagProperties(tag).subscribe(properties -> {
+     *     System.out.printf("Digest:%s,", properties.getDigest());
+     * });
+     * 
+ * * * @param tag name of the tag that uniquely identifies a given tag. * @return The {@link ArtifactTagProperties properties} associated with the given tag. @@ -386,7 +442,17 @@ public Mono getTagProperties(String tag) { * *

Retrieve all the tags associated with the given repository from the most recently updated to the last.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.listTagPropertiesWithOptions}. + * + *
+     * client.listTagProperties(ArtifactTagOrderBy.LAST_UPDATED_ON_DESCENDING)
+     *     .byPage(10)
+     *     .subscribe(tagPropertiesPagedResponse -> {
+     *         tagPropertiesPagedResponse.getValue()
+     *             .stream()
+     *             .forEach(tagProperties -> System.out.println(tagProperties.getDigest()));
+     *     });
+     * 
+ * * * @return {@link PagedFlux} of the artifacts for the given repository in the order specified by the options. * @throws ClientAuthenticationException thrown if the client does not have access to the repository. @@ -409,7 +475,17 @@ public PagedFlux listTagProperties() { * *

Retrieve all the tags associated with the given repository from the most recently updated to the last.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.listTagPropertiesWithOptions}. + * + *
+     * client.listTagProperties(ArtifactTagOrderBy.LAST_UPDATED_ON_DESCENDING)
+     *     .byPage(10)
+     *     .subscribe(tagPropertiesPagedResponse -> {
+     *         tagPropertiesPagedResponse.getValue()
+     *             .stream()
+     *             .forEach(tagProperties -> System.out.println(tagProperties.getDigest()));
+     *     });
+     * 
+ * * * @param orderBy The order in which the tags should be returned by the service. * @return {@link PagedFlux} of the artifacts for the given repository in the order specified by the options. @@ -482,7 +558,13 @@ Mono> listTagPropertiesNextSinglePageAsync( * *

Update the writeable properties of a given tag.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.updateTagPropertiesWithResponse}. + * + *
+     * ArtifactTagProperties properties = getTagProperties();
+     * String tag = getTag();
+     * client.updateTagPropertiesWithResponse(tag, properties).subscribe();
+     * 
+ * * * @param tag Name of the tag that uniquely identifies it. * @param tagProperties {@link ArtifactTagProperties value} to be set. @@ -536,7 +618,13 @@ Mono> updateTagPropertiesWithResponse( * *

Update the writeable properties of a given tag.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.updateTagPropertiesWithResponse}. + * + *
+     * ArtifactTagProperties properties = getTagProperties();
+     * String tag = getTag();
+     * client.updateTagPropertiesWithResponse(tag, properties).subscribe();
+     * 
+ * * * @param tag Name of the tag that uniquely identifies it. * @param tagProperties {@link ArtifactTagProperties tagProperties} to be set. @@ -561,7 +649,12 @@ public Mono updateTagProperties(String tag, ArtifactTagPr * *

Update the writeable properties of a given manifest.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.updateManifestPropertiesWithResponse}. + * + *
+     * ArtifactManifestProperties properties = getArtifactManifestProperties();
+     * client.updateManifestPropertiesWithResponse(properties).subscribe();
+     * 
+ * * * @param manifestProperties {@link ArtifactManifestProperties manifestProperties} to be set. * @return A REST response for the completion. @@ -603,7 +696,12 @@ Mono> updateManifestPropertiesWithResponse( * *

Update the writeable properties of a given manifest.

* - * {@codesnippet com.azure.containers.containerregistry.RegistryArtifactAsync.updateManifestProperties}. + * + *
+     * ArtifactManifestProperties properties = getArtifactManifestProperties();
+     * client.updateManifestProperties(properties).subscribe();
+     * 
+ * * * @param manifestProperties {@link ArtifactManifestProperties manifestProperties} to be set. * @return The completion. diff --git a/sdk/containerregistry/azure-containers-containerregistry/src/samples/java/com/azure/containers/containerregistry/ReadmeSamples.java b/sdk/containerregistry/azure-containers-containerregistry/src/samples/java/com/azure/containers/containerregistry/ReadmeSamples.java index 240de3208c342..d93f91cdcf769 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/src/samples/java/com/azure/containers/containerregistry/ReadmeSamples.java +++ b/sdk/containerregistry/azure-containers-containerregistry/src/samples/java/com/azure/containers/containerregistry/ReadmeSamples.java @@ -15,10 +15,6 @@ import com.azure.identity.DefaultAzureCredentialBuilder; /** - * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS - * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING - * LINE NUMBERS OF EXISTING CODE SAMPLES. - *

* Code samples for the README.md * */ @@ -27,24 +23,29 @@ public class ReadmeSamples { private String endpoint = "endpoint"; public void createClient() { + // BEGIN: readme-sample-createClient DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD) .credential(credential) .buildClient(); + // END: readme-sample-createClient } public void createAsyncClient() { + // BEGIN: readme-sample-createAsyncClient DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryAsyncClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD) .credential(credential) .buildAsyncClient(); + // END: readme-sample-createAsyncClient } public void listRepositoryNamesSample() { + // BEGIN: readme-sample-listRepositoryNames DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) @@ -53,11 +54,13 @@ public void listRepositoryNamesSample() { .buildClient(); client.listRepositoryNames().forEach(repository -> System.out.println(repository)); + // END: readme-sample-listRepositoryNames } private final String repositoryName = "repository"; public void getPropertiesThrows() { + // BEGIN: readme-sample-getProperties DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); ContainerRepository containerRepository = new ContainerRegistryClientBuilder() .endpoint(endpoint) @@ -70,23 +73,29 @@ public void getPropertiesThrows() { } catch (HttpResponseException exception) { // Do something with the exception. } + // END: readme-sample-getProperties } public void createAnonymousAccessClient() { + // BEGIN: readme-sample-createAnonymousAccessClient ContainerRegistryClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD) .buildClient(); + // END: readme-sample-createAnonymousAccessClient } public void createAnonymousAccessAsyncClient() { + // BEGIN: readme-sample-createAnonymousAsyncAccessClient ContainerRegistryAsyncClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD) .buildAsyncClient(); + // END: readme-sample-createAnonymousAsyncAccessClient } public void deleteImages() { + // BEGIN: readme-sample-deleteImages TokenCredential defaultCredential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryClient client = new ContainerRegistryClientBuilder() @@ -117,11 +126,13 @@ public void deleteImages() { repository.getArtifact(imageManifest.getDigest()).delete(); }); } + // END: readme-sample-deleteImages } private String tag = "tag"; public void setArtifactProperties() { + // BEGIN: readme-sample-setArtifactProperties TokenCredential defaultCredential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryClient client = new ContainerRegistryClientBuilder() @@ -137,6 +148,7 @@ public void setArtifactProperties() { new ArtifactTagProperties() .setWriteEnabled(false) .setDeleteEnabled(false)); + // END: readme-sample-setArtifactProperties } private final String architecture = "architecture"; @@ -144,6 +156,7 @@ public void setArtifactProperties() { private final String digest = "digest"; public void listTagProperties() { + // BEGIN: readme-sample-listTagProperties ContainerRegistryClient anonymousClient = new ContainerRegistryClientBuilder() .endpoint(endpoint) .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD) @@ -157,9 +170,11 @@ public void listTagProperties() { for (ArtifactTagProperties tag : tags) { System.out.printf(String.format("%s/%s:%s", anonymousClient.getEndpoint(), repositoryName, tag.getName())); } + // END: readme-sample-listTagProperties } public void anonymousClientThrows() { + // BEGIN: readme-sample-anonymousClientThrows final String endpoint = getEndpoint(); final String repositoryName = getRepositoryName(); @@ -174,6 +189,7 @@ public void anonymousClientThrows() { } catch (ClientAuthenticationException ex) { System.out.println("Expected exception: Delete is not allowed on anonymous access"); } + // END: readme-sample-anonymousClientThrows } private static String getEndpoint() { @@ -190,6 +206,7 @@ private static String getTagName() { private final TokenCredential credentials = null; public void nationalCloudSample() { + // BEGIN: readme-sample-nationalCloudSample ContainerRegistryClient containerRegistryClient = new ContainerRegistryClientBuilder() .endpoint(getEndpoint()) .credential(credentials) @@ -199,6 +216,7 @@ public void nationalCloudSample() { containerRegistryClient .listRepositoryNames() .forEach(name -> System.out.println(name)); + // END: readme-sample-nationalCloudSample } } From aa761c3e31236e44c360378843ae1e132db8f9c0 Mon Sep 17 00:00:00 2001 From: Pallavi Taneja Date: Mon, 15 Nov 2021 11:20:34 -0800 Subject: [PATCH 2/2] Move readme file to the new codesnippet tool. --- .../README.md | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/sdk/containerregistry/azure-containers-containerregistry/README.md b/sdk/containerregistry/azure-containers-containerregistry/README.md index 6c5d43074dd27..7df980c64a3f4 100644 --- a/sdk/containerregistry/azure-containers-containerregistry/README.md +++ b/sdk/containerregistry/azure-containers-containerregistry/README.md @@ -37,8 +37,7 @@ The [Azure Identity library][identity] provides easy Azure Active Directory supp Note all the below samples assume you have an endpoint, which is the URL including the name of the login server and the `https://` prefix. More information at [Azure Container Registry portal][container_registry_create_portal] - -```Java +```java readme-sample-createClient DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) @@ -47,8 +46,7 @@ ContainerRegistryClient client = new ContainerRegistryClientBuilder() .buildClient(); ``` - -```Java +```java readme-sample-createAsyncClient DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryAsyncClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) @@ -64,12 +62,11 @@ To authenticate with a registry in a [National Cloud](https://docs.microsoft.com - Set the authorityHost in the credential builder. - Set the authenticationScope in ContainerRegistryClientBuilder. - -```Java +```java readme-sample-nationalCloudSample ContainerRegistryClient containerRegistryClient = new ContainerRegistryClientBuilder() .endpoint(getEndpoint()) .credential(credentials) - .audience(ContainerRegistryAudience.AZURECHINA) + .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_CHINA) .buildClient(); containerRegistryClient @@ -83,16 +80,14 @@ The user must use this setting on a registry that has been enabled for anonymous In this mode, the user can only call listRepositoryNames method and its overload. All the other calls will fail. For more information please read [Anonymous Pull Access](https://docs.microsoft.com/azure/container-registry/container-registry-faq#how-do-i-enable-anonymous-pull-access) - -```Java +```java readme-sample-createAnonymousAccessClient ContainerRegistryClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD) .buildClient(); ``` - -```Java +```java readme-sample-createAnonymousAsyncAccessClient ContainerRegistryAsyncClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD) @@ -127,8 +122,7 @@ For more information please see [Container Registry Concepts](https://docs.micro Iterate through the collection of repositories in the registry. - -```Java +```java readme-sample-listRepositoryNames DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryClient client = new ContainerRegistryClientBuilder() .endpoint(endpoint) @@ -141,8 +135,7 @@ client.listRepositoryNames().forEach(repository -> System.out.println(repository ### List tags with anonymous access - -```Java +```java readme-sample-listTagProperties ContainerRegistryClient anonymousClient = new ContainerRegistryClientBuilder() .endpoint(endpoint) .audience(ContainerRegistryAudience.AZURE_RESOURCE_MANAGER_PUBLIC_CLOUD) @@ -160,8 +153,7 @@ for (ArtifactTagProperties tag : tags) { ### Set artifact properties - -```Java +```java readme-sample-setArtifactProperties TokenCredential defaultCredential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryClient client = new ContainerRegistryClientBuilder() @@ -181,8 +173,7 @@ image.updateTagProperties( ### Delete Images - -```Java +```java readme-sample-deleteImages TokenCredential defaultCredential = new DefaultAzureCredentialBuilder().build(); ContainerRegistryClient client = new ContainerRegistryClientBuilder() @@ -215,9 +206,8 @@ for (String repositoryName : client.listRepositoryNames()) { } ``` -### Delete repository with anonymous access throws - -```Java +### Delete a repository with anonymous access throws +```java readme-sample-anonymousClientThrows final String endpoint = getEndpoint(); final String repositoryName = getRepositoryName(); @@ -239,8 +229,7 @@ try { All container registry service operations will throw a [HttpResponseException][HttpResponseException] on failure. - -```Java +```java readme-sample-getProperties DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); ContainerRepository containerRepository = new ContainerRegistryClientBuilder() .endpoint(endpoint)