diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index eccf7262e301a..a5fd91d4be1d4 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -400,6 +400,8 @@ unreleased_com.azure:azure-identity;1.7.0-beta.2 unreleased_com.azure:azure-identity-providers-core;1.0.0-beta.2 unreleased_com.azure:azure-identity-providers-jdbc-mysql;1.0.0-beta.2 unreleased_com.azure:azure-identity-providers-jdbc-postgresql;1.0.0-beta.2 +unreleased_com.azure:azure-core;1.35.0-beta.1 + # Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current # version and set the version to the released beta. Released beta dependencies are only valid diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/util/polling/SimpleSyncPoller.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/polling/SimpleSyncPoller.java index 23c5d138cac66..ab1e04d6906dc 100644 --- a/sdk/core/azure-core/src/main/java/com/azure/core/util/polling/SimpleSyncPoller.java +++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/polling/SimpleSyncPoller.java @@ -153,7 +153,7 @@ public U getFinalResult() { .apply(currentTerminalPollContext); } else { PollingContext context = this.pollingContext.copy(); - PollingUtil.pollingLoop(pollingContext, null, null, pollOperation, pollInterval); + PollingUtil.pollingLoop(context, null, null, pollOperation, pollInterval); this.terminalPollContext = context; return getFinalResult(); } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlAsyncClient.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlAsyncClient.java index 6102dd4000c6a..8ff7ccb452d57 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlAsyncClient.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlAsyncClient.java @@ -6,56 +6,39 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; -import com.azure.core.exception.HttpResponseException; -import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpRequest; -import com.azure.core.http.HttpResponse; import com.azure.core.http.rest.PagedFlux; import com.azure.core.http.rest.PagedResponse; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; -import com.azure.core.util.IterableStream; import com.azure.core.util.logging.ClientLogger; import com.azure.security.keyvault.administration.implementation.KeyVaultAccessControlClientImpl; import com.azure.security.keyvault.administration.implementation.KeyVaultAccessControlClientImplBuilder; import com.azure.security.keyvault.administration.implementation.KeyVaultAdministrationUtils; import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings; -import com.azure.security.keyvault.administration.implementation.models.DataAction; -import com.azure.security.keyvault.administration.implementation.models.Permission; -import com.azure.security.keyvault.administration.implementation.models.RoleAssignment; import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentCreateParameters; -import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentProperties; -import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentPropertiesWithScope; -import com.azure.security.keyvault.administration.implementation.models.RoleDefinition; import com.azure.security.keyvault.administration.implementation.models.RoleDefinitionCreateParameters; -import com.azure.security.keyvault.administration.implementation.models.RoleDefinitionProperties; -import com.azure.security.keyvault.administration.implementation.models.RoleScope; import com.azure.security.keyvault.administration.models.KeyVaultAdministrationException; -import com.azure.security.keyvault.administration.models.KeyVaultDataAction; -import com.azure.security.keyvault.administration.models.KeyVaultPermission; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition; -import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinitionType; import com.azure.security.keyvault.administration.models.KeyVaultRoleScope; -import com.azure.security.keyvault.administration.models.KeyVaultRoleType; import com.azure.security.keyvault.administration.models.SetRoleDefinitionOptions; import reactor.core.publisher.Mono; -import java.io.IOException; import java.net.URL; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; import java.util.UUID; -import java.util.stream.Collectors; import static com.azure.core.util.FluxUtil.monoError; import static com.azure.core.util.FluxUtil.withContext; import static com.azure.core.util.tracing.Tracer.AZ_TRACING_NAMESPACE_KEY; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.validateRoleDefinitionParameters; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.validateRoleAssignmentParameters; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.validateAndGetRoleDefinitionCreateParameters; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.validateAndGetRoleAssignmentCreateParameters; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.swallowExceptionForStatusCodeAsync; /** * The {@link KeyVaultAccessControlAsyncClient} provides asynchronous methods to view and manage Role Based Access @@ -223,7 +206,7 @@ Mono> listRoleDefinitionsFirstPage(String .doOnError(error -> logger.warning("Failed to list role definitions for roleScope - {}", roleScope, error)) .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) - .map(KeyVaultAccessControlAsyncClient::transformRoleDefinitionsPagedResponse); + .map(KeyVaultAdministrationUtil::transformRoleDefinitionsPagedResponse); } catch (RuntimeException e) { return monoError(logger, e); } @@ -255,7 +238,7 @@ Mono> listRoleDefinitionsNextPage(String c .doOnError(error -> logger.warning("Failed to list next role definitions page - Page {}", continuationToken, error)) .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) - .map(KeyVaultAccessControlAsyncClient::transformRoleDefinitionsPagedResponse); + .map(KeyVaultAdministrationUtil::transformRoleDefinitionsPagedResponse); } catch (RuntimeException e) { return monoError(logger, e); } @@ -396,49 +379,7 @@ public Mono> setRoleDefinitionWithResponse(SetR Mono> setRoleDefinitionWithResponse(SetRoleDefinitionOptions options, Context context) { try { - Objects.requireNonNull(options, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'options'")); - Objects.requireNonNull(options.getRoleScope(), - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'options.getRoleScope()'")); - Objects.requireNonNull(options.getRoleDefinitionName(), - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'options.getRoleDefinitionName()'")); - - List assignableScopes = null; - - if (options.getAssignableScopes() != null) { - assignableScopes = options.getAssignableScopes().stream() - .map(keyVaultRoleScope -> RoleScope.fromString(keyVaultRoleScope.toString())) - .collect(Collectors.toList()); - } - - List permissions = null; - - if (options.getPermissions() != null) { - permissions = options.getPermissions().stream() - .map(keyVaultPermission -> new Permission() - .setActions(keyVaultPermission.getActions()) - .setNotActions(keyVaultPermission.getNotActions()) - .setDataActions(keyVaultPermission.getDataActions().stream() - .map(allowedDataAction -> DataAction.fromString(allowedDataAction.toString())) - .collect(Collectors.toList())) - .setNotDataActions(keyVaultPermission.getNotDataActions().stream() - .map(notDataAction -> DataAction.fromString(notDataAction.toString())) - .collect(Collectors.toList()))) - .collect(Collectors.toList()); - } - - RoleDefinitionProperties roleDefinitionProperties = - new RoleDefinitionProperties() - .setRoleName(options.getRoleDefinitionName()) - .setAssignableScopes(assignableScopes) - .setDescription(options.getDescription()) - .setPermissions(permissions); - RoleDefinitionCreateParameters parameters = - new RoleDefinitionCreateParameters() - .setProperties(roleDefinitionProperties); + RoleDefinitionCreateParameters parameters = validateAndGetRoleDefinitionCreateParameters(options); return clientImpl.getRoleDefinitions() .createOrUpdateWithResponseAsync(vaultUrl, options.getRoleScope().toString(), @@ -450,7 +391,7 @@ Mono> setRoleDefinitionWithResponse(SetRoleDefi .doOnError(error -> logger.warning("Failed to create role definition - {}", options.getRoleDefinitionName(), error)) .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) - .map(KeyVaultAccessControlAsyncClient::transformRoleDefinitionResponse); + .map(KeyVaultAdministrationUtil::transformRoleDefinitionResponse); } catch (RuntimeException e) { return monoError(logger, e); } @@ -541,12 +482,7 @@ public Mono> getRoleDefinitionWithResponse(KeyV Mono> getRoleDefinitionWithResponse(KeyVaultRoleScope roleScope, String roleDefinitionName, Context context) { try { - Objects.requireNonNull(roleScope, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleScope'")); - Objects.requireNonNull(roleDefinitionName, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleDefinitionName'")); + validateRoleDefinitionParameters(roleScope, roleDefinitionName); return clientImpl.getRoleDefinitions() .getWithResponseAsync(vaultUrl, roleScope.toString(), roleDefinitionName, @@ -557,7 +493,7 @@ Mono> getRoleDefinitionWithResponse(KeyVaultRol .doOnError(error -> logger.warning("Failed to retrieved role definition - {}", roleDefinitionName, error)) .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) - .map(KeyVaultAccessControlAsyncClient::transformRoleDefinitionResponse); + .map(KeyVaultAdministrationUtil::transformRoleDefinitionResponse); } catch (RuntimeException e) { return monoError(logger, e); } @@ -641,12 +577,7 @@ Mono> deleteRoleDefinitionWithResponse(KeyVaultRoleScope roleScop String roleDefinitionName, Context context) { try { - Objects.requireNonNull(roleScope, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleScope'")); - Objects.requireNonNull(roleDefinitionName, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleDefinitionName'")); + validateRoleDefinitionParameters(roleScope, roleDefinitionName); return clientImpl.getRoleDefinitions() .deleteWithResponseAsync(vaultUrl, roleScope.toString(), roleDefinitionName, @@ -657,7 +588,7 @@ Mono> deleteRoleDefinitionWithResponse(KeyVaultRoleScope roleScop .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) .map(response -> (Response) new SimpleResponse(response, null)) .onErrorResume(KeyVaultAdministrationException.class, e -> - swallowExceptionForStatusCode(404, e, logger)); + swallowExceptionForStatusCodeAsync(404, e, logger)); } catch (RuntimeException e) { return monoError(logger, e); } @@ -731,7 +662,7 @@ Mono> listRoleAssignmentsFirstPage(String .doOnError(error -> logger.warning("Failed to list role assignments for roleScope - {}", roleScope, error)) .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) - .map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentsPagedResponse); + .map(KeyVaultAdministrationUtil::transformRoleAssignmentsPagedResponse); } catch (RuntimeException e) { return monoError(logger, e); } @@ -762,7 +693,7 @@ Mono> listRoleAssignmentsNextPage(String c .doOnError(error -> logger.warning("Failed to list next role assignments page - Page {}", continuationToken, error)) .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) - .map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentsPagedResponse); + .map(KeyVaultAdministrationUtil::transformRoleAssignmentsPagedResponse); } catch (RuntimeException e) { return monoError(logger, e); } @@ -915,26 +846,7 @@ Mono> createRoleAssignmentWithResponse(KeyVault String roleAssignmentName, Context context) { try { - Objects.requireNonNull(roleScope, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleScope'")); - Objects.requireNonNull(roleAssignmentName, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleAssignmentName'")); - Objects.requireNonNull(principalId, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'principalId'")); - Objects.requireNonNull(roleDefinitionId, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleDefinitionId'")); - - RoleAssignmentProperties roleAssignmentProperties = - new RoleAssignmentProperties() - .setRoleDefinitionId(roleDefinitionId) - .setPrincipalId(principalId); - RoleAssignmentCreateParameters parameters = - new RoleAssignmentCreateParameters() - .setProperties(roleAssignmentProperties); + RoleAssignmentCreateParameters parameters = validateAndGetRoleAssignmentCreateParameters(roleScope, roleDefinitionId, principalId, roleAssignmentName); return clientImpl.getRoleAssignments() .createWithResponseAsync(vaultUrl, roleScope.toString(), roleAssignmentName, parameters, @@ -943,7 +855,7 @@ Mono> createRoleAssignmentWithResponse(KeyVault .doOnSuccess(response -> logger.verbose("Created role assignment - {}", response.getValue().getName())) .doOnError(error -> logger.warning("Failed to create role assignment - {}", roleAssignmentName, error)) .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) - .map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentResponse); + .map(KeyVaultAdministrationUtil::transformRoleAssignmentResponse); } catch (RuntimeException e) { return monoError(logger, e); } @@ -1032,13 +944,7 @@ public Mono> getRoleAssignmentWithResponse(KeyV Mono> getRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, Context context) { try { - Objects.requireNonNull(roleScope, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleScope'")); - Objects.requireNonNull(roleAssignmentName, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleAssignmentName'")); - + validateRoleAssignmentParameters(roleScope, roleAssignmentName); return clientImpl.getRoleAssignments() .getWithResponseAsync(vaultUrl, roleScope.toString(), roleAssignmentName, context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)) @@ -1048,7 +954,7 @@ Mono> getRoleAssignmentWithResponse(KeyVaultRol .doOnError(error -> logger.warning("Failed to retrieve role assignment - {}", roleAssignmentName, error)) .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) - .map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentResponse); + .map(KeyVaultAdministrationUtil::transformRoleAssignmentResponse); } catch (RuntimeException e) { return monoError(logger, e); } @@ -1131,12 +1037,7 @@ public Mono> deleteRoleAssignmentWithResponse(KeyVaultRoleScope r Mono> deleteRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, Context context) { try { - Objects.requireNonNull(roleScope, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleScope'")); - Objects.requireNonNull(roleAssignmentName, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'roleAssignmentName'")); + validateRoleAssignmentParameters(roleScope, roleAssignmentName); return clientImpl.getRoleAssignments() .deleteWithResponseAsync(vaultUrl, roleScope.toString(), roleAssignmentName, @@ -1147,174 +1048,9 @@ Mono> deleteRoleAssignmentWithResponse(KeyVaultRoleScope roleScop .onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException) .map(response -> (Response) new SimpleResponse(response, null)) .onErrorResume(KeyVaultAdministrationException.class, e -> - swallowExceptionForStatusCode(404, e, logger)); + swallowExceptionForStatusCodeAsync(404, e, logger)); } catch (RuntimeException e) { return monoError(logger, e); } } - - @SuppressWarnings("BoundedWildcard") - private static PagedResponse transformRoleDefinitionsPagedResponse( - PagedResponse pagedResponse) { - - List keyVaultRoleDefinitions = new ArrayList<>(); - - for (RoleDefinition roleDefinition : pagedResponse.getValue()) { - keyVaultRoleDefinitions.add(roleDefinitionToKeyVaultRoleDefinition(roleDefinition)); - } - - return new TransformedPagedResponse<>(keyVaultRoleDefinitions, pagedResponse); - } - - private static Response transformRoleDefinitionResponse(Response response) { - KeyVaultRoleDefinition keyVaultRoleDefinition = roleDefinitionToKeyVaultRoleDefinition(response.getValue()); - - return new TransformedResponse<>(keyVaultRoleDefinition, response); - } - - private static KeyVaultRoleDefinition roleDefinitionToKeyVaultRoleDefinition(RoleDefinition roleDefinition) { - List keyVaultPermissions = new ArrayList<>(); - - for (Permission permission : roleDefinition.getPermissions()) { - keyVaultPermissions.add( - new KeyVaultPermission(permission.getActions(), permission.getNotActions(), - permission.getDataActions().stream() - .map(dataAction -> KeyVaultDataAction.fromString(dataAction.toString())) - .collect(Collectors.toList()), - permission.getNotDataActions().stream() - .map(notDataAction -> KeyVaultDataAction.fromString(notDataAction.toString())) - .collect(Collectors.toList()))); - } - - return new KeyVaultRoleDefinition(roleDefinition.getId(), roleDefinition.getName(), - KeyVaultRoleDefinitionType.fromString(roleDefinition.getType().toString()), roleDefinition.getRoleName(), - roleDefinition.getDescription(), KeyVaultRoleType.fromString(roleDefinition.getRoleType().toString()), - keyVaultPermissions, roleDefinition.getAssignableScopes().stream() - .map(roleScope -> KeyVaultRoleScope.fromString(roleScope.toString())) - .collect(Collectors.toList())); - } - - private static PagedResponse transformRoleAssignmentsPagedResponse( - PagedResponse pagedResponse) { - - List keyVaultRoleAssignments = new ArrayList<>(); - - for (RoleAssignment roleAssignment : pagedResponse.getValue()) { - keyVaultRoleAssignments.add(roleAssignmentToKeyVaultRoleAssignment(roleAssignment)); - } - - return new TransformedPagedResponse<>(keyVaultRoleAssignments, pagedResponse); - } - - private static Response transformRoleAssignmentResponse(Response response) { - KeyVaultRoleAssignment keyVaultRoleAssignment = roleAssignmentToKeyVaultRoleAssignment(response.getValue()); - - return new TransformedResponse<>(keyVaultRoleAssignment, response); - } - - private static KeyVaultRoleAssignment roleAssignmentToKeyVaultRoleAssignment(RoleAssignment roleAssignment) { - RoleAssignmentPropertiesWithScope propertiesWithScope = roleAssignment.getProperties(); - - return new KeyVaultRoleAssignment(roleAssignment.getId(), roleAssignment.getName(), roleAssignment.getType(), - new KeyVaultRoleAssignmentProperties(propertiesWithScope.getRoleDefinitionId(), - propertiesWithScope.getPrincipalId(), - KeyVaultRoleScope.fromString(propertiesWithScope.getScope().toString()))); - } - - private static final class TransformedPagedResponse, T, U> implements PagedResponse { - private final L output; - private final PagedResponse pagedResponse; - - TransformedPagedResponse(L output, PagedResponse inputPagedResponse) { - this.output = output; - this.pagedResponse = inputPagedResponse; - } - - @Override - public void close() throws IOException { - } - - @Override - public IterableStream getElements() { - return new IterableStream<>(output); - } - - @Override - public String getContinuationToken() { - return pagedResponse.getContinuationToken(); - } - - @Override - public int getStatusCode() { - return pagedResponse.getStatusCode(); - } - - @Override - public HttpHeaders getHeaders() { - return pagedResponse.getHeaders(); - } - - @Override - public HttpRequest getRequest() { - return pagedResponse.getRequest(); - } - - @Override - public List getValue() { - return output; - } - } - - private static final class TransformedResponse implements Response { - private final T output; - private final Response response; - - TransformedResponse(T output, Response response) { - this.output = output; - this.response = response; - } - - @Override - public int getStatusCode() { - return response.getStatusCode(); - } - - @Override - public HttpHeaders getHeaders() { - return response.getHeaders(); - } - - @Override - public HttpRequest getRequest() { - return response.getRequest(); - } - - @Override - public T getValue() { - return output; - } - } - - /** - * Deserializes a given {@link Response HTTP response} including headers to a given class. - * - * @param statusCode The status code which will trigger exception swallowing. - * @param httpResponseException The {@link HttpResponseException} to be swallowed. - * @param logger {@link ClientLogger} that will be used to record the exception. - * @param The class of the exception to swallow. - * - * @return A {@link Mono} that contains the deserialized response. - */ - static Mono> swallowExceptionForStatusCode(int statusCode, - E httpResponseException, - ClientLogger logger) { - HttpResponse httpResponse = httpResponseException.getResponse(); - - if (httpResponse.getStatusCode() == statusCode) { - return Mono.just(new SimpleResponse<>(httpResponse.getRequest(), httpResponse.getStatusCode(), - httpResponse.getHeaders(), null)); - } - - return monoError(logger, httpResponseException); - } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClient.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClient.java index 50617b00ed83b..6063e38bd1c84 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClient.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClient.java @@ -8,8 +8,20 @@ import com.azure.core.annotation.ServiceMethod; import com.azure.core.http.HttpPipeline; import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; +import com.azure.security.keyvault.administration.implementation.KeyVaultAccessControlClientImpl; +import com.azure.security.keyvault.administration.implementation.KeyVaultAccessControlClientImplBuilder; +import com.azure.security.keyvault.administration.implementation.KeyVaultAdministrationUtils; +import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings; +import com.azure.security.keyvault.administration.implementation.models.KeyVaultErrorException; +import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentCreateParameters; +import com.azure.security.keyvault.administration.implementation.models.RoleDefinitionCreateParameters; +import com.azure.security.keyvault.administration.implementation.models.RoleAssignment; +import com.azure.security.keyvault.administration.implementation.models.RoleDefinition; import com.azure.security.keyvault.administration.models.KeyVaultAdministrationException; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition; @@ -17,8 +29,18 @@ import com.azure.security.keyvault.administration.models.SetRoleDefinitionOptions; import reactor.core.publisher.Mono; +import java.net.URL; +import java.util.Objects; import java.util.UUID; +import static com.azure.core.util.tracing.Tracer.AZ_TRACING_NAMESPACE_KEY; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.enableSyncRestProxy; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.validateRoleDefinitionParameters; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.validateRoleAssignmentParameters; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.validateAndGetRoleDefinitionCreateParameters; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.validateAndGetRoleAssignmentCreateParameters; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.swallowExceptionForStatusCodeSync; + /** * The {@link KeyVaultAccessControlClient} provides synchronous methods to view and manage Role Based Access for the * Azure Key Vault. The client supports creating, listing, updating, and deleting @@ -41,15 +63,52 @@ */ @ServiceClient(builder = KeyVaultAccessControlClientBuilder.class) public final class KeyVaultAccessControlClient { - private final KeyVaultAccessControlAsyncClient asyncClient; + // Please see here + // for more information on Azure resource provider namespaces. + private static final String KEYVAULT_TRACING_NAMESPACE_VALUE = "Microsoft.KeyVault"; /** - * Creates an {@link KeyVaultAccessControlClient} that uses a {@link HttpPipeline pipeline} to service requests. - * - * @param asyncClient The {@link KeyVaultAccessControlAsyncClient} that this client routes its request through. + * The logger to be used. + */ + private final ClientLogger logger = new ClientLogger(KeyVaultAccessControlClient.class); + + /** + * The underlying AutoRest client used to interact with the Key Vault service. + */ + private final KeyVaultAccessControlClientImpl clientImpl; + + /** + * The Key Vault URL this client is associated to. + */ + private final String vaultUrl; + + /** + * The Key Vault Administration Service version to use with this client. + */ + private final String serviceVersion; + + /** + * The {@link HttpPipeline} powering this client. + */ + private final HttpPipeline pipeline; + + + /** + * Package private constructor to be used by {@link KeyVaultAccessControlClientBuilder}. */ - KeyVaultAccessControlClient(KeyVaultAccessControlAsyncClient asyncClient) { - this.asyncClient = asyncClient; + KeyVaultAccessControlClient(URL vaultUrl, HttpPipeline httpPipeline, + KeyVaultAdministrationServiceVersion serviceVersion) { + Objects.requireNonNull(vaultUrl, + KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)); + + this.vaultUrl = vaultUrl.toString(); + this.serviceVersion = serviceVersion.getVersion(); + this.pipeline = httpPipeline; + + clientImpl = new KeyVaultAccessControlClientImplBuilder() + .pipeline(httpPipeline) + .apiVersion(this.serviceVersion) + .buildClient(); } /** @@ -58,7 +117,7 @@ public final class KeyVaultAccessControlClient { * @return The Key Vault URL. */ public String getVaultUrl() { - return asyncClient.getVaultUrl(); + return this.vaultUrl; } /** @@ -88,7 +147,7 @@ public String getVaultUrl() { */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listRoleDefinitions(KeyVaultRoleScope roleScope) { - return new PagedIterable<>(asyncClient.listRoleDefinitions(roleScope, Context.NONE)); + return listRoleDefinitions(roleScope, Context.NONE); } /** @@ -119,7 +178,69 @@ public PagedIterable listRoleDefinitions(KeyVaultRoleSco */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listRoleDefinitions(KeyVaultRoleScope roleScope, Context context) { - return new PagedIterable<>(asyncClient.listRoleDefinitions(roleScope, context)); + final Context contextToUse = enableSyncRestProxy(context); + return new PagedIterable<>( + () -> listRoleDefinitionsFirstPage(vaultUrl, roleScope, contextToUse), + continuationToken -> listRoleDefinitionsNextPage(continuationToken, contextToUse)); + } + + /** + * Lists all {@link KeyVaultRoleDefinition role definitions} in the first page that are applicable at the given + * {@link KeyVaultRoleScope role scope} and above. + * + * @param vaultUrl The URL for the Key Vault this client is associated with. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleDefinition role definition}. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * + * @return A {@link Mono} containing a {@link PagedResponse} of {@link KeyVaultRoleDefinition role definitions} + * for the given {@link KeyVaultRoleScope role scope} from the first page of results. + * + * @throws KeyVaultAdministrationException If the given {@code vaultUrl} or {@code roleScope} are invalid. + * @throws NullPointerException If the {@link KeyVaultRoleScope role scope} is {@code null}. + */ + PagedResponse listRoleDefinitionsFirstPage(String vaultUrl, + KeyVaultRoleScope roleScope, + Context context) { + Objects.requireNonNull(roleScope, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'roleScope'")); + try { + PagedResponse roleDefinitionPagedResponse = clientImpl.getRoleDefinitions() + .listSyncSinglePage(vaultUrl, roleScope.toString(), null, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return KeyVaultAdministrationUtil.transformRoleDefinitionsPagedResponse(roleDefinitionPagedResponse); + } catch (KeyVaultErrorException e) { + throw logger.logExceptionAsError(KeyVaultAdministrationUtils.toKeyVaultAdministrationException(e)); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + } + + /** + * Lists all {@link KeyVaultRoleDefinition role definitions} given by the {@code nextPageLink} that was retrieved + * from a call to + * {@link KeyVaultAccessControlAsyncClient#listRoleDefinitionsFirstPage(String, KeyVaultRoleScope, Context)}. + * + * @param continuationToken The {@link PagedResponse#getContinuationToken() continuationToken} from a previous, + * successful call to one of the {@code listKeyVaultRoleDefinitions} operations. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * + * @return A {@link Mono} containing a {@link PagedResponse} of {@link KeyVaultRoleDefinition role definitions} + * for the given {@link KeyVaultRoleScope role scope} from the next page of results. + * + * @throws KeyVaultAdministrationException If the given {@code continuationToken} is invalid. + */ + PagedResponse listRoleDefinitionsNextPage(String continuationToken, Context context) { + try { + PagedResponse roleDefinitionPagedResponse = clientImpl.getRoleDefinitions() + .listNextSyncSinglePage(continuationToken, vaultUrl, context.addData(AZ_TRACING_NAMESPACE_KEY, + KEYVAULT_TRACING_NAMESPACE_VALUE)); + return KeyVaultAdministrationUtil.transformRoleDefinitionsPagedResponse(roleDefinitionPagedResponse); + } catch (KeyVaultErrorException e) { + throw logger.logExceptionAsError(KeyVaultAdministrationUtils.toKeyVaultAdministrationException(e)); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } } /** @@ -147,7 +268,7 @@ public PagedIterable listRoleDefinitions(KeyVaultRoleSco */ @ServiceMethod(returns = ReturnType.SINGLE) public KeyVaultRoleDefinition setRoleDefinition(KeyVaultRoleScope roleScope) { - return asyncClient.setRoleDefinition(roleScope).block(); + return setRoleDefinition(roleScope, UUID.randomUUID().toString()); } /** @@ -181,7 +302,8 @@ public KeyVaultRoleDefinition setRoleDefinition(KeyVaultRoleScope roleScope) { */ @ServiceMethod(returns = ReturnType.SINGLE) public KeyVaultRoleDefinition setRoleDefinition(KeyVaultRoleScope roleScope, String roleDefinitionName) { - return asyncClient.setRoleDefinition(roleScope, roleDefinitionName).block(); + return setRoleDefinitionWithResponse(new SetRoleDefinitionOptions(roleScope, roleDefinitionName), Context.NONE) + .getValue(); } /** @@ -239,7 +361,19 @@ public KeyVaultRoleDefinition setRoleDefinition(KeyVaultRoleScope roleScope, Str @ServiceMethod(returns = ReturnType.SINGLE) public Response setRoleDefinitionWithResponse(SetRoleDefinitionOptions options, Context context) { - return asyncClient.setRoleDefinitionWithResponse(options, context).block(); + context = enableSyncRestProxy(context); + RoleDefinitionCreateParameters parameters = validateAndGetRoleDefinitionCreateParameters(options); + try { + Response roleDefinitionResponse = clientImpl.getRoleDefinitions() + .createOrUpdateSyncWithResponse(vaultUrl, options.getRoleScope().toString(), + options.getRoleDefinitionName(), parameters, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return KeyVaultAdministrationUtil.transformRoleDefinitionResponse(roleDefinitionResponse); + } catch (KeyVaultErrorException e) { + throw logger.logExceptionAsError(KeyVaultAdministrationUtils.toKeyVaultAdministrationException(e)); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } } /** @@ -271,7 +405,7 @@ public Response setRoleDefinitionWithResponse(SetRoleDef */ @ServiceMethod(returns = ReturnType.SINGLE) public KeyVaultRoleDefinition getRoleDefinition(KeyVaultRoleScope roleScope, String roleDefinitionName) { - return asyncClient.getRoleDefinition(roleScope, roleDefinitionName).block(); + return getRoleDefinitionWithResponse(roleScope, roleDefinitionName, Context.NONE).getValue(); } /** @@ -308,7 +442,18 @@ public KeyVaultRoleDefinition getRoleDefinition(KeyVaultRoleScope roleScope, Str @ServiceMethod(returns = ReturnType.SINGLE) public Response getRoleDefinitionWithResponse(KeyVaultRoleScope roleScope, String roleDefinitionName, Context context) { - return asyncClient.getRoleDefinitionWithResponse(roleScope, roleDefinitionName, context).block(); + validateRoleDefinitionParameters(roleScope, roleDefinitionName); + try { + context = enableSyncRestProxy(context); + Response roleDefinitionResponse = clientImpl.getRoleDefinitions() + .getSyncWithResponse(vaultUrl, roleScope.toString(), roleDefinitionName, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return KeyVaultAdministrationUtil.transformRoleDefinitionResponse(roleDefinitionResponse); + } catch (KeyVaultErrorException e) { + throw logger.logExceptionAsError(KeyVaultAdministrationUtils.toKeyVaultAdministrationException(e)); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } } /** @@ -336,7 +481,7 @@ public Response getRoleDefinitionWithResponse(KeyVaultRo */ @ServiceMethod(returns = ReturnType.SINGLE) public void deleteRoleDefinition(KeyVaultRoleScope roleScope, String roleDefinitionName) { - asyncClient.deleteRoleDefinition(roleScope, roleDefinitionName).block(); + deleteRoleDefinitionWithResponse(roleScope, roleDefinitionName, Context.NONE); } /** @@ -371,7 +516,21 @@ public void deleteRoleDefinition(KeyVaultRoleScope roleScope, String roleDefinit public Response deleteRoleDefinitionWithResponse(KeyVaultRoleScope roleScope, String roleDefinitionName, Context context) { - return asyncClient.deleteRoleDefinitionWithResponse(roleScope, roleDefinitionName, context).block(); + validateRoleDefinitionParameters(roleScope, roleDefinitionName); + try { + context = enableSyncRestProxy(context); + Response roleDefinitionResponse = clientImpl.getRoleDefinitions() + .deleteSyncWithResponse(vaultUrl, roleScope.toString(), roleDefinitionName, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return new SimpleResponse<>(roleDefinitionResponse, null); + + } catch (KeyVaultErrorException e) { + KeyVaultAdministrationException mappedException = KeyVaultAdministrationUtils + .toKeyVaultAdministrationException(e); + return swallowExceptionForStatusCodeSync(404, mappedException, logger); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } } /** @@ -401,7 +560,7 @@ public Response deleteRoleDefinitionWithResponse(KeyVaultRoleScope roleSco */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listRoleAssignments(KeyVaultRoleScope roleScope) { - return new PagedIterable<>(asyncClient.listRoleAssignments(roleScope, Context.NONE)); + return listRoleAssignments(roleScope, Context.NONE); } /** @@ -432,7 +591,68 @@ public PagedIterable listRoleAssignments(KeyVaultRoleSco */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listRoleAssignments(KeyVaultRoleScope roleScope, Context context) { - return new PagedIterable<>(asyncClient.listRoleAssignments(roleScope, context)); + final Context contextToUse = enableSyncRestProxy(context); + return new PagedIterable<>( + () -> listRoleAssignmentsFirstPage(vaultUrl, roleScope, contextToUse), + continuationToken -> listRoleAssignmentsNextPage(continuationToken, context)); + } + + /** + * Lists all {@link KeyVaultRoleAssignment role assignments} in the first page that are applicable at the given + * {@link KeyVaultRoleScope role scope} and above. + * + * @param vaultUrl The URL for the Key Vault this client is associated with. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment role assignment}. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * + * @return A {@link Mono} containing a {@link PagedResponse} of {@link KeyVaultRoleAssignment role assignments} + * in the given {@link KeyVaultRoleScope role scope} from the first page of results. + * + * @throws KeyVaultAdministrationException If the given {@code vaultUrl} or {@code roleScope} are invalid. + * @throws NullPointerException If the {@link KeyVaultRoleScope role scope} is {@code null}. + */ + PagedResponse listRoleAssignmentsFirstPage(String vaultUrl, + KeyVaultRoleScope roleScope, + Context context) { + Objects.requireNonNull(roleScope, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'roleScope'")); + try { + PagedResponse roleAssignmentPagedResponse = clientImpl.getRoleAssignments() + .listForScopeSyncSinglePage(vaultUrl, roleScope.toString(), null, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return KeyVaultAdministrationUtil.transformRoleAssignmentsPagedResponse(roleAssignmentPagedResponse); + } catch (KeyVaultErrorException e) { + throw logger.logExceptionAsError(KeyVaultAdministrationUtils.toKeyVaultAdministrationException(e)); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + } + + /** + * Lists all {@link KeyVaultRoleAssignment role assignments} given by the {@code nextPageLink} that was + * retrieved from a call to {@link KeyVaultAccessControlAsyncClient#listRoleAssignments(KeyVaultRoleScope)}. + * + * @param continuationToken The {@link PagedResponse#getContinuationToken() continuationToken} from a previous, + * successful call to one of the {@code listKeyVaultRoleAssignments} operations. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * + * @return A {@link Mono} containing a {@link PagedResponse} of {@link KeyVaultRoleAssignment role assignments} + * for the given {@link KeyVaultRoleScope role scope} from the first page of results. + * + * @throws KeyVaultAdministrationException If the given {@code continuationToken} is invalid. + */ + PagedResponse listRoleAssignmentsNextPage(String continuationToken, Context context) { + try { + PagedResponse roleAssignmentPagedResponse = clientImpl.getRoleAssignments() + .listForScopeNextSyncSinglePage(continuationToken, vaultUrl, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return KeyVaultAdministrationUtil.transformRoleAssignmentsPagedResponse(roleAssignmentPagedResponse); + } catch (KeyVaultErrorException e) { + throw logger.logExceptionAsError(KeyVaultAdministrationUtils.toKeyVaultAdministrationException(e)); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } } /** @@ -560,8 +780,18 @@ public Response createRoleAssignmentWithResponse(KeyVaul String principalId, String roleAssignmentName, Context context) { - return asyncClient.createRoleAssignmentWithResponse(roleScope, roleDefinitionId, principalId, - roleAssignmentName, context).block(); + RoleAssignmentCreateParameters parameters = validateAndGetRoleAssignmentCreateParameters(roleScope, roleDefinitionId, principalId, roleAssignmentName); + context = enableSyncRestProxy(context); + try { + Response roleAssignmentResponse = clientImpl.getRoleAssignments() + .createSyncWithResponse(vaultUrl, roleScope.toString(), roleAssignmentName, parameters, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return KeyVaultAdministrationUtil.transformRoleAssignmentResponse(roleAssignmentResponse); + } catch (KeyVaultErrorException e) { + throw logger.logExceptionAsError(KeyVaultAdministrationUtils.toKeyVaultAdministrationException(e)); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } } /** @@ -627,7 +857,18 @@ public KeyVaultRoleAssignment getRoleAssignment(KeyVaultRoleScope roleScope, Str @ServiceMethod(returns = ReturnType.SINGLE) public Response getRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, Context context) { - return asyncClient.getRoleAssignmentWithResponse(roleScope, roleAssignmentName, context).block(); + validateRoleAssignmentParameters(roleScope, roleAssignmentName); + try { + context = enableSyncRestProxy(context); + Response roleAssignmentResponse = clientImpl.getRoleAssignments() + .getSyncWithResponse(vaultUrl, roleScope.toString(), roleAssignmentName, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return KeyVaultAdministrationUtil.transformRoleAssignmentResponse(roleAssignmentResponse); + } catch (KeyVaultErrorException e) { + throw logger.logExceptionAsError(KeyVaultAdministrationUtils.toKeyVaultAdministrationException(e)); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } } /** @@ -654,7 +895,7 @@ public Response getRoleAssignmentWithResponse(KeyVaultRo */ @ServiceMethod(returns = ReturnType.SINGLE) public void deleteRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignmentName) { - asyncClient.deleteRoleAssignment(roleScope, roleAssignmentName).block(); + deleteRoleAssignmentWithResponse(roleScope, roleAssignmentName, Context.NONE); } /** @@ -688,6 +929,18 @@ public void deleteRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignm @ServiceMethod(returns = ReturnType.SINGLE) public Response deleteRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, Context context) { - return asyncClient.deleteRoleAssignmentWithResponse(roleScope, roleAssignmentName, context).block(); + validateRoleAssignmentParameters(roleScope, roleAssignmentName); + try { + context = enableSyncRestProxy(context); + Response roleAssignmentResponse = clientImpl.getRoleAssignments() + .deleteSyncWithResponse(vaultUrl, roleScope.toString(), roleAssignmentName, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return new SimpleResponse<>(roleAssignmentResponse, null); + } catch (KeyVaultErrorException e) { + KeyVaultAdministrationException mappedException = KeyVaultAdministrationUtils.toKeyVaultAdministrationException(e); + return swallowExceptionForStatusCodeSync(404, mappedException, logger); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClientBuilder.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClientBuilder.java index 75c712ab90eaa..7942d5a7e1396 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClientBuilder.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClientBuilder.java @@ -29,6 +29,7 @@ import com.azure.core.util.HttpClientOptions; import com.azure.core.util.builder.ClientBuilderUtil; import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.ServiceVersion; import com.azure.security.keyvault.administration.implementation.KeyVaultCredentialPolicy; import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings; @@ -123,7 +124,13 @@ public KeyVaultAccessControlClientBuilder() { * and {@link #retryPolicy(RetryPolicy)} have been set. */ public KeyVaultAccessControlClient buildClient() { - return new KeyVaultAccessControlClient(buildAsyncClient()); + Configuration buildConfiguration = validateEndpointAndGetConfiguration(); + serviceVersion = getServiceVersion(); + if (pipeline != null) { + return new KeyVaultAccessControlClient(vaultUrl, pipeline, serviceVersion); + } + HttpPipeline buildPipeline = getPipeline(buildConfiguration, serviceVersion); + return new KeyVaultAccessControlClient(vaultUrl, buildPipeline, serviceVersion); } /** @@ -141,6 +148,17 @@ public KeyVaultAccessControlClient buildClient() { * and {@link #retryPolicy(RetryPolicy)} have been set. */ public KeyVaultAccessControlAsyncClient buildAsyncClient() { + Configuration buildConfiguration = validateEndpointAndGetConfiguration(); + serviceVersion = getServiceVersion(); + if (pipeline != null) { + return new KeyVaultAccessControlAsyncClient(vaultUrl, pipeline, serviceVersion); + } + HttpPipeline buildPipeline = getPipeline(buildConfiguration, serviceVersion); + return new KeyVaultAccessControlAsyncClient(vaultUrl, buildPipeline, serviceVersion); + } + + + private Configuration validateEndpointAndGetConfiguration() { Configuration buildConfiguration = (configuration == null) ? Configuration.getGlobalConfiguration().clone() : configuration; @@ -152,13 +170,15 @@ public KeyVaultAccessControlAsyncClient buildAsyncClient() { new IllegalStateException( KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED))); } + return buildConfiguration; + } - serviceVersion = serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest(); + private KeyVaultAdministrationServiceVersion getServiceVersion() { + return serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest(); + } - if (pipeline != null) { - return new KeyVaultAccessControlAsyncClient(vaultUrl, pipeline, serviceVersion); - } + private HttpPipeline getPipeline(Configuration buildConfiguration, ServiceVersion serviceVersion) { // Closest to API goes first, closest to wire goes last. final List policies = new ArrayList<>(); @@ -192,12 +212,10 @@ public KeyVaultAccessControlAsyncClient buildAsyncClient() { HttpPolicyProviders.addAfterRetryPolicies(policies); policies.add(new HttpLoggingPolicy(httpLogOptions)); - HttpPipeline buildPipeline = new HttpPipelineBuilder() + return new HttpPipelineBuilder() .policies(policies.toArray(new HttpPipelinePolicy[0])) .httpClient(httpClient) .build(); - - return new KeyVaultAccessControlAsyncClient(vaultUrl, buildPipeline, serviceVersion); } /** diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAdministrationUtil.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAdministrationUtil.java new file mode 100644 index 0000000000000..6018f4f0ed7ef --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAdministrationUtil.java @@ -0,0 +1,383 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.security.keyvault.administration; + +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.IterableStream; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings; +import com.azure.security.keyvault.administration.implementation.models.DataAction; +import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentCreateParameters; +import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentProperties; +import com.azure.security.keyvault.administration.implementation.models.RoleDefinitionCreateParameters; +import com.azure.security.keyvault.administration.implementation.models.RoleScope; +import com.azure.security.keyvault.administration.implementation.models.RoleDefinition; +import com.azure.security.keyvault.administration.implementation.models.RoleDefinitionProperties; +import com.azure.security.keyvault.administration.implementation.models.RoleAssignment; +import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentPropertiesWithScope; +import com.azure.security.keyvault.administration.implementation.models.Permission; +import com.azure.security.keyvault.administration.implementation.models.SelectiveKeyRestoreOperation; +import com.azure.security.keyvault.administration.implementation.models.RestoreOperation; +import com.azure.security.keyvault.administration.implementation.models.FullBackupOperation; +import com.azure.security.keyvault.administration.models.KeyVaultDataAction; +import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinitionType; +import com.azure.security.keyvault.administration.models.KeyVaultRoleType; +import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; +import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties; +import com.azure.security.keyvault.administration.models.KeyVaultPermission; +import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition; +import com.azure.security.keyvault.administration.models.KeyVaultRoleScope; +import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation; +import com.azure.security.keyvault.administration.models.KeyVaultSelectiveKeyRestoreOperation; +import com.azure.security.keyvault.administration.models.KeyVaultLongRunningOperation; +import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation; +import com.azure.security.keyvault.administration.models.SetRoleDefinitionOptions; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.time.Instant; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import static com.azure.security.keyvault.administration.implementation.KeyVaultAdministrationUtils.createKeyVaultErrorFromError; + +/** + * Internal utility class for KeyVault Administration clients. + */ +class KeyVaultAdministrationUtil { + private static final String HTTP_REST_PROXY_SYNC_PROXY_ENABLE = "com.azure.core.http.restproxy.syncproxy.enable"; + + /** + * Deserializes a given {@link Response HTTP response} including headers to a given class. + * + * @param statusCode The status code which will trigger exception swallowing. + * @param httpResponseException The {@link HttpResponseException} to be swallowed. + * @param logger {@link ClientLogger} that will be used to record the exception. + * @param The class of the exception to swallow. + * + * @return A {@link Mono} that contains the deserialized response. + */ + static Mono> swallowExceptionForStatusCodeAsync(int statusCode, + E httpResponseException, + ClientLogger logger) { + try { + return Mono.just(swallowExceptionForStatusCodeSync(statusCode, httpResponseException, logger)); + } catch (RuntimeException e) { + return Mono.error(e); + } + } + + /** + * Synchronously deserializes a given {@link Response HTTP response} including headers to a given class. + * + * @param statusCode The status code which will trigger exception swallowing. + * @param httpResponseException The {@link HttpResponseException} to be swallowed. + * @param logger {@link ClientLogger} that will be used to record the exception. + * @param The class of the exception to swallow. + * + * @return the deserialized response. + */ + static Response swallowExceptionForStatusCodeSync(int statusCode, + E httpResponseException, + ClientLogger logger) { + HttpResponse httpResponse = httpResponseException.getResponse(); + + if (httpResponse.getStatusCode() == statusCode) { + return new SimpleResponse<>(httpResponse.getRequest(), httpResponse.getStatusCode(), + httpResponse.getHeaders(), null); + } + throw logger.logExceptionAsError(httpResponseException); + } + + static RoleAssignmentCreateParameters validateAndGetRoleAssignmentCreateParameters(KeyVaultRoleScope roleScope, String roleDefinitionId, String principalId, String roleAssignmentName) { + validateRoleAssignmentParameters(roleScope, roleAssignmentName); + Objects.requireNonNull(principalId, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'principalId'")); + Objects.requireNonNull(roleDefinitionId, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'roleDefinitionId'")); + + RoleAssignmentProperties roleAssignmentProperties = + new RoleAssignmentProperties() + .setRoleDefinitionId(roleDefinitionId) + .setPrincipalId(principalId); + RoleAssignmentCreateParameters parameters = + new RoleAssignmentCreateParameters() + .setProperties(roleAssignmentProperties); + return parameters; + } + + static RoleDefinitionCreateParameters validateAndGetRoleDefinitionCreateParameters(SetRoleDefinitionOptions options) { + Objects.requireNonNull(options, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'options'")); + Objects.requireNonNull(options.getRoleScope(), + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'options.getRoleScope()'")); + Objects.requireNonNull(options.getRoleDefinitionName(), + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'options.getRoleDefinitionName()'")); + + List assignableScopes = null; + + if (options.getAssignableScopes() != null) { + assignableScopes = options.getAssignableScopes().stream() + .map(keyVaultRoleScope -> RoleScope.fromString(keyVaultRoleScope.toString())) + .collect(Collectors.toList()); + } + + List permissions = null; + + if (options.getPermissions() != null) { + permissions = options.getPermissions().stream() + .map(keyVaultPermission -> new Permission() + .setActions(keyVaultPermission.getActions()) + .setNotActions(keyVaultPermission.getNotActions()) + .setDataActions(keyVaultPermission.getDataActions().stream() + .map(allowedDataAction -> DataAction.fromString(allowedDataAction.toString())) + .collect(Collectors.toList())) + .setNotDataActions(keyVaultPermission.getNotDataActions().stream() + .map(notDataAction -> DataAction.fromString(notDataAction.toString())) + .collect(Collectors.toList()))) + .collect(Collectors.toList()); + } + + RoleDefinitionProperties roleDefinitionProperties = + new RoleDefinitionProperties() + .setRoleName(options.getRoleDefinitionName()) + .setAssignableScopes(assignableScopes) + .setDescription(options.getDescription()) + .setPermissions(permissions); + RoleDefinitionCreateParameters parameters = + new RoleDefinitionCreateParameters() + .setProperties(roleDefinitionProperties); + return parameters; + } + + static void validateRoleAssignmentParameters(KeyVaultRoleScope roleScope, String roleAssignmentName) { + Objects.requireNonNull(roleScope, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'roleScope'")); + Objects.requireNonNull(roleAssignmentName, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'roleAssignmentName'")); + } + + static void validateRoleDefinitionParameters(KeyVaultRoleScope roleScope, String roleDefinitionName) { + Objects.requireNonNull(roleScope, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'roleScope'")); + Objects.requireNonNull(roleDefinitionName, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'roleDefinitionName'")); + } + + @SuppressWarnings("BoundedWildcard") + static PagedResponse transformRoleDefinitionsPagedResponse( + PagedResponse pagedResponse) { + + List keyVaultRoleDefinitions = new ArrayList<>(); + + for (RoleDefinition roleDefinition : pagedResponse.getValue()) { + keyVaultRoleDefinitions.add(roleDefinitionToKeyVaultRoleDefinition(roleDefinition)); + } + + return new TransformedPagedResponse<>(keyVaultRoleDefinitions, pagedResponse); + } + + static Response transformRoleDefinitionResponse(Response response) { + KeyVaultRoleDefinition keyVaultRoleDefinition = roleDefinitionToKeyVaultRoleDefinition(response.getValue()); + + return new TransformedResponse<>(keyVaultRoleDefinition, response); + } + + static KeyVaultRoleDefinition roleDefinitionToKeyVaultRoleDefinition(RoleDefinition roleDefinition) { + List keyVaultPermissions = new ArrayList<>(); + + for (Permission permission : roleDefinition.getPermissions()) { + keyVaultPermissions.add( + new KeyVaultPermission(permission.getActions(), permission.getNotActions(), + permission.getDataActions().stream() + .map(dataAction -> KeyVaultDataAction.fromString(dataAction.toString())) + .collect(Collectors.toList()), + permission.getNotDataActions().stream() + .map(notDataAction -> KeyVaultDataAction.fromString(notDataAction.toString())) + .collect(Collectors.toList()))); + } + + return new KeyVaultRoleDefinition(roleDefinition.getId(), roleDefinition.getName(), + KeyVaultRoleDefinitionType.fromString(roleDefinition.getType().toString()), roleDefinition.getRoleName(), + roleDefinition.getDescription(), KeyVaultRoleType.fromString(roleDefinition.getRoleType().toString()), + keyVaultPermissions, roleDefinition.getAssignableScopes().stream() + .map(roleScope -> KeyVaultRoleScope.fromString(roleScope.toString())) + .collect(Collectors.toList())); + } + + static PagedResponse transformRoleAssignmentsPagedResponse( + PagedResponse pagedResponse) { + + List keyVaultRoleAssignments = new ArrayList<>(); + + for (RoleAssignment roleAssignment : pagedResponse.getValue()) { + keyVaultRoleAssignments.add(roleAssignmentToKeyVaultRoleAssignment(roleAssignment)); + } + + return new TransformedPagedResponse<>(keyVaultRoleAssignments, pagedResponse); + } + + static Response transformRoleAssignmentResponse(Response response) { + KeyVaultRoleAssignment keyVaultRoleAssignment = roleAssignmentToKeyVaultRoleAssignment(response.getValue()); + + return new TransformedResponse<>(keyVaultRoleAssignment, response); + } + + static KeyVaultRoleAssignment roleAssignmentToKeyVaultRoleAssignment(RoleAssignment roleAssignment) { + RoleAssignmentPropertiesWithScope propertiesWithScope = roleAssignment.getProperties(); + + return new KeyVaultRoleAssignment(roleAssignment.getId(), roleAssignment.getName(), roleAssignment.getType(), + new KeyVaultRoleAssignmentProperties(propertiesWithScope.getRoleDefinitionId(), + propertiesWithScope.getPrincipalId(), + KeyVaultRoleScope.fromString(propertiesWithScope.getScope().toString()))); + } + + private static final class TransformedPagedResponse, T, U> implements PagedResponse { + private final L output; + private final PagedResponse pagedResponse; + + TransformedPagedResponse(L output, PagedResponse inputPagedResponse) { + this.output = output; + this.pagedResponse = inputPagedResponse; + } + + @Override + public void close() throws IOException { + } + + @Override + public IterableStream getElements() { + return new IterableStream<>(output); + } + + @Override + public String getContinuationToken() { + return pagedResponse.getContinuationToken(); + } + + @Override + public int getStatusCode() { + return pagedResponse.getStatusCode(); + } + + @Override + public HttpHeaders getHeaders() { + return pagedResponse.getHeaders(); + } + + @Override + public HttpRequest getRequest() { + return pagedResponse.getRequest(); + } + + @Override + public List getValue() { + return output; + } + } + + private static final class TransformedResponse implements Response { + private final T output; + private final Response response; + + TransformedResponse(T output, Response response) { + this.output = output; + this.response = response; + } + + @Override + public int getStatusCode() { + return response.getStatusCode(); + } + + @Override + public HttpHeaders getHeaders() { + return response.getHeaders(); + } + + @Override + public HttpRequest getRequest() { + return response.getRequest(); + } + + @Override + public T getValue() { + return output; + } + } + + static LongRunningOperationStatus toLongRunningOperationStatus(String operationStatus) { + switch (operationStatus) { + case "inprogress": + return LongRunningOperationStatus.IN_PROGRESS; + case "succeeded": + return LongRunningOperationStatus.SUCCESSFULLY_COMPLETED; + case "failed": + return LongRunningOperationStatus.FAILED; + default: + // Should not reach here + return LongRunningOperationStatus.fromString("POLLING_FAILED", true); + } + } + + static KeyVaultLongRunningOperation transformToLongRunningOperation(O operation) { + if (operation instanceof RestoreOperation) { + RestoreOperation restoreOperation = (RestoreOperation) operation; + + return new KeyVaultRestoreOperation(restoreOperation.getStatus(), restoreOperation.getStatusDetails(), + createKeyVaultErrorFromError(restoreOperation.getError()), restoreOperation.getJobId(), + longToOffsetDateTime(restoreOperation.getStartTime()), + longToOffsetDateTime(restoreOperation.getEndTime())); + } else if (operation instanceof SelectiveKeyRestoreOperation) { + SelectiveKeyRestoreOperation selectiveKeyRestoreOperation = (SelectiveKeyRestoreOperation) operation; + + return new KeyVaultSelectiveKeyRestoreOperation(selectiveKeyRestoreOperation.getStatus(), + selectiveKeyRestoreOperation.getStatusDetails(), + createKeyVaultErrorFromError(selectiveKeyRestoreOperation.getError()), + selectiveKeyRestoreOperation.getJobId(), + longToOffsetDateTime(selectiveKeyRestoreOperation.getStartTime()), + longToOffsetDateTime(selectiveKeyRestoreOperation.getEndTime())); + } else if (operation instanceof FullBackupOperation) { + FullBackupOperation fullBackupOperation = (FullBackupOperation) operation; + + return new KeyVaultBackupOperation(fullBackupOperation.getStatus(), fullBackupOperation.getStatusDetails(), + createKeyVaultErrorFromError(fullBackupOperation.getError()), fullBackupOperation.getJobId(), + longToOffsetDateTime(fullBackupOperation.getStartTime()), + longToOffsetDateTime(fullBackupOperation.getEndTime()), + fullBackupOperation.getAzureStorageBlobContainerUri()); + } else { + throw new UnsupportedOperationException(); + } + } + + static OffsetDateTime longToOffsetDateTime(Long epochInSeconds) { + return epochInSeconds == null ? null + : OffsetDateTime.ofInstant(Instant.ofEpochSecond(epochInSeconds), ZoneOffset.UTC); + } + + static Context enableSyncRestProxy(Context context) { + return context.addData(HTTP_REST_PROXY_SYNC_PROXY_ENABLE, true); + } +} diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupAsyncClient.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupAsyncClient.java index ec33a046182f5..f192b5a42b54a 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupAsyncClient.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupAsyncClient.java @@ -19,11 +19,9 @@ import com.azure.security.keyvault.administration.implementation.KeyVaultBackupClientImpl; import com.azure.security.keyvault.administration.implementation.KeyVaultBackupClientImplBuilder; import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings; -import com.azure.security.keyvault.administration.implementation.models.FullBackupOperation; import com.azure.security.keyvault.administration.implementation.models.RestoreOperation; import com.azure.security.keyvault.administration.implementation.models.RestoreOperationParameters; import com.azure.security.keyvault.administration.implementation.models.SASTokenParameter; -import com.azure.security.keyvault.administration.implementation.models.SelectiveKeyRestoreOperation; import com.azure.security.keyvault.administration.implementation.models.SelectiveKeyRestoreOperationParameters; import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation; import com.azure.security.keyvault.administration.models.KeyVaultAdministrationException; @@ -37,9 +35,6 @@ import java.net.URL; import java.time.Duration; -import java.time.Instant; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; import java.util.Locale; import java.util.Objects; import java.util.function.Function; @@ -47,6 +42,9 @@ import static com.azure.core.util.FluxUtil.monoError; import static com.azure.core.util.FluxUtil.withContext; import static com.azure.core.util.tracing.Tracer.AZ_TRACING_NAMESPACE_KEY; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.transformToLongRunningOperation; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.toLongRunningOperationStatus; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.longToOffsetDateTime; import static com.azure.security.keyvault.administration.implementation.KeyVaultAdministrationUtils.createKeyVaultErrorFromError; /** @@ -306,20 +304,6 @@ private static Mono> processBackupOperatio toLongRunningOperationStatus(operationStatus.toLowerCase(Locale.US)), response.getValue())); } - private static LongRunningOperationStatus toLongRunningOperationStatus(String operationStatus) { - switch (operationStatus) { - case "inprogress": - return LongRunningOperationStatus.IN_PROGRESS; - case "succeeded": - return LongRunningOperationStatus.SUCCESSFULLY_COMPLETED; - case "failed": - return LongRunningOperationStatus.FAILED; - default: - // Should not reach here - return LongRunningOperationStatus.fromString("POLLING_FAILED", true); - } - } - /** * Initiates a full restore of the Key Vault. * @@ -471,7 +455,7 @@ private Function, Mono> processRestoreOperationResponse( + static Mono> processRestoreOperationResponse( Response response) { String operationStatus = response.getValue().getStatus().toLowerCase(Locale.US); @@ -656,37 +640,7 @@ private static Mono> processS toLongRunningOperationStatus(operationStatus.toLowerCase(Locale.US)), response.getValue())); } - private static KeyVaultLongRunningOperation transformToLongRunningOperation(O operation) { - if (operation instanceof RestoreOperation) { - RestoreOperation restoreOperation = (RestoreOperation) operation; - - return new KeyVaultRestoreOperation(restoreOperation.getStatus(), restoreOperation.getStatusDetails(), - createKeyVaultErrorFromError(restoreOperation.getError()), restoreOperation.getJobId(), - longToOffsetDateTime(restoreOperation.getStartTime()), - longToOffsetDateTime(restoreOperation.getEndTime())); - } else if (operation instanceof SelectiveKeyRestoreOperation) { - SelectiveKeyRestoreOperation selectiveKeyRestoreOperation = (SelectiveKeyRestoreOperation) operation; - - return new KeyVaultSelectiveKeyRestoreOperation(selectiveKeyRestoreOperation.getStatus(), - selectiveKeyRestoreOperation.getStatusDetails(), - createKeyVaultErrorFromError(selectiveKeyRestoreOperation.getError()), - selectiveKeyRestoreOperation.getJobId(), - longToOffsetDateTime(selectiveKeyRestoreOperation.getStartTime()), - longToOffsetDateTime(selectiveKeyRestoreOperation.getEndTime())); - } else if (operation instanceof FullBackupOperation) { - FullBackupOperation fullBackupOperation = (FullBackupOperation) operation; - - return new KeyVaultBackupOperation(fullBackupOperation.getStatus(), fullBackupOperation.getStatusDetails(), - createKeyVaultErrorFromError(fullBackupOperation.getError()), fullBackupOperation.getJobId(), - longToOffsetDateTime(fullBackupOperation.getStartTime()), - longToOffsetDateTime(fullBackupOperation.getEndTime()), - fullBackupOperation.getAzureStorageBlobContainerUri()); - } else { - throw new UnsupportedOperationException(); - } - } - - private static KeyVaultLongRunningOperation restoreOperationToSelectiveKeyRestoreOperation(RestoreOperation operation) { + static KeyVaultLongRunningOperation restoreOperationToSelectiveKeyRestoreOperation(RestoreOperation operation) { return new KeyVaultSelectiveKeyRestoreOperation(operation.getStatus(), operation.getStatusDetails(), createKeyVaultErrorFromError(operation.getError()), @@ -694,9 +648,4 @@ private static KeyVaultLongRunningOperation restoreOperationToSelectiveKeyRestor longToOffsetDateTime(operation.getStartTime()), longToOffsetDateTime(operation.getEndTime())); } - - private static OffsetDateTime longToOffsetDateTime(Long epochInSeconds) { - return epochInSeconds == null ? null - : OffsetDateTime.ofInstant(Instant.ofEpochSecond(epochInSeconds), ZoneOffset.UTC); - } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupClient.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupClient.java index 82858b2716295..63b0886d72eb7 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupClient.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupClient.java @@ -6,7 +6,27 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollResponse; +import com.azure.core.util.polling.PollingContext; import com.azure.core.util.polling.SyncPoller; +import com.azure.security.keyvault.administration.implementation.KeyVaultBackupClientImpl; +import com.azure.security.keyvault.administration.implementation.KeyVaultBackupClientImplBuilder; +import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings; +import com.azure.security.keyvault.administration.implementation.models.RestoreOperation; +import com.azure.security.keyvault.administration.implementation.models.RestoreOperationParameters; +import com.azure.security.keyvault.administration.implementation.models.SASTokenParameter; +import com.azure.security.keyvault.administration.implementation.models.SelectiveKeyRestoreOperationParameters; +import com.azure.security.keyvault.administration.implementation.models.FullBackupOperation; +import com.azure.security.keyvault.administration.implementation.models.FullBackupResponse; +import com.azure.security.keyvault.administration.implementation.models.FullRestoreOperationResponse; +import com.azure.security.keyvault.administration.implementation.models.SelectiveKeyRestoreOperationResponse; import com.azure.security.keyvault.administration.models.KeyVaultAdministrationException; import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation; import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation; @@ -14,6 +34,18 @@ import com.azure.security.keyvault.administration.models.KeyVaultSelectiveKeyRestoreOperation; import com.azure.security.keyvault.administration.models.KeyVaultSelectiveKeyRestoreResult; +import java.net.URL; +import java.time.Duration; +import java.util.Locale; +import java.util.Objects; +import java.util.function.Function; + +import static com.azure.core.util.tracing.Tracer.AZ_TRACING_NAMESPACE_KEY; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.enableSyncRestProxy; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.transformToLongRunningOperation; +import static com.azure.security.keyvault.administration.KeyVaultAdministrationUtil.toLongRunningOperationStatus; +import static com.azure.security.keyvault.administration.KeyVaultBackupAsyncClient.restoreOperationToSelectiveKeyRestoreOperation; + /** * The {@link KeyVaultBackupClient} provides synchronous methods to perform backup and restore operations of an Azure * Key Vault. @@ -37,15 +69,61 @@ public final class KeyVaultBackupClient { private final KeyVaultBackupAsyncClient asyncClient; + // Please see here + // for more information on Azure resource provider namespaces. + private static final String KEYVAULT_TRACING_NAMESPACE_VALUE = "Microsoft.KeyVault"; + + private static final Duration DEFAULT_POLLING_INTERVAL = Duration.ofSeconds(1); + /** - * Creates an {@link KeyVaultBackupClient} that uses a {@code pipeline} to service requests - * - * @param asyncClient The {@link KeyVaultBackupAsyncClient} that the client routes its request through. + * The logger to be used. + */ + private final ClientLogger logger = new ClientLogger(KeyVaultBackupClient.class); + + /** + * The underlying AutoRest client used to interact with the Key Vault service. */ - KeyVaultBackupClient(KeyVaultBackupAsyncClient asyncClient) { - this.asyncClient = asyncClient; + private final KeyVaultBackupClientImpl clientImpl; + + /** + * The Key Vault URL this client is associated to. + */ + private final String vaultUrl; + + /** + * The Key Vault Administration Service version to use with this client. + */ + private final String serviceVersion; + + /** + * The {@link HttpPipeline} powering this client. + */ + private final HttpPipeline pipeline; + + Duration getDefaultPollingInterval() { + return DEFAULT_POLLING_INTERVAL; + } + + /** + * Package private constructor to be used by {@link KeyVaultBackupClientBuilder}. + */ + KeyVaultBackupClient(URL vaultUrl, HttpPipeline httpPipeline, + KeyVaultAdministrationServiceVersion serviceVersion) { + Objects.requireNonNull(vaultUrl, + KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)); + + this.vaultUrl = vaultUrl.toString(); + this.serviceVersion = serviceVersion.getVersion(); + this.pipeline = httpPipeline; + this.asyncClient = null; + + clientImpl = new KeyVaultBackupClientImplBuilder() + .pipeline(httpPipeline) + .apiVersion(this.serviceVersion) + .buildClient(); } + /** * Get the vault endpoint URL. * @@ -98,7 +176,119 @@ public String getVaultUrl() { */ @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) public SyncPoller beginBackup(String blobStorageUrl, String sasToken) { - return asyncClient.beginBackup(blobStorageUrl, sasToken).getSyncPoller(); + if (blobStorageUrl == null) { + throw logger.logExceptionAsError(new NullPointerException( + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'blobStorageUrl'"))); + } + + if (sasToken == null) { + throw logger.logExceptionAsError(new NullPointerException( + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'sasToken'"))); + } + + Context context = Context.NONE; + return SyncPoller.createPoller( + getDefaultPollingInterval(), + cxt -> new PollResponse<>(LongRunningOperationStatus.NOT_STARTED, backupActivationOperation(blobStorageUrl, sasToken, context).apply(cxt)), + backupPollOperation(context), + (pollingContext, firstResponse) -> { + throw logger.logExceptionAsError(new RuntimeException("Cancellation is not supported")); + }, + backupFetchOperation()); + } + + /** + * Initiates a full backup of the Key Vault. + * + * @param blobStorageUrl The URL for the Blob Storage resource where the backup will be located. + * @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * + * @return A {@link Response} containing the {@link KeyVaultBackupOperation backup operation} status. + * + * @throws KeyVaultAdministrationException If the given {@code blobStorageUrl} or {@code sasToken} are invalid. + */ + Response backupWithResponse(String blobStorageUrl, String sasToken, + Context context) { + SASTokenParameter sasTokenParameter = new SASTokenParameter() + .setStorageResourceUri(blobStorageUrl) + .setToken(sasToken); + context = enableSyncRestProxy(context); + + try { + FullBackupResponse backupOperationResponse = clientImpl.fullBackupSyncWithResponse(vaultUrl, sasTokenParameter, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return new SimpleResponse<>(backupOperationResponse.getRequest(), backupOperationResponse.getStatusCode(), + backupOperationResponse.getHeaders(), + (KeyVaultBackupOperation) transformToLongRunningOperation(backupOperationResponse.getValue())); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + } + + private Function, KeyVaultBackupOperation> backupActivationOperation( + String blobStorageUrl, String sasToken, Context context) { + return (pollingContext) -> { + try { + return backupWithResponse(blobStorageUrl, sasToken, context).getValue(); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + }; + } + + private Function, PollResponse> backupPollOperation(Context context) { + return (pollingContext) -> { + try { + PollResponse pollResponse = pollingContext.getLatestResponse(); + + if (pollResponse.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED + || pollResponse.getStatus() == LongRunningOperationStatus.FAILED) { + return pollResponse; + } + + final KeyVaultBackupOperation keyVaultBackupOperation = pollResponse.getValue(); + + if (keyVaultBackupOperation == null) { + logger.warning("Backup operation does not exist. Activation operation failed."); + return new PollResponse( + LongRunningOperationStatus.fromString("BACKUP_START_FAILED", true), null); + } + + final String jobId = keyVaultBackupOperation.getOperationId(); + Context contextToUse = enableSyncRestProxy(context); + + Response backupOperationResponse = clientImpl.fullBackupStatusSyncWithResponse(vaultUrl, jobId, + contextToUse.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return processBackupOperationResponse(new SimpleResponse<>(backupOperationResponse, + (KeyVaultBackupOperation) transformToLongRunningOperation(backupOperationResponse.getValue()))); + } catch (HttpResponseException e) { + //noinspection ThrowableNotThrown + logger.logExceptionAsError(e); + return new PollResponse<>(LongRunningOperationStatus.FAILED, null); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + }; + } + + private Function, String> backupFetchOperation() { + return (pollingContext) -> { + try { + return pollingContext.getLatestResponse().getValue().getAzureStorageBlobContainerUrl(); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + }; + } + + private static PollResponse processBackupOperationResponse( + Response response) { + String operationStatus = response.getValue().getStatus().toLowerCase(Locale.US); + return new PollResponse<>( + toLongRunningOperationStatus(operationStatus.toLowerCase(Locale.US)), response.getValue()); } /** @@ -146,7 +336,118 @@ public SyncPoller beginBackup(String blobStorag */ @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) public SyncPoller beginRestore(String folderUrl, String sasToken) { - return asyncClient.beginRestore(folderUrl, sasToken).getSyncPoller(); + if (folderUrl == null) { + throw logger.logExceptionAsError(new NullPointerException( + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'folderUrl'"))); + } + if (sasToken == null) { + throw logger.logExceptionAsError(new NullPointerException( + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'sasToken'"))); + } + Context context = Context.NONE; + return SyncPoller.createPoller(getDefaultPollingInterval(), + cxt -> new PollResponse<>(LongRunningOperationStatus.NOT_STARTED, restoreActivationOperation(folderUrl, sasToken, context).apply(cxt)), + restorePollOperation(context), + (pollingContext, firstResponse) -> { + throw logger.logExceptionAsError(new RuntimeException("Cancellation is not supported")); + }, + (pollingContext) -> new KeyVaultRestoreResult()); + } + + /** + * Initiates a full restore of the Key Vault. + * + * @param folderUrl The URL for the Blob Storage resource where the backup is located, including the path to + * the blob container where the backup resides. This would be the exact value that is returned as the result of a + * backup operation. An example of such a URL may look like the following: + * https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313. + * @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * + * @return A {@link Response} containing the {@link KeyVaultRestoreOperation backup operation} status. + * + * @throws KeyVaultAdministrationException If the given {@code folderUrl} or {@code sasToken} are invalid. + */ + Response restoreWithResponse(String folderUrl, String sasToken, Context context) { + String[] segments = folderUrl.split("/"); + String folderName = segments[segments.length - 1]; + String containerUrl = folderUrl.substring(0, folderUrl.length() - folderName.length()); + + SASTokenParameter sasTokenParameter = new SASTokenParameter() + .setStorageResourceUri(containerUrl) + .setToken(sasToken); + + RestoreOperationParameters restoreOperationParameters = new RestoreOperationParameters() + .setSasTokenParameters(sasTokenParameter) + .setFolderToRestore(folderName); + context = enableSyncRestProxy(context); + + try { + FullRestoreOperationResponse restoreOperationResponse = clientImpl.fullRestoreOperationSyncWithResponse(vaultUrl, restoreOperationParameters, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return new SimpleResponse<>(restoreOperationResponse.getRequest(), + restoreOperationResponse.getStatusCode(), + restoreOperationResponse.getHeaders(), + (KeyVaultRestoreOperation) transformToLongRunningOperation(restoreOperationResponse.getValue())); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + } + + private Function, KeyVaultRestoreOperation> restoreActivationOperation(String folderUrl, String sasToken, Context context) { + return (pollingContext) -> { + try { + return restoreWithResponse(folderUrl, sasToken, context).getValue(); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + }; + } + + private Function, PollResponse> restorePollOperation(Context context) { + return (pollingContext) -> { + try { + PollResponse pollResponse = pollingContext.getLatestResponse(); + + if (pollResponse.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED + || pollResponse.getStatus() == LongRunningOperationStatus.FAILED) { + + return pollResponse; + } + + final KeyVaultRestoreOperation keyVaultRestoreOperation = pollResponse.getValue(); + + if (keyVaultRestoreOperation == null) { + logger.warning("Restore operation does not exist. Activation operation failed."); + + return new PollResponse<>(LongRunningOperationStatus.fromString("RESTORE_START_FAILED", true), null); + } + + final String jobId = keyVaultRestoreOperation.getOperationId(); + Context contextToUse = enableSyncRestProxy(context); + + Response response = clientImpl.restoreStatusSyncWithResponse(vaultUrl, jobId, + contextToUse.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return processRestoreOperationResponse(new SimpleResponse<>(response, + (KeyVaultRestoreOperation) transformToLongRunningOperation(response.getValue()))); + + } catch (HttpResponseException e) { + //noinspection ThrowableNotThrown + logger.logExceptionAsError(e); + return new PollResponse<>(LongRunningOperationStatus.FAILED, null); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + }; + } + + private static PollResponse processRestoreOperationResponse( + Response response) { + String operationStatus = response.getValue().getStatus().toLowerCase(Locale.US); + return new PollResponse<>( + toLongRunningOperationStatus(operationStatus.toLowerCase(Locale.US)), response.getValue()); } /** @@ -197,6 +498,128 @@ public SyncPoller beginRestore( */ @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) public SyncPoller beginSelectiveKeyRestore(String keyName, String folderUrl, String sasToken) { - return asyncClient.beginSelectiveKeyRestore(keyName, folderUrl, sasToken).getSyncPoller(); + if (keyName == null) { + throw logger.logExceptionAsError(new NullPointerException( + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'keyName'"))); + } + + if (folderUrl == null) { + throw logger.logExceptionAsError(new NullPointerException( + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'folderUrl'"))); + } + + if (sasToken == null) { + throw logger.logExceptionAsError(new NullPointerException( + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'sasToken'"))); + } + + Context context = Context.NONE; + return SyncPoller.createPoller(getDefaultPollingInterval(), + cxt -> new PollResponse<>(LongRunningOperationStatus.NOT_STARTED, selectiveKeyRestoreActivationOperation(keyName, folderUrl, sasToken, context).apply(cxt)), + selectiveKeyRestorePollOperation(context), + (pollingContext, firstResponse) -> { + throw logger.logExceptionAsError(new RuntimeException("Cancellation is not supported")); + }, + (pollingContext) -> new KeyVaultSelectiveKeyRestoreResult()); + } + + /** + * Restores all versions of a given key using the supplied SAS token pointing to a previously stored Azure Blob + * storage backup folder. + * + * @param keyName The name of the key to be restored. + * @param folderUrl The URL for the Blob Storage resource where the backup is located, including the path to + * the blob container where the backup resides. This would be the exact value that is returned as the result of a + * backup operation. An example of such a URL may look like the following: + * https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313. + * @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * + * @return A {@link Response} containing the {@link KeyVaultSelectiveKeyRestoreOperation backup operation} status. + */ + Response selectiveKeyRestoreWithResponse(String keyName, + String folderUrl, + String sasToken, + Context context) { + String[] segments = folderUrl.split("/"); + String folderName = segments[segments.length - 1]; + String containerUrl = folderUrl.substring(0, folderUrl.length() - folderName.length()); + + SASTokenParameter sasTokenParameter = new SASTokenParameter() + .setStorageResourceUri(containerUrl) + .setToken(sasToken); + + SelectiveKeyRestoreOperationParameters selectiveKeyRestoreOperationParameters = + new SelectiveKeyRestoreOperationParameters() + .setSasTokenParameters(sasTokenParameter) + .setFolder(folderName); + context = enableSyncRestProxy(context); + + try { + SelectiveKeyRestoreOperationResponse restoreOperationResponse = clientImpl.selectiveKeyRestoreOperationSyncWithResponse(vaultUrl, keyName, + selectiveKeyRestoreOperationParameters, context.addData(AZ_TRACING_NAMESPACE_KEY, + KEYVAULT_TRACING_NAMESPACE_VALUE)); + return new SimpleResponse<>(restoreOperationResponse.getRequest(), + restoreOperationResponse.getStatusCode(), + restoreOperationResponse.getHeaders(), + (KeyVaultSelectiveKeyRestoreOperation) transformToLongRunningOperation( + restoreOperationResponse.getValue())); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + } + + private Function, KeyVaultSelectiveKeyRestoreOperation> selectiveKeyRestoreActivationOperation(String keyName, String folderUrl, String sasToken, Context context) { + return (pollingContext) -> { + try { + return selectiveKeyRestoreWithResponse(keyName, folderUrl, sasToken, context).getValue(); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + }; + } + + private Function, PollResponse> selectiveKeyRestorePollOperation(Context context) { + return (pollingContext) -> { + try { + PollResponse pollResponse = pollingContext.getLatestResponse(); + + if (pollResponse.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED + || pollResponse.getStatus() == LongRunningOperationStatus.FAILED) { + return pollResponse; + } + + final KeyVaultSelectiveKeyRestoreOperation keyVaultSelectiveKeyRestoreOperation = pollResponse.getValue(); + + if (keyVaultSelectiveKeyRestoreOperation == null) { + logger.warning("Restore operation does not exist. Activation operation failed."); + + return new PollResponse<>(LongRunningOperationStatus.fromString("SELECTIVE_RESTORE_START_FAILED", true), null); + } + final String jobId = keyVaultSelectiveKeyRestoreOperation.getOperationId(); + Context contextToUse = enableSyncRestProxy(context); + Response response = clientImpl.restoreStatusSyncWithResponse(vaultUrl, jobId, + contextToUse.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)); + return processSelectiveKeyRestoreOperationResponse(new SimpleResponse<>(response, + (KeyVaultSelectiveKeyRestoreOperation) restoreOperationToSelectiveKeyRestoreOperation(response.getValue()))); + } catch (HttpResponseException e) { + //noinspection ThrowableNotThrown + logger.logExceptionAsError(e); + + return new PollResponse<>(LongRunningOperationStatus.FAILED, null); + } catch (RuntimeException e) { + throw logger.logExceptionAsError(e); + } + }; + } + + private static PollResponse processSelectiveKeyRestoreOperationResponse( + Response response) { + String operationStatus = response.getValue().getStatus().toLowerCase(Locale.US); + return new PollResponse<>( + toLongRunningOperationStatus(operationStatus.toLowerCase(Locale.US)), response.getValue()); } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupClientBuilder.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupClientBuilder.java index 734127906c5f7..83cb7cbe8889d 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupClientBuilder.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupClientBuilder.java @@ -121,8 +121,14 @@ public KeyVaultBackupClientBuilder() { * @throws IllegalStateException If both {@link #retryOptions(RetryOptions)} * and {@link #retryPolicy(RetryPolicy)} have been set. */ - public KeyVaultBackupClient buildClient() { - return new KeyVaultBackupClient(buildAsyncClient()); + public KeyVaultBackupClient buildClient() { + Configuration buildConfiguration = validateEndpointAndGetBuildConfiguration(); + serviceVersion = getServiceVersion(); + if (pipeline != null) { + return new KeyVaultBackupClient(vaultUrl, pipeline, serviceVersion); + } + HttpPipeline buildPipeline = getPipeline(buildConfiguration); + return new KeyVaultBackupClient(vaultUrl, buildPipeline, serviceVersion); } /** @@ -140,6 +146,16 @@ public KeyVaultBackupClient buildClient() { * and {@link #retryPolicy(RetryPolicy)} have been set. */ public KeyVaultBackupAsyncClient buildAsyncClient() { + Configuration buildConfiguration = validateEndpointAndGetBuildConfiguration(); + serviceVersion = getServiceVersion(); + if (pipeline != null) { + return new KeyVaultBackupAsyncClient(vaultUrl, pipeline, serviceVersion); + } + HttpPipeline buildPipeline = getPipeline(buildConfiguration); + return new KeyVaultBackupAsyncClient(vaultUrl, buildPipeline, serviceVersion); + } + + private Configuration validateEndpointAndGetBuildConfiguration() { Configuration buildConfiguration = (configuration == null) ? Configuration.getGlobalConfiguration().clone() : configuration; @@ -151,12 +167,14 @@ public KeyVaultBackupAsyncClient buildAsyncClient() { new IllegalStateException( KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED))); } + return buildConfiguration; + } - serviceVersion = serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest(); + private KeyVaultAdministrationServiceVersion getServiceVersion() { + return serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest(); + } - if (pipeline != null) { - return new KeyVaultBackupAsyncClient(vaultUrl, pipeline, serviceVersion); - } + private HttpPipeline getPipeline(Configuration buildConfiguration) { // Closest to API goes first, closest to wire goes last. final List policies = new ArrayList<>(); @@ -191,12 +209,10 @@ public KeyVaultBackupAsyncClient buildAsyncClient() { HttpPolicyProviders.addAfterRetryPolicies(policies); policies.add(new HttpLoggingPolicy(httpLogOptions)); - HttpPipeline buildPipeline = new HttpPipelineBuilder() + return new HttpPipelineBuilder() .policies(policies.toArray(new HttpPipelinePolicy[0])) .httpClient(httpClient) .build(); - - return new KeyVaultBackupAsyncClient(vaultUrl, buildPipeline, serviceVersion); } /** diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultAccessControlClientImplBuilder.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultAccessControlClientImplBuilder.java index e151be7cf782e..200d41876d606 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultAccessControlClientImplBuilder.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultAccessControlClientImplBuilder.java @@ -6,22 +6,29 @@ import com.azure.core.annotation.Generated; import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.HttpTrait; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; import com.azure.core.http.policy.AddHeadersPolicy; import com.azure.core.http.policy.CookiePolicy; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpLoggingPolicy; import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.http.policy.UserAgentPolicy; import com.azure.core.util.ClientOptions; import com.azure.core.util.Configuration; import com.azure.core.util.CoreUtils; +import com.azure.core.util.builder.ClientBuilderUtil; import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; import java.util.ArrayList; @@ -32,13 +39,17 @@ /** A builder for creating a new instance of the KeyVaultAccessControlClient type. */ @ServiceClientBuilder(serviceClients = {KeyVaultAccessControlClientImpl.class}) -public final class KeyVaultAccessControlClientImplBuilder { +public final class KeyVaultAccessControlClientImplBuilder + implements HttpTrait, + ConfigurationTrait { @Generated private static final String SDK_NAME = "name"; @Generated private static final String SDK_VERSION = "version"; @Generated private final Map properties = new HashMap<>(); + @Generated private final List pipelinePolicies; + /** Create an instance of the KeyVaultAccessControlClientImplBuilder. */ @Generated public KeyVaultAccessControlClientImplBuilder() { @@ -46,158 +57,139 @@ public KeyVaultAccessControlClientImplBuilder() { } /* - * Api Version + * The HTTP pipeline to send requests through. */ - @Generated private String apiVersion; + @Generated private HttpPipeline pipeline; - /** - * Sets Api Version. - * - * @param apiVersion the apiVersion value. - * @return the KeyVaultAccessControlClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultAccessControlClientImplBuilder apiVersion(String apiVersion) { - this.apiVersion = apiVersion; + @Override + public KeyVaultAccessControlClientImplBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; return this; } /* - * The HTTP pipeline to send requests through + * The HTTP client used to send the request. */ - @Generated private HttpPipeline pipeline; + @Generated private HttpClient httpClient; - /** - * Sets The HTTP pipeline to send requests through. - * - * @param pipeline the pipeline value. - * @return the KeyVaultAccessControlClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultAccessControlClientImplBuilder pipeline(HttpPipeline pipeline) { - this.pipeline = pipeline; + @Override + public KeyVaultAccessControlClientImplBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; return this; } /* - * The serializer to serialize an object into a string + * The logging configuration for HTTP requests and responses. */ - @Generated private SerializerAdapter serializerAdapter; + @Generated private HttpLogOptions httpLogOptions; - /** - * Sets The serializer to serialize an object into a string. - * - * @param serializerAdapter the serializerAdapter value. - * @return the KeyVaultAccessControlClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultAccessControlClientImplBuilder serializerAdapter(SerializerAdapter serializerAdapter) { - this.serializerAdapter = serializerAdapter; + @Override + public KeyVaultAccessControlClientImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; return this; } /* - * The HTTP client used to send the request. + * The client options such as application ID and custom headers to set on a request. */ - @Generated private HttpClient httpClient; + @Generated private ClientOptions clientOptions; - /** - * Sets The HTTP client used to send the request. - * - * @param httpClient the httpClient value. - * @return the KeyVaultAccessControlClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultAccessControlClientImplBuilder httpClient(HttpClient httpClient) { - this.httpClient = httpClient; + @Override + public KeyVaultAccessControlClientImplBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; return this; } /* - * The configuration store that is used during construction of the service - * client. + * The retry options to configure retry policy for failed requests. */ - @Generated private Configuration configuration; + @Generated private RetryOptions retryOptions; - /** - * Sets The configuration store that is used during construction of the service client. - * - * @param configuration the configuration value. - * @return the KeyVaultAccessControlClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultAccessControlClientImplBuilder configuration(Configuration configuration) { - this.configuration = configuration; + @Override + public KeyVaultAccessControlClientImplBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** {@inheritDoc}. */ + @Generated + @Override + public KeyVaultAccessControlClientImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { + pipelinePolicies.add(customPolicy); return this; } /* - * The logging configuration for HTTP requests and responses. + * The configuration store that is used during construction of the service client. */ - @Generated private HttpLogOptions httpLogOptions; + @Generated private Configuration configuration; - /** - * Sets The logging configuration for HTTP requests and responses. - * - * @param httpLogOptions the httpLogOptions value. - * @return the KeyVaultAccessControlClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultAccessControlClientImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) { - this.httpLogOptions = httpLogOptions; + @Override + public KeyVaultAccessControlClientImplBuilder configuration(Configuration configuration) { + this.configuration = configuration; return this; } /* - * The retry policy that will attempt to retry failed requests, if - * applicable. + * Api Version */ - @Generated private RetryPolicy retryPolicy; + @Generated private String apiVersion; /** - * Sets The retry policy that will attempt to retry failed requests, if applicable. + * Sets Api Version. * - * @param retryPolicy the retryPolicy value. + * @param apiVersion the apiVersion value. * @return the KeyVaultAccessControlClientImplBuilder. */ @Generated - public KeyVaultAccessControlClientImplBuilder retryPolicy(RetryPolicy retryPolicy) { - this.retryPolicy = retryPolicy; + public KeyVaultAccessControlClientImplBuilder apiVersion(String apiVersion) { + this.apiVersion = apiVersion; return this; } /* - * The list of Http pipeline policies to add. - */ - @Generated private final List pipelinePolicies; - - /* - * The client options such as application ID and custom headers to set on a - * request. + * The serializer to serialize an object into a string */ - @Generated private ClientOptions clientOptions; + @Generated private SerializerAdapter serializerAdapter; /** - * Sets The client options such as application ID and custom headers to set on a request. + * Sets The serializer to serialize an object into a string. * - * @param clientOptions the clientOptions value. + * @param serializerAdapter the serializerAdapter value. * @return the KeyVaultAccessControlClientImplBuilder. */ @Generated - public KeyVaultAccessControlClientImplBuilder clientOptions(ClientOptions clientOptions) { - this.clientOptions = clientOptions; + public KeyVaultAccessControlClientImplBuilder serializerAdapter(SerializerAdapter serializerAdapter) { + this.serializerAdapter = serializerAdapter; return this; } + /* + * The retry policy that will attempt to retry failed requests, if applicable. + */ + @Generated private RetryPolicy retryPolicy; + /** - * Adds a custom Http pipeline policy. + * Sets The retry policy that will attempt to retry failed requests, if applicable. * - * @param customPolicy The custom Http pipeline policy to add. + * @param retryPolicy the retryPolicy value. * @return the KeyVaultAccessControlClientImplBuilder. */ @Generated - public KeyVaultAccessControlClientImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { - pipelinePolicies.add(customPolicy); + public KeyVaultAccessControlClientImplBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; return this; } @@ -208,17 +200,12 @@ public KeyVaultAccessControlClientImplBuilder addPolicy(HttpPipelinePolicy custo */ @Generated public KeyVaultAccessControlClientImpl buildClient() { - if (apiVersion == null) { - this.apiVersion = "7.3"; - } - if (pipeline == null) { - this.pipeline = createHttpPipeline(); - } - if (serializerAdapter == null) { - this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter(); - } + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + String localApiVersion = (apiVersion != null) ? apiVersion : "7.3"; + SerializerAdapter localSerializerAdapter = + (serializerAdapter != null) ? serializerAdapter : JacksonAdapter.createDefaultSerializerAdapter(); KeyVaultAccessControlClientImpl client = - new KeyVaultAccessControlClientImpl(pipeline, serializerAdapter, apiVersion); + new KeyVaultAccessControlClientImpl(localPipeline, localSerializerAdapter, localApiVersion); return client; } @@ -237,6 +224,8 @@ private HttpPipeline createHttpPipeline() { String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion"); String applicationId = CoreUtils.getApplicationId(clientOptions, httpLogOptions); policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); HttpHeaders headers = new HttpHeaders(); clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue())); if (headers.getSize() > 0) { @@ -247,7 +236,8 @@ private HttpPipeline createHttpPipeline() { .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) .collect(Collectors.toList())); HttpPolicyProviders.addBeforeRetryPolicies(policies); - policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); policies.add(new CookiePolicy()); policies.addAll( this.pipelinePolicies.stream() diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultBackupClientImpl.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultBackupClientImpl.java index 1f2e95893fa8a..b40567396f826 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultBackupClientImpl.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultBackupClientImpl.java @@ -26,6 +26,7 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; import com.azure.security.keyvault.administration.implementation.models.FullBackupOperation; @@ -35,6 +36,7 @@ import com.azure.security.keyvault.administration.implementation.models.RestoreOperation; import com.azure.security.keyvault.administration.implementation.models.RestoreOperationParameters; import com.azure.security.keyvault.administration.implementation.models.SASTokenParameter; +import com.azure.security.keyvault.administration.implementation.models.SelectiveKeyRestoreOperation; import com.azure.security.keyvault.administration.implementation.models.SelectiveKeyRestoreOperationParameters; import com.azure.security.keyvault.administration.implementation.models.SelectiveKeyRestoreOperationResponse; import reactor.core.publisher.Mono; @@ -136,6 +138,16 @@ Mono fullBackup( @HeaderParam("Accept") String accept, Context context); + @Post("/backup") + @ExpectedResponses({202}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + FullBackupResponse fullBackupSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @QueryParam("api-version") String apiVersion, + @BodyParam("application/json") SASTokenParameter azureStorageBlobContainerUri, + @HeaderParam("Accept") String accept, + Context context); + @Get("/backup/{jobId}/pending") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -146,6 +158,16 @@ Mono> fullBackupStatus( @HeaderParam("Accept") String accept, Context context); + @Get("/backup/{jobId}/pending") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response fullBackupStatusSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam("jobId") String jobId, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, + Context context); + @Put("/restore") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -156,6 +178,16 @@ Mono fullRestoreOperation( @HeaderParam("Accept") String accept, Context context); + @Put("/restore") + @ExpectedResponses({202}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + FullRestoreOperationResponse fullRestoreOperationSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @QueryParam("api-version") String apiVersion, + @BodyParam("application/json") RestoreOperationParameters restoreBlobDetails, + @HeaderParam("Accept") String accept, + Context context); + @Get("/restore/{jobId}/pending") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -166,6 +198,16 @@ Mono> restoreStatus( @HeaderParam("Accept") String accept, Context context); + @Get("/restore/{jobId}/pending") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response restoreStatusSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam("jobId") String jobId, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, + Context context); + @Put("/keys/{keyName}/restore") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -176,6 +218,40 @@ Mono selectiveKeyRestoreOperation( @BodyParam("application/json") SelectiveKeyRestoreOperationParameters restoreBlobDetails, @HeaderParam("Accept") String accept, Context context); + + @Put("/keys/{keyName}/restore") + @ExpectedResponses({202}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + SelectiveKeyRestoreOperationResponse selectiveKeyRestoreOperationSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam("keyName") String keyName, + @QueryParam("api-version") String apiVersion, + @BodyParam("application/json") SelectiveKeyRestoreOperationParameters restoreBlobDetails, + @HeaderParam("Accept") String accept, + Context context); + } + + /** + * Creates a full backup using a user-provided SAS token to an Azure blob storage container. This operation is + * supported only by the Managed HSM service. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param azureStorageBlobContainerUri Azure blob shared access signature token pointing to a valid Azure blob + * container where full backup needs to be stored. This token needs to be valid for at least next 24 hours from + * the time of making this call. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono fullBackupWithResponseAsync( + String vaultBaseUrl, SASTokenParameter azureStorageBlobContainerUri) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.fullBackup( + vaultBaseUrl, this.getApiVersion(), azureStorageBlobContainerUri, accept, context)); } /** @@ -199,6 +275,145 @@ public Mono fullBackupWithResponseAsync( return service.fullBackup(vaultBaseUrl, this.getApiVersion(), azureStorageBlobContainerUri, accept, context); } + /** + * Creates a full backup using a user-provided SAS token to an Azure blob storage container. This operation is + * supported only by the Managed HSM service. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param azureStorageBlobContainerUri Azure blob shared access signature token pointing to a valid Azure blob + * container where full backup needs to be stored. This token needs to be valid for at least next 24 hours from + * the time of making this call. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono fullBackupAsync( + String vaultBaseUrl, SASTokenParameter azureStorageBlobContainerUri) { + return fullBackupWithResponseAsync(vaultBaseUrl, azureStorageBlobContainerUri) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Creates a full backup using a user-provided SAS token to an Azure blob storage container. This operation is + * supported only by the Managed HSM service. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param azureStorageBlobContainerUri Azure blob shared access signature token pointing to a valid Azure blob + * container where full backup needs to be stored. This token needs to be valid for at least next 24 hours from + * the time of making this call. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono fullBackupAsync( + String vaultBaseUrl, SASTokenParameter azureStorageBlobContainerUri, Context context) { + return fullBackupWithResponseAsync(vaultBaseUrl, azureStorageBlobContainerUri, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Creates a full backup using a user-provided SAS token to an Azure blob storage container. This operation is + * supported only by the Managed HSM service. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param azureStorageBlobContainerUri Azure blob shared access signature token pointing to a valid Azure blob + * container where full backup needs to be stored. This token needs to be valid for at least next 24 hours from + * the time of making this call. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public FullBackupResponse fullBackupSyncWithResponse( + String vaultBaseUrl, SASTokenParameter azureStorageBlobContainerUri) { + final String accept = "application/json"; + return service.fullBackupSync( + vaultBaseUrl, this.getApiVersion(), azureStorageBlobContainerUri, accept, Context.NONE); + } + + /** + * Creates a full backup using a user-provided SAS token to an Azure blob storage container. This operation is + * supported only by the Managed HSM service. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param azureStorageBlobContainerUri Azure blob shared access signature token pointing to a valid Azure blob + * container where full backup needs to be stored. This token needs to be valid for at least next 24 hours from + * the time of making this call. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public FullBackupResponse fullBackupSyncWithResponse( + String vaultBaseUrl, SASTokenParameter azureStorageBlobContainerUri, Context context) { + final String accept = "application/json"; + return service.fullBackupSync( + vaultBaseUrl, this.getApiVersion(), azureStorageBlobContainerUri, accept, context); + } + + /** + * Creates a full backup using a user-provided SAS token to an Azure blob storage container. This operation is + * supported only by the Managed HSM service. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param azureStorageBlobContainerUri Azure blob shared access signature token pointing to a valid Azure blob + * container where full backup needs to be stored. This token needs to be valid for at least next 24 hours from + * the time of making this call. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public FullBackupOperation fullBackupSync(String vaultBaseUrl, SASTokenParameter azureStorageBlobContainerUri) { + return fullBackupSyncWithResponse(vaultBaseUrl, azureStorageBlobContainerUri, Context.NONE).getValue(); + } + + /** + * Creates a full backup using a user-provided SAS token to an Azure blob storage container. This operation is + * supported only by the Managed HSM service. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param azureStorageBlobContainerUri Azure blob shared access signature token pointing to a valid Azure blob + * container where full backup needs to be stored. This token needs to be valid for at least next 24 hours from + * the time of making this call. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public FullBackupOperation fullBackupSync( + String vaultBaseUrl, SASTokenParameter azureStorageBlobContainerUri, Context context) { + return fullBackupSyncWithResponse(vaultBaseUrl, azureStorageBlobContainerUri, context).getValue(); + } + + /** + * Returns the status of full backup operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The id returned as part of the backup request. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> fullBackupStatusWithResponseAsync(String vaultBaseUrl, String jobId) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.fullBackupStatus(vaultBaseUrl, jobId, this.getApiVersion(), accept, context)); + } + /** * Returns the status of full backup operation. * @@ -218,64 +433,564 @@ public Mono> fullBackupStatusWithResponseAsync( } /** - * Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage backup folder. + * Returns the status of full backup operation. * * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. - * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup - * was stored. + * @param jobId The id returned as part of the backup request. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono fullBackupStatusAsync(String vaultBaseUrl, String jobId) { + return fullBackupStatusWithResponseAsync(vaultBaseUrl, jobId).flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Returns the status of full backup operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The id returned as part of the backup request. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws KeyVaultErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return restore operation on successful completion of {@link Mono}. + * @return full backup operation on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono fullRestoreOperationWithResponseAsync( - String vaultBaseUrl, RestoreOperationParameters restoreBlobDetails, Context context) { + public Mono fullBackupStatusAsync(String vaultBaseUrl, String jobId, Context context) { + return fullBackupStatusWithResponseAsync(vaultBaseUrl, jobId, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Returns the status of full backup operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The id returned as part of the backup request. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response fullBackupStatusSyncWithResponse(String vaultBaseUrl, String jobId) { final String accept = "application/json"; - return service.fullRestoreOperation(vaultBaseUrl, this.getApiVersion(), restoreBlobDetails, accept, context); + return service.fullBackupStatusSync(vaultBaseUrl, jobId, this.getApiVersion(), accept, Context.NONE); } /** - * Returns the status of restore operation. + * Returns the status of full backup operation. * * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. - * @param jobId The Job Id returned part of the restore operation. + * @param jobId The id returned as part of the backup request. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws KeyVaultErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return restore operation along with {@link Response} on successful completion of {@link Mono}. + * @return full backup operation along with {@link Response}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> restoreStatusWithResponseAsync( + public Response fullBackupStatusSyncWithResponse( String vaultBaseUrl, String jobId, Context context) { final String accept = "application/json"; - return service.restoreStatus(vaultBaseUrl, jobId, this.getApiVersion(), accept, context); + return service.fullBackupStatusSync(vaultBaseUrl, jobId, this.getApiVersion(), accept, context); } /** - * Restores all key versions of a given key using user supplied SAS token pointing to a previously stored Azure Blob - * storage backup folder. + * Returns the status of full backup operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The id returned as part of the backup request. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public FullBackupOperation fullBackupStatusSync(String vaultBaseUrl, String jobId) { + return fullBackupStatusSyncWithResponse(vaultBaseUrl, jobId, Context.NONE).getValue(); + } + + /** + * Returns the status of full backup operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The id returned as part of the backup request. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return full backup operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public FullBackupOperation fullBackupStatusSync(String vaultBaseUrl, String jobId, Context context) { + return fullBackupStatusSyncWithResponse(vaultBaseUrl, jobId, context).getValue(); + } + + /** + * Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage backup folder. * * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. - * @param keyName The name of the key to be restored from the user supplied backup. * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup * was stored. - * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws KeyVaultErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return selective Key Restore operation on successful completion of {@link Mono}. + * @return restore operation on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono selectiveKeyRestoreOperationWithResponseAsync( - String vaultBaseUrl, - String keyName, - SelectiveKeyRestoreOperationParameters restoreBlobDetails, + public Mono fullRestoreOperationWithResponseAsync( + String vaultBaseUrl, RestoreOperationParameters restoreBlobDetails) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.fullRestoreOperation( + vaultBaseUrl, this.getApiVersion(), restoreBlobDetails, accept, context)); + } + + /** + * Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono fullRestoreOperationWithResponseAsync( + String vaultBaseUrl, RestoreOperationParameters restoreBlobDetails, Context context) { + final String accept = "application/json"; + return service.fullRestoreOperation(vaultBaseUrl, this.getApiVersion(), restoreBlobDetails, accept, context); + } + + /** + * Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono fullRestoreOperationAsync( + String vaultBaseUrl, RestoreOperationParameters restoreBlobDetails) { + return fullRestoreOperationWithResponseAsync(vaultBaseUrl, restoreBlobDetails) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono fullRestoreOperationAsync( + String vaultBaseUrl, RestoreOperationParameters restoreBlobDetails, Context context) { + return fullRestoreOperationWithResponseAsync(vaultBaseUrl, restoreBlobDetails, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public FullRestoreOperationResponse fullRestoreOperationSyncWithResponse( + String vaultBaseUrl, RestoreOperationParameters restoreBlobDetails) { + final String accept = "application/json"; + return service.fullRestoreOperationSync( + vaultBaseUrl, this.getApiVersion(), restoreBlobDetails, accept, Context.NONE); + } + + /** + * Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public FullRestoreOperationResponse fullRestoreOperationSyncWithResponse( + String vaultBaseUrl, RestoreOperationParameters restoreBlobDetails, Context context) { + final String accept = "application/json"; + return service.fullRestoreOperationSync( + vaultBaseUrl, this.getApiVersion(), restoreBlobDetails, accept, context); + } + + /** + * Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RestoreOperation fullRestoreOperationSync( + String vaultBaseUrl, RestoreOperationParameters restoreBlobDetails) { + return fullRestoreOperationSyncWithResponse(vaultBaseUrl, restoreBlobDetails, Context.NONE).getValue(); + } + + /** + * Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RestoreOperation fullRestoreOperationSync( + String vaultBaseUrl, RestoreOperationParameters restoreBlobDetails, Context context) { + return fullRestoreOperationSyncWithResponse(vaultBaseUrl, restoreBlobDetails, context).getValue(); + } + + /** + * Returns the status of restore operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The Job Id returned part of the restore operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> restoreStatusWithResponseAsync(String vaultBaseUrl, String jobId) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.restoreStatus(vaultBaseUrl, jobId, this.getApiVersion(), accept, context)); + } + + /** + * Returns the status of restore operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The Job Id returned part of the restore operation. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> restoreStatusWithResponseAsync( + String vaultBaseUrl, String jobId, Context context) { + final String accept = "application/json"; + return service.restoreStatus(vaultBaseUrl, jobId, this.getApiVersion(), accept, context); + } + + /** + * Returns the status of restore operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The Job Id returned part of the restore operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono restoreStatusAsync(String vaultBaseUrl, String jobId) { + return restoreStatusWithResponseAsync(vaultBaseUrl, jobId).flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Returns the status of restore operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The Job Id returned part of the restore operation. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono restoreStatusAsync(String vaultBaseUrl, String jobId, Context context) { + return restoreStatusWithResponseAsync(vaultBaseUrl, jobId, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Returns the status of restore operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The Job Id returned part of the restore operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response restoreStatusSyncWithResponse(String vaultBaseUrl, String jobId) { + final String accept = "application/json"; + return service.restoreStatusSync(vaultBaseUrl, jobId, this.getApiVersion(), accept, Context.NONE); + } + + /** + * Returns the status of restore operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The Job Id returned part of the restore operation. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response restoreStatusSyncWithResponse( + String vaultBaseUrl, String jobId, Context context) { + final String accept = "application/json"; + return service.restoreStatusSync(vaultBaseUrl, jobId, this.getApiVersion(), accept, context); + } + + /** + * Returns the status of restore operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The Job Id returned part of the restore operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RestoreOperation restoreStatusSync(String vaultBaseUrl, String jobId) { + return restoreStatusSyncWithResponse(vaultBaseUrl, jobId, Context.NONE).getValue(); + } + + /** + * Returns the status of restore operation. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param jobId The Job Id returned part of the restore operation. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RestoreOperation restoreStatusSync(String vaultBaseUrl, String jobId, Context context) { + return restoreStatusSyncWithResponse(vaultBaseUrl, jobId, context).getValue(); + } + + /** + * Restores all key versions of a given key using user supplied SAS token pointing to a previously stored Azure Blob + * storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param keyName The name of the key to be restored from the user supplied backup. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return selective Key Restore operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono selectiveKeyRestoreOperationWithResponseAsync( + String vaultBaseUrl, String keyName, SelectiveKeyRestoreOperationParameters restoreBlobDetails) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.selectiveKeyRestoreOperation( + vaultBaseUrl, keyName, this.getApiVersion(), restoreBlobDetails, accept, context)); + } + + /** + * Restores all key versions of a given key using user supplied SAS token pointing to a previously stored Azure Blob + * storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param keyName The name of the key to be restored from the user supplied backup. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return selective Key Restore operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono selectiveKeyRestoreOperationWithResponseAsync( + String vaultBaseUrl, + String keyName, + SelectiveKeyRestoreOperationParameters restoreBlobDetails, Context context) { final String accept = "application/json"; return service.selectiveKeyRestoreOperation( vaultBaseUrl, keyName, this.getApiVersion(), restoreBlobDetails, accept, context); } + + /** + * Restores all key versions of a given key using user supplied SAS token pointing to a previously stored Azure Blob + * storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param keyName The name of the key to be restored from the user supplied backup. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return selective Key Restore operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono selectiveKeyRestoreOperationAsync( + String vaultBaseUrl, String keyName, SelectiveKeyRestoreOperationParameters restoreBlobDetails) { + return selectiveKeyRestoreOperationWithResponseAsync(vaultBaseUrl, keyName, restoreBlobDetails) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Restores all key versions of a given key using user supplied SAS token pointing to a previously stored Azure Blob + * storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param keyName The name of the key to be restored from the user supplied backup. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return selective Key Restore operation on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono selectiveKeyRestoreOperationAsync( + String vaultBaseUrl, + String keyName, + SelectiveKeyRestoreOperationParameters restoreBlobDetails, + Context context) { + return selectiveKeyRestoreOperationWithResponseAsync(vaultBaseUrl, keyName, restoreBlobDetails, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Restores all key versions of a given key using user supplied SAS token pointing to a previously stored Azure Blob + * storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param keyName The name of the key to be restored from the user supplied backup. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return selective Key Restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SelectiveKeyRestoreOperationResponse selectiveKeyRestoreOperationSyncWithResponse( + String vaultBaseUrl, String keyName, SelectiveKeyRestoreOperationParameters restoreBlobDetails) { + final String accept = "application/json"; + return service.selectiveKeyRestoreOperationSync( + vaultBaseUrl, keyName, this.getApiVersion(), restoreBlobDetails, accept, Context.NONE); + } + + /** + * Restores all key versions of a given key using user supplied SAS token pointing to a previously stored Azure Blob + * storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param keyName The name of the key to be restored from the user supplied backup. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return selective Key Restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SelectiveKeyRestoreOperationResponse selectiveKeyRestoreOperationSyncWithResponse( + String vaultBaseUrl, + String keyName, + SelectiveKeyRestoreOperationParameters restoreBlobDetails, + Context context) { + final String accept = "application/json"; + return service.selectiveKeyRestoreOperationSync( + vaultBaseUrl, keyName, this.getApiVersion(), restoreBlobDetails, accept, context); + } + + /** + * Restores all key versions of a given key using user supplied SAS token pointing to a previously stored Azure Blob + * storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param keyName The name of the key to be restored from the user supplied backup. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return selective Key Restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SelectiveKeyRestoreOperation selectiveKeyRestoreOperationSync( + String vaultBaseUrl, String keyName, SelectiveKeyRestoreOperationParameters restoreBlobDetails) { + return selectiveKeyRestoreOperationSyncWithResponse(vaultBaseUrl, keyName, restoreBlobDetails, Context.NONE) + .getValue(); + } + + /** + * Restores all key versions of a given key using user supplied SAS token pointing to a previously stored Azure Blob + * storage backup folder. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param keyName The name of the key to be restored from the user supplied backup. + * @param restoreBlobDetails The Azure blob SAS token pointing to a folder where the previous successful full backup + * was stored. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return selective Key Restore operation. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SelectiveKeyRestoreOperation selectiveKeyRestoreOperationSync( + String vaultBaseUrl, + String keyName, + SelectiveKeyRestoreOperationParameters restoreBlobDetails, + Context context) { + return selectiveKeyRestoreOperationSyncWithResponse(vaultBaseUrl, keyName, restoreBlobDetails, context) + .getValue(); + } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultBackupClientImplBuilder.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultBackupClientImplBuilder.java index c88b894f7f96d..74e0d4e25f739 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultBackupClientImplBuilder.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultBackupClientImplBuilder.java @@ -6,22 +6,29 @@ import com.azure.core.annotation.Generated; import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.HttpTrait; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; import com.azure.core.http.policy.AddHeadersPolicy; import com.azure.core.http.policy.CookiePolicy; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpLoggingPolicy; import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.http.policy.UserAgentPolicy; import com.azure.core.util.ClientOptions; import com.azure.core.util.Configuration; import com.azure.core.util.CoreUtils; +import com.azure.core.util.builder.ClientBuilderUtil; import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; import java.util.ArrayList; @@ -32,13 +39,16 @@ /** A builder for creating a new instance of the KeyVaultBackupClient type. */ @ServiceClientBuilder(serviceClients = {KeyVaultBackupClientImpl.class}) -public final class KeyVaultBackupClientImplBuilder { +public final class KeyVaultBackupClientImplBuilder + implements HttpTrait, ConfigurationTrait { @Generated private static final String SDK_NAME = "name"; @Generated private static final String SDK_VERSION = "version"; @Generated private final Map properties = new HashMap<>(); + @Generated private final List pipelinePolicies; + /** Create an instance of the KeyVaultBackupClientImplBuilder. */ @Generated public KeyVaultBackupClientImplBuilder() { @@ -46,158 +56,139 @@ public KeyVaultBackupClientImplBuilder() { } /* - * Api Version + * The HTTP pipeline to send requests through. */ - @Generated private String apiVersion; + @Generated private HttpPipeline pipeline; - /** - * Sets Api Version. - * - * @param apiVersion the apiVersion value. - * @return the KeyVaultBackupClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultBackupClientImplBuilder apiVersion(String apiVersion) { - this.apiVersion = apiVersion; + @Override + public KeyVaultBackupClientImplBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; return this; } /* - * The HTTP pipeline to send requests through + * The HTTP client used to send the request. */ - @Generated private HttpPipeline pipeline; + @Generated private HttpClient httpClient; - /** - * Sets The HTTP pipeline to send requests through. - * - * @param pipeline the pipeline value. - * @return the KeyVaultBackupClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultBackupClientImplBuilder pipeline(HttpPipeline pipeline) { - this.pipeline = pipeline; + @Override + public KeyVaultBackupClientImplBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; return this; } /* - * The serializer to serialize an object into a string + * The logging configuration for HTTP requests and responses. */ - @Generated private SerializerAdapter serializerAdapter; + @Generated private HttpLogOptions httpLogOptions; - /** - * Sets The serializer to serialize an object into a string. - * - * @param serializerAdapter the serializerAdapter value. - * @return the KeyVaultBackupClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultBackupClientImplBuilder serializerAdapter(SerializerAdapter serializerAdapter) { - this.serializerAdapter = serializerAdapter; + @Override + public KeyVaultBackupClientImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; return this; } /* - * The HTTP client used to send the request. + * The client options such as application ID and custom headers to set on a request. */ - @Generated private HttpClient httpClient; + @Generated private ClientOptions clientOptions; - /** - * Sets The HTTP client used to send the request. - * - * @param httpClient the httpClient value. - * @return the KeyVaultBackupClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultBackupClientImplBuilder httpClient(HttpClient httpClient) { - this.httpClient = httpClient; + @Override + public KeyVaultBackupClientImplBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; return this; } /* - * The configuration store that is used during construction of the service - * client. + * The retry options to configure retry policy for failed requests. */ - @Generated private Configuration configuration; + @Generated private RetryOptions retryOptions; - /** - * Sets The configuration store that is used during construction of the service client. - * - * @param configuration the configuration value. - * @return the KeyVaultBackupClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultBackupClientImplBuilder configuration(Configuration configuration) { - this.configuration = configuration; + @Override + public KeyVaultBackupClientImplBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** {@inheritDoc}. */ + @Generated + @Override + public KeyVaultBackupClientImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { + pipelinePolicies.add(customPolicy); return this; } /* - * The logging configuration for HTTP requests and responses. + * The configuration store that is used during construction of the service client. */ - @Generated private HttpLogOptions httpLogOptions; + @Generated private Configuration configuration; - /** - * Sets The logging configuration for HTTP requests and responses. - * - * @param httpLogOptions the httpLogOptions value. - * @return the KeyVaultBackupClientImplBuilder. - */ + /** {@inheritDoc}. */ @Generated - public KeyVaultBackupClientImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) { - this.httpLogOptions = httpLogOptions; + @Override + public KeyVaultBackupClientImplBuilder configuration(Configuration configuration) { + this.configuration = configuration; return this; } /* - * The retry policy that will attempt to retry failed requests, if - * applicable. + * Api Version */ - @Generated private RetryPolicy retryPolicy; + @Generated private String apiVersion; /** - * Sets The retry policy that will attempt to retry failed requests, if applicable. + * Sets Api Version. * - * @param retryPolicy the retryPolicy value. + * @param apiVersion the apiVersion value. * @return the KeyVaultBackupClientImplBuilder. */ @Generated - public KeyVaultBackupClientImplBuilder retryPolicy(RetryPolicy retryPolicy) { - this.retryPolicy = retryPolicy; + public KeyVaultBackupClientImplBuilder apiVersion(String apiVersion) { + this.apiVersion = apiVersion; return this; } /* - * The list of Http pipeline policies to add. - */ - @Generated private final List pipelinePolicies; - - /* - * The client options such as application ID and custom headers to set on a - * request. + * The serializer to serialize an object into a string */ - @Generated private ClientOptions clientOptions; + @Generated private SerializerAdapter serializerAdapter; /** - * Sets The client options such as application ID and custom headers to set on a request. + * Sets The serializer to serialize an object into a string. * - * @param clientOptions the clientOptions value. + * @param serializerAdapter the serializerAdapter value. * @return the KeyVaultBackupClientImplBuilder. */ @Generated - public KeyVaultBackupClientImplBuilder clientOptions(ClientOptions clientOptions) { - this.clientOptions = clientOptions; + public KeyVaultBackupClientImplBuilder serializerAdapter(SerializerAdapter serializerAdapter) { + this.serializerAdapter = serializerAdapter; return this; } + /* + * The retry policy that will attempt to retry failed requests, if applicable. + */ + @Generated private RetryPolicy retryPolicy; + /** - * Adds a custom Http pipeline policy. + * Sets The retry policy that will attempt to retry failed requests, if applicable. * - * @param customPolicy The custom Http pipeline policy to add. + * @param retryPolicy the retryPolicy value. * @return the KeyVaultBackupClientImplBuilder. */ @Generated - public KeyVaultBackupClientImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { - pipelinePolicies.add(customPolicy); + public KeyVaultBackupClientImplBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; return this; } @@ -208,16 +199,12 @@ public KeyVaultBackupClientImplBuilder addPolicy(HttpPipelinePolicy customPolicy */ @Generated public KeyVaultBackupClientImpl buildClient() { - if (apiVersion == null) { - this.apiVersion = "7.3"; - } - if (pipeline == null) { - this.pipeline = createHttpPipeline(); - } - if (serializerAdapter == null) { - this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter(); - } - KeyVaultBackupClientImpl client = new KeyVaultBackupClientImpl(pipeline, serializerAdapter, apiVersion); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + String localApiVersion = (apiVersion != null) ? apiVersion : "7.3"; + SerializerAdapter localSerializerAdapter = + (serializerAdapter != null) ? serializerAdapter : JacksonAdapter.createDefaultSerializerAdapter(); + KeyVaultBackupClientImpl client = + new KeyVaultBackupClientImpl(localPipeline, localSerializerAdapter, localApiVersion); return client; } @@ -236,6 +223,8 @@ private HttpPipeline createHttpPipeline() { String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion"); String applicationId = CoreUtils.getApplicationId(clientOptions, httpLogOptions); policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); HttpHeaders headers = new HttpHeaders(); clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue())); if (headers.getSize() > 0) { @@ -246,7 +235,8 @@ private HttpPipeline createHttpPipeline() { .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) .collect(Collectors.toList())); HttpPolicyProviders.addBeforeRetryPolicies(policies); - policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); policies.add(new CookiePolicy()); policies.addAll( this.pipelinePolicies.stream() diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/RoleAssignmentsImpl.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/RoleAssignmentsImpl.java index a22710657e41d..6df6a514179be 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/RoleAssignmentsImpl.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/RoleAssignmentsImpl.java @@ -18,11 +18,14 @@ import com.azure.core.annotation.ServiceInterface; import com.azure.core.annotation.ServiceMethod; import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.PagedResponse; import com.azure.core.http.rest.PagedResponseBase; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; import com.azure.security.keyvault.administration.implementation.models.KeyVaultErrorException; import com.azure.security.keyvault.administration.implementation.models.RoleAssignment; import com.azure.security.keyvault.administration.implementation.models.RoleAssignmentCreateParameters; @@ -66,6 +69,17 @@ Mono> delete( @HeaderParam("Accept") String accept, Context context); + @Delete("/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response deleteSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam(value = "scope", encoded = true) String scope, + @PathParam("roleAssignmentName") String roleAssignmentName, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, + Context context); + @Put("/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -78,6 +92,18 @@ Mono> create( @HeaderParam("Accept") String accept, Context context); + @Put("/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}") + @ExpectedResponses({201}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response createSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam(value = "scope", encoded = true) String scope, + @PathParam("roleAssignmentName") String roleAssignmentName, + @QueryParam("api-version") String apiVersion, + @BodyParam("application/json") RoleAssignmentCreateParameters parameters, + @HeaderParam("Accept") String accept, + Context context); + @Get("/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -89,6 +115,17 @@ Mono> get( @HeaderParam("Accept") String accept, Context context); + @Get("/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response getSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam(value = "scope", encoded = true) String scope, + @PathParam("roleAssignmentName") String roleAssignmentName, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, + Context context); + @Get("/{scope}/providers/Microsoft.Authorization/roleAssignments") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -100,6 +137,17 @@ Mono> listForScope( @HeaderParam("Accept") String accept, Context context); + @Get("/{scope}/providers/Microsoft.Authorization/roleAssignments") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response listForScopeSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam(value = "scope", encoded = true) String scope, + @QueryParam("$filter") String filter, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, + Context context); + @Get("{nextLink}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -108,6 +156,36 @@ Mono> listForScopeNext( @HostParam("vaultBaseUrl") String vaultBaseUrl, @HeaderParam("Accept") String accept, Context context); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response listForScopeNextSync( + @PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @HeaderParam("Accept") String accept, + Context context); + } + + /** + * Deletes a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to delete. + * @param roleAssignmentName The name of the role assignment to delete. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteWithResponseAsync( + String vaultBaseUrl, String scope, String roleAssignmentName) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.delete( + vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), accept, context)); } /** @@ -129,6 +207,142 @@ public Mono> deleteWithResponseAsync( return service.delete(vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), accept, context); } + /** + * Deletes a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to delete. + * @param roleAssignmentName The name of the role assignment to delete. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteAsync(String vaultBaseUrl, String scope, String roleAssignmentName) { + return deleteWithResponseAsync(vaultBaseUrl, scope, roleAssignmentName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Deletes a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to delete. + * @param roleAssignmentName The name of the role assignment to delete. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteAsync( + String vaultBaseUrl, String scope, String roleAssignmentName, Context context) { + return deleteWithResponseAsync(vaultBaseUrl, scope, roleAssignmentName, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Deletes a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to delete. + * @param roleAssignmentName The name of the role assignment to delete. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteSyncWithResponse( + String vaultBaseUrl, String scope, String roleAssignmentName) { + final String accept = "application/json"; + return service.deleteSync( + vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), accept, Context.NONE); + } + + /** + * Deletes a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to delete. + * @param roleAssignmentName The name of the role assignment to delete. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteSyncWithResponse( + String vaultBaseUrl, String scope, String roleAssignmentName, Context context) { + final String accept = "application/json"; + return service.deleteSync( + vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), accept, context); + } + + /** + * Deletes a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to delete. + * @param roleAssignmentName The name of the role assignment to delete. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleAssignment deleteSync(String vaultBaseUrl, String scope, String roleAssignmentName) { + return deleteSyncWithResponse(vaultBaseUrl, scope, roleAssignmentName, Context.NONE).getValue(); + } + + /** + * Deletes a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to delete. + * @param roleAssignmentName The name of the role assignment to delete. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleAssignment deleteSync(String vaultBaseUrl, String scope, String roleAssignmentName, Context context) { + return deleteSyncWithResponse(vaultBaseUrl, scope, roleAssignmentName, context).getValue(); + } + + /** + * Creates a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to create. + * @param roleAssignmentName The name of the role assignment to create. It can be any valid GUID. + * @param parameters Parameters for the role assignment. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> createWithResponseAsync( + String vaultBaseUrl, String scope, String roleAssignmentName, RoleAssignmentCreateParameters parameters) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.create( + vaultBaseUrl, + scope, + roleAssignmentName, + this.client.getApiVersion(), + parameters, + accept, + context)); + } + /** * Creates a role assignment. * @@ -155,79 +369,587 @@ public Mono> createWithResponseAsync( } /** - * Get the specified role assignment. + * Creates a role assignment. * * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. - * @param scope The scope of the role assignment. - * @param roleAssignmentName The name of the role assignment to get. - * @param context The context to associate with this operation. + * @param scope The scope of the role assignment to create. + * @param roleAssignmentName The name of the role assignment to create. It can be any valid GUID. + * @param parameters Parameters for the role assignment. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws KeyVaultErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the specified role assignment along with {@link Response} on successful completion of {@link Mono}. + * @return role Assignments on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getWithResponseAsync( - String vaultBaseUrl, String scope, String roleAssignmentName, Context context) { - final String accept = "application/json"; - return service.get(vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), accept, context); + public Mono createAsync( + String vaultBaseUrl, String scope, String roleAssignmentName, RoleAssignmentCreateParameters parameters) { + return createWithResponseAsync(vaultBaseUrl, scope, roleAssignmentName, parameters) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); } /** - * Gets role assignments for a scope. + * Creates a role assignment. * * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. - * @param scope The scope of the role assignments. - * @param filter The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or - * above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope - * for the specified principal. + * @param scope The scope of the role assignment to create. + * @param roleAssignmentName The name of the role assignment to create. It can be any valid GUID. + * @param parameters Parameters for the role assignment. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws KeyVaultErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return role assignments for a scope along with {@link PagedResponse} on successful completion of {@link Mono}. + * @return role Assignments on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> listForScopeSinglePageAsync( - String vaultBaseUrl, String scope, String filter, Context context) { + public Mono createAsync( + String vaultBaseUrl, + String scope, + String roleAssignmentName, + RoleAssignmentCreateParameters parameters, + Context context) { + return createWithResponseAsync(vaultBaseUrl, scope, roleAssignmentName, parameters, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Creates a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to create. + * @param roleAssignmentName The name of the role assignment to create. It can be any valid GUID. + * @param parameters Parameters for the role assignment. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response createSyncWithResponse( + String vaultBaseUrl, String scope, String roleAssignmentName, RoleAssignmentCreateParameters parameters) { final String accept = "application/json"; - return service.listForScope(vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, context) - .map( - res -> - new PagedResponseBase<>( - res.getRequest(), - res.getStatusCode(), - res.getHeaders(), - res.getValue().getValue(), - res.getValue().getNextLink(), - null)); + return service.createSync( + vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), parameters, accept, Context.NONE); } /** - * Get the next page of items. + * Creates a role assignment. * - * @param nextLink The nextLink parameter. * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to create. + * @param roleAssignmentName The name of the role assignment to create. It can be any valid GUID. + * @param parameters Parameters for the role assignment. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws KeyVaultErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return role assignment list operation result along with {@link PagedResponse} on successful completion of {@link - * Mono}. + * @return role Assignments along with {@link Response}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> listForScopeNextSinglePageAsync( - String nextLink, String vaultBaseUrl, Context context) { + public Response createSyncWithResponse( + String vaultBaseUrl, + String scope, + String roleAssignmentName, + RoleAssignmentCreateParameters parameters, + Context context) { final String accept = "application/json"; - return service.listForScopeNext(nextLink, vaultBaseUrl, accept, context) - .map( - res -> - new PagedResponseBase<>( - res.getRequest(), - res.getStatusCode(), - res.getHeaders(), - res.getValue().getValue(), - res.getValue().getNextLink(), - null)); + return service.createSync( + vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), parameters, accept, context); + } + + /** + * Creates a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to create. + * @param roleAssignmentName The name of the role assignment to create. It can be any valid GUID. + * @param parameters Parameters for the role assignment. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleAssignment createSync( + String vaultBaseUrl, String scope, String roleAssignmentName, RoleAssignmentCreateParameters parameters) { + return createSyncWithResponse(vaultBaseUrl, scope, roleAssignmentName, parameters, Context.NONE).getValue(); + } + + /** + * Creates a role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment to create. + * @param roleAssignmentName The name of the role assignment to create. It can be any valid GUID. + * @param parameters Parameters for the role assignment. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role Assignments. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleAssignment createSync( + String vaultBaseUrl, + String scope, + String roleAssignmentName, + RoleAssignmentCreateParameters parameters, + Context context) { + return createSyncWithResponse(vaultBaseUrl, scope, roleAssignmentName, parameters, context).getValue(); + } + + /** + * Get the specified role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment. + * @param roleAssignmentName The name of the role assignment to get. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role assignment along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getWithResponseAsync( + String vaultBaseUrl, String scope, String roleAssignmentName) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.get( + vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), accept, context)); + } + + /** + * Get the specified role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment. + * @param roleAssignmentName The name of the role assignment to get. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role assignment along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getWithResponseAsync( + String vaultBaseUrl, String scope, String roleAssignmentName, Context context) { + final String accept = "application/json"; + return service.get(vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), accept, context); + } + + /** + * Get the specified role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment. + * @param roleAssignmentName The name of the role assignment to get. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role assignment on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getAsync(String vaultBaseUrl, String scope, String roleAssignmentName) { + return getWithResponseAsync(vaultBaseUrl, scope, roleAssignmentName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get the specified role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment. + * @param roleAssignmentName The name of the role assignment to get. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role assignment on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getAsync( + String vaultBaseUrl, String scope, String roleAssignmentName, Context context) { + return getWithResponseAsync(vaultBaseUrl, scope, roleAssignmentName, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get the specified role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment. + * @param roleAssignmentName The name of the role assignment to get. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role assignment along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSyncWithResponse(String vaultBaseUrl, String scope, String roleAssignmentName) { + final String accept = "application/json"; + return service.getSync( + vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), accept, Context.NONE); + } + + /** + * Get the specified role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment. + * @param roleAssignmentName The name of the role assignment to get. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role assignment along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSyncWithResponse( + String vaultBaseUrl, String scope, String roleAssignmentName, Context context) { + final String accept = "application/json"; + return service.getSync(vaultBaseUrl, scope, roleAssignmentName, this.client.getApiVersion(), accept, context); + } + + /** + * Get the specified role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment. + * @param roleAssignmentName The name of the role assignment to get. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role assignment. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleAssignment getSync(String vaultBaseUrl, String scope, String roleAssignmentName) { + return getSyncWithResponse(vaultBaseUrl, scope, roleAssignmentName, Context.NONE).getValue(); + } + + /** + * Get the specified role assignment. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignment. + * @param roleAssignmentName The name of the role assignment to get. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role assignment. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleAssignment getSync(String vaultBaseUrl, String scope, String roleAssignmentName, Context context) { + return getSyncWithResponse(vaultBaseUrl, scope, roleAssignmentName, context).getValue(); + } + + /** + * Gets role assignments for a scope. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignments. + * @param filter The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or + * above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope + * for the specified principal. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignments for a scope along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> listForScopeSinglePageAsync( + String vaultBaseUrl, String scope, String filter) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.listForScope( + vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, context)) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null)); + } + + /** + * Gets role assignments for a scope. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignments. + * @param filter The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or + * above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope + * for the specified principal. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignments for a scope along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> listForScopeSinglePageAsync( + String vaultBaseUrl, String scope, String filter, Context context) { + final String accept = "application/json"; + return service.listForScope(vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, context) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null)); + } + + /** + * Gets role assignments for a scope. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignments. + * @param filter The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or + * above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope + * for the specified principal. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignments for a scope as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listForScopeAsync(String vaultBaseUrl, String scope, String filter) { + return new PagedFlux<>( + () -> listForScopeSinglePageAsync(vaultBaseUrl, scope, filter), + nextLink -> listForScopeNextSinglePageAsync(nextLink, vaultBaseUrl)); + } + + /** + * Gets role assignments for a scope. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignments. + * @param filter The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or + * above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope + * for the specified principal. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignments for a scope as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listForScopeAsync( + String vaultBaseUrl, String scope, String filter, Context context) { + return new PagedFlux<>( + () -> listForScopeSinglePageAsync(vaultBaseUrl, scope, filter, context), + nextLink -> listForScopeNextSinglePageAsync(nextLink, vaultBaseUrl, context)); + } + + /** + * Gets role assignments for a scope. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignments. + * @param filter The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or + * above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope + * for the specified principal. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignments for a scope along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public PagedResponse listForScopeSyncSinglePage(String vaultBaseUrl, String scope, String filter) { + final String accept = "application/json"; + Response res = + service.listForScopeSync( + vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, Context.NONE); + return new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null); + } + + /** + * Gets role assignments for a scope. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignments. + * @param filter The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or + * above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope + * for the specified principal. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignments for a scope along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public PagedResponse listForScopeSyncSinglePage( + String vaultBaseUrl, String scope, String filter, Context context) { + final String accept = "application/json"; + Response res = + service.listForScopeSync(vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, context); + return new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null); + } + + /** + * Gets role assignments for a scope. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignments. + * @param filter The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or + * above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope + * for the specified principal. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignments for a scope as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listForScopeSync(String vaultBaseUrl, String scope, String filter) { + return new PagedIterable<>( + () -> listForScopeSyncSinglePage(vaultBaseUrl, scope, filter, Context.NONE), + nextLink -> listForScopeNextSyncSinglePage(nextLink, vaultBaseUrl)); + } + + /** + * Gets role assignments for a scope. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role assignments. + * @param filter The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or + * above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope + * for the specified principal. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignments for a scope as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listForScopeSync( + String vaultBaseUrl, String scope, String filter, Context context) { + return new PagedIterable<>( + () -> listForScopeSyncSinglePage(vaultBaseUrl, scope, filter, context), + nextLink -> listForScopeNextSyncSinglePage(nextLink, vaultBaseUrl, context)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items + *

The nextLink parameter. + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignment list operation result along with {@link PagedResponse} on successful completion of {@link + * Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> listForScopeNextSinglePageAsync(String nextLink, String vaultBaseUrl) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.listForScopeNext(nextLink, vaultBaseUrl, accept, context)) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items + *

The nextLink parameter. + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignment list operation result along with {@link PagedResponse} on successful completion of {@link + * Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> listForScopeNextSinglePageAsync( + String nextLink, String vaultBaseUrl, Context context) { + final String accept = "application/json"; + return service.listForScopeNext(nextLink, vaultBaseUrl, accept, context) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items + *

The nextLink parameter. + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignment list operation result along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public PagedResponse listForScopeNextSyncSinglePage(String nextLink, String vaultBaseUrl) { + final String accept = "application/json"; + Response res = + service.listForScopeNextSync(nextLink, vaultBaseUrl, accept, Context.NONE); + return new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items + *

The nextLink parameter. + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role assignment list operation result along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public PagedResponse listForScopeNextSyncSinglePage( + String nextLink, String vaultBaseUrl, Context context) { + final String accept = "application/json"; + Response res = service.listForScopeNextSync(nextLink, vaultBaseUrl, accept, context); + return new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null); } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/RoleDefinitionsImpl.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/RoleDefinitionsImpl.java index 5e042aed55263..90aa6ed9b0ea9 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/RoleDefinitionsImpl.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/RoleDefinitionsImpl.java @@ -18,11 +18,14 @@ import com.azure.core.annotation.ServiceInterface; import com.azure.core.annotation.ServiceMethod; import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.PagedResponse; import com.azure.core.http.rest.PagedResponseBase; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; import com.azure.security.keyvault.administration.implementation.models.KeyVaultErrorException; import com.azure.security.keyvault.administration.implementation.models.RoleDefinition; import com.azure.security.keyvault.administration.implementation.models.RoleDefinitionCreateParameters; @@ -66,6 +69,17 @@ Mono> delete( @HeaderParam("Accept") String accept, Context context); + @Delete("/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response deleteSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam(value = "scope", encoded = true) String scope, + @PathParam("roleDefinitionName") String roleDefinitionName, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, + Context context); + @Put("/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -78,6 +92,18 @@ Mono> createOrUpdate( @HeaderParam("Accept") String accept, Context context); + @Put("/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}") + @ExpectedResponses({201}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response createOrUpdateSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam(value = "scope", encoded = true) String scope, + @PathParam("roleDefinitionName") String roleDefinitionName, + @QueryParam("api-version") String apiVersion, + @BodyParam("application/json") RoleDefinitionCreateParameters parameters, + @HeaderParam("Accept") String accept, + Context context); + @Get("/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -89,6 +115,17 @@ Mono> get( @HeaderParam("Accept") String accept, Context context); + @Get("/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response getSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam(value = "scope", encoded = true) String scope, + @PathParam("roleDefinitionName") String roleDefinitionName, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, + Context context); + @Get("/{scope}/providers/Microsoft.Authorization/roleDefinitions") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -100,6 +137,17 @@ Mono> list( @HeaderParam("Accept") String accept, Context context); + @Get("/{scope}/providers/Microsoft.Authorization/roleDefinitions") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response listSync( + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @PathParam(value = "scope", encoded = true) String scope, + @QueryParam("$filter") String filter, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, + Context context); + @Get("{nextLink}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(KeyVaultErrorException.class) @@ -108,6 +156,36 @@ Mono> listNext( @HostParam("vaultBaseUrl") String vaultBaseUrl, @HeaderParam("Accept") String accept, Context context); + + @Get("{nextLink}") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(KeyVaultErrorException.class) + Response listNextSync( + @PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("vaultBaseUrl") String vaultBaseUrl, + @HeaderParam("Accept") String accept, + Context context); + } + + /** + * Deletes a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to delete. Managed HSM only supports '/'. + * @param roleDefinitionName The name (GUID) of the role definition to delete. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteWithResponseAsync( + String vaultBaseUrl, String scope, String roleDefinitionName) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.delete( + vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), accept, context)); } /** @@ -129,6 +207,142 @@ public Mono> deleteWithResponseAsync( return service.delete(vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), accept, context); } + /** + * Deletes a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to delete. Managed HSM only supports '/'. + * @param roleDefinitionName The name (GUID) of the role definition to delete. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteAsync(String vaultBaseUrl, String scope, String roleDefinitionName) { + return deleteWithResponseAsync(vaultBaseUrl, scope, roleDefinitionName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Deletes a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to delete. Managed HSM only supports '/'. + * @param roleDefinitionName The name (GUID) of the role definition to delete. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteAsync( + String vaultBaseUrl, String scope, String roleDefinitionName, Context context) { + return deleteWithResponseAsync(vaultBaseUrl, scope, roleDefinitionName, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Deletes a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to delete. Managed HSM only supports '/'. + * @param roleDefinitionName The name (GUID) of the role definition to delete. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteSyncWithResponse( + String vaultBaseUrl, String scope, String roleDefinitionName) { + final String accept = "application/json"; + return service.deleteSync( + vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), accept, Context.NONE); + } + + /** + * Deletes a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to delete. Managed HSM only supports '/'. + * @param roleDefinitionName The name (GUID) of the role definition to delete. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteSyncWithResponse( + String vaultBaseUrl, String scope, String roleDefinitionName, Context context) { + final String accept = "application/json"; + return service.deleteSync( + vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), accept, context); + } + + /** + * Deletes a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to delete. Managed HSM only supports '/'. + * @param roleDefinitionName The name (GUID) of the role definition to delete. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleDefinition deleteSync(String vaultBaseUrl, String scope, String roleDefinitionName) { + return deleteSyncWithResponse(vaultBaseUrl, scope, roleDefinitionName, Context.NONE).getValue(); + } + + /** + * Deletes a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to delete. Managed HSM only supports '/'. + * @param roleDefinitionName The name (GUID) of the role definition to delete. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleDefinition deleteSync(String vaultBaseUrl, String scope, String roleDefinitionName, Context context) { + return deleteSyncWithResponse(vaultBaseUrl, scope, roleDefinitionName, context).getValue(); + } + + /** + * Creates or updates a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to create or update. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to create or update. It can be any valid GUID. + * @param parameters Parameters for the role definition. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> createOrUpdateWithResponseAsync( + String vaultBaseUrl, String scope, String roleDefinitionName, RoleDefinitionCreateParameters parameters) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.createOrUpdate( + vaultBaseUrl, + scope, + roleDefinitionName, + this.client.getApiVersion(), + parameters, + accept, + context)); + } + /** * Creates or updates a custom role definition. * @@ -155,79 +369,577 @@ public Mono> createOrUpdateWithResponseAsync( } /** - * Get the specified role definition. + * Creates or updates a custom role definition. * * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. - * @param scope The scope of the role definition to get. Managed HSM only supports '/'. - * @param roleDefinitionName The name of the role definition to get. - * @param context The context to associate with this operation. + * @param scope The scope of the role definition to create or update. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to create or update. It can be any valid GUID. + * @param parameters Parameters for the role definition. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws KeyVaultErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the specified role definition along with {@link Response} on successful completion of {@link Mono}. + * @return role definition on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getWithResponseAsync( - String vaultBaseUrl, String scope, String roleDefinitionName, Context context) { - final String accept = "application/json"; - return service.get(vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), accept, context); + public Mono createOrUpdateAsync( + String vaultBaseUrl, String scope, String roleDefinitionName, RoleDefinitionCreateParameters parameters) { + return createOrUpdateWithResponseAsync(vaultBaseUrl, scope, roleDefinitionName, parameters) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); } /** - * Get all role definitions that are applicable at scope and above. + * Creates or updates a custom role definition. * * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. - * @param scope The scope of the role definition. - * @param filter The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as - * well. + * @param scope The scope of the role definition to create or update. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to create or update. It can be any valid GUID. + * @param parameters Parameters for the role definition. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws KeyVaultErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return all role definitions that are applicable at scope and above along with {@link PagedResponse} on - * successful completion of {@link Mono}. + * @return role definition on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> listSinglePageAsync( - String vaultBaseUrl, String scope, String filter, Context context) { + public Mono createOrUpdateAsync( + String vaultBaseUrl, + String scope, + String roleDefinitionName, + RoleDefinitionCreateParameters parameters, + Context context) { + return createOrUpdateWithResponseAsync(vaultBaseUrl, scope, roleDefinitionName, parameters, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Creates or updates a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to create or update. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to create or update. It can be any valid GUID. + * @param parameters Parameters for the role definition. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response createOrUpdateSyncWithResponse( + String vaultBaseUrl, String scope, String roleDefinitionName, RoleDefinitionCreateParameters parameters) { final String accept = "application/json"; - return service.list(vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, context) - .map( - res -> - new PagedResponseBase<>( - res.getRequest(), - res.getStatusCode(), - res.getHeaders(), - res.getValue().getValue(), - res.getValue().getNextLink(), - null)); + return service.createOrUpdateSync( + vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), parameters, accept, Context.NONE); } /** - * Get the next page of items. + * Creates or updates a custom role definition. * - * @param nextLink The nextLink parameter. * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to create or update. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to create or update. It can be any valid GUID. + * @param parameters Parameters for the role definition. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws KeyVaultErrorException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return role definition list operation result along with {@link PagedResponse} on successful completion of {@link - * Mono}. + * @return role definition along with {@link Response}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> listNextSinglePageAsync( - String nextLink, String vaultBaseUrl, Context context) { + public Response createOrUpdateSyncWithResponse( + String vaultBaseUrl, + String scope, + String roleDefinitionName, + RoleDefinitionCreateParameters parameters, + Context context) { final String accept = "application/json"; - return service.listNext(nextLink, vaultBaseUrl, accept, context) - .map( - res -> - new PagedResponseBase<>( - res.getRequest(), - res.getStatusCode(), - res.getHeaders(), - res.getValue().getValue(), - res.getValue().getNextLink(), - null)); + return service.createOrUpdateSync( + vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), parameters, accept, context); + } + + /** + * Creates or updates a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to create or update. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to create or update. It can be any valid GUID. + * @param parameters Parameters for the role definition. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleDefinition createOrUpdateSync( + String vaultBaseUrl, String scope, String roleDefinitionName, RoleDefinitionCreateParameters parameters) { + return createOrUpdateSyncWithResponse(vaultBaseUrl, scope, roleDefinitionName, parameters, Context.NONE) + .getValue(); + } + + /** + * Creates or updates a custom role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to create or update. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to create or update. It can be any valid GUID. + * @param parameters Parameters for the role definition. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleDefinition createOrUpdateSync( + String vaultBaseUrl, + String scope, + String roleDefinitionName, + RoleDefinitionCreateParameters parameters, + Context context) { + return createOrUpdateSyncWithResponse(vaultBaseUrl, scope, roleDefinitionName, parameters, context).getValue(); + } + + /** + * Get the specified role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to get. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to get. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role definition along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getWithResponseAsync( + String vaultBaseUrl, String scope, String roleDefinitionName) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.get( + vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), accept, context)); + } + + /** + * Get the specified role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to get. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to get. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role definition along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getWithResponseAsync( + String vaultBaseUrl, String scope, String roleDefinitionName, Context context) { + final String accept = "application/json"; + return service.get(vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), accept, context); + } + + /** + * Get the specified role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to get. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to get. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role definition on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getAsync(String vaultBaseUrl, String scope, String roleDefinitionName) { + return getWithResponseAsync(vaultBaseUrl, scope, roleDefinitionName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get the specified role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to get. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to get. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role definition on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getAsync( + String vaultBaseUrl, String scope, String roleDefinitionName, Context context) { + return getWithResponseAsync(vaultBaseUrl, scope, roleDefinitionName, context) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get the specified role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to get. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to get. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role definition along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSyncWithResponse(String vaultBaseUrl, String scope, String roleDefinitionName) { + final String accept = "application/json"; + return service.getSync( + vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), accept, Context.NONE); + } + + /** + * Get the specified role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to get. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to get. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role definition along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSyncWithResponse( + String vaultBaseUrl, String scope, String roleDefinitionName, Context context) { + final String accept = "application/json"; + return service.getSync(vaultBaseUrl, scope, roleDefinitionName, this.client.getApiVersion(), accept, context); + } + + /** + * Get the specified role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to get. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to get. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role definition. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleDefinition getSync(String vaultBaseUrl, String scope, String roleDefinitionName) { + return getSyncWithResponse(vaultBaseUrl, scope, roleDefinitionName, Context.NONE).getValue(); + } + + /** + * Get the specified role definition. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition to get. Managed HSM only supports '/'. + * @param roleDefinitionName The name of the role definition to get. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the specified role definition. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public RoleDefinition getSync(String vaultBaseUrl, String scope, String roleDefinitionName, Context context) { + return getSyncWithResponse(vaultBaseUrl, scope, roleDefinitionName, context).getValue(); + } + + /** + * Get all role definitions that are applicable at scope and above. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition. + * @param filter The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as + * well. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all role definitions that are applicable at scope and above along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> listSinglePageAsync(String vaultBaseUrl, String scope, String filter) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.list(vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, context)) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null)); + } + + /** + * Get all role definitions that are applicable at scope and above. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition. + * @param filter The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as + * well. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all role definitions that are applicable at scope and above along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> listSinglePageAsync( + String vaultBaseUrl, String scope, String filter, Context context) { + final String accept = "application/json"; + return service.list(vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, context) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null)); + } + + /** + * Get all role definitions that are applicable at scope and above. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition. + * @param filter The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as + * well. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all role definitions that are applicable at scope and above as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listAsync(String vaultBaseUrl, String scope, String filter) { + return new PagedFlux<>( + () -> listSinglePageAsync(vaultBaseUrl, scope, filter), + nextLink -> listNextSinglePageAsync(nextLink, vaultBaseUrl)); + } + + /** + * Get all role definitions that are applicable at scope and above. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition. + * @param filter The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as + * well. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all role definitions that are applicable at scope and above as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listAsync(String vaultBaseUrl, String scope, String filter, Context context) { + return new PagedFlux<>( + () -> listSinglePageAsync(vaultBaseUrl, scope, filter, context), + nextLink -> listNextSinglePageAsync(nextLink, vaultBaseUrl, context)); + } + + /** + * Get all role definitions that are applicable at scope and above. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition. + * @param filter The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as + * well. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all role definitions that are applicable at scope and above along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public PagedResponse listSyncSinglePage(String vaultBaseUrl, String scope, String filter) { + final String accept = "application/json"; + Response res = + service.listSync(vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, Context.NONE); + return new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null); + } + + /** + * Get all role definitions that are applicable at scope and above. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition. + * @param filter The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as + * well. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all role definitions that are applicable at scope and above along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public PagedResponse listSyncSinglePage( + String vaultBaseUrl, String scope, String filter, Context context) { + final String accept = "application/json"; + Response res = + service.listSync(vaultBaseUrl, scope, filter, this.client.getApiVersion(), accept, context); + return new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null); + } + + /** + * Get all role definitions that are applicable at scope and above. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition. + * @param filter The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as + * well. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all role definitions that are applicable at scope and above as paginated response with {@link + * PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listSync(String vaultBaseUrl, String scope, String filter) { + return new PagedIterable<>( + () -> listSyncSinglePage(vaultBaseUrl, scope, filter, Context.NONE), + nextLink -> listNextSyncSinglePage(nextLink, vaultBaseUrl)); + } + + /** + * Get all role definitions that are applicable at scope and above. + * + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param scope The scope of the role definition. + * @param filter The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as + * well. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return all role definitions that are applicable at scope and above as paginated response with {@link + * PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listSync(String vaultBaseUrl, String scope, String filter, Context context) { + return new PagedIterable<>( + () -> listSyncSinglePage(vaultBaseUrl, scope, filter, context), + nextLink -> listNextSyncSinglePage(nextLink, vaultBaseUrl, context)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items + *

The nextLink parameter. + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition list operation result along with {@link PagedResponse} on successful completion of {@link + * Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> listNextSinglePageAsync(String nextLink, String vaultBaseUrl) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.listNext(nextLink, vaultBaseUrl, accept, context)) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items + *

The nextLink parameter. + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition list operation result along with {@link PagedResponse} on successful completion of {@link + * Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> listNextSinglePageAsync( + String nextLink, String vaultBaseUrl, Context context) { + final String accept = "application/json"; + return service.listNext(nextLink, vaultBaseUrl, accept, context) + .map( + res -> + new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items + *

The nextLink parameter. + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition list operation result along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public PagedResponse listNextSyncSinglePage(String nextLink, String vaultBaseUrl) { + final String accept = "application/json"; + Response res = service.listNextSync(nextLink, vaultBaseUrl, accept, Context.NONE); + return new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items + *

The nextLink parameter. + * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws KeyVaultErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return role definition list operation result along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public PagedResponse listNextSyncSinglePage(String nextLink, String vaultBaseUrl, Context context) { + final String accept = "application/json"; + Response res = service.listNextSync(nextLink, vaultBaseUrl, accept, context); + return new PagedResponseBase<>( + res.getRequest(), + res.getStatusCode(), + res.getHeaders(), + res.getValue().getValue(), + res.getValue().getNextLink(), + null); } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/DataAction.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/DataAction.java index acc1e6d0c21b1..7bacb70ea5750 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/DataAction.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/DataAction.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; -/** Defines values for DataAction. */ +/** Supported permissions for data actions. */ public final class DataAction extends ExpandableStringEnum { /** Static value Microsoft.KeyVault/managedHsm/keys/read/action for DataAction. */ public static final DataAction READ_HSM_KEY = fromString("Microsoft.KeyVault/managedHsm/keys/read/action"); @@ -139,7 +139,11 @@ public static DataAction fromString(String name) { return fromString(name, DataAction.class); } - /** @return known DataAction values. */ + /** + * Gets known DataAction values. + * + * @return known DataAction values. + */ public static Collection values() { return values(DataAction.class); } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/Error.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/Error.java index ca8046fbc6eb1..3b16bfabbccb7 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/Error.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/Error.java @@ -28,6 +28,9 @@ public final class Error { @JsonProperty(value = "innererror", access = JsonProperty.Access.WRITE_ONLY) private Error innerError; + /** Creates an instance of Error class. */ + public Error() {} + /** * Get the code property: The error code. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupHeaders.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupHeaders.java index fd19d98eb707c..c9a832e833290 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupHeaders.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupHeaders.java @@ -5,6 +5,7 @@ package com.azure.security.keyvault.administration.implementation.models; import com.azure.core.annotation.Fluent; +import com.azure.core.http.HttpHeaders; import com.fasterxml.jackson.annotation.JsonProperty; /** The FullBackupHeaders model. */ @@ -22,6 +23,20 @@ public final class FullBackupHeaders { @JsonProperty(value = "Azure-AsyncOperation") private String azureAsyncOperation; + // HttpHeaders containing the raw property values. + /** + * Creates an instance of FullBackupHeaders class. + * + * @param rawHeaders The raw HttpHeaders that will be used to create the property values. + */ + public FullBackupHeaders(HttpHeaders rawHeaders) { + String retryAfter = rawHeaders.getValue("Retry-After"); + if (retryAfter != null) { + this.retryAfter = Integer.parseInt(retryAfter); + } + this.azureAsyncOperation = rawHeaders.getValue("Azure-AsyncOperation"); + } + /** * Get the retryAfter property: The Retry-After property. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupOperation.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupOperation.java index cc96e2041f9bd..447a826252ada 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupOperation.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupOperation.java @@ -52,6 +52,9 @@ public final class FullBackupOperation { @JsonProperty(value = "azureStorageBlobContainerUri") private String azureStorageBlobContainerUri; + /** Creates an instance of FullBackupOperation class. */ + public FullBackupOperation() {} + /** * Get the status property: Status of the backup operation. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupResponse.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupResponse.java index 826929edf15d5..8e20f8aa73d62 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupResponse.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullBackupResponse.java @@ -28,7 +28,11 @@ public FullBackupResponse( super(request, statusCode, rawHeaders, value, headers); } - /** @return the deserialized response body. */ + /** + * Gets the deserialized response body. + * + * @return the deserialized response body. + */ @Override public FullBackupOperation getValue() { return super.getValue(); diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullRestoreOperationHeaders.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullRestoreOperationHeaders.java index 035707472745e..ee9a34c1a0d91 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullRestoreOperationHeaders.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullRestoreOperationHeaders.java @@ -5,6 +5,7 @@ package com.azure.security.keyvault.administration.implementation.models; import com.azure.core.annotation.Fluent; +import com.azure.core.http.HttpHeaders; import com.fasterxml.jackson.annotation.JsonProperty; /** The FullRestoreOperationHeaders model. */ @@ -22,6 +23,20 @@ public final class FullRestoreOperationHeaders { @JsonProperty(value = "Azure-AsyncOperation") private String azureAsyncOperation; + // HttpHeaders containing the raw property values. + /** + * Creates an instance of FullRestoreOperationHeaders class. + * + * @param rawHeaders The raw HttpHeaders that will be used to create the property values. + */ + public FullRestoreOperationHeaders(HttpHeaders rawHeaders) { + String retryAfter = rawHeaders.getValue("Retry-After"); + if (retryAfter != null) { + this.retryAfter = Integer.parseInt(retryAfter); + } + this.azureAsyncOperation = rawHeaders.getValue("Azure-AsyncOperation"); + } + /** * Get the retryAfter property: The Retry-After property. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullRestoreOperationResponse.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullRestoreOperationResponse.java index e35b341ab4c3e..6c8b69b122232 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullRestoreOperationResponse.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/FullRestoreOperationResponse.java @@ -28,7 +28,11 @@ public FullRestoreOperationResponse( super(request, statusCode, rawHeaders, value, headers); } - /** @return the deserialized response body. */ + /** + * Gets the deserialized response body. + * + * @return the deserialized response body. + */ @Override public RestoreOperation getValue() { return super.getValue(); diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/KeyVaultError.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/KeyVaultError.java index 2d08c68279821..888a3d9342ffe 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/KeyVaultError.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/KeyVaultError.java @@ -16,6 +16,9 @@ public final class KeyVaultError { @JsonProperty(value = "error", access = JsonProperty.Access.WRITE_ONLY) private Error error; + /** Creates an instance of KeyVaultError class. */ + public KeyVaultError() {} + /** * Get the error property: The key vault server error. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/KeyVaultErrorException.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/KeyVaultErrorException.java index 77b9441be30ee..898aa0af3233d 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/KeyVaultErrorException.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/KeyVaultErrorException.java @@ -30,6 +30,7 @@ public KeyVaultErrorException(String message, HttpResponse response, KeyVaultErr super(message, response, value); } + /** {@inheritDoc} */ @Override public KeyVaultError getValue() { return (KeyVaultError) super.getValue(); diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/Permission.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/Permission.java index bde54a4f21aba..e19189c6c3191 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/Permission.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/Permission.java @@ -18,8 +18,8 @@ public final class Permission { private List actions; /* - * Action permissions that are excluded but not denied. They may be granted - * by other role definitions assigned to a principal. + * Action permissions that are excluded but not denied. They may be granted by other role definitions assigned to a + * principal. */ @JsonProperty(value = "notActions") private List notActions; @@ -31,12 +31,15 @@ public final class Permission { private List dataActions; /* - * Data action permissions that are excluded but not denied. They may be - * granted by other role definitions assigned to a principal. + * Data action permissions that are excluded but not denied. They may be granted by other role definitions assigned + * to a principal. */ @JsonProperty(value = "notDataActions") private List notDataActions; + /** Creates an instance of Permission class. */ + public Permission() {} + /** * Get the actions property: Action permissions that are granted. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RestoreOperation.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RestoreOperation.java index 8c12d0cfd8a47..248810c3b3333 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RestoreOperation.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RestoreOperation.java @@ -46,6 +46,9 @@ public final class RestoreOperation { @JsonProperty(value = "endTime") private Long endTime; + /** Creates an instance of RestoreOperation class. */ + public RestoreOperation() {} + /** * Get the status property: Status of the restore operation. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RestoreOperationParameters.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RestoreOperationParameters.java index 4048b51aa2b4c..60bf24d418b07 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RestoreOperationParameters.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RestoreOperationParameters.java @@ -17,12 +17,14 @@ public final class RestoreOperationParameters { private SASTokenParameter sasTokenParameters; /* - * The Folder name of the blob where the previous successful full backup - * was stored + * The Folder name of the blob where the previous successful full backup was stored */ @JsonProperty(value = "folderToRestore", required = true) private String folderToRestore; + /** Creates an instance of RestoreOperationParameters class. */ + public RestoreOperationParameters() {} + /** * Get the sasTokenParameters property: The sasTokenParameters property. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignment.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignment.java index 0379dc7eaf486..48c736ac9b455 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignment.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignment.java @@ -34,6 +34,9 @@ public final class RoleAssignment { @JsonProperty(value = "properties") private RoleAssignmentPropertiesWithScope properties; + /** Creates an instance of RoleAssignment class. */ + public RoleAssignment() {} + /** * Get the id property: The role assignment ID. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentCreateParameters.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentCreateParameters.java index 08f2052b7b334..aa5b24461a0a7 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentCreateParameters.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentCreateParameters.java @@ -16,6 +16,9 @@ public final class RoleAssignmentCreateParameters { @JsonProperty(value = "properties", required = true) private RoleAssignmentProperties properties; + /** Creates an instance of RoleAssignmentCreateParameters class. */ + public RoleAssignmentCreateParameters() {} + /** * Get the properties property: Role assignment properties. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentFilter.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentFilter.java index 458671cf8604c..c7d72cca913ab 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentFilter.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentFilter.java @@ -16,6 +16,9 @@ public final class RoleAssignmentFilter { @JsonProperty(value = "principalId") private String principalId; + /** Creates an instance of RoleAssignmentFilter class. */ + public RoleAssignmentFilter() {} + /** * Get the principalId property: Returns role assignment of the specific principal. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentListResult.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentListResult.java index 29096bd35f177..bf06f2c90e60f 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentListResult.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentListResult.java @@ -23,6 +23,9 @@ public final class RoleAssignmentListResult { @JsonProperty(value = "nextLink") private String nextLink; + /** Creates an instance of RoleAssignmentListResult class. */ + public RoleAssignmentListResult() {} + /** * Get the value property: Role assignment list. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentProperties.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentProperties.java index 46d3c7ff62630..02abad9155ac7 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentProperties.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentProperties.java @@ -17,13 +17,15 @@ public final class RoleAssignmentProperties { private String roleDefinitionId; /* - * The principal ID assigned to the role. This maps to the ID inside the - * Active Directory. It can point to a user, service principal, or security - * group. + * The principal ID assigned to the role. This maps to the ID inside the Active Directory. It can point to a user, + * service principal, or security group. */ @JsonProperty(value = "principalId", required = true) private String principalId; + /** Creates an instance of RoleAssignmentProperties class. */ + public RoleAssignmentProperties() {} + /** * Get the roleDefinitionId property: The role definition ID used in the role assignment. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentPropertiesWithScope.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentPropertiesWithScope.java index 9c607bc7c46e5..09c3ca4cb0f0b 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentPropertiesWithScope.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleAssignmentPropertiesWithScope.java @@ -28,6 +28,9 @@ public final class RoleAssignmentPropertiesWithScope { @JsonProperty(value = "principalId") private String principalId; + /** Creates an instance of RoleAssignmentPropertiesWithScope class. */ + public RoleAssignmentPropertiesWithScope() {} + /** * Get the scope property: The role scope. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinition.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinition.java index 8c2b0b98414d0..6869447d0d3fd 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinition.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinition.java @@ -61,6 +61,9 @@ public class RoleDefinition { @JsonProperty(value = "properties.assignableScopes") private List assignableScopes; + /** Creates an instance of RoleDefinition class. */ + public RoleDefinition() {} + /** * Get the id property: The role definition ID. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionCreateParameters.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionCreateParameters.java index 3ed961b756bd4..7ecc76aa4e7c9 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionCreateParameters.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionCreateParameters.java @@ -16,6 +16,9 @@ public final class RoleDefinitionCreateParameters { @JsonProperty(value = "properties", required = true) private RoleDefinitionProperties properties; + /** Creates an instance of RoleDefinitionCreateParameters class. */ + public RoleDefinitionCreateParameters() {} + /** * Get the properties property: Role definition properties. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionFilter.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionFilter.java index 30260424862d2..2583919d77553 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionFilter.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionFilter.java @@ -16,6 +16,9 @@ public final class RoleDefinitionFilter { @JsonProperty(value = "roleName") private String roleName; + /** Creates an instance of RoleDefinitionFilter class. */ + public RoleDefinitionFilter() {} + /** * Get the roleName property: Returns role definition with the specific name. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionListResult.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionListResult.java index 1bbaeff80b5a6..1917f653589db 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionListResult.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionListResult.java @@ -23,6 +23,9 @@ public final class RoleDefinitionListResult { @JsonProperty(value = "nextLink") private String nextLink; + /** Creates an instance of RoleDefinitionListResult class. */ + public RoleDefinitionListResult() {} + /** * Get the value property: Role definition list. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionProperties.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionProperties.java index 2456dceba1e16..c06096a0d1f11 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionProperties.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionProperties.java @@ -41,6 +41,9 @@ public final class RoleDefinitionProperties { @JsonProperty(value = "assignableScopes") private List assignableScopes; + /** Creates an instance of RoleDefinitionProperties class. */ + public RoleDefinitionProperties() {} + /** * Get the roleName property: The role name. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionType.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionType.java index 671b83e32c7b4..b44dcb2a514fa 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionType.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleDefinitionType.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; -/** Defines values for RoleDefinitionType. */ +/** The role definition type. */ public final class RoleDefinitionType extends ExpandableStringEnum { /** Static value Microsoft.Authorization/roleDefinitions for RoleDefinitionType. */ public static final RoleDefinitionType MICROSOFT_AUTHORIZATION_ROLE_DEFINITIONS = @@ -25,7 +25,11 @@ public static RoleDefinitionType fromString(String name) { return fromString(name, RoleDefinitionType.class); } - /** @return known RoleDefinitionType values. */ + /** + * Gets known RoleDefinitionType values. + * + * @return known RoleDefinitionType values. + */ public static Collection values() { return values(RoleDefinitionType.class); } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleScope.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleScope.java index 8952e5d385f86..42ae82d8f75d0 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleScope.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleScope.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; -/** Defines values for RoleScope. */ +/** The role scope. */ public final class RoleScope extends ExpandableStringEnum { /** Static value / for RoleScope. */ public static final RoleScope GLOBAL = fromString("/"); @@ -27,7 +27,11 @@ public static RoleScope fromString(String name) { return fromString(name, RoleScope.class); } - /** @return known RoleScope values. */ + /** + * Gets known RoleScope values. + * + * @return known RoleScope values. + */ public static Collection values() { return values(RoleScope.class); } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleType.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleType.java index 52f22567508ef..61584a69fda09 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleType.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/RoleType.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; -/** Defines values for RoleType. */ +/** The role type. */ public final class RoleType extends ExpandableStringEnum { /** Static value AKVBuiltInRole for RoleType. */ public static final RoleType BUILT_IN_ROLE = fromString("AKVBuiltInRole"); @@ -27,7 +27,11 @@ public static RoleType fromString(String name) { return fromString(name, RoleType.class); } - /** @return known RoleType values. */ + /** + * Gets known RoleType values. + * + * @return known RoleType values. + */ public static Collection values() { return values(RoleType.class); } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SASTokenParameter.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SASTokenParameter.java index f8f169dca8658..dd0986607d82f 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SASTokenParameter.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SASTokenParameter.java @@ -22,6 +22,9 @@ public final class SASTokenParameter { @JsonProperty(value = "token", required = true) private String token; + /** Creates an instance of SASTokenParameter class. */ + public SASTokenParameter() {} + /** * Get the storageResourceUri property: Azure Blob storage container Uri. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperation.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperation.java index 0615db4e29696..5ce916c7a532e 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperation.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperation.java @@ -46,6 +46,9 @@ public final class SelectiveKeyRestoreOperation { @JsonProperty(value = "endTime") private Long endTime; + /** Creates an instance of SelectiveKeyRestoreOperation class. */ + public SelectiveKeyRestoreOperation() {} + /** * Get the status property: Status of the restore operation. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationHeaders.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationHeaders.java index 6202d682a7800..9eb6b170f1f45 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationHeaders.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationHeaders.java @@ -5,6 +5,7 @@ package com.azure.security.keyvault.administration.implementation.models; import com.azure.core.annotation.Fluent; +import com.azure.core.http.HttpHeaders; import com.fasterxml.jackson.annotation.JsonProperty; /** The SelectiveKeyRestoreOperationHeaders model. */ @@ -22,6 +23,20 @@ public final class SelectiveKeyRestoreOperationHeaders { @JsonProperty(value = "Azure-AsyncOperation") private String azureAsyncOperation; + // HttpHeaders containing the raw property values. + /** + * Creates an instance of SelectiveKeyRestoreOperationHeaders class. + * + * @param rawHeaders The raw HttpHeaders that will be used to create the property values. + */ + public SelectiveKeyRestoreOperationHeaders(HttpHeaders rawHeaders) { + String retryAfter = rawHeaders.getValue("Retry-After"); + if (retryAfter != null) { + this.retryAfter = Integer.parseInt(retryAfter); + } + this.azureAsyncOperation = rawHeaders.getValue("Azure-AsyncOperation"); + } + /** * Get the retryAfter property: The Retry-After property. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationParameters.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationParameters.java index 9c5e86c532996..1fef8399a8ab6 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationParameters.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationParameters.java @@ -17,12 +17,14 @@ public final class SelectiveKeyRestoreOperationParameters { private SASTokenParameter sasTokenParameters; /* - * The Folder name of the blob where the previous successful full backup - * was stored + * The Folder name of the blob where the previous successful full backup was stored */ @JsonProperty(value = "folder", required = true) private String folder; + /** Creates an instance of SelectiveKeyRestoreOperationParameters class. */ + public SelectiveKeyRestoreOperationParameters() {} + /** * Get the sasTokenParameters property: The sasTokenParameters property. * diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationResponse.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationResponse.java index 5e946a826a385..4d36ae2d00586 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationResponse.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/SelectiveKeyRestoreOperationResponse.java @@ -29,7 +29,11 @@ public SelectiveKeyRestoreOperationResponse( super(request, statusCode, rawHeaders, value, headers); } - /** @return the deserialized response body. */ + /** + * Gets the deserialized response body. + * + * @return the deserialized response body. + */ @Override public SelectiveKeyRestoreOperation getValue() { return super.getValue(); diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/package-info.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/package-info.java index 4300970afe6ef..81c794e36bc16 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/package-info.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/models/package-info.java @@ -3,7 +3,7 @@ // Code generated by Microsoft (R) AutoRest Code Generator. /** - * Package containing the data models for KeyVaultAccessControlClient and KeyVaultBackupClient. The key vault client - * performs cryptographic key operations and vault operations against the Key Vault service. + * Package containing the data models for KeyVaultBackupClient. The key vault client performs cryptographic key + * operations and vault operations against the Key Vault service. */ package com.azure.security.keyvault.administration.implementation.models; diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/package-info.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/package-info.java index 1b4e3c41171c0..8779a93c26f2a 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/package-info.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/package-info.java @@ -3,7 +3,7 @@ // Code generated by Microsoft (R) AutoRest Code Generator. /** - * Package containing the implementations for KeyVaultAccessControlClient. The key vault client performs cryptographic - * key operations and vault operations against the Key Vault service. + * Package containing the implementations for KeyVaultBackupClient. The key vault client performs cryptographic key + * operations and vault operations against the Key Vault service. */ package com.azure.security.keyvault.administration.implementation; diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultAccessControlAsyncClientTest.java b/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultAccessControlAsyncClientTest.java index 08359dc33fcee..65d4653e53566 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultAccessControlAsyncClientTest.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultAccessControlAsyncClientTest.java @@ -3,6 +3,7 @@ package com.azure.security.keyvault.administration; import com.azure.core.http.HttpClient; +import com.azure.core.test.http.AssertingHttpClientBuilder; import com.azure.security.keyvault.administration.models.KeyVaultAdministrationException; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties; @@ -24,13 +25,25 @@ public class KeyVaultAccessControlAsyncClientTest extends KeyVaultAccessControlClientTestBase { private KeyVaultAccessControlAsyncClient asyncClient; + private void getClient(HttpClient httpClient, boolean forCleanup) { + asyncClient = getClientBuilder(buildAsyncAssertingClient(httpClient == null ? interceptorManager.getPlaybackClient() + : httpClient), forCleanup).buildAsyncClient(); + } + + private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { + return new AssertingHttpClientBuilder(httpClient) + .skipRequest((ignored1, ignored2) -> false) + .assertAsync() + .build(); + } + /** * Tests that existing {@link KeyVaultRoleDefinition role definitions} can be retrieved from the Key Vault. */ @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void listRoleDefinitions(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); StepVerifier.create(asyncClient.listRoleDefinitions(KeyVaultRoleScope.GLOBAL)) .thenConsumeWhile(roleDefinition -> { @@ -55,7 +68,7 @@ public void listRoleDefinitions(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void setRoleDefinition(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); try { @@ -86,7 +99,7 @@ public void setRoleDefinition(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void getRoleDefinition(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); try { @@ -117,7 +130,7 @@ public void getRoleDefinition(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void deleteRoleDefinition(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); // Create a role definition to delete, then delete the role definition. @@ -138,7 +151,7 @@ public void deleteRoleDefinition(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void deleteNonExistingRoleDefinitionDoesNotThrow(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); // Try to delete a non-existent role definition. @@ -181,7 +194,7 @@ public void listRoleAssignments(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void createRoleAssignment(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); String roleAssignmentName = testResourceNamer.randomUuid(); @@ -228,7 +241,7 @@ public void createRoleAssignment(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void createExistingRoleAssignmentThrows(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); String roleAssignmentName = testResourceNamer.randomUuid(); @@ -259,7 +272,7 @@ public void createExistingRoleAssignmentThrows(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void getRoleAssignment(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); String roleAssignmentName = testResourceNamer.randomUuid(); @@ -296,7 +309,7 @@ public void getRoleAssignment(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void deleteRoleAssignment(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); String roleAssignmentName = testResourceNamer.randomUuid(); @@ -328,7 +341,7 @@ public void deleteRoleAssignment(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void deleteNonExistingRoleAssignmentDoesNotThrow(HttpClient httpClient) { - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); + getClient(httpClient, false); String roleAssignmentName = testResourceNamer.randomUuid(); // Try to delete a non-existent role assignment. diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClientTest.java b/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClientTest.java index 03a6331f49389..8b2eb79b439fa 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClientTest.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClientTest.java @@ -5,6 +5,7 @@ import com.azure.core.http.HttpClient; import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.Response; +import com.azure.core.test.http.AssertingHttpClientBuilder; import com.azure.core.util.Context; import com.azure.security.keyvault.administration.models.KeyVaultAdministrationException; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; @@ -16,6 +17,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -24,13 +26,25 @@ public class KeyVaultAccessControlClientTest extends KeyVaultAccessControlClientTestBase { private KeyVaultAccessControlClient client; + private void getClient(HttpClient httpClient, boolean forCleanup) { + client = getClientBuilder(buildSyncAssertingClient(httpClient == null ? interceptorManager.getPlaybackClient() + : httpClient), forCleanup).buildClient(); + } + + private HttpClient buildSyncAssertingClient(HttpClient httpClient) { + return new AssertingHttpClientBuilder(httpClient) + .skipRequest((ignored1, ignored2) -> true) + .assertSync() + .build(); + } + /** * Tests that existing {@link KeyVaultRoleDefinition role definitions} can be retrieved from the Key Vault. */ @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void listRoleDefinitions(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); PagedIterable roleDefinitions = client.listRoleDefinitions(KeyVaultRoleScope.GLOBAL); assertTrue(roleDefinitions.iterator().hasNext()); @@ -53,7 +67,7 @@ public void listRoleDefinitions(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void setRoleDefinition(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); try { @@ -82,7 +96,7 @@ public void setRoleDefinition(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void getRoleDefinition(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); try { @@ -111,7 +125,7 @@ public void getRoleDefinition(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void deleteRoleDefinition(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); // Create a role definition to delete. @@ -135,7 +149,7 @@ public void deleteRoleDefinition(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void deleteNonExistingRoleDefinitionDoesNotThrow(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); // Try to delete a non-existent role definition. Response deleteResponse = @@ -151,7 +165,7 @@ public void deleteNonExistingRoleDefinitionDoesNotThrow(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void listRoleAssignments(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); PagedIterable roleAssignments = client.listRoleAssignments(KeyVaultRoleScope.GLOBAL); assertTrue(roleAssignments.iterator().hasNext()); @@ -176,7 +190,7 @@ public void listRoleAssignments(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void createRoleAssignment(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); String roleAssignmentName = testResourceNamer.randomUuid(); @@ -216,7 +230,7 @@ public void createRoleAssignment(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void createExistingRoleAssignmentThrows(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); String roleAssignmentName = testResourceNamer.randomUuid(); @@ -248,7 +262,7 @@ public void createExistingRoleAssignmentThrows(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void getRoleAssignment(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); String roleAssignmentName = testResourceNamer.randomUuid(); @@ -284,7 +298,7 @@ public void getRoleAssignment(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void deleteRoleAssignment(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); String roleDefinitionName = testResourceNamer.randomUuid(); String roleAssignmentName = testResourceNamer.randomUuid(); @@ -321,7 +335,7 @@ public void deleteRoleAssignment(HttpClient httpClient) { @ParameterizedTest(name = DISPLAY_NAME) @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") public void deleteNonExistingRoleAssignmentDoesNotThrow(HttpClient httpClient) { - client = getClientBuilder(httpClient, false).buildClient(); + getClient(httpClient, false); String roleAssignmentName = testResourceNamer.randomUuid(); // Try to delete a non-existent role assignment. Response deleteResponse = diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultBackupAsyncClientTest.java b/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultBackupAsyncClientTest.java index 672426127b762..bdb4e9690a377 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultBackupAsyncClientTest.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultBackupAsyncClientTest.java @@ -3,6 +3,7 @@ package com.azure.security.keyvault.administration; import com.azure.core.http.HttpClient; +import com.azure.core.test.http.AssertingHttpClientBuilder; import com.azure.core.util.polling.AsyncPollResponse; import com.azure.core.util.polling.LongRunningOperationStatus; import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation; @@ -31,13 +32,20 @@ public class KeyVaultBackupAsyncClientTest extends KeyVaultBackupClientTestBase private KeyVaultBackupAsyncClient asyncClient; private void getAsyncClient(HttpClient httpClient, boolean forCleanup) { - asyncClient = spy(getClientBuilder(httpClient, forCleanup).buildAsyncClient()); - + asyncClient = spy(getClientBuilder(buildAsyncAssertingClient(httpClient == null ? interceptorManager.getPlaybackClient() + : httpClient), forCleanup).buildAsyncClient()); if (interceptorManager.isPlaybackMode()) { when(asyncClient.getDefaultPollingInterval()).thenReturn(Duration.ofMillis(10)); } } + private HttpClient buildAsyncAssertingClient(HttpClient httpClient) { + return new AssertingHttpClientBuilder(httpClient) + .skipRequest((ignored1, ignored2) -> false) + .assertAsync() + .build(); + } + /** * Tests that a Key Vault or MHSM can be backed up. */ diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultBackupClientTest.java b/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultBackupClientTest.java index 9e6fb310f0ec3..69fcdcd309d16 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultBackupClientTest.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/test/java/com/azure/security/keyvault/administration/KeyVaultBackupClientTest.java @@ -3,6 +3,7 @@ package com.azure.security.keyvault.administration; import com.azure.core.http.HttpClient; +import com.azure.core.test.http.AssertingHttpClientBuilder; import com.azure.core.util.polling.LongRunningOperationStatus; import com.azure.core.util.polling.PollResponse; import com.azure.core.util.polling.SyncPoller; @@ -33,13 +34,18 @@ public class KeyVaultBackupClientTest extends KeyVaultBackupClientTestBase { private KeyVaultBackupClient client; private void getClient(HttpClient httpClient, boolean forCleanup) { - KeyVaultBackupAsyncClient asyncClient = spy(getClientBuilder(httpClient, forCleanup).buildAsyncClient()); - + client = spy(getClientBuilder(buildSyncAssertingClient(httpClient == null ? interceptorManager.getPlaybackClient() + : httpClient), forCleanup).buildClient()); if (interceptorManager.isPlaybackMode()) { - when(asyncClient.getDefaultPollingInterval()).thenReturn(Duration.ofMillis(10)); + when(client.getDefaultPollingInterval()).thenReturn(Duration.ofMillis(10)); } + } - client = new KeyVaultBackupClient(asyncClient); + private HttpClient buildSyncAssertingClient(HttpClient httpClient) { + return new AssertingHttpClientBuilder(httpClient) + .skipRequest((ignored1, ignored2) -> true) + .assertSync() + .build(); } /** diff --git a/sdk/keyvault/azure-security-keyvault-administration/swagger/autorest.md b/sdk/keyvault/azure-security-keyvault-administration/swagger/autorest.md index 33e1e04ed0317..17164bbf6dc4d 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/swagger/autorest.md +++ b/sdk/keyvault/azure-security-keyvault-administration/swagger/autorest.md @@ -44,7 +44,7 @@ models-subpackage: implementation.models custom-types-subpackage: models generate-client-as-impl: true service-interface-as-public: true -sync-methods: none +enable-sync-stack: true add-context-parameter: true context-client-method-parameter: true ```