Skip to content

Commit

Permalink
Arch board feedback and language alignment for Key Vault Keys (Azure#…
Browse files Browse the repository at this point in the history
…27442)

* Applied PR feedback.

* Renamed the parameter `name` to `keyName` in `getKeyRotationPolicy` and `updateKeyRotationPolicy` methods on both `KeyClient` and `KeyAsyncClient`. Renamed `options` to `releaseKeyOptions` in `releaseKey` methods on both clients as well.

* Updated CHANGELOG.
  • Loading branch information
vcolin7 authored Mar 4, 2022
1 parent 7373178 commit b3fe9aa
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 90 deletions.
2 changes: 2 additions & 0 deletions sdk/keyvault/azure-security-keyvault-keys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Features Added

### Breaking Changes
- Changed `getRandomBytes` operations in `KeyClient` and `KeyAsyncClient` to return `byte[]` instead of `RandomBytes`.
- Removed the `RandomBytes` class.

### Bugs Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ public Mono<ReleaseKeyResult> releaseKey(String name, String version, String tar
* @param version The version of the key to retrieve. If this is empty or {@code null}, this call is equivalent to
* calling {@link KeyAsyncClient#releaseKey(String, String)}, with the latest key version being released.
* @param targetAttestationToken The attestation assertion for the target of the key release.
* @param options Additional {@link ReleaseKeyOptions options} for releasing a {@link KeyVaultKey key}.
* @param releaseKeyOptions Additional {@link ReleaseKeyOptions options} for releasing a {@link KeyVaultKey key}.
*
* @return A {@link Mono} containing the {@link Response HTTP response} for this operation and the
* {@link ReleaseKeyResult} containing the released key.
Expand All @@ -2063,17 +2063,17 @@ public Mono<ReleaseKeyResult> releaseKey(String name, String version, String tar
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<ReleaseKeyResult>> releaseKeyWithResponse(String name, String version,
String targetAttestationToken,
ReleaseKeyOptions options) {
ReleaseKeyOptions releaseKeyOptions) {
try {
return withContext(context ->
releaseKeyWithResponse(name, version, targetAttestationToken, options, context));
releaseKeyWithResponse(name, version, targetAttestationToken, releaseKeyOptions, context));
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

Mono<Response<ReleaseKeyResult>> releaseKeyWithResponse(String name, String version, String targetAttestationToken,
ReleaseKeyOptions options, Context context) {
ReleaseKeyOptions releaseKeyOptions, Context context) {
try {
if (CoreUtils.isNullOrEmpty(name)) {
return monoError(logger, new IllegalArgumentException("'name' cannot be null or empty"));
Expand All @@ -2084,12 +2084,12 @@ Mono<Response<ReleaseKeyResult>> releaseKeyWithResponse(String name, String vers
new IllegalArgumentException("'targetAttestationToken' cannot be null or empty"));
}

options = options == null ? new ReleaseKeyOptions() : options;
releaseKeyOptions = releaseKeyOptions == null ? new ReleaseKeyOptions() : releaseKeyOptions;

KeyReleaseParameters keyReleaseParameters = new KeyReleaseParameters()
.setTargetAttestationToken(targetAttestationToken)
.setAlgorithm(options.getAlgorithm())
.setNonce(options.getNonce());
.setAlgorithm(releaseKeyOptions.getAlgorithm())
.setNonce(releaseKeyOptions.getNonce());

return service.release(vaultUrl, name, version, keyServiceVersion.getVersion(), keyReleaseParameters,
"application/json", context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE))
Expand Down Expand Up @@ -2200,17 +2200,17 @@ Mono<Response<KeyVaultKey>> rotateKeyWithResponse(String name, Context context)
* </pre>
* <!-- end com.azure.security.keyvault.keys.KeyAsyncClient.getKeyRotationPolicy#String -->
*
* @param name The name of the {@link KeyVaultKey key}.
* @param keyName The name of the {@link KeyVaultKey key}.
*
* @return A {@link Mono} containing the {@link KeyRotationPolicy} for the key.
*
* @throws IllegalArgumentException If {@code name} is {@code null} or empty.
* @throws ResourceNotFoundException If the {@link KeyVaultKey key} for the provided {@code name} does not exist.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<KeyRotationPolicy> getKeyRotationPolicy(String name) {
public Mono<KeyRotationPolicy> getKeyRotationPolicy(String keyName) {
try {
return getKeyRotationPolicyWithResponse(name).flatMap(FluxUtil::toMono);
return getKeyRotationPolicyWithResponse(keyName).flatMap(FluxUtil::toMono);
} catch (RuntimeException e) {
return monoError(logger, e);
}
Expand All @@ -2234,7 +2234,7 @@ public Mono<KeyRotationPolicy> getKeyRotationPolicy(String name) {
* </pre>
* <!-- end com.azure.security.keyvault.keys.KeyAsyncClient.getKeyRotationPolicyWithResponse#String -->
*
* @param name The name of the {@link KeyVaultKey key}.
* @param keyName The name of the {@link KeyVaultKey key}.
*
* @return A {@link Mono} containing the {@link Response HTTP response} for this operation and the
* {@link KeyRotationPolicy} for the key.
Expand All @@ -2243,24 +2243,24 @@ public Mono<KeyRotationPolicy> getKeyRotationPolicy(String name) {
* @throws ResourceNotFoundException If the {@link KeyVaultKey key} for the provided {@code name} does not exist.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<KeyRotationPolicy>> getKeyRotationPolicyWithResponse(String name) {
public Mono<Response<KeyRotationPolicy>> getKeyRotationPolicyWithResponse(String keyName) {
try {
return withContext(context -> getKeyRotationPolicyWithResponse(name, context));
return withContext(context -> getKeyRotationPolicyWithResponse(keyName, context));
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

Mono<Response<KeyRotationPolicy>> getKeyRotationPolicyWithResponse(String name, Context context) {
Mono<Response<KeyRotationPolicy>> getKeyRotationPolicyWithResponse(String keyName, Context context) {
try {
if (CoreUtils.isNullOrEmpty(name)) {
return monoError(logger, new IllegalArgumentException("'name' cannot be null or empty"));
if (CoreUtils.isNullOrEmpty(keyName)) {
return monoError(logger, new IllegalArgumentException("'keyName' cannot be null or empty"));
}

return service.getKeyRotationPolicy(vaultUrl, name, keyServiceVersion.getVersion(), "application/json",
return service.getKeyRotationPolicy(vaultUrl, keyName, keyServiceVersion.getVersion(), "application/json",
context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE))
.doOnRequest(ignored -> logger.verbose("Retrieving key rotation policy for key with name.", name))
.doOnSuccess(response -> logger.verbose("Retrieved key rotation policy for key with name.", name))
.doOnRequest(ignored -> logger.verbose("Retrieving key rotation policy for key with name.", keyName))
.doOnSuccess(response -> logger.verbose("Retrieved key rotation policy for key with name.", keyName))
.doOnError(error -> logger.warning("Failed to retrieve key rotation policy - {}", error));
} catch (RuntimeException e) {
return monoError(logger, e);
Expand Down Expand Up @@ -2296,7 +2296,7 @@ Mono<Response<KeyRotationPolicy>> getKeyRotationPolicyWithResponse(String name,
* </pre>
* <!-- end com.azure.security.keyvault.keys.KeyAsyncClient.updateKeyRotationPolicy#String-KeyRotationPolicy -->
*
* @param name The name of the {@link KeyVaultKey key}.
* @param keyName The name of the {@link KeyVaultKey key}.
* @param keyRotationPolicy The {@link KeyRotationPolicy} for the key.
*
* @return A {@link Mono} containing the {@link KeyRotationPolicy} for the key.
Expand All @@ -2305,9 +2305,9 @@ Mono<Response<KeyRotationPolicy>> getKeyRotationPolicyWithResponse(String name,
* @throws ResourceNotFoundException If the {@link KeyVaultKey key} for the provided {@code name} does not exist.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<KeyRotationPolicy> updateKeyRotationPolicy(String name, KeyRotationPolicy keyRotationPolicy) {
public Mono<KeyRotationPolicy> updateKeyRotationPolicy(String keyName, KeyRotationPolicy keyRotationPolicy) {
try {
return updateKeyRotationPolicyWithResponse(name, keyRotationPolicy).flatMap(FluxUtil::toMono);
return updateKeyRotationPolicyWithResponse(keyName, keyRotationPolicy).flatMap(FluxUtil::toMono);
} catch (RuntimeException e) {
return monoError(logger, e);
}
Expand Down Expand Up @@ -2344,7 +2344,7 @@ public Mono<KeyRotationPolicy> updateKeyRotationPolicy(String name, KeyRotationP
* </pre>
* <!-- end com.azure.security.keyvault.keys.KeyAsyncClient.updateKeyRotationPolicyWithResponse#String-KeyRotationPolicy -->
*
* @param name The name of the {@link KeyVaultKey key}.
* @param keyName The name of the {@link KeyVaultKey key}.
* @param keyRotationPolicy The {@link KeyRotationPolicy} for the key.
*
* @return A {@link Mono} containing the {@link Response HTTP response} for this operation and the
Expand All @@ -2354,25 +2354,28 @@ public Mono<KeyRotationPolicy> updateKeyRotationPolicy(String name, KeyRotationP
* @throws ResourceNotFoundException If the {@link KeyVaultKey key} for the provided {@code name} does not exist.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<KeyRotationPolicy>> updateKeyRotationPolicyWithResponse(String name, KeyRotationPolicy keyRotationPolicy) {
public Mono<Response<KeyRotationPolicy>> updateKeyRotationPolicyWithResponse(String keyName,
KeyRotationPolicy keyRotationPolicy) {
try {
return withContext(context ->
updateKeyRotationPolicyWithResponse(name, keyRotationPolicy, context));
updateKeyRotationPolicyWithResponse(keyName, keyRotationPolicy, context));
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

Mono<Response<KeyRotationPolicy>> updateKeyRotationPolicyWithResponse(String name, KeyRotationPolicy keyRotationPolicy, Context context) {
Mono<Response<KeyRotationPolicy>> updateKeyRotationPolicyWithResponse(String keyName,
KeyRotationPolicy keyRotationPolicy,
Context context) {
try {
if (CoreUtils.isNullOrEmpty(name)) {
return monoError(logger, new IllegalArgumentException("'name' cannot be null or empty"));
if (CoreUtils.isNullOrEmpty(keyName)) {
return monoError(logger, new IllegalArgumentException("'keyName' cannot be null or empty"));
}

return service.updateKeyRotationPolicy(vaultUrl, name, keyServiceVersion.getVersion(), keyRotationPolicy,
return service.updateKeyRotationPolicy(vaultUrl, keyName, keyServiceVersion.getVersion(), keyRotationPolicy,
"application/json", context.addData(AZ_TRACING_NAMESPACE_KEY, KEYVAULT_TRACING_NAMESPACE_VALUE))
.doOnRequest(ignored -> logger.verbose("Updating key rotation policy for key with name.", name))
.doOnSuccess(response -> logger.verbose("Updated key rotation policy for key with name.", name))
.doOnRequest(ignored -> logger.verbose("Updating key rotation policy for key with name.", keyName))
.doOnSuccess(response -> logger.verbose("Updated key rotation policy for key with name.", keyName))
.doOnError(error -> logger.warning("Failed to retrieve key rotation policy - {}", error));
} catch (RuntimeException e) {
return monoError(logger, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ public ReleaseKeyResult releaseKey(String name, String version, String targetAtt
* is equivalent to calling {@link KeyAsyncClient#releaseKey(String, String)}, with the latest key version being
* released.
* @param targetAttestationToken The attestation assertion for the target of the key release.
* @param options Additional {@link ReleaseKeyOptions options} for releasing a {@link KeyVaultKey key}.
* @param releaseKeyOptions Additional {@link ReleaseKeyOptions options} for releasing a {@link KeyVaultKey key}.
* @param context Additional {@link Context} that is passed through the {@link HttpPipeline} during the service
* call.
*
Expand All @@ -1583,8 +1583,8 @@ public ReleaseKeyResult releaseKey(String name, String version, String targetAtt
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<ReleaseKeyResult> releaseKeyWithResponse(String name, String version, String targetAttestationToken,
ReleaseKeyOptions options, Context context) {
return client.releaseKeyWithResponse(name, version, targetAttestationToken, options, context).block();
ReleaseKeyOptions releaseKeyOptions, Context context) {
return client.releaseKeyWithResponse(name, version, targetAttestationToken, releaseKeyOptions, context).block();
}

/**
Expand Down Expand Up @@ -1663,16 +1663,16 @@ public Response<KeyVaultKey> rotateKeyWithResponse(String name, Context context)
* </pre>
* <!-- end com.azure.security.keyvault.keys.KeyClient.getKeyRotationPolicy#String -->
*
* @param name The name of the {@link KeyVaultKey key}.
* @param keyName The name of the {@link KeyVaultKey key}.
*
* @return The {@link KeyRotationPolicy} for the {@link KeyVaultKey key}.
*
* @throws IllegalArgumentException If {@code name} is {@code null} or empty.
* @throws ResourceNotFoundException If the {@link KeyVaultKey key} for the provided {@code name} does not exist.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public KeyRotationPolicy getKeyRotationPolicy(String name) {
return client.getKeyRotationPolicy(name).block();
public KeyRotationPolicy getKeyRotationPolicy(String keyName) {
return client.getKeyRotationPolicy(keyName).block();
}

/**
Expand All @@ -1692,7 +1692,7 @@ public KeyRotationPolicy getKeyRotationPolicy(String name) {
* </pre>
* <!-- end com.azure.security.keyvault.keys.KeyClient.getKeyRotationPolicyWithResponse#String-Context -->
*
* @param name The name of the {@link KeyVaultKey key}.
* @param keyName The name of the {@link KeyVaultKey key}.
* @param context Additional {@link Context} that is passed through the {@link HttpPipeline} during the service
* call.
*
Expand All @@ -1703,8 +1703,8 @@ public KeyRotationPolicy getKeyRotationPolicy(String name) {
* @throws ResourceNotFoundException If the {@link KeyVaultKey key} for the provided {@code name} does not exist.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyRotationPolicy> getKeyRotationPolicyWithResponse(String name, Context context) {
return client.getKeyRotationPolicyWithResponse(name, context).block();
public Response<KeyRotationPolicy> getKeyRotationPolicyWithResponse(String keyName, Context context) {
return client.getKeyRotationPolicyWithResponse(keyName, context).block();
}

/**
Expand Down Expand Up @@ -1736,7 +1736,7 @@ public Response<KeyRotationPolicy> getKeyRotationPolicyWithResponse(String name,
* </pre>
* <!-- end com.azure.security.keyvault.keys.KeyClient.updateKeyRotationPolicy#String-KeyRotationPolicy -->
*
* @param name The name of the {@link KeyVaultKey key}.
* @param keyName The name of the {@link KeyVaultKey key}.
* @param keyRotationPolicy The {@link KeyRotationPolicy} for the ke{@link KeyVaultKey key}y.
*
* @return The {@link KeyRotationPolicy} for the {@link KeyVaultKey key}.
Expand All @@ -1745,8 +1745,8 @@ public Response<KeyRotationPolicy> getKeyRotationPolicyWithResponse(String name,
* @throws ResourceNotFoundException If the {@link KeyVaultKey key} for the provided {@code name} does not exist.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public KeyRotationPolicy updateKeyRotationPolicy(String name, KeyRotationPolicy keyRotationPolicy) {
return client.updateKeyRotationPolicy(name, keyRotationPolicy).block();
public KeyRotationPolicy updateKeyRotationPolicy(String keyName, KeyRotationPolicy keyRotationPolicy) {
return client.updateKeyRotationPolicy(keyName, keyRotationPolicy).block();
}

/**
Expand Down Expand Up @@ -1779,7 +1779,7 @@ public KeyRotationPolicy updateKeyRotationPolicy(String name, KeyRotationPolicy
* </pre>
* <!-- end com.azure.security.keyvault.keys.KeyClient.updateKeyRotationPolicyWithResponse#String-KeyRotationPolicy-Context -->
*
* @param name The name of the {@link KeyVaultKey key}.
* @param keyName The name of the {@link KeyVaultKey key}.
* @param keyRotationPolicy The {@link KeyRotationPolicy} for the key.
* @param context Additional {@link Context} that is passed through the {@link HttpPipeline} during the service
* call.
Expand All @@ -1791,7 +1791,9 @@ public KeyRotationPolicy updateKeyRotationPolicy(String name, KeyRotationPolicy
* @throws ResourceNotFoundException If the {@link KeyVaultKey key} for the provided {@code name} does not exist.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyRotationPolicy> updateKeyRotationPolicyWithResponse(String name, KeyRotationPolicy keyRotationPolicy, Context context) {
return client.updateKeyRotationPolicyWithResponse(name, keyRotationPolicy, context).block();
public Response<KeyRotationPolicy> updateKeyRotationPolicyWithResponse(String keyName,
KeyRotationPolicy keyRotationPolicy,
Context context) {
return client.updateKeyRotationPolicyWithResponse(keyName, keyRotationPolicy, context).block();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public CreateEcKeyOptions setEnabled(Boolean enabled) {
*
* @return The updated {@link CreateEcKeyOptions} object.
*/
@Override
public CreateEcKeyOptions setExportable(Boolean exportable) {
super.setExportable(exportable);

Expand All @@ -168,6 +169,7 @@ public CreateEcKeyOptions setExportable(Boolean exportable) {
*
* @return The updated {@link CreateEcKeyOptions} object.
*/
@Override
public CreateEcKeyOptions setReleasePolicy(KeyReleasePolicy releasePolicy) {
super.setReleasePolicy(releasePolicy);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public CreateOctKeyOptions setTags(Map<String, String> tags) {
*
* @return The updated {@link CreateOctKeyOptions} object.
*/
@Override
public CreateOctKeyOptions setEnabled(Boolean enabled) {
super.setEnabled(enabled);

Expand All @@ -154,6 +155,7 @@ public CreateOctKeyOptions setEnabled(Boolean enabled) {
*
* @return The updated {@link CreateOctKeyOptions} object.
*/
@Override
public CreateOctKeyOptions setExportable(Boolean exportable) {
super.setExportable(exportable);

Expand All @@ -167,6 +169,7 @@ public CreateOctKeyOptions setExportable(Boolean exportable) {
*
* @return The updated {@link CreateOctKeyOptions} object.
*/
@Override
public CreateOctKeyOptions setReleasePolicy(KeyReleasePolicy releasePolicy) {
super.setReleasePolicy(releasePolicy);

Expand Down
Loading

0 comments on commit b3fe9aa

Please sign in to comment.