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 c84e917b59829..feb4ad90cb7bc 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 @@ -28,7 +28,7 @@ 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.KeyVaultRoleAssignmentScope; +import com.azure.security.keyvault.administration.models.KeyVaultRoleScope; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinitionProperties; import reactor.core.publisher.Mono; @@ -67,18 +67,24 @@ public final class KeyVaultAccessControlAsyncClient { private final KeyVaultAccessControlClientImpl clientImpl; /** - * The Kay Vault URL this client is associated to. + * 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; + /** * Package private constructor to be used by {@link KeyVaultAccessControlClientBuilder}. */ - KeyVaultAccessControlAsyncClient(URL vaultUrl, HttpPipeline httpPipeline) { + KeyVaultAccessControlAsyncClient(URL vaultUrl, HttpPipeline httpPipeline, KeyVaultAdministrationServiceVersion serviceVersion) { Objects.requireNonNull(vaultUrl, KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)); this.vaultUrl = vaultUrl.toString(); + this.serviceVersion = serviceVersion.getVersion(); clientImpl = new KeyVaultAccessControlClientImplBuilder() .pipeline(httpPipeline) @@ -96,16 +102,15 @@ public String getVaultUrl() { /** * Lists all {@link KeyVaultRoleDefinition role definitions} that are applicable at the given - * {@link KeyVaultRoleAssignmentScope roleScope} and above. + * {@link KeyVaultRoleScope role scope} and above. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleDefinition role - * definitions}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleDefinition role definitions}. * @return A {@link PagedFlux} containing the {@link KeyVaultRoleDefinition role definitions} for the given - * {@link KeyVaultRoleAssignmentScope roleScope}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * {@link KeyVaultRoleScope role scope}. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listRoleDefinitions(KeyVaultRoleAssignmentScope roleScope) { + public PagedFlux listRoleDefinitions(KeyVaultRoleScope roleScope) { return new PagedFlux<>( () -> withContext(context -> listRoleDefinitionsFirstPage(vaultUrl, roleScope, context)), continuationToken -> withContext(context -> listRoleDefinitionsNextPage(continuationToken, context))); @@ -113,16 +118,15 @@ public PagedFlux listRoleDefinitions(KeyVaultRoleAssignm /** * Lists all {@link KeyVaultRoleDefinition role definitions} that are applicable at the given - * {@link KeyVaultRoleAssignmentScope roleScope} and above. + * {@link KeyVaultRoleScope role scope} and above. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleDefinition role - * definitions}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleDefinition role definitions}. * @param context Additional {@link Context} that is passed through the HTTP pipeline during the service call. * @return A {@link PagedFlux} containing the {@link KeyVaultRoleDefinition role definitions} for the given - * {@link KeyVaultRoleAssignmentScope roleScope}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * {@link KeyVaultRoleScope role scope}. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} is {@code null}. */ - PagedFlux listRoleDefinitions(KeyVaultRoleAssignmentScope roleScope, Context context) { + PagedFlux listRoleDefinitions(KeyVaultRoleScope roleScope, Context context) { return new PagedFlux<>( () -> listRoleDefinitionsFirstPage(vaultUrl, roleScope, context), continuationToken -> listRoleDefinitionsNextPage(continuationToken, context)); @@ -130,16 +134,16 @@ PagedFlux listRoleDefinitions(KeyVaultRoleAssignmentScop /** * Lists all {@link KeyVaultRoleDefinition role definitions} in the first page that are applicable at the given - * {@link KeyVaultRoleAssignmentScope roleScope} and above. + * {@link KeyVaultRoleScope role scope} and above. * * @param vaultUrl The URL for the Key Vault this client is associated with. - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleDefinition}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleDefinition}. * @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 KeyVaultRoleAssignmentScope roleScope} from the first page of results. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * for the given {@link KeyVaultRoleScope role scope} from the first page of results. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} is {@code null}. */ - Mono> listRoleDefinitionsFirstPage(String vaultUrl, KeyVaultRoleAssignmentScope roleScope, Context context) { + Mono> listRoleDefinitionsFirstPage(String vaultUrl, KeyVaultRoleScope roleScope, Context context) { Objects.requireNonNull(roleScope, String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), "'roleScope'")); @@ -161,13 +165,13 @@ Mono> listRoleDefinitionsFirstPage(String /** * Lists all {@link KeyVaultRoleDefinition role definitions} given by the {@code nextPageLink} that was retrieved * from a call to - * {@link KeyVaultAccessControlAsyncClient#listRoleDefinitionsFirstPage(String, KeyVaultRoleAssignmentScope, Context)}. + * {@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 KeyVaultRoleAssignmentScope roleScope} from the next page of results. + * for the given {@link KeyVaultRoleScope role scope} from the next page of results. */ Mono> listRoleDefinitionsNextPage(String continuationToken, Context context) { try { @@ -186,15 +190,15 @@ Mono> listRoleDefinitionsNextPage(String c /** * Lists all {@link KeyVaultRoleAssignment role assignments} that are applicable at the given - * {@link KeyVaultRoleAssignmentScope roleScope} and above. + * {@link KeyVaultRoleScope role scope} and above. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. * @return A {@link PagedFlux} containing the {@link KeyVaultRoleAssignment role assignments} for the given - * {@link KeyVaultRoleAssignmentScope roleScope}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * {@link KeyVaultRoleScope role scope}. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listRoleAssignments(KeyVaultRoleAssignmentScope roleScope) { + public PagedFlux listRoleAssignments(KeyVaultRoleScope roleScope) { return new PagedFlux<>( () -> withContext(context -> listRoleAssignmentsFirstPage(vaultUrl, roleScope, context)), continuationToken -> withContext(context -> listRoleAssignmentsNextPage(continuationToken, context))); @@ -202,32 +206,32 @@ public PagedFlux listRoleAssignments(KeyVaultRoleAssignm /** * Lists all {@link KeyVaultRoleAssignment role assignments} that are applicable at the given - * {@link KeyVaultRoleAssignmentScope roleScope} and above. + * {@link KeyVaultRoleScope role scope} and above. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return A {@link PagedFlux} containing the {@link KeyVaultRoleAssignment role assignments} for the given - * {@link KeyVaultRoleAssignmentScope roleScope}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * {@link KeyVaultRoleScope role scope}. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} is {@code null}. */ - PagedFlux listRoleAssignments(KeyVaultRoleAssignmentScope roleScope, Context context) { + PagedFlux listRoleAssignments(KeyVaultRoleScope roleScope, Context context) { return new PagedFlux<>( () -> listRoleAssignmentsFirstPage(vaultUrl, roleScope, context), continuationToken -> listRoleAssignmentsNextPage(continuationToken, context)); } /** - * Lists all {@link KeyVaultRoleAssignment role assignments} in the first page that are applicable at - * the given {@link KeyVaultRoleAssignmentScope roleScope} and above. + * 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 KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. * @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 KeyVaultRoleAssignmentScope roleScope} from the first page of results. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * in the given {@link KeyVaultRoleScope role scope} from the first page of results. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} is {@code null}. */ - Mono> listRoleAssignmentsFirstPage(String vaultUrl, KeyVaultRoleAssignmentScope roleScope, Context context) { + Mono> listRoleAssignmentsFirstPage(String vaultUrl, KeyVaultRoleScope roleScope, Context context) { Objects.requireNonNull(roleScope, String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), "'roleScope'")); @@ -248,14 +252,13 @@ Mono> listRoleAssignmentsFirstPage(String /** * Lists all {@link KeyVaultRoleAssignment role assignments} given by the {@code nextPageLink} that was - * retrieved from a call to - * {@link KeyVaultAccessControlAsyncClient#listRoleAssignments(KeyVaultRoleAssignmentScope)}. + * 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 KeyVaultRoleAssignmentScope roleScope} from the first page of results. + * for the given {@link KeyVaultRoleScope role scope} from the first page of results. */ Mono> listRoleAssignmentsNextPage(String continuationToken, Context context) { try { @@ -273,165 +276,155 @@ Mono> listRoleAssignmentsNextPage(String c } /** - * Creates a {@link KeyVaultRoleAssignment} with a randomly generated {@link UUID name}. + * Creates a {@link KeyVaultRoleAssignment} with a randomly generated name. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment} to - * create. - * @param properties Properties for the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment} to create. + * @param roleDefinitionId The {@link KeyVaultRoleDefinition role definition} ID for the role assignment. + * @param principalId The principal ID assigned to the role. This maps to the ID inside the Active Directory. * @return A {@link Mono} containing the created {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or - * {@link KeyVaultRoleAssignmentProperties properties} are {@code null}. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope}, {@link String roleAssignmentName}, + * {@link String roleDefinitionId} or {@link String principalId} are {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono createRoleAssignment(KeyVaultRoleAssignmentScope roleScope, KeyVaultRoleAssignmentProperties properties) { - return createRoleAssignment(roleScope, UUID.randomUUID(), properties); + public Mono createRoleAssignment(KeyVaultRoleScope roleScope, String roleDefinitionId, String principalId) { + return createRoleAssignment(roleScope, UUID.randomUUID().toString(), roleDefinitionId, principalId); } /** * Creates a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment} to - * create. - * @param name The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. - * @param properties Properties for the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment} to create. + * @param roleAssignmentName The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. + * @param roleDefinitionId The {@link KeyVaultRoleDefinition role definition} ID for the role assignment. + * @param principalId The principal ID assigned to the role. This maps to the ID inside the Active Directory. * @return A {@link Mono} containing the created {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope}, {@link UUID name} or - * {@link KeyVaultRoleAssignmentProperties properties} are {@code null}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono createRoleAssignment(KeyVaultRoleAssignmentScope roleScope, UUID name, KeyVaultRoleAssignmentProperties properties) { - return createRoleAssignmentWithResponse(roleScope, name, properties).flatMap(FluxUtil::toMono); - } - - /** - * Creates a {@link KeyVaultRoleAssignment} with a randomly generated {@link UUID name}. - * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment} to - * create. - * @param properties Properties for the {@link KeyVaultRoleAssignment}. - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the created - * {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or - * {@link KeyVaultRoleAssignmentProperties properties} are {@code null}. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope}, {@link String roleAssignmentName}, + * {@link String roleDefinitionId} or {@link String principalId} are {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> createRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, KeyVaultRoleAssignmentProperties properties) { - return createRoleAssignmentWithResponse(roleScope, UUID.randomUUID(), properties); + public Mono createRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignmentName, String roleDefinitionId, String principalId) { + return createRoleAssignmentWithResponse(roleScope, roleAssignmentName, roleDefinitionId, principalId).flatMap(FluxUtil::toMono); } /** * Creates a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment} to - * create. - * @param name The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. - * @param properties Properties for the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment} to create. + * @param roleAssignmentName The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. + * @param roleDefinitionId The {@link KeyVaultRoleDefinition role definition} ID for the role assignment. + * @param principalId The principal ID assigned to the role. This maps to the ID inside the Active Directory. * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the created * {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope}, {@link UUID name} or - * {@link KeyVaultRoleAssignmentProperties properties} are {@code null}. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope}, {@link String roleAssignmentName}, + * {@link String roleDefinitionId} or {@link String principalId} are {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> createRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, UUID name, KeyVaultRoleAssignmentProperties properties) { - return withContext(context -> createRoleAssignmentWithResponse(roleScope, name, properties, context)); + public Mono> createRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, String roleDefinitionId, String principalId) { + return withContext(context -> createRoleAssignmentWithResponse(roleScope, roleAssignmentName, roleDefinitionId, principalId, context)); } /** * Creates a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment} to - * create. - * @param name The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. - * @param properties Properties for the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment} to create. + * @param roleAssignmentName The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. + * @param roleDefinitionId The {@link KeyVaultRoleDefinition role definition} ID for the role assignment. + * @param principalId The principal ID assigned to the role. This maps to the ID inside the Active Directory. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the created * {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope}, {@link UUID name} or - * {@link KeyVaultRoleAssignmentProperties properties} are {@code null}. + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope}, {@link String roleAssignmentName}, + * {@link String roleDefinitionId} or {@link String principalId} are {@code null}. */ - Mono> createRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, UUID name, KeyVaultRoleAssignmentProperties properties, Context context) { + Mono> createRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, String roleDefinitionId, String principalId, Context context) { Objects.requireNonNull(roleScope, String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), "'roleScope'")); - Objects.requireNonNull(name, + Objects.requireNonNull(roleAssignmentName, + String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), + "'roleAssignmentName'")); + Objects.requireNonNull(principalId, String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'name'")); - Objects.requireNonNull(properties, + "'principalId'")); + Objects.requireNonNull(roleDefinitionId, String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'properties'")); + "'roleDefinitionId'")); RoleAssignmentProperties roleAssignmentProperties = new RoleAssignmentProperties() - .setRoleDefinitionId(properties.getRoleDefinitionId()) - .setPrincipalId(properties.getPrincipalId()); + .setRoleDefinitionId(roleDefinitionId) + .setPrincipalId(principalId); RoleAssignmentCreateParameters parameters = new RoleAssignmentCreateParameters() .setProperties(roleAssignmentProperties); - - return clientImpl.getRoleAssignments() - .createWithResponseAsync(vaultUrl, roleScope.toString(), name.toString(), parameters, - context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)) - .doOnRequest(ignored -> logger.info("Creating role assignment - {}", name)) - .doOnSuccess(response -> logger.info("Created role assignment - {}", response.getValue().getName())) - .doOnError(error -> logger.warning("Failed to create role assignment - {}", name, error)) - .map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentResponse); + try { + return clientImpl.getRoleAssignments() + .createWithResponseAsync(vaultUrl, roleScope.toString(), roleAssignmentName, parameters, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)) + .doOnRequest(ignored -> logger.info("Creating role assignment - {}", roleAssignmentName)) + .doOnSuccess(response -> logger.info("Created role assignment - {}", response.getValue().getName())) + .doOnError(error -> logger.warning("Failed to create role assignment - {}", roleAssignmentName, error)) + .map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentResponse); + } catch (RuntimeException e) { + return monoError(logger, e); + } } /** * Gets a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name used of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name used of the {@link KeyVaultRoleAssignment}. * @return A {@link Mono} containing the {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link String name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} or {@link String roleAssignmentName} are * {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getRoleAssignment(KeyVaultRoleAssignmentScope roleScope, String name) { - return getRoleAssignmentWithResponse(roleScope, name).flatMap(FluxUtil::toMono); + public Mono getRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignmentName) { + return getRoleAssignmentWithResponse(roleScope, roleAssignmentName).flatMap(FluxUtil::toMono); } /** * Gets a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name of the {@link KeyVaultRoleAssignment}. * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the * {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link String name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} or {@link String roleAssignmentName} are * {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, String name) { - return withContext(context -> getRoleAssignmentWithResponse(roleScope, name, context)); + public Mono> getRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName) { + return withContext(context -> getRoleAssignmentWithResponse(roleScope, roleAssignmentName, context)); } /** * Gets a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name of the {@link KeyVaultRoleAssignment}. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the * {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link String name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} or {@link String roleAssignmentName} are * {@code null}. */ - Mono> getRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, String name, Context context) { + Mono> getRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, Context context) { Objects.requireNonNull(roleScope, String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), "'roleScope'")); - Objects.requireNonNull(name, + Objects.requireNonNull(roleAssignmentName, String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'name'")); + "'roleAssignmentName'")); try { return clientImpl.getRoleAssignments() - .getWithResponseAsync(vaultUrl, roleScope.toString(), name, context.addData(AZ_TRACING_NAMESPACE_KEY, + .getWithResponseAsync(vaultUrl, roleScope.toString(), roleAssignmentName, context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)) - .doOnRequest(ignored -> logger.info("Retrieving role assignment - {}", name)) + .doOnRequest(ignored -> logger.info("Retrieving role assignment - {}", roleAssignmentName)) .doOnSuccess(response -> logger.info("Retrieved role assignment - {}", response.getValue().getName())) - .doOnError(error -> logger.warning("Failed to retrieved role assignment - {}", name, error)) + .doOnError(error -> logger.warning("Failed to retrieved role assignment - {}", roleAssignmentName, error)) .map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentResponse); } catch (RuntimeException e) { return monoError(logger, e); @@ -441,58 +434,58 @@ Mono> getRoleAssignmentWithResponse(KeyVaultRol /** * Deletes a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name of the {@link KeyVaultRoleAssignment}. * @return A {@link Mono} containing the {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link String name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} or {@link String roleAssignmentName} are * {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono deleteRoleAssignment(KeyVaultRoleAssignmentScope roleScope, String name) { - return deleteRoleAssignmentWithResponse(roleScope, name).flatMap(FluxUtil::toMono); + public Mono deleteRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignmentName) { + return deleteRoleAssignmentWithResponse(roleScope, roleAssignmentName).flatMap(FluxUtil::toMono); } /** * Deletes a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name of the {@link KeyVaultRoleAssignment}. * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the * {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link String name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} or {@link String roleAssignmentName} are * {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> deleteRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, String name) { - return withContext(context -> deleteRoleAssignmentWithResponse(roleScope, name, context)); + public Mono> deleteRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName) { + return withContext(context -> deleteRoleAssignmentWithResponse(roleScope, roleAssignmentName, context)); } /** * Deletes a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name of the {@link KeyVaultRoleAssignment}. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the * {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link String name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope role scope} or {@link String roleAssignmentName} are * {@code null}. */ - Mono> deleteRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, String name, Context context) { + Mono> deleteRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, Context context) { Objects.requireNonNull(roleScope, String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), "'roleScope'")); - Objects.requireNonNull(name, + Objects.requireNonNull(roleAssignmentName, String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'name'")); + "'roleAssignmentName'")); try { return clientImpl.getRoleAssignments() - .deleteWithResponseAsync(vaultUrl, roleScope.toString(), name, context.addData(AZ_TRACING_NAMESPACE_KEY, + .deleteWithResponseAsync(vaultUrl, roleScope.toString(), roleAssignmentName, context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)) - .doOnRequest(ignored -> logger.info("Deleting role assignment - {}", name)) + .doOnRequest(ignored -> logger.info("Deleting role assignment - {}", roleAssignmentName)) .doOnSuccess(response -> logger.info("Deleted role assignment - {}", response.getValue().getName())) - .doOnError(error -> logger.warning("Failed to delete role assignment - {}", name, error)) + .doOnError(error -> logger.warning("Failed to delete role assignment - {}", roleAssignmentName, error)) .map(KeyVaultAccessControlAsyncClient::transformRoleAssignmentResponse); } catch (RuntimeException e) { return monoError(logger, e); @@ -546,7 +539,7 @@ private static KeyVaultRoleAssignment roleAssignmentToKeyVaultRoleAssignment(Rol return new KeyVaultRoleAssignment(roleAssignment.getId(), roleAssignment.getName(), roleAssignment.getType(), new KeyVaultRoleAssignmentProperties(propertiesWithScope.getRoleDefinitionId(), - propertiesWithScope.getPrincipalId()), KeyVaultRoleAssignmentScope.fromString(propertiesWithScope.getScope())); + propertiesWithScope.getPrincipalId()), KeyVaultRoleScope.fromString(propertiesWithScope.getScope())); } private static final class TransformedPagedResponse, T, U> implements PagedResponse { 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 97044d618c6a2..c8cf21bb97e5f 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 @@ -11,7 +11,7 @@ import com.azure.core.util.Context; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentScope; +import com.azure.security.keyvault.administration.models.KeyVaultRoleScope; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition; import reactor.core.publisher.Mono; @@ -47,168 +47,170 @@ public String getVaultUrl() { /** * Get all {@link KeyVaultRoleDefinition role definitions} that are applicable at the given - * {@link KeyVaultRoleAssignmentScope roleScope} and above. + * {@link KeyVaultRoleScope role scope} and above. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleDefinition role + * @param roleScope The {@link KeyVaultRoleScope roleScope} of the {@link KeyVaultRoleDefinition role * definitions}. * @return A {@link PagedIterable} containing the {@link KeyVaultRoleDefinition role definitions} for the given - * {@link KeyVaultRoleAssignmentScope roleScope}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * {@link KeyVaultRoleScope roleScope}. + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listRoleDefinitions(KeyVaultRoleAssignmentScope roleScope) { + public PagedIterable listRoleDefinitions(KeyVaultRoleScope roleScope) { return new PagedIterable<>(asyncClient.listRoleDefinitions(roleScope, Context.NONE)); } /** * Get all {@link KeyVaultRoleDefinition role definitions} that are applicable at the given - * {@link KeyVaultRoleAssignmentScope roleScope} and above. + * {@link KeyVaultRoleScope role scope} and above. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleDefinition role - * definitions}. + * @param roleScope The {@link KeyVaultRoleScope scope} of the {@link KeyVaultRoleDefinition role definitions}. * @param context Additional {@link Context} that is passed through the HTTP pipeline during the service call. * @return A {@link PagedIterable} containing the {@link KeyVaultRoleDefinition role definitions} for the given - * {@link KeyVaultRoleAssignmentScope roleScope}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * {@link KeyVaultRoleScope roleScope}. + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listRoleDefinitions(KeyVaultRoleAssignmentScope roleScope, Context context) { + public PagedIterable listRoleDefinitions(KeyVaultRoleScope roleScope, Context context) { return new PagedIterable<>(asyncClient.listRoleDefinitions(roleScope, context)); } /** * Get all {@link KeyVaultRoleAssignment role assignments} that are applicable at the given - * {@link KeyVaultRoleAssignmentScope roleScope} and above. + * {@link KeyVaultRoleScope role scope} and above. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope scope} of the {@link KeyVaultRoleAssignment}. * @return A {@link PagedIterable} containing the {@link KeyVaultRoleAssignment role assignments} for the given - * {@link KeyVaultRoleAssignmentScope roleScope}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * {@link KeyVaultRoleScope roleScope}. + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listRoleAssignments(KeyVaultRoleAssignmentScope roleScope) { + public PagedIterable listRoleAssignments(KeyVaultRoleScope roleScope) { return new PagedIterable<>(asyncClient.listRoleAssignments(roleScope, Context.NONE)); } /** * Get all {@link KeyVaultRoleAssignment role assignments} that are applicable at the given - * {@link KeyVaultRoleAssignmentScope roleScope} and above. + * {@link KeyVaultRoleScope role scope} and above. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope scope} of the {@link KeyVaultRoleAssignment}. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return A {@link PagedIterable} containing the {@link KeyVaultRoleAssignment role assignments} for the given - * {@link KeyVaultRoleAssignmentScope roleScope}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} is {@code null}. + * {@link KeyVaultRoleScope roleScope}. + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listRoleAssignments(KeyVaultRoleAssignmentScope roleScope, Context context) { + public PagedIterable listRoleAssignments(KeyVaultRoleScope roleScope, Context context) { return new PagedIterable<>(asyncClient.listRoleAssignments(roleScope, context)); } /** - * Creates a {@link KeyVaultRoleAssignment} with a randomly generated {@link UUID name}. + * Creates a {@link KeyVaultRoleAssignment} with a randomly generated {@link String name}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment} to - * create. - * @param properties Properties for the {@link KeyVaultRoleAssignment}. - * @return The created {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or - * {@link KeyVaultRoleAssignmentProperties properties} are {@code null}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment} to create. + * @param roleDefinitionId The {@link KeyVaultRoleDefinition role definition} ID for the role assignment. + * @param principalId The principal ID assigned to the role. This maps to the ID inside the Active Directory. + * @return A {@link Mono} containing the created {@link KeyVaultRoleAssignment}. + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope}, {@link String roleAssignmentName}, + * {@link String roleDefinitionId} or {@link String principalId} are {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public KeyVaultRoleAssignment createRoleAssignment(KeyVaultRoleAssignmentScope roleScope, KeyVaultRoleAssignmentProperties properties) { - return createRoleAssignmentWithResponse(roleScope, UUID.randomUUID(), properties, Context.NONE).getValue(); + public KeyVaultRoleAssignment createRoleAssignment(KeyVaultRoleScope roleScope, String roleDefinitionId, String principalId) { + return createRoleAssignmentWithResponse(roleScope, UUID.randomUUID().toString(), roleDefinitionId, principalId, + Context.NONE).getValue(); } /** * Creates a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment} to - * create. - * @param name The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. - * @param properties Properties for the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment} to create. + * @param roleAssignmentName The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. + * @param roleDefinitionId The {@link KeyVaultRoleDefinition role definition} ID for the role assignment. + * @param principalId The principal ID assigned to the role. This maps to the ID inside the Active Directory. * @return The created {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope}, {@link UUID name} or + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope}, {@link String roleAssignmentName} or * {@link KeyVaultRoleAssignmentProperties properties} are {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public KeyVaultRoleAssignment createRoleAssignment(KeyVaultRoleAssignmentScope roleScope, UUID name, KeyVaultRoleAssignmentProperties properties) { - return createRoleAssignmentWithResponse(roleScope, name, properties, Context.NONE).getValue(); + public KeyVaultRoleAssignment createRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignmentName, String roleDefinitionId, String principalId) { + return createRoleAssignmentWithResponse(roleScope, roleAssignmentName, roleDefinitionId, principalId, + Context.NONE).getValue(); } /** * Creates a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment} to - * create. - * @param name The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. - * @param properties Properties for the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment} to create. + * @param roleAssignmentName The name used to create the {@link KeyVaultRoleAssignment}. It can be any valid UUID. + * @param roleDefinitionId The {@link KeyVaultRoleDefinition role definition} ID for the role assignment. + * @param principalId The principal ID assigned to the role. This maps to the ID inside the Active Directory. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the created * {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope}, {@link UUID name} or + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope}, {@link String roleAssignmentName} or * {@link KeyVaultRoleAssignmentProperties properties} are {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response createRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, UUID name, KeyVaultRoleAssignmentProperties properties, Context context) { - return asyncClient.createRoleAssignmentWithResponse(roleScope, name, properties, context).block(); + public Response createRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, String roleDefinitionId, String principalId, Context context) { + return asyncClient.createRoleAssignmentWithResponse(roleScope, roleAssignmentName, roleDefinitionId, + principalId, context).block(); } /** * Gets a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name of the {@link KeyVaultRoleAssignment}. * @return The {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link UUID name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope} or {@link String roleAssignmentName} are * {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public KeyVaultRoleAssignment getRoleAssignment(KeyVaultRoleAssignmentScope roleScope, String name) { - return getRoleAssignmentWithResponse(roleScope, name, Context.NONE).getValue(); + public KeyVaultRoleAssignment getRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignmentName) { + return getRoleAssignmentWithResponse(roleScope, roleAssignmentName, Context.NONE).getValue(); } /** * Gets a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name of the {@link KeyVaultRoleAssignment}. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return The {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link UUID name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope} or {@link String roleAssignmentName} are * {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response getRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, String name, Context context) { - return asyncClient.getRoleAssignmentWithResponse(roleScope, name, context).block(); + public Response getRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, Context context) { + return asyncClient.getRoleAssignmentWithResponse(roleScope, roleAssignmentName, context).block(); } /** * Deletes a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name of the {@link KeyVaultRoleAssignment}. * @return The {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link UUID name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope} or {@link String roleAssignmentName} are * {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public KeyVaultRoleAssignment deleteRoleAssignment(KeyVaultRoleAssignmentScope roleScope, String name) { - return deleteRoleAssignmentWithResponse(roleScope, name, Context.NONE).getValue(); + public KeyVaultRoleAssignment deleteRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignmentName) { + return deleteRoleAssignmentWithResponse(roleScope, roleAssignmentName, Context.NONE).getValue(); } /** * Deletes a {@link KeyVaultRoleAssignment}. * - * @param roleScope The {@link KeyVaultRoleAssignmentScope roleScope} of the {@link KeyVaultRoleAssignment}. - * @param name The name of the {@link KeyVaultRoleAssignment}. + * @param roleScope The {@link KeyVaultRoleScope role scope} of the {@link KeyVaultRoleAssignment}. + * @param roleAssignmentName The name of the {@link KeyVaultRoleAssignment}. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return The {@link KeyVaultRoleAssignment}. - * @throws NullPointerException if the {@link KeyVaultRoleAssignmentScope roleScope} or {@link UUID name} are + * @throws NullPointerException if the {@link KeyVaultRoleScope roleScope} or {@link String roleAssignmentName} are * {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response deleteRoleAssignmentWithResponse(KeyVaultRoleAssignmentScope roleScope, String name, Context context) { - return asyncClient.deleteRoleAssignmentWithResponse(roleScope, name, context).block(); + public Response deleteRoleAssignmentWithResponse(KeyVaultRoleScope roleScope, String roleAssignmentName, Context context) { + return asyncClient.deleteRoleAssignmentWithResponse(roleScope, roleAssignmentName, context).block(); } } 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 98278f2d16ba7..373a6af60656b 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 @@ -74,6 +74,7 @@ public final class KeyVaultAccessControlClientBuilder { private RetryPolicy retryPolicy; private Configuration configuration; private ClientOptions clientOptions; + private KeyVaultAdministrationServiceVersion serviceVersion; /** * Creates a {@link KeyVaultAccessControlClientBuilder} instance that is able to configure and construct @@ -125,8 +126,10 @@ public KeyVaultAccessControlAsyncClient buildAsyncClient() { KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED))); } + serviceVersion = serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest(); + if (pipeline != null) { - return new KeyVaultAccessControlAsyncClient(vaultUrl, pipeline); + return new KeyVaultAccessControlAsyncClient(vaultUrl, pipeline, serviceVersion); } // Closest to API goes first, closest to wire goes last. @@ -158,7 +161,7 @@ public KeyVaultAccessControlAsyncClient buildAsyncClient() { .httpClient(httpClient) .build(); - return new KeyVaultAccessControlAsyncClient(vaultUrl, buildPipeline); + return new KeyVaultAccessControlAsyncClient(vaultUrl, buildPipeline, serviceVersion); } /** @@ -295,13 +298,28 @@ public KeyVaultAccessControlClientBuilder retryPolicy(RetryPolicy retryPolicy) { *

More About Azure Core: Telemetry policy * * @param clientOptions the {@link ClientOptions} to be set on the client. - * @return The updated KeyVaultAccessControlClientBuilder object. + * @return The updated {@link KeyVaultAccessControlClientBuilder} object. */ public KeyVaultAccessControlClientBuilder clientOptions(ClientOptions clientOptions) { this.clientOptions = clientOptions; return this; } + /** + * Sets the {@link KeyVaultAdministrationServiceVersion} that is used when making API requests. + *

+ * If a service version is not provided, the service version that will be used will be the latest known service + * version based on the version of the client library being used. If no service version is specified, updating to a + * newer version the client library will have the result of potentially moving to a newer service version. + * + * @param serviceVersion {@link KeyVaultAdministrationServiceVersion} of the service API used when making requests. + * @return The updated {@link KeyVaultAccessControlClientBuilder} object. + */ + public KeyVaultAccessControlClientBuilder serviceVersion(KeyVaultAdministrationServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + return this; + } + private URL getBuildEndpoint(Configuration configuration) { if (vaultUrl != null) { return vaultUrl; diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAdministrationServiceVersion.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAdministrationServiceVersion.java new file mode 100644 index 0000000000000..a8d4d1f74ac8e --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAdministrationServiceVersion.java @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.security.keyvault.administration; + +import com.azure.core.util.ServiceVersion; + +/** + * The versions of Azure Key Vault Administration service supported by this client library. + */ +public enum KeyVaultAdministrationServiceVersion implements ServiceVersion { + V7_2_PREVIEW("7.2-preview"); + + private final String version; + + KeyVaultAdministrationServiceVersion(String version) { + this.version = version; + } + + @Override + public String getVersion() { + return this.version; + } + + /** + * Gets the latest service version supported by this client library. + * + * @return The latest {@link KeyVaultAdministrationServiceVersion}. + */ + public static KeyVaultAdministrationServiceVersion getLatest() { + return V7_2_PREVIEW; + } +} 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 b0c011462aec5..ab170d67e7833 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 @@ -21,7 +21,6 @@ import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings; import com.azure.security.keyvault.administration.implementation.models.Error; import com.azure.security.keyvault.administration.implementation.models.FullBackupOperation; -import com.azure.security.keyvault.administration.implementation.models.KeyVaultErrorException; 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; @@ -35,6 +34,9 @@ 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; @@ -66,22 +68,28 @@ public final class KeyVaultBackupAsyncClient { private final KeyVaultBackupClientImpl clientImpl; /** - * The Kay Vault URL this client is associated to. + * The Key Vault URL this client is associated to. */ private final String vaultUrl; - Duration getDefaultPollingInterval() { + /** + * The Key Vault Administration Service version to use with this client. + */ + private final String serviceVersion; + + static Duration getDefaultPollingInterval() { return DEFAULT_POLLING_INTERVAL; } /** * Package private constructor to be used by {@link KeyVaultBackupClientBuilder}. */ - KeyVaultBackupAsyncClient(URL vaultUrl, HttpPipeline httpPipeline) { + KeyVaultBackupAsyncClient(URL vaultUrl, HttpPipeline httpPipeline, KeyVaultAdministrationServiceVersion serviceVersion) { Objects.requireNonNull(vaultUrl, KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)); this.vaultUrl = vaultUrl.toString(); + this.serviceVersion = serviceVersion.getVersion(); clientImpl = new KeyVaultBackupClientImplBuilder() .pipeline(httpPipeline) @@ -142,23 +150,26 @@ public PollerFlux beginBackup(String blobStorag * @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 PollerFlux} polling on the {@link KeyVaultBackupOperation backup operation} status. - * @throws KeyVaultErrorException if the operation is unsuccessful. */ Mono> backupWithResponse(String blobStorageUrl, String sasToken, Context context) { SASTokenParameter sasTokenParameter = new SASTokenParameter() .setStorageResourceUri(blobStorageUrl) .setToken(sasToken); - return clientImpl.fullBackupWithResponseAsync(vaultUrl, sasTokenParameter, - context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)) - .doOnRequest(ignored -> logger.info("Backing up at URL - {}", blobStorageUrl)) - .doOnSuccess(response -> logger.info("Backed up at URL - {}", - response.getValue().getAzureStorageBlobContainerUri())) - .doOnError(error -> logger.warning("Failed to backup at URL - {}", blobStorageUrl, error)) - .map(backupOperationResponse -> - new SimpleResponse<>(backupOperationResponse.getRequest(), backupOperationResponse.getStatusCode(), - backupOperationResponse.getHeaders(), - (KeyVaultBackupOperation) transformToLongRunningOperation(backupOperationResponse.getValue()))); + try { + return clientImpl.fullBackupWithResponseAsync(vaultUrl, sasTokenParameter, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)) + .doOnRequest(ignored -> logger.info("Backing up at URL - {}", blobStorageUrl)) + .doOnSuccess(response -> logger.info("Backed up at URL - {}", + response.getValue().getAzureStorageBlobContainerUri())) + .doOnError(error -> logger.warning("Failed to backup at URL - {}", blobStorageUrl, error)) + .map(backupOperationResponse -> + new SimpleResponse<>(backupOperationResponse.getRequest(), backupOperationResponse.getStatusCode(), + backupOperationResponse.getHeaders(), + (KeyVaultBackupOperation) transformToLongRunningOperation(backupOperationResponse.getValue()))); + } catch (RuntimeException e) { + return monoError(logger, e); + } } private Function, Mono> backupActivationOperation(String blobStorageUrl, String sasToken) { @@ -204,19 +215,25 @@ private Function, Mono(LongRunningOperationStatus.FAILED, null)); + } catch (RuntimeException e) { + return monoError(logger, e); } }; } private Function, Mono> backupFetchOperation() { return (pollingContext) -> { - String blobContainerUri = - pollingContext.getLatestResponse().getValue().getAzureStorageBlobContainerUri(); + try { + String blobContainerUri = + pollingContext.getLatestResponse().getValue().getAzureStorageBlobContainerUrl(); - if (blobContainerUri == null) { - return Mono.empty(); - } else { - return Mono.just(blobContainerUri); + if (blobContainerUri == null) { + return Mono.empty(); + } else { + return Mono.just(blobContainerUri); + } + } catch (RuntimeException e) { + return monoError(logger, e); } }; } @@ -242,36 +259,6 @@ private static LongRunningOperationStatus toLongRunningOperationStatus(String op } } - /** - * Gets a pending {@link KeyVaultBackupOperation backup operation} from the Key Vault. - * - * @param jobId The operation identifier. - * @throws NullPointerException if the {@code jobId} is null. - * @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PollerFlux getBackupOperation(String jobId) { - Objects.requireNonNull(jobId, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'jobId'")); - - return new PollerFlux<>(Duration.ofSeconds(1), - (pollingContext) -> Mono.empty(), - backupStatusPollOperation(jobId), - (pollingContext, firstResponse) -> Mono.error(new RuntimeException("Cancellation is not supported")), - backupFetchOperation()); - } - - private Function, Mono>> backupStatusPollOperation(String jobId) { - return (pollingContext) -> - withContext(context -> clientImpl.fullBackupStatusWithResponseAsync(vaultUrl, jobId, - context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE))) - .map(response -> - new SimpleResponse<>(response, - (KeyVaultBackupOperation) transformToLongRunningOperation(response.getValue()))) - .flatMap(KeyVaultBackupAsyncClient::processBackupOperationResponse); - } - /** * Initiates a full restore of the Key Vault. * @@ -279,7 +266,7 @@ private Function, Mono beginRestore(String backupFold * 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 pollingInterval The interval at which the operation status will be polled for. - * @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status. + * @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation restore operation} status. * @throws NullPointerException if the {@code backupFolderUrl} or {@code sasToken} are {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -323,7 +310,6 @@ public PollerFlux beginRestore(String backupFold * @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 PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status. - * @throws KeyVaultErrorException if the operation is unsuccessful. */ Mono> restoreWithResponse(String backupFolderUrl, String sasToken, Context context) { String[] segments = backupFolderUrl.split("/"); @@ -338,16 +324,22 @@ Mono> restoreWithResponse(String backupFolder .setSasTokenParameters(sasTokenParameter) .setFolderToRestore(folderName); - return clientImpl.fullRestoreOperationWithResponseAsync(vaultUrl, restoreOperationParameters, - context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)) - .doOnRequest(ignored -> logger.info("Restoring from location - {}", backupFolderUrl)) - .doOnSuccess(response -> logger.info("Restored from location - {}", backupFolderUrl)) - .doOnError(error -> - logger.warning("Failed to restore from location - {}", backupFolderUrl, error)) - .map(restoreOperationResponse -> - new SimpleResponse<>(restoreOperationResponse.getRequest(), restoreOperationResponse.getStatusCode(), - restoreOperationResponse.getHeaders(), - (KeyVaultRestoreOperation) transformToLongRunningOperation(restoreOperationResponse.getValue()))); + try { + return clientImpl.fullRestoreOperationWithResponseAsync(vaultUrl, restoreOperationParameters, + context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE)) + .doOnRequest(ignored -> logger.info("Restoring from location - {}", backupFolderUrl)) + .doOnSuccess(response -> logger.info("Restored from location - {}", backupFolderUrl)) + .doOnError(error -> + logger.warning("Failed to restore from location - {}", backupFolderUrl, error)) + .map(restoreOperationResponse -> + new SimpleResponse<>(restoreOperationResponse.getRequest(), + restoreOperationResponse.getStatusCode(), + restoreOperationResponse.getHeaders(), + (KeyVaultRestoreOperation) transformToLongRunningOperation( + restoreOperationResponse.getValue()))); + } catch (RuntimeException e) { + return monoError(logger, e); + } } private Function, Mono> restoreActivationOperation(String backupFolderUrl, String sasToken) { @@ -394,6 +386,8 @@ private Function, Mono(LongRunningOperationStatus.FAILED, null)); + } catch (RuntimeException e) { + return monoError(logger, e); } }; } @@ -405,36 +399,6 @@ private static Mono> processRestoreOperat toLongRunningOperationStatus(operationStatus.toLowerCase(Locale.US)), response.getValue())); } - /** - * Gets a pending {@link KeyVaultRestoreOperation full or selective restore operation} from the Key Vault. - * - * @param jobId The operation identifier. - * @throws NullPointerException if the {@code jobId} is null. - * @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation restore operation} status. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public PollerFlux getRestoreOperation(String jobId) { - Objects.requireNonNull(jobId, - String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED), - "'jobId'")); - - return new PollerFlux<>(Duration.ofSeconds(1), - (pollingContext) -> Mono.empty(), - restoreStatusPollOperation(jobId), - (pollingContext, firstResponse) -> Mono.error(new RuntimeException("Cancellation is not supported")), - (pollingContext) -> Mono.empty()); - } - - private Function, Mono>> restoreStatusPollOperation(String jobId) { - return (pollingContext) -> - withContext(context -> clientImpl.restoreStatusWithResponseAsync(vaultUrl, jobId, - context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE))) - .map(response -> - new SimpleResponse<>(response, - (KeyVaultRestoreOperation) transformToLongRunningOperation(response.getValue()))) - .flatMap(KeyVaultBackupAsyncClient::processRestoreOperationResponse); - } - /** * Restores all versions of a given key using the supplied SAS token pointing to a previously stored Azure Blob * storage backup folder. @@ -444,7 +408,7 @@ private Function, Mono beginSelectiveRestore(String k * 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 pollingInterval The interval at which the operation status will be polled for. - * @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status. + * @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation restore operation} status. * @throws NullPointerException if the {@code keyName}, {@code backupFolderUrl} or {@code sasToken} are {@code * null}. */ @@ -497,7 +461,6 @@ public PollerFlux beginSelectiveRestore(String k * @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 PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status. - * @throws KeyVaultErrorException if the operation is unsuccessful. */ Mono> selectiveRestoreWithResponse(String keyName, String backupFolderUrl, String sasToken, Context context) { String[] segments = backupFolderUrl.split("/"); @@ -513,19 +476,25 @@ Mono> selectiveRestoreWithResponse(String key .setSasTokenParameters(sasTokenParameter) .setFolder(folderName); - return clientImpl.selectiveKeyRestoreOperationWithResponseAsync(vaultUrl, keyName, - selectiveKeyRestoreOperationParameters, context.addData(AZ_TRACING_NAMESPACE_KEY, - KEYVAULT_TRACING_NAMESPACE_VALUE)) - .doOnRequest(ignored -> - logger.info("Restoring key \"{}\" from location - {}", keyName, backupFolderUrl)) - .doOnSuccess(response -> - logger.info("Restored key \"{}\" from location - {}", keyName, backupFolderUrl)) - .doOnError(error -> - logger.warning("Failed to restore key \"{}\" from location - {}", keyName, backupFolderUrl, error)) - .map(restoreOperationResponse -> - new SimpleResponse<>(restoreOperationResponse.getRequest(), restoreOperationResponse.getStatusCode(), - restoreOperationResponse.getHeaders(), - (KeyVaultRestoreOperation) transformToLongRunningOperation(restoreOperationResponse.getValue()))); + try { + return clientImpl.selectiveKeyRestoreOperationWithResponseAsync(vaultUrl, keyName, + selectiveKeyRestoreOperationParameters, context.addData(AZ_TRACING_NAMESPACE_KEY, + KEYVAULT_TRACING_NAMESPACE_VALUE)) + .doOnRequest(ignored -> + logger.info("Restoring key \"{}\" from location - {}", keyName, backupFolderUrl)) + .doOnSuccess(response -> + logger.info("Restored key \"{}\" from location - {}", keyName, backupFolderUrl)) + .doOnError(error -> + logger.warning("Failed to restore key \"{}\" from location - {}", keyName, backupFolderUrl, error)) + .map(restoreOperationResponse -> + new SimpleResponse<>(restoreOperationResponse.getRequest(), + restoreOperationResponse.getStatusCode(), + restoreOperationResponse.getHeaders(), + (KeyVaultRestoreOperation) transformToLongRunningOperation( + restoreOperationResponse.getValue()))); + } catch (RuntimeException e) { + return monoError(logger, e); + } } private Function, Mono> selectiveRestoreActivationOperation(String keyName, String backupFolderUrl, String sasToken) { @@ -572,6 +541,8 @@ private Function, Mono(LongRunningOperationStatus.FAILED, null)); + } catch (RuntimeException e) { + return monoError(logger, e); } }; } @@ -580,24 +551,26 @@ private static KeyVaultLongRunningOperation transformToLongRunningOperation( if (operation instanceof RestoreOperation) { RestoreOperation restoreOperation = (RestoreOperation) operation; - return new KeyVaultRestoreOperation(restoreOperation.getStatus(), - restoreOperation.getStatusDetails(), + return new KeyVaultRestoreOperation(restoreOperation.getStatus(), restoreOperation.getStatusDetails(), createKeyVaultErrorFromError(restoreOperation.getError()), restoreOperation.getJobId(), - restoreOperation.getStartTime(), restoreOperation.getEndTime()); + longToOffsetDateTime(restoreOperation.getStartTime()), + longToOffsetDateTime(restoreOperation.getEndTime())); } else if (operation instanceof SelectiveKeyRestoreOperation) { SelectiveKeyRestoreOperation selectiveKeyRestoreOperation = (SelectiveKeyRestoreOperation) operation; return new KeyVaultRestoreOperation(selectiveKeyRestoreOperation.getStatus(), selectiveKeyRestoreOperation.getStatusDetails(), createKeyVaultErrorFromError(selectiveKeyRestoreOperation.getError()), - selectiveKeyRestoreOperation.getJobId(), selectiveKeyRestoreOperation.getStartTime(), - selectiveKeyRestoreOperation.getEndTime()); + 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(), - fullBackupOperation.getStartTime(), fullBackupOperation.getEndTime(), + longToOffsetDateTime(fullBackupOperation.getStartTime()), + longToOffsetDateTime(fullBackupOperation.getEndTime()), fullBackupOperation.getAzureStorageBlobContainerUri()); } else { throw new UnsupportedOperationException(); @@ -612,4 +585,9 @@ private static KeyVaultError createKeyVaultErrorFromError(Error error) { return new KeyVaultError(error.getCode(), error.getMessage(), createKeyVaultErrorFromError(error.getInnerError())); } + + 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 63d221657edee..3f58baa9126ca 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,6 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; -import com.azure.core.util.polling.PollerFlux; import com.azure.core.util.polling.SyncPoller; import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation; import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation; @@ -66,18 +65,6 @@ public SyncPoller beginBackup(String blobStorag return asyncClient.beginBackup(blobStorageUrl, sasToken, pollingInterval).getSyncPoller(); } - /** - * Gets a pending {@link KeyVaultBackupOperation backup operation} from the Key Vault. - * - * @param jobId The operation identifier. - * @throws NullPointerException if the {@code jobId} is null. - * @return A {@link SyncPoller} to poll on the backup operation status. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public SyncPoller getBackupOperation(String jobId) { - return asyncClient.getBackupOperation(jobId).getSyncPoller(); - } - /** * Initiates a full restore of the Key Vault. * @@ -85,7 +72,7 @@ public SyncPoller getBackupOperation(String job * 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. - * @return A {@link SyncPoller} polling on the {@link KeyVaultRestoreOperation backup operation} status. + * @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status. * @throws NullPointerException if the {@code backupFolderUrl} or {@code sasToken} are {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -101,7 +88,7 @@ public SyncPoller beginRestore(String backupFold * 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 pollingInterval The interval at which the operation status will be polled for. - * @return A {@link SyncPoller} polling on the {@link KeyVaultRestoreOperation backup operation} status. + * @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status. * @throws NullPointerException if the {@code backupFolderUrl} or {@code sasToken} are {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -109,18 +96,6 @@ public SyncPoller beginRestore(String backupFold return asyncClient.beginRestore(backupFolderUrl, sasToken, pollingInterval).getSyncPoller(); } - /** - * Gets a pending {@link KeyVaultRestoreOperation full or selective restore operation} from the Key Vault. - * - * @param jobId The operation identifier. - * @throws NullPointerException if the {@code jobId} is null. - * @return A {@link SyncPoller} to poll on the restore operation status. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public SyncPoller getRestoreOperation(String jobId) { - return asyncClient.getRestoreOperation(jobId).getSyncPoller(); - } - /** * Restores all versions of a given key using the supplied SAS token pointing to a previously stored Azure Blob * storage backup folder. @@ -130,7 +105,7 @@ public SyncPoller getRestoreOperation(String job * 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. - * @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status. + * @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status. * @throws NullPointerException if the {@code keyName}, {@code backupFolderUrl} or {@code sasToken} are {@code * null}. */ @@ -149,7 +124,7 @@ public SyncPoller beginSelectiveRestore(String k * 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 pollingInterval The interval at which the operation status will be polled for. - * @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status. + * @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status. * @throws NullPointerException if the {@code keyName}, {@code backupFolderUrl} or {@code sasToken} are {@code * null}. */ 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 623e854ee85cc..5cfabc774a16c 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 @@ -73,6 +73,7 @@ public final class KeyVaultBackupClientBuilder { private RetryPolicy retryPolicy; private Configuration configuration; private ClientOptions clientOptions; + private KeyVaultAdministrationServiceVersion serviceVersion; /** * Creates a {@link KeyVaultBackupClientBuilder} instance that is able to configure and construct instances of @@ -124,8 +125,10 @@ public KeyVaultBackupAsyncClient buildAsyncClient() { KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED))); } + serviceVersion = serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest(); + if (pipeline != null) { - return new KeyVaultBackupAsyncClient(vaultUrl, pipeline); + return new KeyVaultBackupAsyncClient(vaultUrl, pipeline, serviceVersion); } // Closest to API goes first, closest to wire goes last. @@ -157,7 +160,7 @@ public KeyVaultBackupAsyncClient buildAsyncClient() { .httpClient(httpClient) .build(); - return new KeyVaultBackupAsyncClient(vaultUrl, buildPipeline); + return new KeyVaultBackupAsyncClient(vaultUrl, buildPipeline, serviceVersion); } /** @@ -295,13 +298,28 @@ public KeyVaultBackupClientBuilder retryPolicy(RetryPolicy retryPolicy) { *

More About Azure Core: Telemetry policy * * @param clientOptions the {@link ClientOptions} to be set on the client. - * @return The updated KeyVaultBackupClientBuilder object. + * @return The updated {@link KeyVaultBackupClientBuilder} object. */ public KeyVaultBackupClientBuilder clientOptions(ClientOptions clientOptions) { this.clientOptions = clientOptions; return this; } + /** + * Sets the {@link KeyVaultAdministrationServiceVersion} that is used when making API requests. + *

+ * If a service version is not provided, the service version that will be used will be the latest known service + * version based on the version of the client library being used. If no service version is specified, updating to a + * newer version the client library will have the result of potentially moving to a newer service version. + * + * @param serviceVersion {@link KeyVaultAdministrationServiceVersion} of the service API used when making requests. + * @return The updated {@link KeyVaultBackupClientBuilder} object. + */ + public KeyVaultBackupClientBuilder serviceVersion(KeyVaultAdministrationServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + return this; + } + private URL getBuildEndpoint(Configuration configuration) { if (vaultUrl != null) { return vaultUrl; diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultBackupOperation.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultBackupOperation.java index c95a5765a6aee..adb8dac2a396b 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultBackupOperation.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultBackupOperation.java @@ -3,11 +3,16 @@ package com.azure.security.keyvault.administration.models; +import com.azure.core.annotation.Immutable; + +import java.time.OffsetDateTime; + /** * A class that contains the details of a backup operation. */ +@Immutable public final class KeyVaultBackupOperation extends KeyVaultLongRunningOperation { - private final String azureStorageBlobContainerUri; + private final String azureStorageBlobContainerUrl; /** * Creates an object containing the details of a {@link KeyVaultBackupOperation}. @@ -15,14 +20,14 @@ public final class KeyVaultBackupOperation extends KeyVaultLongRunningOperation * @param status Status of the {@link KeyVaultBackupOperation}. * @param statusDetails The status details of the {@link KeyVaultBackupOperation}. * @param error Error encountered, if any, during the {@link KeyVaultBackupOperation}. - * @param startTime The start time of the {@link KeyVaultBackupOperation} in UTC. - * @param endTime The end time of the {@link KeyVaultBackupOperation} in UTC. + * @param startTime The start time of the {@link KeyVaultBackupOperation}. + * @param endTime The end time of the {@link KeyVaultBackupOperation}. * @param jobId Identifier for the full {@link KeyVaultBackupOperation}. - * @param azureStorageBlobContainerUri The Azure blob storage container URI which contains the backup. + * @param azureStorageBlobContainerUrl The Azure blob storage container URI which contains the backup. */ - public KeyVaultBackupOperation(String status, String statusDetails, KeyVaultError error, String jobId, Long startTime, Long endTime, String azureStorageBlobContainerUri) { + public KeyVaultBackupOperation(String status, String statusDetails, KeyVaultError error, String jobId, OffsetDateTime startTime, OffsetDateTime endTime, String azureStorageBlobContainerUrl) { super(status, statusDetails, error, jobId, startTime, endTime); - this.azureStorageBlobContainerUri = azureStorageBlobContainerUri; + this.azureStorageBlobContainerUrl = azureStorageBlobContainerUrl; } /** @@ -30,7 +35,7 @@ public KeyVaultBackupOperation(String status, String statusDetails, KeyVaultErro * * @return The backup URI in {@link String} form. */ - public String getAzureStorageBlobContainerUri() { - return azureStorageBlobContainerUri; + public String getAzureStorageBlobContainerUrl() { + return azureStorageBlobContainerUrl; } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultError.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultError.java index 16f98eba519ad..a57d6aeeaf74e 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultError.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultError.java @@ -3,9 +3,12 @@ package com.azure.security.keyvault.administration.models; +import com.azure.core.annotation.Immutable; + /** * A class that represents an error occurred in a Key Vault operation. */ +@Immutable public final class KeyVaultError { private final String code; private final String message; diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultLongRunningOperation.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultLongRunningOperation.java index 0c39d6ed4231f..d4696456175c7 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultLongRunningOperation.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultLongRunningOperation.java @@ -3,16 +3,21 @@ package com.azure.security.keyvault.administration.models; +import com.azure.core.annotation.Immutable; + +import java.time.OffsetDateTime; + /** * A class that contains the details of a long running operation. */ +@Immutable public class KeyVaultLongRunningOperation { private final String status; private final String statusDetails; private final KeyVaultError error; private final String jobId; - private final Long startTime; - private final Long endTime; + private final OffsetDateTime startTime; + private final OffsetDateTime endTime; /** * Creates an object containing the details of a {@link KeyVaultLongRunningOperation}. @@ -20,11 +25,11 @@ public class KeyVaultLongRunningOperation { * @param status Status of the {@link KeyVaultLongRunningOperation}. * @param statusDetails The status details of the {@link KeyVaultLongRunningOperation}. * @param error Error encountered, if any, during the {@link KeyVaultLongRunningOperation}. - * @param startTime The start time of the {@link KeyVaultLongRunningOperation} in UTC. - * @param endTime The end time of the {@link KeyVaultLongRunningOperation} in UTC. + * @param startTime The start time of the {@link KeyVaultLongRunningOperation}. + * @param endTime The end time of the {@link KeyVaultLongRunningOperation}. * @param jobId Identifier for the full {@link KeyVaultLongRunningOperation}. */ - public KeyVaultLongRunningOperation(String status, String statusDetails, KeyVaultError error, String jobId, Long startTime, Long endTime) { + public KeyVaultLongRunningOperation(String status, String statusDetails, KeyVaultError error, String jobId, OffsetDateTime startTime, OffsetDateTime endTime) { this.status = status; this.statusDetails = statusDetails; this.error = error; @@ -61,20 +66,20 @@ public KeyVaultError getError() { } /** - * Get the start time of the {@link KeyVaultLongRunningOperation} in UTC. + * Get the start time of the {@link KeyVaultLongRunningOperation}. * - * @return The start time in UTC. + * @return The start time. */ - public Long getStartTime() { + public OffsetDateTime getStartTime() { return startTime; } /** - * Get the end time of the {@link KeyVaultLongRunningOperation} in UTC. + * Get the end time of the {@link KeyVaultLongRunningOperation}. * - * @return The end time in UTC. + * @return The end time. */ - public Long getEndTime() { + public OffsetDateTime getEndTime() { return endTime; } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultPermission.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultPermission.java index 4ab5eaa738342..7bcae4cdb6f35 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultPermission.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultPermission.java @@ -3,29 +3,32 @@ package com.azure.security.keyvault.administration.models; +import com.azure.core.annotation.Immutable; + import java.util.List; /** * A class describing allowed and denied actions and data actions of a {@link KeyVaultRoleDefinition}. */ +@Immutable public final class KeyVaultPermission { - private final List actions; + private final List allowedActions; private final List deniedActions; - private final List dataActions; + private final List allowedDataActions; private final List deniedDataActions; /** * Creates a new {@link KeyVaultPermission} with the specified allowed and denied actions and data actions. * - * @param actions The actions this {@link KeyVaultPermission permission} allows. + * @param allowedActions The actions this {@link KeyVaultPermission permission} allows. * @param deniedActions The actions this {@link KeyVaultPermission permission} denies. - * @param dataActions The data actions this {@link KeyVaultPermission permission} allows. + * @param allowedDataActions The data actions this {@link KeyVaultPermission permission} allows. * @param deniedDataActions The data actions this {@link KeyVaultPermission permission} denies. */ - public KeyVaultPermission(List actions, List deniedActions, List dataActions, List deniedDataActions) { - this.actions = actions; + public KeyVaultPermission(List allowedActions, List deniedActions, List allowedDataActions, List deniedDataActions) { + this.allowedActions = allowedActions; this.deniedActions = deniedActions; - this.dataActions = dataActions; + this.allowedDataActions = allowedDataActions; this.deniedDataActions = deniedDataActions; } @@ -34,8 +37,8 @@ public KeyVaultPermission(List actions, List deniedActions, List * * @return The allowed actions. */ - public List getActions() { - return actions; + public List getAllowedActions() { + return allowedActions; } /** @@ -52,8 +55,8 @@ public List getDeniedActions() { * * @return The allowed data actions. */ - public List getDataActions() { - return dataActions; + public List getAllowedDataActions() { + return allowedDataActions; } /** diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRestoreOperation.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRestoreOperation.java index 3949c121d48d9..a7e0d38575883 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRestoreOperation.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRestoreOperation.java @@ -3,9 +3,14 @@ package com.azure.security.keyvault.administration.models; +import com.azure.core.annotation.Immutable; + +import java.time.OffsetDateTime; + /** * A class that contains the details of a restore operation. */ +@Immutable public final class KeyVaultRestoreOperation extends KeyVaultLongRunningOperation { /** * Creates an object containing the details of a {@link KeyVaultRestoreOperation}. @@ -13,11 +18,11 @@ public final class KeyVaultRestoreOperation extends KeyVaultLongRunningOperation * @param status Status of the {@link KeyVaultRestoreOperation}. * @param statusDetails The status details of the {@link KeyVaultRestoreOperation}. * @param error Error encountered, if any, during the {@link KeyVaultRestoreOperation}. - * @param startTime The start time of the {@link KeyVaultRestoreOperation} in UTC. - * @param endTime The end time of the {@link KeyVaultRestoreOperation} in UTC. + * @param startTime The start time of the {@link KeyVaultRestoreOperation}. + * @param endTime The end time of the {@link KeyVaultRestoreOperation}. * @param jobId Identifier for the full {@link KeyVaultRestoreOperation}. */ - public KeyVaultRestoreOperation(String status, String statusDetails, KeyVaultError error, String jobId, Long startTime, Long endTime) { + public KeyVaultRestoreOperation(String status, String statusDetails, KeyVaultError error, String jobId, OffsetDateTime startTime, OffsetDateTime endTime) { super(status, statusDetails, error, jobId, startTime, endTime); } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignment.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignment.java index bf4cc805e1c41..b6f12bb48272e 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignment.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignment.java @@ -3,15 +3,18 @@ package com.azure.security.keyvault.administration.models; +import com.azure.core.annotation.Immutable; + /** * A class that defines a role assignment. */ +@Immutable public final class KeyVaultRoleAssignment { private final String id; private final String name; private final String type; private final KeyVaultRoleAssignmentProperties properties; - private final KeyVaultRoleAssignmentScope scope; + private final KeyVaultRoleScope roleScope; /** * Creates a new {@link KeyVaultRoleAssignment role assignment} with the specified details. @@ -21,15 +24,14 @@ public final class KeyVaultRoleAssignment { * @param type The type of this {@link KeyVaultRoleAssignment role assignment}. * @param properties {@link KeyVaultRoleAssignmentProperties properties} of this {@link KeyVaultRoleAssignment * role assignment}. - * @param roleScope The {@link KeyVaultRoleAssignmentScope scope} of this {@link KeyVaultRoleAssignment role - * assignment}. + * @param roleScope The {@link KeyVaultRoleScope scope} of this {@link KeyVaultRoleAssignment role assignment}. */ - public KeyVaultRoleAssignment(String id, String name, String type, KeyVaultRoleAssignmentProperties properties, KeyVaultRoleAssignmentScope roleScope) { + public KeyVaultRoleAssignment(String id, String name, String type, KeyVaultRoleAssignmentProperties properties, KeyVaultRoleScope roleScope) { this.id = id; this.name = name; this.type = type; this.properties = properties; - this.scope = roleScope; + this.roleScope = roleScope; } /** @@ -69,11 +71,11 @@ public KeyVaultRoleAssignmentProperties getProperties() { } /** - * Get the {@link KeyVaultRoleAssignment role assignment} {@link KeyVaultRoleAssignmentScope scope}. + * Get the {@link KeyVaultRoleAssignment role assignment} {@link KeyVaultRoleScope scope}. * - * @return The {@link KeyVaultRoleAssignment role assignment} {@link KeyVaultRoleAssignmentScope scope}. + * @return The {@link KeyVaultRoleAssignment role assignment} {@link KeyVaultRoleScope scope}. */ - public KeyVaultRoleAssignmentScope getScope() { - return scope; + public KeyVaultRoleScope getRoleScope() { + return roleScope; } } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignmentProperties.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignmentProperties.java index b35c645231664..a8c7be118cf2b 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignmentProperties.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignmentProperties.java @@ -3,6 +3,7 @@ package com.azure.security.keyvault.administration.models; +import com.azure.core.annotation.Immutable; import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings; import java.util.Objects; @@ -10,6 +11,7 @@ /** * A class that defines a role assignment's properties. */ +@Immutable public final class KeyVaultRoleAssignmentProperties { private final String roleDefinitionId; private final String principalId; diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignmentScope.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignmentScope.java deleted file mode 100644 index 0356d3fde614f..0000000000000 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleAssignmentScope.java +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.security.keyvault.administration.models; - -import com.azure.core.util.ExpandableStringEnum; - -import java.net.URI; - -/** - * A class that defines the scope of a role. - */ -public final class KeyVaultRoleAssignmentScope extends ExpandableStringEnum { - public static final KeyVaultRoleAssignmentScope GLOBAL = fromString("/"); - public static final KeyVaultRoleAssignmentScope KEYS = fromString("/keys"); - - /** - * Creates or finds a {@link KeyVaultRoleAssignmentScope} from its string representation. - * - * @param name A name to look for. - * @return The corresponding {@link KeyVaultRoleAssignmentScope} - */ - public static KeyVaultRoleAssignmentScope fromString(String name) { - return fromString(name, KeyVaultRoleAssignmentScope.class); - } - - /** - * Creates or finds a {@link KeyVaultRoleAssignmentScope} from its string representation. - * - * @param uri A URI to look for. - * @return The corresponding {@link KeyVaultRoleAssignmentScope} - */ - public static KeyVaultRoleAssignmentScope fromUri(URI uri) { - return fromString(uri.getRawPath(), KeyVaultRoleAssignmentScope.class); - } -} diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleDefinition.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleDefinition.java index 832e29fc587ec..8e5ff31250ada 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleDefinition.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleDefinition.java @@ -3,9 +3,12 @@ package com.azure.security.keyvault.administration.models; +import com.azure.core.annotation.Immutable; + /** * A class that defines a role. */ +@Immutable public final class KeyVaultRoleDefinition { private final String id; private final String name; diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleDefinitionProperties.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleDefinitionProperties.java index fb71bfa77954f..219e35cd60fcc 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleDefinitionProperties.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleDefinitionProperties.java @@ -3,11 +3,14 @@ package com.azure.security.keyvault.administration.models; +import com.azure.core.annotation.Immutable; + import java.util.List; /** * A class that defines a role definition's properties. */ +@Immutable public final class KeyVaultRoleDefinitionProperties { private final String roleName; private final String description; @@ -22,8 +25,8 @@ public final class KeyVaultRoleDefinitionProperties { * @param roleName The name of the role. * @param roleDescription The description of the role. * @param roleType The type of the role. - * @param permissions The {@link KeyVaultPermission permissions} the {@link KeyVaultRoleDefinition role - * definition} has. + * @param permissions The {@link KeyVaultPermission permissions} the {@link KeyVaultRoleDefinition role definition} + * has. * @param assignableScopes The assignable scopes of the {@link KeyVaultRoleDefinition role definition}. */ public KeyVaultRoleDefinitionProperties(String roleName, String roleDescription, String roleType, List permissions, List assignableScopes) { diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleScope.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleScope.java new file mode 100644 index 0000000000000..ae654c7dda0dd --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/models/KeyVaultRoleScope.java @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.security.keyvault.administration.models; + +import com.azure.core.util.ExpandableStringEnum; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * A class that defines the scope of a role. + */ +public final class KeyVaultRoleScope extends ExpandableStringEnum { + public static final KeyVaultRoleScope GLOBAL = fromString("/"); + public static final KeyVaultRoleScope KEYS = fromString("/keys"); + + /** + * Creates or finds a {@link KeyVaultRoleScope} from its string representation. + * + * @param name A name to look for. + * @return The corresponding {@link KeyVaultRoleScope}. + */ + public static KeyVaultRoleScope fromString(String name) { + return fromString(name, KeyVaultRoleScope.class); + } + + /** + * Creates or finds a {@link KeyVaultRoleScope} from its string representation. + * + * @param url A string representing a URL containing the name of the scope to look for. + * @return The corresponding {@link KeyVaultRoleScope}. + * @throws MalformedURLException If the given {@link String URL String} is malformed. + */ + public static KeyVaultRoleScope fromUrl(String url) throws MalformedURLException { + return fromString(new URL(url).getPath(), KeyVaultRoleScope.class); + } + + /** + * Creates or finds a {@link KeyVaultRoleScope} from its string representation. + * + * @param url A URL containing the name of the scope to look for. + * @return The corresponding {@link KeyVaultRoleScope}. + */ + public static KeyVaultRoleScope fromUrl(URL url) { + return fromString(url.getPath(), KeyVaultRoleScope.class); + } +} diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/module-info.java b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/module-info.java index 8bd509800fd72..b774368e84470 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/main/java/module-info.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/main/java/module-info.java @@ -6,8 +6,8 @@ exports com.azure.security.keyvault.administration; exports com.azure.security.keyvault.administration.models; - exports com.azure.security.keyvault.administration.implementation; - exports com.azure.security.keyvault.administration.implementation.models; + + exports com.azure.security.keyvault.administration.implementation.models to com.azure.core; opens com.azure.security.keyvault.administration to com.fasterxml.jackson.databind; opens com.azure.security.keyvault.administration.models to com.fasterxml.jackson.databind; diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/AccessControlHelloWorld.java b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/AccessControlHelloWorld.java index e8063d4ee061e..6870ea6f34f63 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/AccessControlHelloWorld.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/AccessControlHelloWorld.java @@ -5,8 +5,7 @@ import com.azure.identity.DefaultAzureCredentialBuilder; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentScope; +import com.azure.security.keyvault.administration.models.KeyVaultRoleScope; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition; import java.util.ArrayList; @@ -38,13 +37,13 @@ public static void main(String[] args) { Let's get all of them. */ List roleDefinitions = new ArrayList<>(); - for (KeyVaultRoleDefinition roleDefinition : accessControlClient.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL)) { + for (KeyVaultRoleDefinition roleDefinition : accessControlClient.listRoleDefinitions(KeyVaultRoleScope.GLOBAL)) { roleDefinitions.add(roleDefinition); System.out.printf("Retrieved role definition with name: %s %n", roleDefinition.getName()); } // Before assigning any new roles, let's list all the current role assignments. - for (KeyVaultRoleAssignment roleAssignment : accessControlClient.listRoleAssignments(KeyVaultRoleAssignmentScope.GLOBAL)) { + for (KeyVaultRoleAssignment roleAssignment : accessControlClient.listRoleAssignments(KeyVaultRoleScope.GLOBAL)) { System.out.printf("Retrieved role assignment with name: %s %n", roleAssignment.getName()); } @@ -58,24 +57,23 @@ See the README (https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/keyv az ad signed-in-user show --query objectId */ String servicePrincipalId = ""; KeyVaultRoleDefinition roleDefinition = roleDefinitions.get(0); - KeyVaultRoleAssignmentProperties assignmentProperties = - new KeyVaultRoleAssignmentProperties(roleDefinition.getId(), servicePrincipalId); KeyVaultRoleAssignment createdRoleAssignment = - accessControlClient.createRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, assignmentProperties); + accessControlClient.createRoleAssignment(KeyVaultRoleScope.GLOBAL, roleDefinition.getId(), + servicePrincipalId); System.out.printf("Created role assignment with name: %s %n", createdRoleAssignment.getName()); /* To get an existing role assignment, we'll need the 'name' property from an existing assignment. Let's use the createdAssignment from the previous example. */ KeyVaultRoleAssignment retrievedRoleAssignment = - accessControlClient.getRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, createdRoleAssignment.getName()); + accessControlClient.getRoleAssignment(KeyVaultRoleScope.GLOBAL, createdRoleAssignment.getName()); System.out.printf("Retrieved role assignment with name: %s %n", retrievedRoleAssignment.getName()); /* To remove a role assignment from a service principal, the role assignment must be deleted. Let's delete the createdAssignment from the previous example. */ KeyVaultRoleAssignment deletedRoleAssignment = - accessControlClient.deleteRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, createdRoleAssignment.getName()); + accessControlClient.deleteRoleAssignment(KeyVaultRoleScope.GLOBAL, createdRoleAssignment.getName()); System.out.printf("Deleted role assignment with name: %s %n", deletedRoleAssignment.getName()); } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/AccessControlHelloWorldAsync.java b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/AccessControlHelloWorldAsync.java index 522efde9d02b3..c66d4004a243c 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/AccessControlHelloWorldAsync.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/AccessControlHelloWorldAsync.java @@ -5,8 +5,7 @@ import com.azure.identity.DefaultAzureCredentialBuilder; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentScope; +import com.azure.security.keyvault.administration.models.KeyVaultRoleScope; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition; import java.util.ArrayList; @@ -38,7 +37,7 @@ public static void main(String[] args) throws InterruptedException { Let's get all of them. */ List roleDefinitions = new ArrayList<>(); - accessControlAsyncClient.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL) + accessControlAsyncClient.listRoleDefinitions(KeyVaultRoleScope.GLOBAL) .doOnNext((roleDefinition) -> { roleDefinitions.add(roleDefinition); System.out.printf("Retrieved role definition with name: %s %n", roleDefinition.getName()); @@ -46,7 +45,7 @@ public static void main(String[] args) throws InterruptedException { .blockLast(); // Before assigning any new roles, let's get all the current role assignments. - accessControlAsyncClient.listRoleAssignments(KeyVaultRoleAssignmentScope.GLOBAL) + accessControlAsyncClient.listRoleAssignments(KeyVaultRoleScope.GLOBAL) .doOnNext((roleAssignment -> System.out.printf("Retrieved role assignment with name: %s %n", roleAssignment.getName()))) .blockLast(); @@ -61,24 +60,22 @@ See the README (https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/keyv az ad signed-in-user show --query objectId */ String servicePrincipalId = ""; KeyVaultRoleDefinition roleDefinition = roleDefinitions.get(0); - KeyVaultRoleAssignmentProperties assignmentProperties = - new KeyVaultRoleAssignmentProperties(roleDefinition.getId(), servicePrincipalId); KeyVaultRoleAssignment createdRoleAssignment = - accessControlAsyncClient.createRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, assignmentProperties) - .block(); + accessControlAsyncClient.createRoleAssignment(KeyVaultRoleScope.GLOBAL, roleDefinition.getId(), + servicePrincipalId).block(); /* To get an existing role assignment, we'll need the 'name' property from an existing assignment. Let's use the createdAssignment from the previous example. */ assert createdRoleAssignment != null; - accessControlAsyncClient.getRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, createdRoleAssignment.getName()) + accessControlAsyncClient.getRoleAssignment(KeyVaultRoleScope.GLOBAL, createdRoleAssignment.getName()) .doOnSuccess((retrievedRoleAssignment) -> System.out.printf("Retrieved role assignment with name: %s %n", retrievedRoleAssignment.getName())) .block(); /* To remove a role assignment from a service principal, the role assignment must be deleted. Let's delete the createdAssignment from the previous example. */ - accessControlAsyncClient.deleteRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, createdRoleAssignment.getName()) + accessControlAsyncClient.deleteRoleAssignment(KeyVaultRoleScope.GLOBAL, createdRoleAssignment.getName()) .doOnSuccess((deletedRoleAssignment) -> System.out.printf("Retrieved role assignment with name: %s %n", deletedRoleAssignment.getName())) .block(); diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/BackupAndRestoreHelloWorldAsync.java b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/BackupAndRestoreHelloWorldAsync.java index ecb06400cdd6b..9f658cbb68105 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/BackupAndRestoreHelloWorldAsync.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/BackupAndRestoreHelloWorldAsync.java @@ -17,7 +17,7 @@ public class BackupAndRestoreHelloWorldAsync { * @param args Unused. Arguments to the program. * @throws IllegalArgumentException when an invalid key vault URL is passed. */ - public static void main(String[] args) throws InterruptedException { + public static void main(String[] args) { /* Instantiate a KeyVaultAccessControlClient that will be used to call the service. Notice that the client is using default Azure credentials. To make default credentials work, ensure that environment variables 'AZURE_CLIENT_ID', 'AZURE_CLIENT_KEY' and 'AZURE_TENANT_ID' are set with the service principal credentials. @@ -47,7 +47,7 @@ Alternatively, it is possible to generate a SAS token in Storage Explorer (https /* Now let's restore the entire collection of keys from the backup. We will need the get the URI for the location the backup, as well as Shared Access Signature for accessing it. */ - String backupFolderUrl = backupPollResponse.getValue().getAzureStorageBlobContainerUri(); + String backupFolderUrl = backupPollResponse.getValue().getAzureStorageBlobContainerUrl(); backupAsyncClient.beginRestore(backupFolderUrl, sasToken).blockLast(); diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/CreateRoleAssignmentsForDifferentScopes.java b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/CreateRoleAssignmentsForDifferentScopes.java index c604e48ac445d..d3a456822c0f9 100644 --- a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/CreateRoleAssignmentsForDifferentScopes.java +++ b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/CreateRoleAssignmentsForDifferentScopes.java @@ -5,8 +5,7 @@ import com.azure.identity.DefaultAzureCredentialBuilder; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentScope; +import com.azure.security.keyvault.administration.models.KeyVaultRoleScope; /** * This sample demonstrates how to create role assignments in the key vault for different scopes. @@ -42,11 +41,8 @@ of the role definitions returned from listRoleDefinitions(). Alternatively, you String roleDefinitionId = ""; String servicePrincipalId = ""; - KeyVaultRoleAssignmentProperties roleAssignmentProperties = - new KeyVaultRoleAssignmentProperties(roleDefinitionId, servicePrincipalId); - KeyVaultRoleAssignment roleAssignmentForAllKeys = - accessControlClient.createRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentProperties); + accessControlClient.createRoleAssignment(KeyVaultRoleScope.GLOBAL, roleDefinitionId, servicePrincipalId); System.out.printf("Created role assignment with name: %s %n", roleAssignmentForAllKeys.getName()); @@ -56,8 +52,8 @@ of the role definitions returned from listRoleDefinitions(). Alternatively, you String keyId = ""; KeyVaultRoleAssignment roleAssignmentForSingleKey = - accessControlClient.createRoleAssignment(KeyVaultRoleAssignmentScope.fromString(keyId), - roleAssignmentProperties); + accessControlClient.createRoleAssignment(KeyVaultRoleScope.fromString(keyId), roleDefinitionId, + servicePrincipalId); System.out.printf("Created role assignment with name: %s %n", roleAssignmentForSingleKey.getName()); } diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/ResumeBackupAndRestore.java b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/ResumeBackupAndRestore.java deleted file mode 100644 index c9f91e4d6b12e..0000000000000 --- a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/ResumeBackupAndRestore.java +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.security.keyvault.administration; - -import com.azure.core.util.polling.SyncPoller; -import com.azure.identity.DefaultAzureCredentialBuilder; -import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation; -import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation; - -/** - * This sample demonstrates how to selectively restore a key from key vault backup synchronously. - */ -public class ResumeBackupAndRestore { - /** - * Authenticates with the key vault and shows how to re-hydrate long running synchronous operations such as backup - * and restore. - * - * @param args Unused. Arguments to the program. - * @throws IllegalArgumentException when an invalid key vault URL is passed. - */ - public static void main(String[] args) { - /* Instantiate a KeyVaultAccessControlClient that will be used to call the service. Notice that the client is - using default Azure credentials. To make default credentials work, ensure that environment variables - 'AZURE_CLIENT_ID', 'AZURE_CLIENT_KEY' and 'AZURE_TENANT_ID' are set with the service principal credentials. - - To get started, you'll need a URI to an Azure Key Vault. See the README (https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/keyvault/azure-security-keyvault-administration/README.md) - for links and instructions. */ - KeyVaultBackupClient backupClient = new KeyVaultBackupClientBuilder() - .vaultUrl("https://{YOUR_VAULT_NAME}.vault.azure.net") - .credential(new DefaultAzureCredentialBuilder().build()) - .buildClient(); - - /* The ID from a started backup operation on one client can be saved to persistent storage instead of waiting - for completion immediately. */ - String blobStorageUrl = ""; - String sasToken = ""; - - SyncPoller originalBackupPoller = - backupClient.beginBackup(blobStorageUrl, sasToken); - - KeyVaultBackupOperation originalBackupOperation = originalBackupPoller.poll().getValue(); - String backupJobId = originalBackupOperation.getJobId(); - - /* At some later time, another client can use the persisted operation ID, check the status and retrieve the - result of a previously started backup operation. */ - SyncPoller anotherBackupPoller = - backupClient.getBackupOperation(backupJobId); - - anotherBackupPoller.waitForCompletion(); - - // Get the backup URL to begin a restore operation at some point. - String backupFolderUrl = anotherBackupPoller.getFinalResult(); - - SyncPoller originalRestorePoller = - backupClient.beginRestore(backupFolderUrl, sasToken); - - KeyVaultRestoreOperation originalRestoreOperation = originalRestorePoller.poll().getValue(); - String restoreJobId = originalRestoreOperation.getJobId(); - - /* Similarly to as with backup operations, you can check the status and retrieve the result of a previously - started restore operation. */ - SyncPoller anotherRestorePoller = - backupClient.getRestoreOperation(restoreJobId); - - anotherRestorePoller.waitForCompletion(); - } -} diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/ResumeBackupAndRestoreAsync.java b/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/ResumeBackupAndRestoreAsync.java deleted file mode 100644 index e2b0c2e6dea79..0000000000000 --- a/sdk/keyvault/azure-security-keyvault-administration/src/samples/java/com.azure.security.keyvault.administration/ResumeBackupAndRestoreAsync.java +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.security.keyvault.administration; - -import com.azure.core.util.polling.AsyncPollResponse; -import com.azure.core.util.polling.PollerFlux; -import com.azure.identity.DefaultAzureCredentialBuilder; -import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation; -import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation; -import reactor.core.publisher.Mono; - -/** - * This sample demonstrates how to selectively restore a key from key vault backup asynchronously. - */ -public class ResumeBackupAndRestoreAsync { - /** - * Authenticates with the key vault and shows how to re-hydrate long running asynchronous operations such as backup - * and restore. - * - * @param args Unused. Arguments to the program. - * @throws IllegalArgumentException when an invalid key vault URL is passed. - */ - public static void main(String[] args) { - /* Instantiate a KeyVaultAccessControlClient that will be used to call the service. Notice that the client is - using default Azure credentials. To make default credentials work, ensure that environment variables - 'AZURE_CLIENT_ID', 'AZURE_CLIENT_KEY' and 'AZURE_TENANT_ID' are set with the service principal credentials. - - To get started, you'll need a URI to an Azure Key Vault. See the README (https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/keyvault/azure-security-keyvault-administration/README.md) - for links and instructions. */ - KeyVaultBackupAsyncClient backupAsyncClient = new KeyVaultBackupClientBuilder() - .vaultUrl("https://{YOUR_VAULT_NAME}.vault.azure.net") - .credential(new DefaultAzureCredentialBuilder().build()) - .buildAsyncClient(); - - /* The ID from a started backup operation on one client can be saved to persistent storage instead of waiting - for completion immediately. */ - String blobStorageUrl = ""; - String sasToken = ""; - - PollerFlux originalBackupPollerFlux = - backupAsyncClient.beginBackup(blobStorageUrl, sasToken); - - String backupJobId = originalBackupPollerFlux.blockFirst().getValue().getJobId(); - - /* At some later time, another client can use the persisted operation ID, check the status and retrieve the - result of a previously started backup operation. */ - Mono> backupMono = - backupAsyncClient.getBackupOperation(backupJobId) - .doOnNext(pollResponse -> { - System.out.println("-----------------------------------------------------------------------------"); - System.out.println(pollResponse.getStatus()); - System.out.println(pollResponse.getValue().getStatus()); - System.out.println(pollResponse.getValue().getStatusDetails()); - }) - .last(); - - // Get the backup URI to begin a restore operation at some point. - String backupFolderUrl = backupMono.block().getValue().getAzureStorageBlobContainerUri(); - - PollerFlux originalRestorePollerFlux = - backupAsyncClient.beginRestore(backupFolderUrl, sasToken); - - String restoreJobId = originalRestorePollerFlux.blockFirst().getValue().getJobId(); - - /* Similarly to as with backup operations, you can check the status and retrieve the result of a previously - started restore operation. */ - backupAsyncClient.getRestoreOperation(restoreJobId) - .doOnNext(pollResponse -> { - System.out.println("-----------------------------------------------------------------------------"); - System.out.println(pollResponse.getStatus()); - System.out.println(pollResponse.getValue().getStatus()); - System.out.println(pollResponse.getValue().getStatusDetails()); - }) - .blockLast(); - - /* NOTE: block(), blockFirst() and blockLast() will block until all the above operations on are completed. This - is strongly discouraged for use in production as it eliminates the benefits of asynchronous IO. It is used here - for the sake of explaining where to get the jobId and backupFolderUrl parameters and to ensure the sample runs - to completion. */ - } -} 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 42638b8dec3a8..3b552f831dde1 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 @@ -7,7 +7,7 @@ import com.azure.core.test.TestMode; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentScope; +import com.azure.security.keyvault.administration.models.KeyVaultRoleScope; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinitionProperties; import org.junit.jupiter.params.ParameterizedTest; @@ -15,9 +15,11 @@ import java.util.ArrayList; import java.util.List; -import java.util.UUID; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class KeyVaultAccessControlAsyncClientTest extends KeyVaultAccessControlClientTestBase { private KeyVaultAccessControlAsyncClient asyncClient; @@ -43,7 +45,7 @@ public void listRoleDefinitions(HttpClient httpClient) { List roleDefinitions = new ArrayList<>(); - asyncClient.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL).subscribe(roleDefinitions::add); + asyncClient.listRoleDefinitions(KeyVaultRoleScope.GLOBAL).subscribe(roleDefinitions::add); assertTrue(roleDefinitions.iterator().hasNext()); @@ -79,7 +81,7 @@ public void listRoleAssignments(HttpClient httpClient) { List roleAssignments = new ArrayList<>(); - asyncClient.listRoleAssignments(KeyVaultRoleAssignmentScope.GLOBAL).subscribe(roleAssignments::add); + asyncClient.listRoleAssignments(KeyVaultRoleScope.GLOBAL).subscribe(roleAssignments::add); sleepInLiveOrRecordMode(5000); for (KeyVaultRoleAssignment roleAssignment : roleAssignments) { @@ -111,7 +113,7 @@ public void createRoleAssignment(HttpClient httpClient) { List roleDefinitions = new ArrayList<>(); - asyncClient.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL).subscribe(roleDefinitions::add); + asyncClient.listRoleDefinitions(KeyVaultRoleScope.GLOBAL).subscribe(roleDefinitions::add); sleepInLiveOrRecordMode(5000); KeyVaultRoleDefinition roleDefinition = null; @@ -124,33 +126,31 @@ public void createRoleAssignment(HttpClient httpClient) { assertNotNull(roleDefinition); - UUID roleAssignmentName = UUID.fromString("d0bedeb4-7431-407d-81cd-278929c98218"); - KeyVaultRoleAssignmentProperties creationProperties = - new KeyVaultRoleAssignmentProperties(roleDefinition.getId(), clientId); + String roleAssignmentName = "d0bedeb4-7431-407d-81cd-278929c98218"; try { // Create a role assignment. KeyVaultRoleAssignment roleAssignment = - asyncClient.createRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName, - creationProperties).block(); + asyncClient.createRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName, roleDefinition.getId(), + clientId).block(); assertNotNull(roleAssignment); assertNotNull(roleAssignment.getId()); - assertEquals(roleAssignment.getName(), roleAssignmentName.toString()); + assertEquals(roleAssignment.getName(), roleAssignmentName); assertNotNull(roleAssignment.getType()); - assertNotNull(roleAssignment.getScope()); + assertNotNull(roleAssignment.getRoleScope()); KeyVaultRoleAssignmentProperties properties = roleAssignment.getProperties(); assertNotNull(properties); - assertEquals(creationProperties.getPrincipalId(), properties.getPrincipalId()); - assertEquals(creationProperties.getRoleDefinitionId(), properties.getRoleDefinitionId()); + assertEquals(clientId, properties.getPrincipalId()); + assertEquals(roleDefinition.getId(), properties.getRoleDefinitionId()); } finally { if (getTestMode() != TestMode.PLAYBACK) { // Clean up the role assignment. KeyVaultAccessControlAsyncClient cleanupClient = getClientBuilder(httpClient, true).buildAsyncClient(); - cleanupClient.deleteRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName.toString()); + cleanupClient.deleteRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName); } } } @@ -171,7 +171,7 @@ public void getRoleAssignment(HttpClient httpClient) { List roleDefinitions = new ArrayList<>(); - asyncClient.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL).subscribe(roleDefinitions::add); + asyncClient.listRoleDefinitions(KeyVaultRoleScope.GLOBAL).subscribe(roleDefinitions::add); sleepInLiveOrRecordMode(5000); KeyVaultRoleDefinition roleDefinition = null; @@ -184,40 +184,38 @@ public void getRoleAssignment(HttpClient httpClient) { assertNotNull(roleDefinition); - UUID roleAssignmentName = UUID.fromString("658d6c14-98c2-4a53-a523-be8609eb7f8b"); - KeyVaultRoleAssignmentProperties creationProperties = - new KeyVaultRoleAssignmentProperties(roleDefinition.getId(), clientId); + String roleAssignmentName = "658d6c14-98c2-4a53-a523-be8609eb7f8b"; try { // Create a role assignment to retrieve. KeyVaultRoleAssignment createdRoleAssignment = - asyncClient.createRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName, - creationProperties).block(); + asyncClient.createRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName, roleDefinition.getId(), + clientId).block(); assertNotNull(createdRoleAssignment); // Get the role assignment. KeyVaultRoleAssignment retrievedRoleAssignment = - asyncClient.getRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName.toString()) + asyncClient.getRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName) .block(); assertNotNull(retrievedRoleAssignment); assertEquals(createdRoleAssignment.getId(), retrievedRoleAssignment.getId()); assertEquals(createdRoleAssignment.getName(), retrievedRoleAssignment.getName()); assertEquals(createdRoleAssignment.getType(), retrievedRoleAssignment.getType()); - assertEquals(createdRoleAssignment.getScope(), retrievedRoleAssignment.getScope()); + assertEquals(createdRoleAssignment.getRoleScope(), retrievedRoleAssignment.getRoleScope()); KeyVaultRoleAssignmentProperties retrievedProperties = retrievedRoleAssignment.getProperties(); assertNotNull(retrievedProperties); - assertEquals(creationProperties.getPrincipalId(), retrievedProperties.getPrincipalId()); - assertEquals(creationProperties.getRoleDefinitionId(), retrievedProperties.getRoleDefinitionId()); + assertEquals(clientId, retrievedProperties.getPrincipalId()); + assertEquals(roleDefinition.getId(), retrievedProperties.getRoleDefinitionId()); } finally { if (getTestMode() != TestMode.PLAYBACK) { // Clean up the role assignment. KeyVaultAccessControlAsyncClient cleanupClient = getClientBuilder(httpClient, true).buildAsyncClient(); - cleanupClient.deleteRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName.toString()); + cleanupClient.deleteRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName); } } } @@ -238,7 +236,7 @@ public void deleteRoleAssignment(HttpClient httpClient) { List roleDefinitions = new ArrayList<>(); - asyncClient.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL).subscribe(roleDefinitions::add); + asyncClient.listRoleDefinitions(KeyVaultRoleScope.GLOBAL).subscribe(roleDefinitions::add); sleepInLiveOrRecordMode(5000); KeyVaultRoleDefinition roleDefinition = null; @@ -251,32 +249,29 @@ public void deleteRoleAssignment(HttpClient httpClient) { assertNotNull(roleDefinition); - UUID roleAssignmentName = UUID.fromString("33785c35-4196-46b5-9d99-d5bcb2b9ca1d"); - KeyVaultRoleAssignmentProperties creationProperties = - new KeyVaultRoleAssignmentProperties(roleDefinition.getId(), clientId); + String roleAssignmentName = "33785c35-4196-46b5-9d99-d5bcb2b9ca1d"; // Create a role assignment to delete. KeyVaultRoleAssignment createdRoleAssignment = - asyncClient.createRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName, - creationProperties).block(); + asyncClient.createRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName, roleDefinition.getId(), + clientId).block(); assertNotNull(createdRoleAssignment); // Delete the role assignment. KeyVaultRoleAssignment deletedRoleAssignment = - asyncClient.deleteRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName.toString()).block(); - //client.deleteRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, "df0c4b30-93b9-4142-9523-ef3ec26ac99f"); + asyncClient.deleteRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName).block(); assertNotNull(deletedRoleAssignment); assertEquals(createdRoleAssignment.getId(), deletedRoleAssignment.getId()); assertEquals(createdRoleAssignment.getName(), deletedRoleAssignment.getName()); assertEquals(createdRoleAssignment.getType(), deletedRoleAssignment.getType()); - assertEquals(createdRoleAssignment.getScope(), deletedRoleAssignment.getScope()); + assertEquals(createdRoleAssignment.getRoleScope(), deletedRoleAssignment.getRoleScope()); KeyVaultRoleAssignmentProperties retrievedProperties = deletedRoleAssignment.getProperties(); assertNotNull(retrievedProperties); - assertEquals(creationProperties.getPrincipalId(), retrievedProperties.getPrincipalId()); - assertEquals(creationProperties.getRoleDefinitionId(), retrievedProperties.getRoleDefinitionId()); + assertEquals(clientId, retrievedProperties.getPrincipalId()); + assertEquals(roleDefinition.getId(), retrievedProperties.getRoleDefinitionId()); } } 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 78db4e4cc8f5b..c05c1b8081a34 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 @@ -8,15 +8,16 @@ import com.azure.core.test.TestMode; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignment; import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentProperties; -import com.azure.security.keyvault.administration.models.KeyVaultRoleAssignmentScope; +import com.azure.security.keyvault.administration.models.KeyVaultRoleScope; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinition; import com.azure.security.keyvault.administration.models.KeyVaultRoleDefinitionProperties; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class KeyVaultAccessControlClientTest extends KeyVaultAccessControlClientTestBase { private KeyVaultAccessControlClient client; @@ -41,7 +42,7 @@ public void listRoleDefinitions(HttpClient httpClient) { client = getClientBuilder(httpClient, false).buildClient(); PagedIterable roleDefinitions = - client.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL); + client.listRoleDefinitions(KeyVaultRoleScope.GLOBAL); assertTrue(roleDefinitions.iterator().hasNext()); @@ -76,7 +77,7 @@ public void listRoleAssignments(HttpClient httpClient) { client = getClientBuilder(httpClient, false).buildClient(); PagedIterable roleAssignments = - client.listRoleAssignments(KeyVaultRoleAssignmentScope.GLOBAL); + client.listRoleAssignments(KeyVaultRoleScope.GLOBAL); assertTrue(roleAssignments.iterator().hasNext()); @@ -108,7 +109,7 @@ public void createRoleAssignment(HttpClient httpClient) { client = getClientBuilder(httpClient, false).buildClient(); PagedIterable roleDefinitions = - client.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL); + client.listRoleDefinitions(KeyVaultRoleScope.GLOBAL); KeyVaultRoleDefinition roleDefinition = null; @@ -121,32 +122,31 @@ public void createRoleAssignment(HttpClient httpClient) { assertNotNull(roleDefinition); - UUID roleAssignmentName = UUID.fromString("d0bedeb4-7431-407d-81cd-278929c98218"); - KeyVaultRoleAssignmentProperties creationProperties = - new KeyVaultRoleAssignmentProperties(roleDefinition.getId(), clientId); + String roleAssignmentName = "d0bedeb4-7431-407d-81cd-278929c98218"; try { // Create a role assignment. KeyVaultRoleAssignment createdRoleAssignment = - client.createRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName, creationProperties); + client.createRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName, roleDefinition.getId(), + clientId); assertNotNull(createdRoleAssignment); assertNotNull(createdRoleAssignment.getId()); - assertEquals(createdRoleAssignment.getName(), roleAssignmentName.toString()); + assertEquals(createdRoleAssignment.getName(), roleAssignmentName); assertNotNull(createdRoleAssignment.getType()); - assertNotNull(createdRoleAssignment.getScope()); + assertNotNull(createdRoleAssignment.getRoleScope()); KeyVaultRoleAssignmentProperties properties = createdRoleAssignment.getProperties(); assertNotNull(properties); - assertEquals(creationProperties.getPrincipalId(), properties.getPrincipalId()); - assertEquals(creationProperties.getRoleDefinitionId(), properties.getRoleDefinitionId()); + assertEquals(clientId, properties.getPrincipalId()); + assertEquals(roleDefinition.getId(), properties.getRoleDefinitionId()); } finally { if (getTestMode() != TestMode.PLAYBACK) { // Clean up the role assignment. KeyVaultAccessControlClient cleanupClient = getClientBuilder(httpClient, true).buildClient(); - cleanupClient.deleteRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName.toString()); + cleanupClient.deleteRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName); } } } @@ -166,7 +166,7 @@ public void getRoleAssignment(HttpClient httpClient) { client = getClientBuilder(httpClient, false).buildClient(); PagedIterable roleDefinitions = - client.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL); + client.listRoleDefinitions(KeyVaultRoleScope.GLOBAL); KeyVaultRoleDefinition roleDefinition = null; @@ -178,36 +178,35 @@ public void getRoleAssignment(HttpClient httpClient) { assertNotNull(roleDefinition); - UUID roleAssignmentName = UUID.fromString("658d6c14-98c2-4a53-a523-be8609eb7f8b"); - KeyVaultRoleAssignmentProperties creationProperties = - new KeyVaultRoleAssignmentProperties(roleDefinition.getId(), clientId); + String roleAssignmentName = "658d6c14-98c2-4a53-a523-be8609eb7f8b"; try { // Create a role assignment to retrieve. KeyVaultRoleAssignment createdRoleAssignment = - client.createRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName, creationProperties); + client.createRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName, roleDefinition.getId(), + clientId); // Get the role assignment. KeyVaultRoleAssignment retrievedRoleAssignment = - client.getRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName.toString()); + client.getRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName); assertNotNull(retrievedRoleAssignment); assertEquals(createdRoleAssignment.getId(), retrievedRoleAssignment.getId()); assertEquals(createdRoleAssignment.getName(), retrievedRoleAssignment.getName()); assertEquals(createdRoleAssignment.getType(), retrievedRoleAssignment.getType()); - assertEquals(createdRoleAssignment.getScope(), retrievedRoleAssignment.getScope()); + assertEquals(createdRoleAssignment.getRoleScope(), retrievedRoleAssignment.getRoleScope()); KeyVaultRoleAssignmentProperties retrievedProperties = retrievedRoleAssignment.getProperties(); assertNotNull(retrievedProperties); - assertEquals(creationProperties.getPrincipalId(), retrievedProperties.getPrincipalId()); - assertEquals(creationProperties.getRoleDefinitionId(), retrievedProperties.getRoleDefinitionId()); + assertEquals(clientId, retrievedProperties.getPrincipalId()); + assertEquals(roleDefinition.getId(), retrievedProperties.getRoleDefinitionId()); } finally { if (getTestMode() != TestMode.PLAYBACK) { // Clean up the role assignment. KeyVaultAccessControlClient cleanupClient = getClientBuilder(httpClient, true).buildClient(); - cleanupClient.deleteRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName.toString()); + cleanupClient.deleteRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName); } } } @@ -227,7 +226,7 @@ public void deleteRoleAssignment(HttpClient httpClient) { client = getClientBuilder(httpClient, false).buildClient(); PagedIterable roleDefinitions = - client.listRoleDefinitions(KeyVaultRoleAssignmentScope.GLOBAL); + client.listRoleDefinitions(KeyVaultRoleScope.GLOBAL); KeyVaultRoleDefinition roleDefinition = null; @@ -239,28 +238,26 @@ public void deleteRoleAssignment(HttpClient httpClient) { assertNotNull(roleDefinition); - UUID roleAssignmentName = UUID.fromString("33785c35-4196-46b5-9d99-d5bcb2b9ca1d"); - KeyVaultRoleAssignmentProperties creationProperties = - new KeyVaultRoleAssignmentProperties(roleDefinition.getId(), clientId); + String roleAssignmentName = "33785c35-4196-46b5-9d99-d5bcb2b9ca1d"; // Create a role assignment to delete. KeyVaultRoleAssignment createdRoleAssignment = - client.createRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName, creationProperties); + client.createRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName, roleDefinition.getId(), clientId); // Delete the role assignment. KeyVaultRoleAssignment deletedRoleAssignment = - client.deleteRoleAssignment(KeyVaultRoleAssignmentScope.GLOBAL, roleAssignmentName.toString()); + client.deleteRoleAssignment(KeyVaultRoleScope.GLOBAL, roleAssignmentName); assertNotNull(deletedRoleAssignment); assertEquals(createdRoleAssignment.getId(), deletedRoleAssignment.getId()); assertEquals(createdRoleAssignment.getName(), deletedRoleAssignment.getName()); assertEquals(createdRoleAssignment.getType(), deletedRoleAssignment.getType()); - assertEquals(createdRoleAssignment.getScope(), deletedRoleAssignment.getScope()); + assertEquals(createdRoleAssignment.getRoleScope(), deletedRoleAssignment.getRoleScope()); KeyVaultRoleAssignmentProperties retrievedProperties = deletedRoleAssignment.getProperties(); assertNotNull(retrievedProperties); - assertEquals(creationProperties.getPrincipalId(), retrievedProperties.getPrincipalId()); - assertEquals(creationProperties.getRoleDefinitionId(), retrievedProperties.getRoleDefinitionId()); + assertEquals(clientId, retrievedProperties.getPrincipalId()); + assertEquals(roleDefinition.getId(), retrievedProperties.getRoleDefinitionId()); } } 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 09e1066fc6e97..0787eb497e376 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 @@ -7,13 +7,14 @@ import com.azure.core.test.TestMode; import com.azure.core.util.polling.AsyncPollResponse; import com.azure.core.util.polling.LongRunningOperationStatus; -import com.azure.core.util.polling.PollerFlux; import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation; import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class KeyVaultBackupAsyncClientTest extends KeyVaultBackupClientTestBase { private KeyVaultBackupAsyncClient asyncClient; @@ -50,42 +51,6 @@ public void beginBackup(HttpClient httpClient) { assertTrue(backupBlobUri.startsWith(blobStorageUrl)); } - /** - * Tests that a backup operation can be obtained by using its {@code jobId}. - */ - @SuppressWarnings("ConstantConditions") - @ParameterizedTest(name = DISPLAY_NAME) - @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") - public void getBackupStatus(HttpClient httpClient) { - if (getTestMode() != TestMode.PLAYBACK) { - // Currently there is no Managed HSM environment for pipeline testing. - // TODO: Remove once there is a proper cloud environment available. - return; - } - - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); - - PollerFlux backupPollerFlux = - asyncClient.beginBackup(blobStorageUrl, sasToken); - String jobId = backupPollerFlux.blockFirst().getValue().getJobId(); - - PollerFlux backupStatusPollerFlux = asyncClient.getBackupOperation(jobId); - - AsyncPollResponse backupPollResponse = backupPollerFlux.blockLast(); - AsyncPollResponse backupStatusPollResponse = - backupStatusPollerFlux.blockLast(); - - KeyVaultBackupOperation backupOperation = backupPollResponse.getValue(); - KeyVaultBackupOperation backupStatusOperation = backupStatusPollResponse.getValue(); - - String backupBlobUri = backupPollResponse.getFinalResult().block(); - String backupStatusBlobUri = backupStatusPollResponse.getFinalResult().block(); - - assertEquals(backupBlobUri, backupStatusBlobUri); - assertEquals(backupOperation.getStartTime(), backupStatusOperation.getStartTime()); - assertEquals(backupOperation.getEndTime(), backupStatusOperation.getEndTime()); - } - /** * Tests that a Key Vault can be restored from a backup. */ @@ -114,45 +79,6 @@ public void beginRestore(HttpClient httpClient) { assertEquals(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, restorePollResponse.getStatus()); } - /** - * Tests that a restore operation can be obtained by using its {@code jobId}. - */ - @SuppressWarnings("ConstantConditions") - @ParameterizedTest(name = DISPLAY_NAME) - @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") - public void getRestoreStatus(HttpClient httpClient) { - if (getTestMode() != TestMode.PLAYBACK) { - // Currently there is no Managed HSM environment for pipeline testing. - // TODO: Remove once there is a proper cloud environment available. - return; - } - - asyncClient = getClientBuilder(httpClient, false).buildAsyncClient(); - - // Create a backup - AsyncPollResponse backupPollResponse = - asyncClient.beginBackup(blobStorageUrl, sasToken).blockLast(); - - // Restore the backup - String backupFolderUrl = backupPollResponse.getFinalResult().block(); - PollerFlux restorePollerFlux = - asyncClient.beginRestore(backupFolderUrl, sasToken); - - // Get job status via its ID - String jobId = restorePollerFlux.blockFirst().getValue().getJobId(); - PollerFlux restoreStatusPollerFlux = asyncClient.getRestoreOperation(jobId); - - AsyncPollResponse restorePollResponse = restorePollerFlux.blockLast(); - AsyncPollResponse restoreStatusPollResponse = - restoreStatusPollerFlux.blockLast(); - - KeyVaultRestoreOperation backupOperation = restorePollResponse.getValue(); - KeyVaultRestoreOperation backupStatusOperation = restoreStatusPollResponse.getValue(); - - assertEquals(backupOperation.getStartTime(), backupStatusOperation.getStartTime()); - assertEquals(backupOperation.getEndTime(), backupStatusOperation.getEndTime()); - } - /** * Tests that a key can be restored from a backup. */ 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 ea980612b55d1..c31cdd96a4a98 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 @@ -13,7 +13,9 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class KeyVaultBackupClientTest extends KeyVaultBackupClientTestBase { private KeyVaultBackupClient client; @@ -50,36 +52,6 @@ public void beginBackup(HttpClient httpClient) { assertTrue(backupBlobUri.startsWith(blobStorageUrl)); } - /** - * Tests that a backup operation can be obtained by using its {@code jobId}. - */ - @ParameterizedTest(name = DISPLAY_NAME) - @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") - public void getBackupStatus(HttpClient httpClient) { - if (getTestMode() != TestMode.PLAYBACK) { - // Currently there is no Managed HSM environment for pipeline testing. - // TODO: Remove once there is a proper cloud environment available. - return; - } - - client = getClientBuilder(httpClient, false).buildClient(); - - SyncPoller backupPoller = client.beginBackup(blobStorageUrl, sasToken); - String jobId = backupPoller.poll().getValue().getJobId(); - - SyncPoller backupStatusPoller = client.getBackupOperation(jobId); - - KeyVaultBackupOperation backupOperation = backupPoller.waitForCompletion().getValue(); - KeyVaultBackupOperation backupStatusOperation = backupStatusPoller.waitForCompletion().getValue(); - - String backupBlobUri = backupPoller.getFinalResult(); - String backupStatusBlobUri = backupStatusPoller.getFinalResult(); - - assertEquals(backupBlobUri, backupStatusBlobUri); - assertEquals(backupOperation.getStartTime(), backupStatusOperation.getStartTime()); - assertEquals(backupOperation.getEndTime(), backupStatusOperation.getEndTime()); - } - /** * Tests that a Key Vault can be restored from a backup. */ @@ -110,40 +82,6 @@ public void beginRestore(HttpClient httpClient) { assertEquals(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, restoreResponse.getStatus()); } - /** - * Tests that a restore operation can be obtained by using its {@code jobId}. - */ - @ParameterizedTest(name = DISPLAY_NAME) - @MethodSource("com.azure.security.keyvault.administration.KeyVaultAdministrationClientTestBase#createHttpClients") - public void getRestoreStatus(HttpClient httpClient) { - if (getTestMode() != TestMode.PLAYBACK) { - // Currently there is no Managed HSM environment for pipeline testing. - // TODO: Remove once there is a proper cloud environment available. - return; - } - - client = getClientBuilder(httpClient, false).buildClient(); - - // Create a backup - SyncPoller backupPoller = client.beginBackup(blobStorageUrl, sasToken); - - backupPoller.waitForCompletion(); - - // Restore the backup - String backupFolderUrl = backupPoller.getFinalResult(); - SyncPoller restorePoller = client.beginRestore(backupFolderUrl, sasToken); - - // Get job status via its ID - String jobId = restorePoller.poll().getValue().getJobId(); - SyncPoller restoreStatusPoller = client.getRestoreOperation(jobId); - - KeyVaultRestoreOperation restoreOperation = restorePoller.waitForCompletion().getValue(); - KeyVaultRestoreOperation restoreStatusOperation = restoreStatusPoller.waitForCompletion().getValue(); - - assertEquals(restoreOperation.getStartTime(), restoreStatusOperation.getStartTime()); - assertEquals(restoreOperation.getEndTime(), restoreStatusOperation.getEndTime()); - } - /** * Tests that a key can be restored from a backup. */ diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/test/resources/session-records/getBackupStatus.json b/sdk/keyvault/azure-security-keyvault-administration/src/test/resources/session-records/getBackupStatus.json deleted file mode 100644 index 81c1d464c827b..0000000000000 --- a/sdk/keyvault/azure-security-keyvault-administration/src/test/resources/session-records/getBackupStatus.json +++ /dev/null @@ -1,135 +0,0 @@ -{ - "networkCallRecords" : [ { - "Method" : "POST", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/backup?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)", - "Content-Type" : "application/json" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 01:44:06 GMT", - "server" : "Kestrel", - "content-length" : "216", - "x-frame-options" : "SAMEORIGIN", - "retry-after" : "0", - "StatusCode" : "202", - "x-ms-server-latency" : "4663", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "5a8f20bc-eee5-11ea-bf6e-0242ac120003", - "Body" : "{\"status\":\"InProgress\",\"statusDetails\":null,\"error\":{\"code\":null,\"message\":null,\"innererror\":null},\"startTime\":1599270244,\"endTime\":null,\"jobId\":\"bff4961da63f44e0ae9cdf6924b37243\",\"azureStorageBlobContainerUri\":null}", - "azure-asyncoperation" : "https://eastus2.chriss-eu2.managedhsm-int.azure-int.net/backup/bff4961da63f44e0ae9cdf6924b37243/pending" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/backup/bff4961da63f44e0ae9cdf6924b37243/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 01:44:07 GMT", - "server" : "Kestrel", - "content-length" : "216", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "580", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "5a8f20bc-eee5-11ea-bf6e-0242ac120003", - "Body" : "{\"azureStorageBlobContainerUri\":null,\"endTime\":null,\"error\":{\"code\":null,\"innererror\":null,\"message\":null},\"jobId\":\"bff4961da63f44e0ae9cdf6924b37243\",\"startTime\":1599270244,\"status\":\"InProgress\",\"statusDetails\":null}" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/backup/bff4961da63f44e0ae9cdf6924b37243/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 01:44:07 GMT", - "server" : "Kestrel", - "content-length" : "216", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "580", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "5a8f20bc-eee5-11ea-bf6e-0242ac120003", - "Body" : "{\"azureStorageBlobContainerUri\":null,\"endTime\":null,\"error\":{\"code\":null,\"innererror\":null,\"message\":null},\"jobId\":\"bff4961da63f44e0ae9cdf6924b37243\",\"startTime\":1599270244,\"status\":\"InProgress\",\"statusDetails\":null}" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/backup/bff4961da63f44e0ae9cdf6924b37243/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 01:44:19 GMT", - "server" : "Kestrel", - "content-length" : "263", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "461", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "5a8f20bc-eee5-11ea-bf6e-0242ac120003", - "Body" : "{\"azureStorageBlobContainerUri\":\"https://testaccount.blob.core.windows.net/backup/testKeyVault\",\"endTime\":1599270258,\"error\":null,\"jobId\":\"bff4961da63f44e0ae9cdf6924b37243\",\"startTime\":1599270244,\"status\":\"Succeeded\",\"statusDetails\":null}" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/backup/bff4961da63f44e0ae9cdf6924b37243/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 01:44:19 GMT", - "server" : "Kestrel", - "content-length" : "263", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "461", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "5a8f20bc-eee5-11ea-bf6e-0242ac120003", - "Body" : "{\"azureStorageBlobContainerUri\":\"https://testaccount.blob.core.windows.net/backup/testKeyVault\",\"endTime\":1599270258,\"error\":null,\"jobId\":\"bff4961da63f44e0ae9cdf6924b37243\",\"startTime\":1599270244,\"status\":\"Succeeded\",\"statusDetails\":null}" - }, - "Exception" : null - }], - "variables" : [ ] -} diff --git a/sdk/keyvault/azure-security-keyvault-administration/src/test/resources/session-records/getRestoreStatus.json b/sdk/keyvault/azure-security-keyvault-administration/src/test/resources/session-records/getRestoreStatus.json deleted file mode 100644 index 789a15de56dbf..0000000000000 --- a/sdk/keyvault/azure-security-keyvault-administration/src/test/resources/session-records/getRestoreStatus.json +++ /dev/null @@ -1,240 +0,0 @@ -{ - "networkCallRecords" : [ { - "Method" : "POST", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/backup?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)", - "Content-Type" : "application/json" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 02:10:42 GMT", - "server" : "Kestrel", - "content-length" : "216", - "x-frame-options" : "SAMEORIGIN", - "retry-after" : "0", - "StatusCode" : "202", - "x-ms-server-latency" : "956", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "0a92d500-eeee-11ea-ad45-0242ac120005", - "Body" : "{\"status\":\"InProgress\",\"statusDetails\":null,\"error\":{\"code\":null,\"message\":null,\"innererror\":null},\"startTime\":1599271842,\"endTime\":null,\"jobId\":\"41b6e77196cb46f8a1eafe715312d672\",\"azureStorageBlobContainerUri\":null}", - "azure-asyncoperation" : "https://eastus2.chriss-eu2.managedhsm-int.azure-int.net/backup/41b6e77196cb46f8a1eafe715312d672/pending" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/backup/41b6e77196cb46f8a1eafe715312d672/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 02:10:43 GMT", - "server" : "Kestrel", - "content-length" : "216", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "669", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "0a92d500-eeee-11ea-ad45-0242ac120005", - "Body" : "{\"azureStorageBlobContainerUri\":null,\"endTime\":null,\"error\":{\"code\":null,\"innererror\":null,\"message\":null},\"jobId\":\"41b6e77196cb46f8a1eafe715312d672\",\"startTime\":1599271842,\"status\":\"InProgress\",\"statusDetails\":null}" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/backup/41b6e77196cb46f8a1eafe715312d672/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 02:10:52 GMT", - "server" : "Kestrel", - "content-length" : "263", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "586", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "0a92d500-eeee-11ea-ad45-0242ac120005", - "Body" : "{\"azureStorageBlobContainerUri\":\"https://testaccount.blob.core.windows.net/backup/testKeyVault\",\"endTime\":1599271853,\"error\":null,\"jobId\":\"41b6e77196cb46f8a1eafe715312d672\",\"startTime\":1599271842,\"status\":\"Succeeded\",\"statusDetails\":null}" - }, - "Exception" : null - }, { - "Method" : "PUT", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/restore?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)", - "Content-Type" : "application/json" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 02:11:04 GMT", - "server" : "Kestrel", - "content-length" : "180", - "x-frame-options" : "SAMEORIGIN", - "retry-after" : "0", - "StatusCode" : "202", - "x-ms-server-latency" : "722", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "0a92d500-eeee-11ea-ad45-0242ac120005", - "Body" : "{\"endTime\":null,\"error\":{\"code\":null,\"innererror\":null,\"message\":null},\"jobId\":\"39009818fe314387916f1513179d12cd\",\"startTime\":1599271865,\"status\":\"InProgress\",\"statusDetails\":null}", - "azure-asyncoperation" : "https://eastus2.chriss-eu2.managedhsm-int.azure-int.net/restore/39009818fe314387916f1513179d12cd/pending" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/restore/39009818fe314387916f1513179d12cd/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 02:11:06 GMT", - "server" : "Kestrel", - "content-length" : "180", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "600", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "0a92d500-eeee-11ea-ad45-0242ac120005", - "Body" : "{\"endTime\":null,\"error\":{\"code\":null,\"innererror\":null,\"message\":null},\"jobId\":\"39009818fe314387916f1513179d12cd\",\"startTime\":1599271865,\"status\":\"InProgress\",\"statusDetails\":null}" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/restore/39009818fe314387916f1513179d12cd/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 02:11:06 GMT", - "server" : "Kestrel", - "content-length" : "180", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "600", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "0a92d500-eeee-11ea-ad45-0242ac120005", - "Body" : "{\"endTime\":null,\"error\":{\"code\":null,\"innererror\":null,\"message\":null},\"jobId\":\"39009818fe314387916f1513179d12cd\",\"startTime\":1599271865,\"status\":\"InProgress\",\"statusDetails\":null}" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/restore/39009818fe314387916f1513179d12cd/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 02:11:23 GMT", - "server" : "Kestrel", - "content-length" : "143", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "558", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "0a92d500-eeee-11ea-ad45-0242ac120005", - "Body" : "{\"endTime\":1599271882,\"error\":null,\"jobId\":\"39009818fe314387916f1513179d12cd\",\"startTime\":1599271865,\"status\":\"Succeeded\",\"statusDetails\":null}" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/restore/39009818fe314387916f1513179d12cd/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 02:11:23 GMT", - "server" : "Kestrel", - "content-length" : "143", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "543", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "0a92d500-eeee-11ea-ad45-0242ac120005", - "Body" : "{\"endTime\":1599271882,\"error\":null,\"jobId\":\"39009818fe314387916f1513179d12cd\",\"startTime\":1599271865,\"status\":\"Succeeded\",\"statusDetails\":null}" - }, - "Exception" : null - }, { - "Method" : "GET", - "Uri" : "https://REDACTED.chriss-eu2.managedhsm-int.azure-int.net/restore/39009818fe314387916f1513179d12cd/pending?api-version=7.2-preview", - "Headers" : { - "User-Agent" : "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)" - }, - "Response" : { - "date" : "Sat, 05 Sep 2020 02:11:23 GMT", - "server" : "Kestrel", - "content-length" : "143", - "x-frame-options" : "SAMEORIGIN", - "x-ms-build-version" : "1.0.20200904-1-42b8eab8-develop", - "retry-after" : "0", - "StatusCode" : "200", - "strict-transport-security" : "max-age=31536000; includeSubDomains", - "x-ms-server-latency" : "558", - "content-security-policy" : "default-src 'self'", - "x-content-type-options" : "nosniff", - "x-ms-keyvault-region" : "EASTUS", - "content-type" : "application/json; charset=utf-8", - "x-ms-keyvault-network-info" : "addr=174.127.169.154", - "cache-control" : "no-cache", - "x-ms-request-id" : "0a92d500-eeee-11ea-ad45-0242ac120005", - "Body" : "{\"endTime\":1599271882,\"error\":null,\"jobId\":\"39009818fe314387916f1513179d12cd\",\"startTime\":1599271865,\"status\":\"Succeeded\",\"statusDetails\":null}" - }, - "Exception" : null - }], - "variables" : [ ] -}