Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eaa2d52
Updated Autorest configuration file for Key Vault Administration to i…
vcolin7 Oct 20, 2022
0172a73
Generated code for handling new Settings APIs.
vcolin7 Oct 20, 2022
aa7b954
Updated Autorest configuration file to rename a couple operations.
vcolin7 Oct 20, 2022
9263c26
Re-generated code with new operation names.
vcolin7 Oct 20, 2022
0c68c8d
Moved "settings" specific configuration to the right tag in Autorest …
vcolin7 Oct 20, 2022
72ef240
Added new sync and async clients.
vcolin7 Oct 20, 2022
b98d6bc
Updated Autorest config file to generate sync methods in the impl cli…
vcolin7 Oct 20, 2022
749ca15
Re-generated code.
vcolin7 Oct 20, 2022
d92a845
Created new public types and updated public clients to use them.
vcolin7 Oct 20, 2022
886d752
Updated the KeyVaultSettingsClientBuilder to conform to other public …
vcolin7 Oct 20, 2022
991fa64
Updated the Autorest configuration file and re-generated code.
vcolin7 Oct 25, 2022
fcba976
Updated public classes due to code re-generation.
vcolin7 Oct 25, 2022
e7722cf
Added new preview service version to KeyVaultAdministrationServiceVer…
vcolin7 Oct 25, 2022
6ec4438
Updated CHANGELOG.
vcolin7 Oct 25, 2022
cbda868
Fixed issues with KeyVaultSettingsClientBuilder.
vcolin7 Oct 26, 2022
3abd27d
Added a result model for the `listSettings` operations and updated cl…
vcolin7 Oct 26, 2022
f9824b7
Fixed typo for `listSettings` APIs.
vcolin7 Oct 26, 2022
9ca5e44
Renamed `createOrUpdateSetting()` to `updateSetting()` in `KeyVaultSe…
vcolin7 Oct 26, 2022
3882819
Added missing Javadoc.
vcolin7 Oct 26, 2022
147c175
Fixed SpotBugs issues.
vcolin7 Oct 26, 2022
9501120
Applied APIView feedback.
vcolin7 Oct 26, 2022
96aa7ee
Updated `KeyVaultAdministrationServiceVersion.getLatest()` to return …
vcolin7 Oct 28, 2022
f67ee7f
Updated autorest.md to match what the service returns in SettingListR…
vcolin7 Nov 6, 2022
83612e6
Changed updateSetting methods in clients to take a `KeyVaultSetting` …
vcolin7 Nov 6, 2022
09e4b40
Merge branch 'main' into key-vault-settings
vcolin7 Nov 11, 2022
5790629
Re-generated Settings impl client.
vcolin7 Nov 11, 2022
5f033db
Re-recorded tests.
vcolin7 Nov 11, 2022
ef8798d
Merge branch 'main' into key-vault-settings
vcolin7 Nov 11, 2022
797d866
Added tests and recordings for Settings clients.
vcolin7 Nov 11, 2022
98788e3
Fixed tests and recordings.
vcolin7 Nov 11, 2022
1f2f4ed
Update KeyVaultSettingsClient.java
vcolin7 Nov 11, 2022
058a44d
Update KeyVaultSettingsAsyncClientTest.java
vcolin7 Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 4.3.0-beta.1 (Unreleased)

### Features Added
- Added `KeyVaultSettingsClient` and `KeyVaultSettingsAsyncClient` to get and update Managed HSM settings.
- Added support for service version `7.4-preview.1`.

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ public enum KeyVaultAdministrationServiceVersion implements ServiceVersion {
/**
* Service version {@code 7.3}.
*/
V7_3("7.3");
V7_3("7.3"),

/**
* Service version {@code 7.3}.
*/
V7_4_PREVIEW_1("7.4-preview.1");

private final String version;

Expand All @@ -36,6 +41,6 @@ public String getVersion() {
* @return The latest {@link KeyVaultAdministrationServiceVersion}.
*/
public static KeyVaultAdministrationServiceVersion getLatest() {
return V7_3;
return V7_4_PREVIEW_1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.security.keyvault.administration;

import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import com.azure.security.keyvault.administration.implementation.KeyVaultAdministrationUtils;
import com.azure.security.keyvault.administration.implementation.KeyVaultErrorCodeStrings;
import com.azure.security.keyvault.administration.implementation.KeyVaultSettingsClientImpl;
import com.azure.security.keyvault.administration.implementation.models.KeyVaultErrorException;
import com.azure.security.keyvault.administration.implementation.models.Setting;
import com.azure.security.keyvault.administration.models.KeyVaultListSettingsResult;
import com.azure.security.keyvault.administration.models.KeyVaultSetting;
import com.azure.security.keyvault.administration.models.KeyVaultSettingType;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static com.azure.core.util.FluxUtil.monoError;

/**
* The {@link KeyVaultSettingsAsyncClient} provides asynchronous methods to create, update, get and list
* {@link KeyVaultSetting settings} for the Azure Key Vault.
*
* <p>Instances of this client are obtained by calling the {@link KeyVaultSettingsClientBuilder#buildAsyncClient()}
* method on a {@link KeyVaultSettingsClientBuilder} object.</p>
*
* @see KeyVaultSettingsClientBuilder
*/
@ServiceClient(builder = KeyVaultSettingsClientBuilder.class, isAsync = true, serviceInterfaces =
KeyVaultSettingsClientImpl.KeyVaultSettingsClientService.class)
public final class KeyVaultSettingsAsyncClient {
private final String vaultUrl;
private final KeyVaultSettingsClientImpl implClient;
private final ClientLogger logger = new ClientLogger(KeyVaultSettingsAsyncClient.class);

/**
* Creates a {@link KeyVaultSettingsAsyncClient} that uses a {@link KeyVaultSettingsClientImpl} to service requests.
*
* @param vaultUrl The URL of the key vault this client will act on.
* @param implClient The implementation client used to service requests.
*/
KeyVaultSettingsAsyncClient(String vaultUrl, KeyVaultSettingsClientImpl implClient) {
this.vaultUrl = vaultUrl;
this.implClient = implClient;
}

/**
* Updates a given {@link KeyVaultSetting account setting}.
*
* @param setting The {@link KeyVaultSetting account setting} to update.
*
* @return A {@link Mono} containing the updated {@link KeyVaultSetting account setting}.
*
* @throws NullPointerException if {@code setting} is {@code null}.
* @throws IllegalArgumentException thrown if {@code name} or {@code value} is {@code null} or empty.
* @throws KeyVaultErrorException thrown if the request is rejected by the server.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<KeyVaultSetting> updateSetting(KeyVaultSetting setting) {
Objects.requireNonNull(setting,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'setting'"));

if (CoreUtils.isNullOrEmpty(setting.getName())) {
throw logger.logExceptionAsError(new IllegalArgumentException("Setting name cannot be null or empty"));
}

try {
return this.implClient.updateSettingAsync(vaultUrl, setting.getName(), setting.asString())
.doOnRequest(ignored -> logger.verbose("Updating account setting - {}", setting.getName()))
.doOnSuccess(response -> logger.verbose("Updated account setting - {}", setting.getName()))
.doOnError(error -> logger.warning("Failed updating account setting - {}", setting.getName(), error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultSettingsAsyncClient::transformToKeyVaultSetting);
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

/**
* Updates a given {@link KeyVaultSetting account setting}.
*
* @param setting The {@link KeyVaultSetting account setting} to update.
*
* @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the updated
* {@link KeyVaultSetting account setting}.
*
* @throws NullPointerException if {@code setting} is {@code null}.
* @throws IllegalArgumentException thrown if {@code name} is {@code null} or empty.
* @throws KeyVaultErrorException thrown if the request is rejected by the server.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<KeyVaultSetting>> updateSettingWithResponse(KeyVaultSetting setting) {
Objects.requireNonNull(setting,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'setting'"));


if (CoreUtils.isNullOrEmpty(setting.getName())) {
throw logger.logExceptionAsError(new IllegalArgumentException("'name' cannot be empty or null"));
}

try {
return this.implClient.updateSettingWithResponseAsync(vaultUrl, setting.getName(), setting.asString())
.doOnRequest(ignored -> logger.verbose("Updating account setting - {}", setting.getName()))
.doOnSuccess(response -> logger.verbose("Updated account setting - {}", setting.getName()))
.doOnError(error -> logger.warning("Failed updating account setting - {}", setting.getName(), error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(response -> new SimpleResponse<>(response, transformToKeyVaultSetting(response.getValue())));
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

/**
* Get the value of a specific account setting.
*
* @param name The name of setting to retrieve the value of.
*
* @return A {@link Mono} containing the {@link KeyVaultSetting account setting}.
*
* @throws IllegalArgumentException thrown if {@code name} is {@code null} or empty.
* @throws KeyVaultErrorException thrown if the request is rejected by the server.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<KeyVaultSetting> getSetting(String name) {
if (CoreUtils.isNullOrEmpty(name)) {
throw logger.logExceptionAsError(new IllegalArgumentException("'name' cannot be empty or null"));
}

try {
return this.implClient.getSettingAsync(vaultUrl, name)
.doOnRequest(ignored -> logger.verbose("Retrieving account setting - {}", name))
.doOnSuccess(response -> logger.verbose("Retrieved account setting - {}", name))
.doOnError(error -> logger.warning("Failed retrieving account setting - {}", name, error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultSettingsAsyncClient::transformToKeyVaultSetting);
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

/**
* Get the value of a specific account setting.
*
* @param name The name of setting to retrieve the value of.
*
* @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the
* {@link KeyVaultSetting account setting}.
*
* @throws IllegalArgumentException thrown if {@code name} is {@code null} or empty.
* @throws KeyVaultErrorException thrown if the request is rejected by the server.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<KeyVaultSetting>> getSettingWithResponse(String name) {
if (CoreUtils.isNullOrEmpty(name)) {
throw logger.logExceptionAsError(new IllegalArgumentException("'name' cannot be empty or null"));
}

try {
return this.implClient.getSettingWithResponseAsync(vaultUrl, name)
.doOnRequest(ignored -> logger.verbose("Retrieving account setting - {}", name))
.doOnSuccess(response -> logger.verbose("Retrieved account setting - {}", name))
.doOnError(error -> logger.warning("Failed retrieving account setting - {}", name, error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(response -> new SimpleResponse<>(response, transformToKeyVaultSetting(response.getValue())));
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

/**
* List the account's settings.
*
* @return A {@link Mono} containing a {@link KeyVaultListSettingsResult result object} wrapping the list of
* {@link KeyVaultSetting account settings}.
*
* @throws KeyVaultErrorException thrown if the request is rejected by the server.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<KeyVaultListSettingsResult> listSettings() {
try {
return this.implClient.getSettingsAsync(vaultUrl)
.doOnRequest(ignored -> logger.verbose("Listing account settings"))
.doOnSuccess(response -> logger.verbose("Listed account settings successfully"))
.doOnError(error -> logger.warning("Failed listing account settings", error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(settingsListResult -> {
List<KeyVaultSetting> keyVaultSettings = new ArrayList<>();

settingsListResult.getSettings().forEach(setting ->
keyVaultSettings.add(transformToKeyVaultSetting(setting)));

return new KeyVaultListSettingsResult(keyVaultSettings);
});
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

/**
* List the account's settings.
*
* @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains a
* {@link KeyVaultListSettingsResult result object} wrapping the list of {@link KeyVaultSetting account settings}.
*
* @throws KeyVaultErrorException thrown if the request is rejected by the server.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<KeyVaultListSettingsResult>> listSettingsWithResponse() {
try {
return this.implClient.getSettingsWithResponseAsync(vaultUrl)
.doOnRequest(ignored -> logger.verbose("Listing account settings"))
.doOnSuccess(response -> logger.verbose("Listed account settings successfully"))
.doOnError(error -> logger.warning("Failed listing account settings", error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(response -> {
List<KeyVaultSetting> keyVaultSettings = new ArrayList<>();

response.getValue().getSettings().forEach(setting ->
keyVaultSettings.add(transformToKeyVaultSetting(setting)));

return new SimpleResponse<>(response, new KeyVaultListSettingsResult(keyVaultSettings));
});
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

static KeyVaultSetting transformToKeyVaultSetting(Setting setting) {
return new KeyVaultSetting(setting.getName(), setting.getValue(),
KeyVaultSettingType.fromString(setting.getType().toString()));
}
}
Loading