Skip to content

Commit

Permalink
[Key Vault] Removed the use of a properties file for error messages i…
Browse files Browse the repository at this point in the history
…n favor of using constants. (Azure#36341)

* Removed the use of a properties file for error messages in favor of using constants from a class in KV Admin.

* Removed the use of a properties file for error messages in favor of using constants from a class in KV Certs.

* Removed the use of a properties file for error messages in favor of using constants from a class in KV Keys.

* Removed the use of a properties file for error messages in favor of using constants from a class in KV Secrets.

* Fixed pipeline error.
  • Loading branch information
vcolin7 authored Aug 15, 2023
1 parent 7a9a545 commit 05cffab
Show file tree
Hide file tree
Showing 24 changed files with 81 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public final class KeyVaultAccessControlAsyncClient {
*/
KeyVaultAccessControlAsyncClient(URL vaultUrl, HttpPipeline httpPipeline,
KeyVaultAdministrationServiceVersion serviceVersion) {
Objects.requireNonNull(vaultUrl,
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED));
Objects.requireNonNull(vaultUrl, KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED);

this.vaultUrl = vaultUrl.toString();
this.serviceVersion = serviceVersion.getVersion();
Expand Down Expand Up @@ -186,8 +185,7 @@ Mono<PagedResponse<KeyVaultRoleDefinition>> listRoleDefinitionsFirstPage(String
Context context) {
try {
Objects.requireNonNull(roleScope,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'roleScope'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'roleScope'"));

return clientImpl.getRoleDefinitions()
.listSinglePageAsync(vaultUrl, roleScope.toString(), null,
Expand Down Expand Up @@ -641,8 +639,7 @@ Mono<PagedResponse<KeyVaultRoleAssignment>> listRoleAssignmentsFirstPage(String
Context context) {
try {
Objects.requireNonNull(roleScope,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'roleScope'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'roleScope'"));

return clientImpl.getRoleAssignments()
.listForScopeSinglePageAsync(vaultUrl, roleScope.toString(), null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public final class KeyVaultAccessControlClient {
*/
KeyVaultAccessControlClient(URL vaultUrl, HttpPipeline httpPipeline,
KeyVaultAdministrationServiceVersion serviceVersion) {
Objects.requireNonNull(vaultUrl,
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED));
Objects.requireNonNull(vaultUrl, KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED);

this.vaultUrl = vaultUrl.toString();
this.serviceVersion = serviceVersion.getVersion();
Expand Down Expand Up @@ -193,8 +192,7 @@ PagedResponse<KeyVaultRoleDefinition> listRoleDefinitionsFirstPage(String vaultU
KeyVaultRoleScope roleScope,
Context context) {
Objects.requireNonNull(roleScope,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'roleScope'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'roleScope'"));
try {
PagedResponse<RoleDefinition> roleDefinitionPagedResponse = clientImpl.getRoleDefinitions()
.listSinglePage(vaultUrl, roleScope.toString(), null,
Expand Down Expand Up @@ -605,8 +603,7 @@ PagedResponse<KeyVaultRoleAssignment> listRoleAssignmentsFirstPage(String vaultU
KeyVaultRoleScope roleScope,
Context context) {
Objects.requireNonNull(roleScope,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'roleScope'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'roleScope'"));
try {
PagedResponse<RoleAssignment> roleAssignmentPagedResponse = clientImpl.getRoleAssignments()
.listForScopeSinglePage(vaultUrl, roleScope.toString(), null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.HttpClientOptions;
import com.azure.core.util.ServiceVersion;
import com.azure.core.util.TracingOptions;
import com.azure.core.util.builder.ClientBuilderUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.ServiceVersion;
import com.azure.core.util.tracing.Tracer;
import com.azure.core.util.tracing.TracerProvider;
import com.azure.security.keyvault.administration.implementation.KeyVaultCredentialPolicy;
Expand Down Expand Up @@ -174,8 +174,7 @@ private Configuration validateEndpointAndGetConfiguration() {

if (buildEndpoint == null) {
throw LOGGER.logExceptionAsError(
new IllegalStateException(
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)));
new IllegalStateException(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED));
}
return buildConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,20 @@ static <E extends HttpResponseException> Response<Void> swallowExceptionForStatu
static RoleAssignmentCreateParameters validateAndGetRoleAssignmentCreateParameters(KeyVaultRoleScope roleScope, String roleDefinitionId, String principalId, String roleAssignmentName) {
validateRoleAssignmentParameters(roleScope, roleAssignmentName);
Objects.requireNonNull(principalId,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'principalId'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'principalId'"));
Objects.requireNonNull(roleDefinitionId,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'roleDefinitionId'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'roleDefinitionId'"));

RoleAssignmentProperties roleAssignmentProperties = new RoleAssignmentProperties(roleDefinitionId, principalId);
return new RoleAssignmentCreateParameters(roleAssignmentProperties);
}

static RoleDefinitionCreateParameters validateAndGetRoleDefinitionCreateParameters(SetRoleDefinitionOptions options) {
Objects.requireNonNull(options,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'options'"));
Objects.requireNonNull(options, String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'options'"));
Objects.requireNonNull(options.getRoleScope(),
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'options.getRoleScope()'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'options.getRoleScope()'"));
Objects.requireNonNull(options.getRoleDefinitionName(),
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'options.getRoleDefinitionName()'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'options.getRoleDefinitionName()'"));

List<Permission> permissions = null;

Expand All @@ -146,21 +140,15 @@ static RoleDefinitionCreateParameters validateAndGetRoleDefinitionCreateParamete
}

static void validateRoleAssignmentParameters(KeyVaultRoleScope roleScope, String roleAssignmentName) {
Objects.requireNonNull(roleScope,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'roleScope'"));
Objects.requireNonNull(roleScope, String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'roleScope'"));
Objects.requireNonNull(roleAssignmentName,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'roleAssignmentName'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'roleAssignmentName'"));
}

static void validateRoleDefinitionParameters(KeyVaultRoleScope roleScope, String roleDefinitionName) {
Objects.requireNonNull(roleScope,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'roleScope'"));
Objects.requireNonNull(roleScope, String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'roleScope'"));
Objects.requireNonNull(roleDefinitionName,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'roleDefinitionName'"));
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'roleDefinitionName'"));
}

@SuppressWarnings("BoundedWildcard")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ Duration getDefaultPollingInterval() {
*/
KeyVaultBackupAsyncClient(URL vaultUrl, HttpPipeline httpPipeline,
KeyVaultAdministrationServiceVersion serviceVersion) {
Objects.requireNonNull(vaultUrl,
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED));
Objects.requireNonNull(vaultUrl, KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED);

this.vaultUrl = vaultUrl.toString();
this.serviceVersion = serviceVersion.getVersion();
Expand Down Expand Up @@ -165,15 +164,14 @@ HttpPipeline getHttpPipeline() {
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public PollerFlux<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken) {
if (blobStorageUrl == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'blobStorageUrl'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'blobStorageUrl'")));
}

if (sasToken == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'sasToken'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'sasToken'")));
}

return new PollerFlux<>(getDefaultPollingInterval(),
Expand Down Expand Up @@ -329,15 +327,13 @@ private static Mono<PollResponse<KeyVaultBackupOperation>> processBackupOperatio
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public PollerFlux<KeyVaultRestoreOperation, KeyVaultRestoreResult> beginRestore(String folderUrl, String sasToken) {
if (folderUrl == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'folderUrl'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'folderUrl'")));
}

if (sasToken == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'sasToken'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'sasToken'")));
}

return new PollerFlux<>(getDefaultPollingInterval(),
Expand Down Expand Up @@ -490,21 +486,18 @@ static Mono<PollResponse<KeyVaultRestoreOperation>> processRestoreOperationRespo
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public PollerFlux<KeyVaultSelectiveKeyRestoreOperation, KeyVaultSelectiveKeyRestoreResult> beginSelectiveKeyRestore(String keyName, String folderUrl, String sasToken) {
if (keyName == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'keyName'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'keyName'")));
}

if (folderUrl == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'folderUrl'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'folderUrl'")));
}

if (sasToken == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'sasToken'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'sasToken'")));
}

return new PollerFlux<>(getDefaultPollingInterval(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ Duration getDefaultPollingInterval() {
*/
KeyVaultBackupClient(URL vaultUrl, HttpPipeline httpPipeline,
KeyVaultAdministrationServiceVersion serviceVersion) {
Objects.requireNonNull(vaultUrl,
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED));
Objects.requireNonNull(vaultUrl, KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED);

this.vaultUrl = vaultUrl.toString();
this.serviceVersion = serviceVersion.getVersion();
Expand Down Expand Up @@ -170,15 +169,14 @@ public String getVaultUrl() {
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken) {
if (blobStorageUrl == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'blobStorageUrl'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(
String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'blobStorageUrl'")));
}

if (sasToken == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'sasToken'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'sasToken'")));
}

Context context = Context.NONE;
Expand Down Expand Up @@ -328,14 +326,12 @@ private static PollResponse<KeyVaultBackupOperation> processBackupOperationRespo
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultRestoreOperation, KeyVaultRestoreResult> beginRestore(String folderUrl, String sasToken) {
if (folderUrl == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'folderUrl'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'folderUrl'")));
}
if (sasToken == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'sasToken'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'sasToken'")));
}
Context context = Context.NONE;
return SyncPoller.createPoller(getDefaultPollingInterval(),
Expand Down Expand Up @@ -486,21 +482,18 @@ private static PollResponse<KeyVaultRestoreOperation> processRestoreOperationRes
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultSelectiveKeyRestoreOperation, KeyVaultSelectiveKeyRestoreResult> beginSelectiveKeyRestore(String keyName, String folderUrl, String sasToken) {
if (keyName == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'keyName'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'keyName'")));
}

if (folderUrl == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'folderUrl'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'folderUrl'")));
}

if (sasToken == null) {
throw LOGGER.logExceptionAsError(new NullPointerException(
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'sasToken'")));
throw LOGGER.logExceptionAsError(
new NullPointerException(String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'sasToken'")));
}

Context context = Context.NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ private Configuration validateEndpointAndGetBuildConfiguration() {

if (buildEndpoint == null) {
throw LOGGER.logExceptionAsError(
new IllegalStateException(
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)));
new IllegalStateException(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED));
}
return buildConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ HttpPipeline getHttpPipeline() {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<KeyVaultSetting> updateSetting(KeyVaultSetting setting) {
Objects.requireNonNull(setting,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'setting'"));
Objects.requireNonNull(setting, String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'setting'"));

try {
String settingValue = null;
Expand Down Expand Up @@ -138,9 +136,7 @@ public Mono<KeyVaultSetting> updateSetting(KeyVaultSetting setting) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<KeyVaultSetting>> updateSettingWithResponse(KeyVaultSetting setting) {
Objects.requireNonNull(setting,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'setting'"));
Objects.requireNonNull(setting, String.format(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED, "'setting'"));

try {
String settingValue = null;
Expand Down
Loading

0 comments on commit 05cffab

Please sign in to comment.