Skip to content

Commit

Permalink
API cleanup and uploadManifest tests (#33553)
Browse files Browse the repository at this point in the history
* API cleanup and uploadManifest tests
  • Loading branch information
lmolkova authored Mar 1, 2023
1 parent 5a32674 commit faee942
Show file tree
Hide file tree
Showing 17 changed files with 2,356 additions and 275 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.containers.containerregistry;

import com.azure.containers.containerregistry.implementation.ArtifactManifestPropertiesHelper;
import com.azure.containers.containerregistry.implementation.ArtifactTagPropertiesHelper;
import com.azure.containers.containerregistry.implementation.AzureContainerRegistryImpl;
import com.azure.containers.containerregistry.implementation.ContainerRegistriesImpl;
import com.azure.containers.containerregistry.implementation.UtilsImpl;
import com.azure.containers.containerregistry.implementation.models.AcrErrorsException;
import com.azure.containers.containerregistry.implementation.models.ArtifactManifestPropertiesInternal;
Expand All @@ -32,8 +33,9 @@

import java.util.Objects;

import static com.azure.containers.containerregistry.implementation.UtilsImpl.enableSync;
import static com.azure.containers.containerregistry.implementation.UtilsImpl.formatFullyQualifiedReference;
import static com.azure.containers.containerregistry.implementation.UtilsImpl.isDigest;
import static com.azure.containers.containerregistry.implementation.UtilsImpl.enableSync;
import static com.azure.containers.containerregistry.implementation.UtilsImpl.mapAcrErrorsException;

/**
Expand All @@ -52,8 +54,14 @@
* <!-- end com.azure.containers.containerregistry.RegistryArtifact.instantiation -->
*/
@ServiceClient(builder = ContainerRegistryClientBuilder.class)
public final class RegistryArtifact extends RegistryArtifactBase {
public final class RegistryArtifact {
private static final ClientLogger LOGGER = new ClientLogger(RegistryArtifact.class);
private final String fullyQualifiedReference;
private final String endpoint;
private final String repositoryName;
private final String tagOrDigest;
private final ContainerRegistriesImpl serviceClient;
private String digest;

/**
* Creates a RegistryArtifact type that sends requests to the given repository in the container registry service at {@code endpoint}.
Expand All @@ -65,7 +73,21 @@ public final class RegistryArtifact extends RegistryArtifactBase {
* @param version {@link ContainerRegistryServiceVersion} of the service to be used when making requests.
*/
RegistryArtifact(String repositoryName, String tagOrDigest, HttpPipeline httpPipeline, String endpoint, String version) {
super(repositoryName, tagOrDigest, httpPipeline, endpoint, version);
Objects.requireNonNull(repositoryName, "'repositoryName' cannot be null.");
if (repositoryName.isEmpty()) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'repositoryName' can't be empty"));
}

Objects.requireNonNull(tagOrDigest, "'tagOrDigest' cannot be null.");
if (tagOrDigest.isEmpty()) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'digest' can't be empty"));
}

this.serviceClient = new AzureContainerRegistryImpl(httpPipeline, endpoint, version).getContainerRegistries();
this.fullyQualifiedReference = formatFullyQualifiedReference(endpoint, repositoryName, tagOrDigest);
this.endpoint = endpoint;
this.repositoryName = repositoryName;
this.tagOrDigest = tagOrDigest;
}

/**
Expand All @@ -88,9 +110,9 @@ public final class RegistryArtifact extends RegistryArtifactBase {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> deleteWithResponse(Context context) {
String res = this.getDigest();
String res = getDigest();
try {
Response<Void> response = this.serviceClient.deleteManifestWithResponse(getRepositoryName(), res, enableSync(context));
Response<Void> response = serviceClient.deleteManifestWithResponse(getRepositoryName(), res, enableSync(context));

return UtilsImpl.deleteResponseToSuccess(response);
} catch (AcrErrorsException exception) {
Expand All @@ -99,15 +121,12 @@ public Response<Void> deleteWithResponse(Context context) {
}

private String getDigest() {
if (this.digest != null) {
return digest;
if (digest == null) {
digest = isDigest(tagOrDigest)
? tagOrDigest
: getTagProperties(tagOrDigest).getDigest();
}

String res = isDigest(tagOrDigest)
? tagOrDigest
: this.getTagProperties(tagOrDigest).getDigest();
this.digest = res;
return res;
return digest;
}

/**
Expand All @@ -128,7 +147,7 @@ private String getDigest() {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void delete() {
this.deleteWithResponse(Context.NONE).getValue();
deleteWithResponse(Context.NONE).getValue();
}

/**
Expand Down Expand Up @@ -160,7 +179,7 @@ public Response<Void> deleteTagWithResponse(String tag, Context context) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'tag' cannot be empty."));
}
try {
Response<Void> response = this.serviceClient.deleteTagWithResponse(getRepositoryName(), tag, enableSync(context));
Response<Void> response = serviceClient.deleteTagWithResponse(getRepositoryName(), tag, enableSync(context));

return UtilsImpl.deleteResponseToSuccess(response);
} catch (AcrErrorsException exception) {
Expand Down Expand Up @@ -190,10 +209,9 @@ public Response<Void> deleteTagWithResponse(String tag, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void deleteTag(String tag) {
this.deleteTagWithResponse(tag, Context.NONE).getValue();
deleteTagWithResponse(tag, Context.NONE).getValue();
}


/**
* Gets the {@link ArtifactManifestProperties properties} associated with an artifact in given {@link #getRepositoryName() repository}.
*
Expand Down Expand Up @@ -221,7 +239,7 @@ public void deleteTag(String tag) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<ArtifactManifestProperties> getManifestPropertiesWithResponse(Context context) {
String res = this.getDigest();
String res = getDigest();
try {
Response<ArtifactManifestPropertiesInternal> internalResponse = this.serviceClient
.getManifestPropertiesWithResponse(getRepositoryName(), res, enableSync(context));
Expand Down Expand Up @@ -257,7 +275,7 @@ public Response<ArtifactManifestProperties> getManifestPropertiesWithResponse(Co
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public ArtifactManifestProperties getManifestProperties() {
return this.getManifestPropertiesWithResponse(Context.NONE).getValue();
return getManifestPropertiesWithResponse(Context.NONE).getValue();
}

/**
Expand Down Expand Up @@ -392,7 +410,7 @@ public PagedIterable<ArtifactTagProperties> listTagProperties() {
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<ArtifactTagProperties> listTagProperties(ArtifactTagOrder order) {
return this.listTagProperties(order, Context.NONE);
return listTagProperties(order, Context.NONE);
}

/**
Expand Down Expand Up @@ -430,35 +448,9 @@ public PagedIterable<ArtifactTagProperties> listTagProperties(ArtifactTagOrder o
return listTagPropertiesSync(order, context);
}

private PagedIterable<ArtifactTagProperties> listTagPropertiesSync(ArtifactTagOrder order, Context context) {
return new PagedIterable<>(
(pageSize) -> listTagPropertiesSinglePageSync(pageSize, order, context),
(token, pageSize) -> listTagPropertiesNextSinglePageSync(token, context));
}

private PagedResponse<ArtifactTagProperties> listTagPropertiesSinglePageSync(Integer pageSize, ArtifactTagOrder order, Context context) {
if (pageSize != null && pageSize < 0) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'pageSize' cannot be negative."));
}

final String orderString = order.equals(ArtifactTagOrder.NONE) ? null : order.toString();

String res = this.getDigest();
try {
PagedResponse<TagAttributesBase> response =
this.serviceClient.getTagsSinglePage(getRepositoryName(), null, pageSize, orderString, res,
enableSync(context));

return UtilsImpl.getPagedResponseWithContinuationToken(response,
baseValues -> UtilsImpl.getTagProperties(baseValues, getRepositoryName()));
} catch (AcrErrorsException exception) {
throw LOGGER.logExceptionAsError(mapAcrErrorsException(exception));
}
}

private PagedResponse<ArtifactTagProperties> listTagPropertiesNextSinglePageSync(String nextLink, Context context) {
try {
PagedResponse<TagAttributesBase> res = this.serviceClient.getTagsNextSinglePage(nextLink,
PagedResponse<TagAttributesBase> res = serviceClient.getTagsNextSinglePage(nextLink,
enableSync(context));

return UtilsImpl.getPagedResponseWithContinuationToken(res,
Expand Down Expand Up @@ -520,7 +512,6 @@ public Response<ArtifactTagProperties> updateTagPropertiesWithResponse(String ta
}
}


/**
* Update the properties {@link ArtifactTagProperties} of the given {@code tag}.
* These properties set whether the given tag can be updated, deleted and retrieved.
Expand Down Expand Up @@ -548,7 +539,7 @@ public Response<ArtifactTagProperties> updateTagPropertiesWithResponse(String ta
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public ArtifactTagProperties updateTagProperties(String tag, ArtifactTagProperties tagProperties) {
return this.updateTagPropertiesWithResponse(tag, tagProperties, Context.NONE).getValue();
return updateTagPropertiesWithResponse(tag, tagProperties, Context.NONE).getValue();
}

/**
Expand Down Expand Up @@ -597,7 +588,6 @@ public Response<ArtifactManifestProperties> updateManifestPropertiesWithResponse
}
}


/**
* Update the writeable properties {@link ArtifactTagProperties} of the artifact with the given {@code digest}.
* These properties set whether the given manifest can be updated, deleted and retrieved.
Expand All @@ -621,6 +611,61 @@ public Response<ArtifactManifestProperties> updateManifestPropertiesWithResponse
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public ArtifactManifestProperties updateManifestProperties(ArtifactManifestProperties manifestProperties) {
return this.updateManifestPropertiesWithResponse(manifestProperties, Context.NONE).getValue();
return updateManifestPropertiesWithResponse(manifestProperties, Context.NONE).getValue();
}

/**
* Gets the Azure Container Registry service endpoint for the current instance.
* @return The service endpoint for the current instance.
*/
public String getRegistryEndpoint() {
return endpoint;
}

/**
* Gets the fully qualified reference for the current instance.
* The fully qualifiedName is of the form 'registryName/repositoryName@digest'
* or 'registryName/repositoryName:tag' based on the docker naming convention and whether
* tag or digest was supplied to the constructor.
* @return Fully qualified reference of the current instance.
* */
public String getFullyQualifiedReference() {
return fullyQualifiedReference;
}

/**
* Gets the repository name for the current instance.
* Gets the repository name for the current instance.
* @return Name of the repository for the current instance.
* */
public String getRepositoryName() {
return repositoryName;
}


private PagedIterable<ArtifactTagProperties> listTagPropertiesSync(ArtifactTagOrder order, Context context) {
return new PagedIterable<>(
(pageSize) -> listTagPropertiesSinglePageSync(pageSize, order, context),
(token, pageSize) -> listTagPropertiesNextSinglePageSync(token, context));
}

private PagedResponse<ArtifactTagProperties> listTagPropertiesSinglePageSync(Integer pageSize, ArtifactTagOrder order, Context context) {
if (pageSize != null && pageSize < 0) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'pageSize' cannot be negative."));
}

final String orderString = order.equals(ArtifactTagOrder.NONE) ? null : order.toString();

String res = getDigest();
try {
PagedResponse<TagAttributesBase> response =
serviceClient.getTagsSinglePage(getRepositoryName(), null, pageSize, orderString, res,
enableSync(context));

return UtilsImpl.getPagedResponseWithContinuationToken(response,
baseValues -> UtilsImpl.getTagProperties(baseValues, getRepositoryName()));
} catch (AcrErrorsException exception) {
throw LOGGER.logExceptionAsError(mapAcrErrorsException(exception));
}
}
}
Loading

0 comments on commit faee942

Please sign in to comment.