Skip to content

Commit

Permalink
Integrate Sync Stack on KV Keys (#30162)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update

* update

* Replaced mentions of KeyAsyncClient with KeyClientImpl

* Added missing logging statements in createRsaKeyWithResponseAsync() and importKeyWithResponseAsync().

* Ensured context null-checks are present for all sync methods and removed them from all async methods.

* Renamed `keyClient` to `implClient` in KeyAsyncClient and KeyClient. Applied formatting fixes.

* Removed getLogger() and getDefaultPollingInterval() from KeyAsyncClient.

* Updated tests to correctly use Mockito's spy() and when() functions on a KeyClientImpl instance.

* Removed unused import from KeyAsyncClient.

* Changed config to open implementation package to unnamed modules for tests.

Co-authored-by: Vinay Gera <vinay_work@hotmail.com>
Co-authored-by: vcolin7 <vicolina@microsoft.com>
  • Loading branch information
3 people authored Aug 4, 2022
1 parent ccafc5b commit 3bcf41a
Show file tree
Hide file tree
Showing 9 changed files with 1,658 additions and 1,047 deletions.
3 changes: 2 additions & 1 deletion sdk/keyvault/azure-security-keyvault-keys/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

--add-opens com.azure.security.keyvault.keys/com.azure.security.keyvault.keys=ALL-UNNAMED
--add-opens com.azure.security.keyvault.keys/com.azure.security.keyvault.keys.cryptography=ALL-UNNAMED
--add-opens com.azure.security.keyvault.keys/com.azure.security.keyvault.keys.implementation=ALL-UNNAMED
--add-opens com.azure.security.keyvault.keys/com.azure.security.keyvault.keys.models=ALL-UNNAMED
</javaModulesSurefireArgLine>
</properties>
Expand Down Expand Up @@ -104,7 +105,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.10.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.11.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.azure.core.util.polling.SyncPoller;
import com.azure.security.keyvault.keys.cryptography.CryptographyClient;
import com.azure.security.keyvault.keys.cryptography.CryptographyClientBuilder;
import com.azure.security.keyvault.keys.implementation.KeyService;
import com.azure.security.keyvault.keys.implementation.KeyClientImpl;
import com.azure.security.keyvault.keys.models.CreateEcKeyOptions;
import com.azure.security.keyvault.keys.models.CreateKeyOptions;
import com.azure.security.keyvault.keys.models.CreateOctKeyOptions;
Expand Down Expand Up @@ -52,17 +52,17 @@
* @see KeyClientBuilder
* @see PagedIterable
*/
@ServiceClient(builder = KeyClientBuilder.class, serviceInterfaces = KeyService.class)
@ServiceClient(builder = KeyClientBuilder.class, serviceInterfaces = KeyClientImpl.KeyService.class)
public final class KeyClient {
private final KeyAsyncClient client;
private final KeyClientImpl implClient;

/**
* Creates a {@link KeyClient} that uses a {@link KeyAsyncClient} to service requests.
* Creates a {@link KeyClient} that uses a {@link KeyClientImpl} to service requests.
*
* @param client The {@link KeyAsyncClient} that the client routes its request through.
* @param implClient the impl client.
*/
KeyClient(KeyAsyncClient client) {
this.client = client;
KeyClient(KeyClientImpl implClient) {
this.implClient = implClient;
}

/**
Expand All @@ -71,7 +71,7 @@ public final class KeyClient {
* @return The vault endpoint url.
*/
public String getVaultUrl() {
return client.getVaultUrl();
return implClient.getVaultUrl();
}

/**
Expand All @@ -94,7 +94,7 @@ public String getVaultUrl() {
* @throws IllegalArgumentException If {@code keyName} is {@code null} or empty.
*/
public CryptographyClient getCryptographyClient(String keyName) {
return client.getCryptographyClientBuilder(keyName, null).buildClient();
return implClient.getCryptographyClientBuilder(keyName, null).buildClient();
}

/**
Expand All @@ -109,7 +109,7 @@ public CryptographyClient getCryptographyClient(String keyName) {
* @throws IllegalArgumentException If {@code keyName} is {@code null} or empty.
*/
public CryptographyClient getCryptographyClient(String keyName, String keyVersion) {
return client.getCryptographyClientBuilder(keyName, keyVersion).buildClient();
return implClient.getCryptographyClientBuilder(keyName, keyVersion).buildClient();
}

/**
Expand Down Expand Up @@ -232,7 +232,7 @@ public KeyVaultKey createKey(CreateKeyOptions createKeyOptions) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyVaultKey> createKeyWithResponse(CreateKeyOptions createKeyOptions, Context context) {
return client.createKeyWithResponse(createKeyOptions, context).block();
return implClient.createKeyWithResponse(createKeyOptions, context);
}

/**
Expand Down Expand Up @@ -324,7 +324,7 @@ public KeyVaultKey createRsaKey(CreateRsaKeyOptions createRsaKeyOptions) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyVaultKey> createRsaKeyWithResponse(CreateRsaKeyOptions createRsaKeyOptions, Context context) {
return client.createRsaKeyWithResponse(createRsaKeyOptions, context).block();
return implClient.createRsaKeyWithResponse(createRsaKeyOptions, context);
}

/**
Expand Down Expand Up @@ -419,7 +419,7 @@ public KeyVaultKey createEcKey(CreateEcKeyOptions createEcKeyOptions) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyVaultKey> createEcKeyWithResponse(CreateEcKeyOptions createEcKeyOptions, Context context) {
return client.createEcKeyWithResponse(createEcKeyOptions, context).block();
return implClient.createEcKeyWithResponse(createEcKeyOptions, context);
}

/**
Expand Down Expand Up @@ -505,7 +505,7 @@ public KeyVaultKey createOctKey(CreateOctKeyOptions createOctKeyOptions) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyVaultKey> createOctKeyWithResponse(CreateOctKeyOptions createOctKeyOptions, Context context) {
return client.createOctKeyWithResponse(createOctKeyOptions, context).block();
return implClient.createOctKeyWithResponse(createOctKeyOptions, context);
}

/**
Expand Down Expand Up @@ -619,7 +619,7 @@ public KeyVaultKey importKey(ImportKeyOptions importKeyOptions) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyVaultKey> importKeyWithResponse(ImportKeyOptions importKeyOptions, Context context) {
return client.importKeyWithResponse(importKeyOptions, context).block();
return implClient.importKeyWithResponse(importKeyOptions, context);
}

/**
Expand Down Expand Up @@ -691,7 +691,7 @@ public KeyVaultKey getKey(String name, String version) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyVaultKey> getKeyWithResponse(String name, String version, Context context) {
return client.getKeyWithResponse(name, version, context).block();
return implClient.getKeyWithResponse(name, version, context);
}

/**
Expand Down Expand Up @@ -807,7 +807,7 @@ public KeyVaultKey updateKeyProperties(KeyProperties keyProperties, KeyOperation
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyVaultKey> updateKeyPropertiesWithResponse(KeyProperties keyProperties, Context context,
KeyOperation... keyOperations) {
return client.updateKeyPropertiesWithResponse(keyProperties, context, keyOperations).block();
return implClient.updateKeyPropertiesWithResponse(keyProperties, context, keyOperations);
}

/**
Expand Down Expand Up @@ -849,7 +849,7 @@ public Response<KeyVaultKey> updateKeyPropertiesWithResponse(KeyProperties keyPr
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<DeletedKey, Void> beginDeleteKey(String name) {
return client.beginDeleteKey(name).getSyncPoller();
return implClient.beginDeleteKeyAsync(name).getSyncPoller();
}

/**
Expand Down Expand Up @@ -906,7 +906,7 @@ public DeletedKey getDeletedKey(String name) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<DeletedKey> getDeletedKeyWithResponse(String name, Context context) {
return client.getDeletedKeyWithResponse(name, context).block();
return implClient.getDeletedKeyWithResponse(name, context);
}

/**
Expand Down Expand Up @@ -959,7 +959,7 @@ public void purgeDeletedKey(String name) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> purgeDeletedKeyWithResponse(String name, Context context) {
return client.purgeDeletedKeyWithResponse(name, context).block();
return implClient.purgeDeletedKeyWithResponse(name, context);
}

/**
Expand Down Expand Up @@ -995,7 +995,7 @@ public Response<Void> purgeDeletedKeyWithResponse(String name, Context context)
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultKey, Void> beginRecoverDeletedKey(String name) {
return client.beginRecoverDeletedKey(name).getSyncPoller();
return implClient.beginRecoverDeletedKeyAsync(name).getSyncPoller();
}

/**
Expand Down Expand Up @@ -1068,7 +1068,7 @@ public byte[] backupKey(String name) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<byte[]> backupKeyWithResponse(String name, Context context) {
return client.backupKeyWithResponse(name, context).block();
return implClient.backupKeyWithResponse(name, context);
}

/**
Expand Down Expand Up @@ -1143,7 +1143,7 @@ public KeyVaultKey restoreKeyBackup(byte[] backup) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyVaultKey> restoreKeyBackupWithResponse(byte[] backup, Context context) {
return client.restoreKeyBackupWithResponse(backup, context).block();
return implClient.restoreKeyBackupWithResponse(backup, context);
}

/**
Expand Down Expand Up @@ -1243,7 +1243,7 @@ public PagedIterable<KeyProperties> listPropertiesOfKeys() {
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<KeyProperties> listPropertiesOfKeys(Context context) {
return new PagedIterable<>(client.listPropertiesOfKeys(context));
return new PagedIterable<>(implClient.listPropertiesOfKeys(context));
}

/**
Expand Down Expand Up @@ -1322,7 +1322,7 @@ public PagedIterable<DeletedKey> listDeletedKeys() {
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<DeletedKey> listDeletedKeys(Context context) {
return new PagedIterable<>(client.listDeletedKeys(context));
return new PagedIterable<>(implClient.listDeletedKeys(context));
}

/**
Expand Down Expand Up @@ -1421,7 +1421,7 @@ public PagedIterable<KeyProperties> listPropertiesOfKeyVersions(String name) {
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<KeyProperties> listPropertiesOfKeyVersions(String name, Context context) {
return new PagedIterable<>(client.listPropertiesOfKeyVersions(name, context));
return new PagedIterable<>(implClient.listPropertiesOfKeyVersions(name, context));
}

/**
Expand All @@ -1445,7 +1445,7 @@ public PagedIterable<KeyProperties> listPropertiesOfKeyVersions(String name, Con
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public byte[] getRandomBytes(int count) {
return client.getRandomBytes(count).block();
return getRandomBytesWithResponse(count, Context.NONE).getValue();
}

/**
Expand Down Expand Up @@ -1474,7 +1474,7 @@ public byte[] getRandomBytes(int count) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<byte[]> getRandomBytesWithResponse(int count, Context context) {
return client.getRandomBytesWithResponse(count, context).block();
return implClient.getRandomBytesWithResponse(count, context);
}

/**
Expand Down Expand Up @@ -1504,7 +1504,8 @@ public Response<byte[]> getRandomBytesWithResponse(int count, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public ReleaseKeyResult releaseKey(String name, String targetAttestationToken) {
return client.releaseKey(name, targetAttestationToken).block();
return releaseKeyWithResponse(name, "", targetAttestationToken, new ReleaseKeyOptions(), Context.NONE)
.getValue();
}

/**
Expand Down Expand Up @@ -1538,7 +1539,8 @@ public ReleaseKeyResult releaseKey(String name, String targetAttestationToken) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public ReleaseKeyResult releaseKey(String name, String version, String targetAttestationToken) {
return client.releaseKey(name, version, targetAttestationToken).block();
return releaseKeyWithResponse(name, version, targetAttestationToken, new ReleaseKeyOptions(), Context.NONE)
.getValue();
}

/**
Expand Down Expand Up @@ -1585,7 +1587,7 @@ public ReleaseKeyResult releaseKey(String name, String version, String targetAtt
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<ReleaseKeyResult> releaseKeyWithResponse(String name, String version, String targetAttestationToken,
ReleaseKeyOptions releaseKeyOptions, Context context) {
return client.releaseKeyWithResponse(name, version, targetAttestationToken, releaseKeyOptions, context).block();
return implClient.releaseKeyWithResponse(name, version, targetAttestationToken, releaseKeyOptions, context);
}

/**
Expand Down Expand Up @@ -1613,7 +1615,7 @@ public Response<ReleaseKeyResult> releaseKeyWithResponse(String name, String ver
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public KeyVaultKey rotateKey(String name) {
return client.rotateKey(name).block();
return rotateKeyWithResponse(name, Context.NONE).getValue();
}

/**
Expand Down Expand Up @@ -1646,7 +1648,7 @@ public KeyVaultKey rotateKey(String name) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyVaultKey> rotateKeyWithResponse(String name, Context context) {
return client.rotateKeyWithResponse(name, context).block();
return implClient.rotateKeyWithResponse(name, context);
}

/**
Expand All @@ -1673,7 +1675,7 @@ public Response<KeyVaultKey> rotateKeyWithResponse(String name, Context context)
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public KeyRotationPolicy getKeyRotationPolicy(String keyName) {
return client.getKeyRotationPolicy(keyName).block();
return getKeyRotationPolicyWithResponse(keyName, Context.NONE).getValue();
}

/**
Expand Down Expand Up @@ -1705,7 +1707,7 @@ public KeyRotationPolicy getKeyRotationPolicy(String keyName) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<KeyRotationPolicy> getKeyRotationPolicyWithResponse(String keyName, Context context) {
return client.getKeyRotationPolicyWithResponse(keyName, context).block();
return implClient.getKeyRotationPolicyWithResponse(keyName, context);
}

/**
Expand Down Expand Up @@ -1747,7 +1749,7 @@ public Response<KeyRotationPolicy> getKeyRotationPolicyWithResponse(String keyNa
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public KeyRotationPolicy updateKeyRotationPolicy(String keyName, KeyRotationPolicy keyRotationPolicy) {
return client.updateKeyRotationPolicy(keyName, keyRotationPolicy).block();
return updateKeyRotationPolicyWithResponse(keyName, keyRotationPolicy, Context.NONE).getValue();
}

/**
Expand Down Expand Up @@ -1795,6 +1797,6 @@ public KeyRotationPolicy updateKeyRotationPolicy(String keyName, KeyRotationPoli
public Response<KeyRotationPolicy> updateKeyRotationPolicyWithResponse(String keyName,
KeyRotationPolicy keyRotationPolicy,
Context context) {
return client.updateKeyRotationPolicyWithResponse(keyName, keyRotationPolicy, context).block();
return implClient.updateKeyRotationPolicyWithResponse(keyName, keyRotationPolicy, context);
}
}
Loading

0 comments on commit 3bcf41a

Please sign in to comment.