diff --git a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle.xml b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle.xml
index 41e4303d4378c..a9dda36594109 100755
--- a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle.xml
+++ b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle.xml
@@ -60,7 +60,12 @@ page at http://checkstyle.sourceforge.net/config.html -->
Create a pipeline without configuration Create a pipeline using the default HTTP client and a retry policy Code Samples Creates a new EC key. Subscribes to the call asynchronously and prints out the newly created key details when a response has been received. The {@link KeyType keyType} indicates the type of key to create. Possible values include: {@link KeyType#EC EC},
+ * {@link KeyType#EC_HSM EC-HSM}, {@link KeyType#RSA RSA}, {@link KeyType#RSA_HSM RSA-HSM} and {@link KeyType#OCT OCT}. Code Samples Creates a new EC key. Subscribes to the call asynchronously and prints out the newly created key details when a response has been received. Code Samples Creates a new Rsa key which activates in one day and expires in one year. Subscribes to the call asynchronously
* and prints out the newly created key details when a response has been received. Code Samples Creates a new RSA key with size 2048 which activates in one day and expires in one year. Subscribes to the call asynchronously
* and prints out the newly created key details when a response has been received. The {@link RsaKeyCreateOptions} is required. The {@link RsaKeyCreateOptions#keySize() keySize} can be optionally specified. The {@link RsaKeyCreateOptions#expires() expires}
+ * and {@link RsaKeyCreateOptions#notBefore() notBefore} values are optional. The {@link RsaKeyCreateOptions#enabled() enabled} field
+ * is set to true by Azure Key Vault, if not specified. The {@link RsaKeyCreateOptions#keyType() keyType} indicates the type of key to create. Possible values include: {@link KeyType#RSA RSA} and
+ * {@link KeyType#RSA_HSM RSA-HSM}. Code Samples Creates a new EC key with P-384 web key curve. The key activates in one day and expires in one year. Subscribes to the call asynchronously
* and prints out the newly created ec key details when a response has been received. The {@link EcKeyCreateOptions} parameter is required. The {@link EcKeyCreateOptions#curve() key curve} can be optionally specified. If not specified,
+ * default value of {@link KeyCurveName#P_256 P-256} is used by Azure Key Vault. The {@link EcKeyCreateOptions#expires() expires} and {@link EcKeyCreateOptions#notBefore() notBefore} values
+ * are optional. The {@link EcKeyCreateOptions#enabled() enabled} field is set to true by Azure Key Vault, if not specified. The {@link EcKeyCreateOptions#keyType() keyType} indicates the type of key to create. Possible values include: {@link KeyType#EC EC} and
+ * {@link KeyType#EC_HSM EC-HSM}. Code Samples Creates a new EC key with P-384 web key curve. The key activates in one day and expires in one year. Subscribes to the call asynchronously
+ * and prints out the newly created ec key details when a response has been received. The {@code keyImportOptions} is required and its fields {@link KeyImportOptions#name() name} and {@link KeyImportOptions#keyMaterial() key material} cannot
+ * be null. The {@link KeyImportOptions#expires() expires} and {@link KeyImportOptions#notBefore() notBefore} values in {@code keyImportOptions}
+ * are optional. If not specified, no values are set for the fields. The {@link KeyImportOptions#enabled() enabled} field is set to true and
+ * the {@link KeyImportOptions#hsm() hsm} field is set to false by Azure Key Vault, if they are not specified. Code Samples Imports a new key into key vault. Subscribes to the call asynchronously and prints out the newly imported key details
+ * when a response has been received. Code Samples Gets a specific version of the key in the key vault. Subscribes to the call asynchronously and prints out the
* returned key details when a response has been received. Code Samples Gets a specific version of the key in the key vault. Subscribes to the call asynchronously and prints out the
+ * returned key details when a response has been received. Code Samples Gets latest version of the key in the key vault. Subscribes to the call asynchronously and prints out the
* returned key details when a response has been received. Code Samples Gets latest version of the key in the key vault. Subscribes to the call asynchronously and prints out the
+ * returned key details when a response has been received. The list operations {@link KeyAsyncClient#listKeys()} and {@link KeyAsyncClient#listKeyVersions(String)} return
* the {@link Flux} containing {@link KeyBase base key} as output excluding the key material of the key.
* This operation can then be used to get the full key with its key material from {@code keyBase}. The list operations {@link KeyAsyncClient#listKeys()} and {@link KeyAsyncClient#listKeyVersions(String)} return
+ * the {@link Flux} containing {@link KeyBase base key} as output excluding the key material of the key.
+ * This operation can then be used to get the full key with its key material from {@code keyBase}. Code Samples Gets latest version of the key, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
* returned key details when a response has been received. Code Samples Gets latest version of the key, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
+ * returned key details when a response has been received. Code Samples Gets latest version of the key, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
* returned key details when a response has been received. Code Samples Gets latest version of the key, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
+ * returned key details when a response has been received. Code Samples Deletes the key in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
+ * deleted key details when a response has been received. Code Samples Deletes the key in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
* deleted key details when a response has been received.
- * HttpPipeline.builder()
+ * new HttpPipelineBuilder()
* .build();
*
*
*
- * HttpPipeline.builder()
+ * new HttpPipelineBuilder()
* .httpClient(HttpClient.createDefault())
* .policies(new RetryPolicy())
* .build();
@@ -41,7 +41,12 @@ public class HttpPipelineBuilder {
private List
- * keyAsyncClient.createKey("keyName", KeyType.EC).subscribe(keyResponse ->
- * System.out.printf("Key is created with name %s and id %s \n", keyResponse.value().name(), keyResponse.value().id()));
- *
+ *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.createKey#string-keyType}
*
* @param name The name of the key being created.
* @param keyType The type of key to create. For valid values, see {@link KeyType KeyType}.
* @throws ResourceModifiedException if {@code name} or {@code keyType} is null.
* @throws HttpRequestException if {@code name} is empty string.
+ * @return A {@link Mono} containing the {@link Key created key}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono
- * KeyCreateOptions keyCreateOptions = new KeyCreateOptions("keyName", KeyType.RSA)
- * .notBefore(OffsetDateTime.now().plusDays(1))
- * .expires(OffsetDateTime.now().plusYears(1));
*
- * keyAsyncClient.createKey(keyCreateOptions).subscribe(keyResponse ->
- * System.out.printf("Key is created with name %s and id %s \n", keyResponse.value().name(), keyResponse.value().id()));
- *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.createKey#keyCreateOptions}
*
* @param keyCreateOptions The key configuration object containing information about the key being created.
* @throws NullPointerException if {@code keyCreateOptions} is {@code null}.
* @throws ResourceModifiedException if {@code keyCreateOptions} is malformed.
* @throws HttpRequestException if {@code name} is empty string.
- * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link Key created key}.
+ * @return A {@link Mono} containing the {@link Key created key}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono
- * RsaKeyCreateOptions rsaKeyCreateOptions = new RsaKeyCreateOptions("keyName", KeyType.RSA)
- * .keySize(2048)
- * .notBefore(OffsetDateTime.now().plusDays(1))
- * .expires(OffsetDateTime.now().plusYears(1));
*
- * keyAsyncClient.createRsaKey(rsaKeyCreateOptions).subscribe(keyResponse ->
- * System.out.printf("RSA Key is created with name %s and id %s \n", keyResponse.value().name(), keyResponse.value().id()));
- *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.createRsaKey#RsaKeyCreateOptions}
+ *
+ * @param rsaKeyCreateOptions The key configuration object containing information about the rsa key being created.
+ * @throws NullPointerException if {@code rsaKeyCreateOptions} is {@code null}.
+ * @throws ResourceModifiedException if {@code rsaKeyCreateOptions} is malformed.
+ * @throws HttpRequestException if {@code name} is empty string.
+ * @return A {@link Mono} containing the {@link Key created key}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono
- * EcKeyCreateOptions ecKeyCreateOptions = new EcKeyCreateOptions("keyName", KeyType.EC)
- * .curve(KeyCurveName.P_384)
- * .notBefore(OffsetDateTime.now().plusDays(1))
- * .expires(OffsetDateTime.now().plusYears(1));
*
- * keyAsyncClient.createEcKey(ecKeyCreateOptions).subscribe(keyResponse ->
- * System.out.printf("EC Key is created with name %s and id %s \n", keyResponse.value().name(), keyResponse.value().id()));
- *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.createEcKey#EcKeyCreateOptions}
+ *
+ * @param ecKeyCreateOptions The key options object containing information about the ec key being created.
+ * @throws NullPointerException if {@code ecKeyCreateOptions} is {@code null}.
+ * @throws ResourceModifiedException if {@code ecKeyCreateOptions} is malformed.
+ * @throws HttpRequestException if {@code name} is empty string.
+ * @return A {@link Mono} containing the {@link Key created key}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono
+ * KeyImportOptions keyImportOptions = new KeyImportOptions("keyName", jsonWebKeyToImport)
+ * .hsm(true)
+ * .expires(OffsetDateTime.now().plusDays(60));
+ *
+ * keyAsyncClient.importKey(keyImportOptions).subscribe(keyResponse ->
+ * System.out.printf("Key is imported with name %s and id %s \n", keyResponse.value().name(), keyResponse.value().id()));
+ *
+ *
+ * @param keyImportOptions The key import configuration object containing information about the json web key being imported.
+ * @throws NullPointerException if {@code keyImportOptions} is {@code null}.
+ * @throws HttpRequestException if {@code name} is empty string.
+ * @return A {@link Mono} containing the {@link Key imported key}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono
- * String keyVersion = "6A385B124DEF4096AF1361A85B16C204";
- * keyAsyncClient.getKey("keyName", keyVersion).subscribe(keyResponse ->
- * System.out.printf("Key returned with name %s, id %s and version %s", keyResponse.value().name(),
- * keyResponse.value().id(), keyResponse.value().version()));
- *
+ *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.getKey#string-string}
+ *
+ * @param name The name of the key, cannot be null
+ * @param version The version of the key to retrieve. If this is an empty String or null, this call is equivalent to calling {@link KeyAsyncClient#getKey(String)}, with the latest version being retrieved.
+ * @throws ResourceNotFoundException when a key with {@code name} and {@code version} doesn't exist in the key vault.
+ * @throws HttpRequestException if {@code name} or {@code version} is empty string.
+ * @return A {@link Mono} containing the requested {@link Key key}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono
- * keyAsyncClient.getKey("keyName").subscribe(keyResponse ->
- * System.out.printf("Key with name %s, id %s \n", keyResponse.value().name(),
- * keyResponse.value().id()));
- *
+ *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.getKey#string}
+ *
+ * @param name The name of the key.
+ * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault.
+ * @throws HttpRequestException if {@code name} is empty string.
+ * @return A {@link Mono} containing the requested {@link Key key}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono
- * keyAsyncClient.listKeys().subscribe(keyBase ->
- * client.getKey(keyBase).subscribe(keyResponse ->
- * System.out.printf("Key with name %s and value %s \n", keyResponse.value().name(), keyResponse.value().id())));
- *
+ *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.getKey#KeyBase}
+ *
+ * @param keyBase The {@link KeyBase base key} holding attributes of the key being requested.
+ * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault.
+ * @throws HttpRequestException if {@link KeyBase#name()} name} or {@link KeyBase#version() version} is empty string.
+ * @return A {@link Mono} containing the requested {@link Key key}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono
- * keyAsyncClient.getKey("keyName").subscribe(keyResponse -> {
- * Key key = keyResponse.value();
- * //Update the not before time of the key.
- * key.notBefore(OffsetDateTime.now().plusDays(50));
- * keyAsyncClient.updateKey(key).subscribe(updatedKeyResponse ->
- * System.out.printf("Key's updated not before time %s \n", updatedKeyResponse.value().notBefore().toString()));
- * });
- *
+ *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.updateKey#KeyBase}
+ *
+ * @param key The {@link KeyBase base key} object with updated properties.
+ * @throws NullPointerException if {@code key} is {@code null}.
+ * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault.
+ * @throws HttpRequestException if {@link KeyBase#name() name} or {@link KeyBase#version() version} is empty string.
+ * @return A {@link Mono} containing the {@link KeyBase updated key}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono
- * keyAsyncClient.getKey("keyName").subscribe(keyResponse -> {
- * Key key = keyResponse.value();
- * //Update the not before time of the key and associate Encrypt and Decrypt operations with it.
- * key.notBefore(OffsetDateTime.now().plusDays(50));
- * keyAsyncClient.updateKey(key, KeyOperation.ENCRYPT, KeyOperation.DECRYPT).subscribe(updatedKeyResponse ->
- * System.out.printf("Key's updated not before time %s \n", updatedKeyResponse.value().notBefore().toString()));
- * });
- *
+ *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase-keyOperations}
*
* @param key The {@link KeyBase base key} object with updated properties.
* @param keyOperations The updated key operations to associate with the key.
@@ -475,10 +634,34 @@ Mono
- * keyAsyncClient.deleteKey("keyName").subscribe(deletedKeyResponse ->
- * System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.value().recoveryId()));
- *
+ *
+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.deleteKeyWithResponse#string}
*
* @param name The name of the key to be deleted.
* @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault.
@@ -513,7 +717,7 @@ Mono
* //Assuming key is deleted on a soft-delete enabled vault. - * keyAsyncClient.getDeletedKey("keyName").subscribe(deletedKeyResponse -> - * System.out.printf("Deleted Key with recovery Id %s \n", deletedKeyResponse.value().recoveryId())); - *+ * + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.getDeletedKey#string} + * + * @param name The name of the deleted key. + * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a key with {@code name} is empty string. + * @return A {@link Mono} containing the {@link DeletedKey deleted key}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono
Code Samples
+ *Gets the deleted key from the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the + * deleted key details when a response has been received.
+ *+ * //Assuming key is deleted on a soft-delete enabled vault. + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.getDeletedKeyWithResponse#string} * * @param name The name of the deleted key. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. @@ -543,7 +768,7 @@ Mono> deleteKey(String name, Context context) { * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link DeletedKey deleted key}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono > getDeletedKey(String name) { + public Mono > getDeletedKeyWithResponse(String name) { return withContext(context -> getDeletedKey(name, context)); } @@ -563,9 +788,7 @@ Mono > getDeletedKey(String name, Context context) { * status code from the server response when a response has been received. * * //Assuming key is deleted on a soft-delete enabled vault. - * keyAsyncClient.purgeDeletedKey("deletedKeyName").subscribe(purgeResponse -> - * System.out.printf("Purge Status response %rsaPrivateExponent \n", purgeResponse.statusCode())); - *+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.purgeDeletedKey#string} * * @param name The name of the deleted key. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. @@ -594,9 +817,30 @@ MonopurgeDeletedKey(String name, Context context) { * recovered key details when a response has been received. * * //Assuming key is deleted on a soft-delete enabled vault. - * keyAsyncClient.recoverDeletedKey("deletedKeyName").subscribe(recoveredKeyResponse -> - * System.out.printf("Recovered Key with name %s \n", recoveredKeyResponse.value().name())); - *+ * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.recoverDeletedKey#string} + * + * @param name The name of the deleted key to be recovered. + * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a key with {@code name} is empty string. + * @return A {@link Mono} containing the {@link Key recovered key}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public MonorecoverDeletedKey(String name) { + return withContext(context -> recoverDeletedKeyWithResponse(name)) + .flatMap(FluxUtil::toMono); + } + + /** + * Recovers the deleted key in the key vault to its latest version and can only be performed on a soft-delete enabled vault. An attempt + * to recover an non-deleted key will return an error. Consider this the inverse of the delete operation on soft-delete enabled vaults. + * This operation requires the {@code keys/recover} permission. + * + * Code Samples
+ *Recovers the deleted key from the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the + * recovered key details when a response has been received.
+ *+ * //Assuming key is deleted on a soft-delete enabled vault. + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.recoverDeletedKeyWithResponse#string} * * @param name The name of the deleted key to be recovered. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. @@ -604,7 +848,7 @@ MonopurgeDeletedKey(String name, Context context) { * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link Key recovered key}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono > recoverDeletedKey(String name) { + public Mono > recoverDeletedKeyWithResponse(String name) { return withContext(context -> recoverDeletedKey(name, context)); } @@ -628,10 +872,35 @@ Mono > recoverDeletedKey(String name, Context context) { * Code Samples
*Backs up the key from the key vault. Subscribes to the call asynchronously and prints out the * length of the key's backup byte array returned in the response.
- *- * keyAsyncClient.backupKey("keyName").subscribe(keyBackupResponse -> - * System.out.printf("Key's Backup Byte array's length %s \n", keyBackupResponse.value().length)); - *+ * + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.backupKey#string} + * + * @param name The name of the key. + * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a key with {@code name} is empty string. + * @return A {@link Mono} containing the backed up key blob. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public MonobackupKey(String name) { + return withContext(context -> backupKeyWithResponse(name)) + .flatMap(FluxUtil::toMono); + } + + /** + * Requests a backup of the specified key be downloaded to the client. The Key Backup operation exports a key from Azure Key + * Vault in a protected form. Note that this operation does not return key material in a form that can be used outside the Azure Key + * Vault system, the returned key material is either protected to a Azure Key Vault HSM or to Azure Key Vault itself. The intent + * of this operation is to allow a client to generate a key in one Azure Key Vault instance, backup the key, and then restore it + * into another Azure Key Vault instance. The backup operation may be used to export, in protected form, any key type from Azure + * Key Vault. Individual versions of a key cannot be backed up. Backup / Restore can be performed within geographical boundaries only; + * meaning that a backup from one geographical area cannot be restored to another geographical area. For example, a backup + * from the US geographical area cannot be restored in an EU geographical area. This operation requires the {@code key/backup} permission. + * + * Code Samples
+ *Backs up the key from the key vault. Subscribes to the call asynchronously and prints out the + * length of the key's backup byte array returned in the response.
+ * + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.backupKeyWithResponse#string} * * @param name The name of the key. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. @@ -639,7 +908,7 @@ Mono> recoverDeletedKey(String name, Context context) { * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the backed up key blob. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono > backupKey(String name) { + public Mono > backupKeyWithResponse(String name) { return withContext(context -> backupKey(name, context)); } @@ -666,16 +935,42 @@ Mono > backupKey(String name, Context context) { * details when a response has been received. * * //Pass the Key Backup Byte array to the restore operation. - * keyAsyncClient.restoreKey(keyBackupByteArray).subscribe(keyResponse -> - * System.out.printf("Restored Key with name %s and id %s \n", keyResponse.value().name(), keyResponse.value().id())); - *+ * + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.restoreKey#byte} + * + * @param backup The backup blob associated with the key. + * @throws ResourceModifiedException when {@code backup} blob is malformed. + * @return A {@link Mono} containing the {@link Key restored key}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public MonorestoreKey(byte[] backup) { + return withContext(context -> restoreKeyWithResponse(backup)) + .flatMap(FluxUtil::toMono); + } + + /** + * Restores a backed up key to a vault. Imports a previously backed up key into Azure Key Vault, restoring the key, its key identifier, + * attributes and access control policies. The restore operation may be used to import a previously backed up key. The individual versions of a + * key cannot be restored. The key is restored in its entirety with the same key name as it had when it was backed up. If the key name is not + * available in the target Key Vault, the restore operation will be rejected. While the key name is retained during restore, the final key identifier + * will change if the key is restored to a different vault. Restore will restore all versions and preserve version identifiers. The restore operation is subject + * to security constraints: The target Key Vault must be owned by the same Microsoft Azure Subscription as the source Key Vault The user must have restore permission in + * the target Key Vault. This operation requires the {@code keys/restore} permission. + * + * Code Samples
+ *Restores the key in the key vault from its backup. Subscribes to the call asynchronously and prints out the restored key + * details when a response has been received.
+ *+ * //Pass the Key Backup Byte array to the restore operation. + * + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.restoreKeyWithResponse#byte} * * @param backup The backup blob associated with the key. * @throws ResourceModifiedException when {@code backup} blob is malformed. * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link Key restored key}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono* * @param keyImportOptions The key import configuration object containing information about the json web key being imported. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws NullPointerException if {@code keyImportOptions} is {@code null}. * @throws HttpRequestException if {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key imported key}. */ - public Response> restoreKey(byte[] backup) { + public Mono > restoreKeyWithResponse(byte[] backup) { return withContext(context -> restoreKey(backup, context)); } @@ -694,11 +989,8 @@ Mono > restoreKey(byte[] backup, Context context) { * * It is possible to get full keys with key material from this information. Convert the {@link Flux} containing {@link KeyBase base key} to * {@link Flux} containing {@link Key key} using {@link KeyAsyncClient#getKey(KeyBase baseKey)} within {@link Flux#flatMap(Function)}.
- *- * Flux<Key> keys = keyAsyncClient.listKeys() - * .flatMap(keyAsyncClient::getKey) - * .map(Response::value); - *+ * + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.listKeys} * * @return A {@link PagedFlux} containing {@link KeyBase key} of all the keys in the vault. */ @@ -747,10 +1039,8 @@ private Mono> listKeysFirstPage(Context context) { * Code Samples
*Lists the deleted keys in the key vault. Subscribes to the call asynchronously and prints out the * recovery id of each deleted key when a response has been received.
- *- * keyAsyncClient.listDeletedKeys().subscribe(deletedKey -> - * System.out.printf("Deleted key's recovery Id %s \n", deletedKey.recoveryId())); - *+ * + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.listDeletedKeys} * * @return A {@link PagedFlux} containing all of the {@link DeletedKey deleted keys} in the vault. */ @@ -799,11 +1089,8 @@ private Mono> listDeletedKeysFirstPage(Context context * It is possible to get the keys with key material of all the versions from this information. Convert the {@link Flux} * containing {@link KeyBase base key} to {@link Flux} containing {@link Key key} using * {@link KeyAsyncClient#getKey(KeyBase baseKey)} within {@link Flux#flatMap(Function)}.
- *- * Flux<Key> keys = keyAsyncClient.listKeyVersions("keyName") - * .flatMap(keyAsyncClient::getKey) - * .map(Response::value); - *+ * + * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.listKeyVersions} * * @param name The name of the key. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. diff --git a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java index 44e8bac28851e..517883dd328fb 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java +++ b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java @@ -9,6 +9,7 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.VoidResponse; import com.azure.core.implementation.annotation.ServiceClient; +import com.azure.core.util.Context; import com.azure.security.keyvault.keys.models.Key; import com.azure.security.keyvault.keys.models.KeyCreateOptions; import com.azure.security.keyvault.keys.models.DeletedKey; @@ -22,6 +23,7 @@ import com.azure.security.keyvault.keys.models.webkey.KeyType; import java.util.List; +import java.util.Objects; /** * The KeyClient provides synchronous methods to manage {@link Key keys} in the Azure Key Vault. The client @@ -61,10 +63,10 @@ public final class KeyClient { * @param keyType The type of key to create. For valid values, see {@link KeyType KeyType}. * @throws ResourceModifiedException if {@code name} or {@code keyType} is null. * @throws HttpRequestException if {@code name} is empty string. - * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key created key}. + * @return The {@link Key created key}. */ - public ResponsecreateKey(String name, KeyType keyType) { - return client.createKey(name, keyType).block(); + public Key createKey(String name, KeyType keyType) { + return client.createKey(name, keyType, Context.NONE).block().value(); } /** @@ -79,23 +81,41 @@ public Response createKey(String name, KeyType keyType) { * * Code Samples
*Creates a new RSA key which activates in one day and expires in one year. Prints out the details of the created key.
- *- * KeyCreateOptions KeyCreateOptions = new KeyCreateOptions("keyName", KeyType.RSA) - * .notBefore(OffsetDateTime.now().plusDays(1)) - * .expires(OffsetDateTime.now().plusYears(1)); + * {@codesnippet com.azure.keyvault.keys.keyclient.createKey#keyOptions} * - * Key key = keyClient.createKey(keyCreateOptions).value(); - * System.out.printf("Key is created with name %s and id %s \n", key.name(), key.id()); - *+ * @param keyCreateOptions The key options object containing information about the key being created. + * @throws NullPointerException if {@code keyCreateOptions} is {@code null}. + * @throws ResourceModifiedException if {@code keyCreateOptions} is malformed. + * @throws HttpRequestException if {@code name} is empty string. + * @return The {@link Key created key}. + */ + public Key createKey(KeyCreateOptions keyCreateOptions) { + return this.createKeyWithResponse(keyCreateOptions, Context.NONE).value(); + } + + /** + * Creates a new key and stores it in the key vault. The create key operation can be used to create any key type in + * key vault. If the named key already exists, Azure Key Vault creates a new version of the key. It requires the {@code keys/create} permission. + * + *The {@link KeyCreateOptions} is required. The {@link KeyCreateOptions#expires() expires} and {@link KeyCreateOptions#notBefore() notBefore} values + * are optional. The {@link KeyCreateOptions#enabled() enabled} field is set to true by Azure Key Vault, if not specified.
+ * + *The {@link KeyCreateOptions#keyType() keyType} indicates the type of key to create. Possible values include: {@link KeyType#EC EC}, + * {@link KeyType#EC_HSM EC-HSM}, {@link KeyType#RSA RSA}, {@link KeyType#RSA_HSM RSA-HSM} and {@link KeyType#OCT OCT}.
+ * + *Code Samples
+ *Creates a new RSA key which activates in one day and expires in one year. Prints out the details of the created key.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.createKeyWithResponse#keyCreateOptions-Context} * * @param keyCreateOptions The key options object containing information about the key being created. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws NullPointerException if {@code keyCreateOptions} is {@code null}. * @throws ResourceModifiedException if {@code keyCreateOptions} is malformed. * @throws HttpRequestException if {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key created key}. */ - public ResponsecreateKey(KeyCreateOptions keyCreateOptions) { - return client.createKey(keyCreateOptions).block(); + public Response createKeyWithResponse(KeyCreateOptions keyCreateOptions, Context context) { + return client.createKey(keyCreateOptions, context).block(); } /** @@ -111,24 +131,42 @@ public Response createKey(KeyCreateOptions keyCreateOptions) { * * Code Samples
*Creates a new RSA key with size 2048 which activates in one day and expires in one year. Prints out the details of the created key.
- *- * RsaKeyCreateOptions rsaKeyCreateOptions = new RsaKeyCreateOptions("keyName", KeyType.RSA) - * .keySize(2048) - * .notBefore(OffsetDateTime.now().plusDays(1)) - * .expires(OffsetDateTime.now().plusYears(1)); + * {@codesnippet com.azure.keyvault.keys.keyclient.createRsaKey#keyOptions} * - * Key rsaKey = keyClient.createRsaKey(rsaKeyCreateOptions).value(); - * System.out.printf("Key is created with name %s and id %s \n", rsaKey.name(), rsaKey.id()); - *+ * @param rsaKeyCreateOptions The key options object containing information about the rsa key being created. + * @throws NullPointerException if {@code rsaKeyCreateOptions} is {@code null}. + * @throws ResourceModifiedException if {@code rsaKeyCreateOptions} is malformed. + * @throws HttpRequestException if {@code name} is empty string. + * @return The {@link Key created key}. + */ + public Key createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) { + return this.createKeyWithResponse(rsaKeyCreateOptions, Context.NONE).value(); + } + + /** + * Creates a new Rsa key and stores it in the key vault. The create Rsa key operation can be used to create any Rsa key type in + * key vault. If the named key already exists, Azure Key Vault creates a new version of the key. It requires the {@code keys/create} permission. + * + *The {@link RsaKeyCreateOptions} is required. The {@link RsaKeyCreateOptions#keySize() keySize} can be optionally specified. The {@link RsaKeyCreateOptions#expires() expires} + * and {@link RsaKeyCreateOptions#notBefore() notBefore} values are optional. The {@link RsaKeyCreateOptions#enabled() enabled} field + * is set to true by Azure Key Vault, if not specified.
+ * + *The {@link RsaKeyCreateOptions#keyType() keyType} indicates the type of key to create. Possible values include: {@link KeyType#RSA RSA} and + * {@link KeyType#RSA_HSM RSA-HSM}.
+ * + *Code Samples
+ *Creates a new RSA key with size 2048 which activates in one day and expires in one year. Prints out the details of the created key.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions} * * @param rsaKeyCreateOptions The key options object containing information about the rsa key being created. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws NullPointerException if {@code rsaKeyCreateOptions} is {@code null}. * @throws ResourceModifiedException if {@code rsaKeyCreateOptions} is malformed. * @throws HttpRequestException if {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key created key}. */ - public ResponsecreateRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) { - return client.createRsaKey(rsaKeyCreateOptions).block(); + public Response createRsaKeyWithResponse(RsaKeyCreateOptions rsaKeyCreateOptions, Context context) { + return client.createRsaKey(rsaKeyCreateOptions, context).block(); } /** @@ -145,24 +183,43 @@ public Response createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) { * Code Samples
*Creates a new EC key with P-384 web key curve. The key activates in one day and expires in one year. Prints out * the details of the created key.
- *- * EcKeyCreateOptions ecKeyCreateOptions = new EcKeyCreateOptions("keyName", KeyType.EC) - * .curve(KeyCurveName.P_384) - * .notBefore(OffsetDateTime.now().plusDays(1)) - * .expires(OffsetDateTime.now().plusYears(1)); + * {@codesnippet com.azure.keyvault.keys.keyclient.createEcKey#keyOptions} * - * Key ecKey = keyClient.createEcKey(ecKeyCreateOptions).value(); - * System.out.printf("Key is created with name %s and id %s \n", ecKey.name(), ecKey.id()); - *+ * @param ecKeyCreateOptions The key options object containing information about the ec key being created. + * @throws NullPointerException if {@code ecKeyCreateOptions} is {@code null}. + * @throws ResourceModifiedException if {@code ecKeyCreateOptions} is malformed. + * @throws HttpRequestException if {@code name} is empty string. + * @return The {@link Key created key}. + */ + public Key createEcKey(EcKeyCreateOptions ecKeyCreateOptions) { + return this.createEcKeyWithResponse(ecKeyCreateOptions, Context.NONE).value(); + } + + /** + * Creates a new Ec key and stores it in the key vault. The create Ec key operation can be used to create any Ec key type in + * key vault. If the named key already exists, Azure Key Vault creates a new version of the key. It requires the {@code keys/create} permission. + * + *The {@link EcKeyCreateOptions} parameter is required. The {@link EcKeyCreateOptions#curve() key curve} can be optionally specified. If not specified, + * default value of {@link KeyCurveName#P_256 P-256} is used by Azure Key Vault. The {@link EcKeyCreateOptions#expires() expires} and {@link EcKeyCreateOptions#notBefore() notBefore} values + * are optional. The {@link EcKeyCreateOptions#enabled() enabled} field is set to true by Azure Key Vault, if not specified.
+ * + *The {@link EcKeyCreateOptions#keyType() keyType} indicates the type of key to create. Possible values include: {@link KeyType#EC EC} and + * {@link KeyType#EC_HSM EC-HSM}.
+ * + *Code Samples
+ *Creates a new EC key with P-384 web key curve. The key activates in one day and expires in one year. Prints out + * the details of the created key.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions} * * @param ecKeyCreateOptions The key options object containing information about the ec key being created. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws NullPointerException if {@code ecKeyCreateOptions} is {@code null}. * @throws ResourceModifiedException if {@code ecKeyCreateOptions} is malformed. * @throws HttpRequestException if {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key created key}. */ - public ResponsecreateEcKey(EcKeyCreateOptions ecKeyCreateOptions) { - return client.createEcKey(ecKeyCreateOptions).block(); + public Response createEcKeyWithResponse(EcKeyCreateOptions ecKeyCreateOptions, Context context) { + return client.createEcKey(ecKeyCreateOptions, context).block(); } /** @@ -172,17 +229,46 @@ public Response createEcKey(EcKeyCreateOptions ecKeyCreateOptions) { * Code Samples
*Imports a new key into key vault. Prints out the details of the imported key.
*- * Key importedKey = keyClient.importKey("keyName", jsonWebKeyToImport).value(); + * Key importedKey = keyClient.importKey("keyName", jsonWebKeyToImport); * System.out.printf("Key is imported with name %s and id %s \n", importedKey.name(), importedKey.id()); ** * @param name The name for the imported key. * @param keyMaterial The Json web key being imported. * @throws HttpRequestException if {@code name} is empty string. - * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key imported key}. + * @return The {@link Key imported key}. + */ + public Key importKey(String name, JsonWebKey keyMaterial) { + return client.importKey(name, keyMaterial, Context.NONE).block().value(); + } + + /** + * Imports an externally created key and stores it in key vault. The import key operation may be used to import any key type + * into the Azure Key Vault. If the named key already exists, Azure Key Vault creates a new version of the key. This operation requires the {@code keys/import} permission. + * + *The {@code keyImportOptions} is required and its fields {@link KeyImportOptions#name() name} and {@link KeyImportOptions#keyMaterial() key material} cannot + * be null. The {@link KeyImportOptions#expires() expires} and {@link KeyImportOptions#notBefore() notBefore} values in {@code keyImportOptions} are optional. If not + * specified, no values are set for the fields. The {@link KeyImportOptions#enabled() enabled} field is set to true and the {@link KeyImportOptions#hsm() hsm} field is + * set to false by Azure Key Vault, if they are not specified.
+ * + *Code Samples
+ *Imports a new key into key vault. Prints out the details of the imported key.
+ *+ * KeyImportOptions keyImportOptions = new KeyImportOptions("keyName", jsonWebKeyToImport) + * .hsm(true) + * .expires(OffsetDateTime.now().plusDays(60)); + * + * Key importedKey = keyClient.importKey(keyImportOptions); + * System.out.printf("Key is imported with name %s and id %s \n", importedKey.name(), importedKey.id()); + *+ * + * @param keyImportOptions The key import configuration object containing information about the json web key being imported. + * @throws NullPointerException if {@code keyImportOptions} is {@code null}. + * @throws HttpRequestException if {@code name} is empty string. + * @return The {@link Key imported key}. */ - public ResponseimportKey(String name, JsonWebKey keyMaterial) { - return client.importKey(name, keyMaterial).block(); + public Key importKey(KeyImportOptions keyImportOptions) { + return this.importKeyWithResponse(keyImportOptions, Context.NONE).value(); } /** @@ -201,17 +287,18 @@ public Response importKey(String name, JsonWebKey keyMaterial) { * .hsm(true) * .expires(OffsetDateTime.now().plusDays(60)); * - * Key importedKey = keyClient.importKey(keyImportOptions).value(); + * Key importedKey = keyClient.importKey(keyImportOptions, new Context(key1, value1)).value(); * System.out.printf("Key is imported with name %s and id %s \n", importedKey.name(), importedKey.id()); * importKey(KeyImportOptions keyImportOptions) { - return client.importKey(keyImportOptions).block(); + public Response importKeyWithResponse(KeyImportOptions keyImportOptions, Context context) { + return client.importKey(keyImportOptions, context).block(); } /** @@ -219,20 +306,34 @@ public Response importKey(KeyImportOptions keyImportOptions) { * * Code Samples
*Gets a specific version of the key in the key vault. Prints out the details of the returned key.
- *- * String keyVersion = "6A385B124DEF4096AF1361A85B16C204"; - * Key keyWithVersion = keyClient.getKey("keyName", keyVersion).value(); - * System.out.printf("Key is returned with name %s and id %s \n", keyWithVersion.name(), keyWithVersion.id()); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.getKey#string-string} + * + * @param name The name of the key, cannot be null + * @param version The version of the key to retrieve. If this is an empty String or null, this call is equivalent to calling {@link KeyClient#getKey(String)}, with the latest version being retrieved. + * @throws ResourceNotFoundException when a key with {@code name} and {@code version} doesn't exist in the key vault. + * @throws HttpRequestException if {@code name} or {@code version} is empty string. + * @return The requested {@link Key key}. + */ + public Key getKey(String name, String version) { + return this.getKeyWithResponse(name, version, Context.NONE).value(); + } + + /** + * Gets the public part of the specified key and key version. The get key operation is applicable to all key types and it requires the {@code keys/get} permission. + * + *Code Samples
+ *Gets a specific version of the key in the key vault. Prints out the details of the returned key.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.getKeyWithResponse#string-string-Context} * * @param name The name of the key, cannot be null + * @param context Additional context that is passed through the Http pipeline during the service call. * @param version The version of the key to retrieve. If this is an empty String or null, this call is equivalent to calling {@link KeyClient#getKey(String)}, with the latest version being retrieved. * @throws ResourceNotFoundException when a key with {@code name} and {@code version} doesn't exist in the key vault. * @throws HttpRequestException if {@code name} or {@code version} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Key key}. */ - public ResponsegetKey(String name, String version) { - return client.getKey(name, version).block(); + public Response getKeyWithResponse(String name, String version, Context context) { + return client.getKey(name, version, context).block(); } /** @@ -241,21 +342,17 @@ public Response getKey(String name, String version) { * * Code Samples
*Gets the latest version of the key in the key vault. Prints out the details of the returned key.
- *- * Key key = keyClient.getKey("keyName").value(); - * System.out.printf("Key is returned with name %s and id %s \n", key.name(), key.value().id()); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.getKey#string} * * @param name The name of the key. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. * @throws HttpRequestException if {@code name} is empty string. - * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Key key}. + * @return The requested {@link Key key}. */ - public ResponsegetKey(String name) { - return getKey(name, ""); + public Key getKey(String name) { + return this.getKeyWithResponse(name, "", Context.NONE).value(); } - /** * Get public part of the key which represents {@link KeyBase keyBase} from the key vault. The get key operation is applicable * to all key types and it requires the {@code keys/get} permission. @@ -263,18 +360,19 @@ public Response getKey(String name) { * The list operations {@link KeyClient#listKeys()} and {@link KeyClient#listKeyVersions(String)} return * the {@link List} containing {@link KeyBase base key} as output excluding the key material of the key. * This operation can then be used to get the full key with its key material from {@code keyBase}.
- *- * keyClient.listKeys().stream().map(keyClient::getKey).forEach(keyResponse -> - * System.out.printf("Key is returned with name %s and id %s \n", keyResponse.value().name(), keyResponse.value().id())); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.getKey#KeyBase} * * @param keyBase The {@link KeyBase base key} holding attributes of the key being requested. * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault. * @throws HttpRequestException if {@link KeyBase#name()} name} or {@link KeyBase#version() version} is empty string. - * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Key key}. + * @return The requested {@link Key key}. */ - public ResponsegetKey(KeyBase keyBase) { - return client.getKey(keyBase).block(); + public Key getKey(KeyBase keyBase) { + Objects.requireNonNull(keyBase, "The Key Base parameter cannot be null."); + if (keyBase.version() == null) { + return getKey(keyBase.name()); + } + return getKeyWithResponse(keyBase.name(), keyBase.version(), Context.NONE).value(); } /** @@ -284,21 +382,36 @@ public Response getKey(KeyBase keyBase) { * * Code Samples
*Gets the latest version of the key, changes its expiry time and the updates the key in the key vault.
- *- * Key key = keyClient.getKey("keyName").value(); - * key.expires(OffsetDateTime.now().plusDays(60)); - * KeyBase updatedKeyBase = keyClient.updateKey(key).value(); - * Key updatedKey = keyClient.getKey(updatedKeyBase.name()).value(); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.updateKey#KeyBase} + * + * @param key The {@link KeyBase base key} object with updated properties. + * @throws NullPointerException if {@code key} is {@code null}. + * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault. + * @throws HttpRequestException if {@link KeyBase#name() name} or {@link KeyBase#version() version} is empty string. + * @return The {@link KeyBase updated key}. + */ + public Key updateKey(KeyBase key) { + return this.updateKeyWithResponse(key, Context.NONE).value(); + } + + /** + * Updates the attributes and key operations associated with the specified key, but not the cryptographic key material of the specified key in the key vault. The update + * operation changes specified attributes of an existing stored key and attributes that are not specified in the request are left unchanged. + * The cryptographic key material of a key itself cannot be changed. This operation requires the {@code keys/set} permission. + * + *Code Samples
+ *Gets the latest version of the key, changes its expiry time and key operations and the updates the key in the key vault.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.updateKey#KeyBase-keyOperations} * * @param key The {@link KeyBase base key} object with updated properties. + * @param keyOperations The updated key operations to associate with the key. * @throws NullPointerException if {@code key} is {@code null}. * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault. * @throws HttpRequestException if {@link KeyBase#name() name} or {@link KeyBase#version() version} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link KeyBase updated key}. */ - public ResponseupdateKey(KeyBase key) { - return client.updateKey(key).block(); + public Key updateKey(KeyBase key, KeyOperation... keyOperations) { + return this.updateKeyWithResponse(key, Context.NONE, keyOperations).value(); } /** @@ -308,22 +421,18 @@ public Response updateKey(KeyBase key) { * * Code Samples
*Gets the latest version of the key, changes its expiry time and key operations and the updates the key in the key vault.
- *- * Key key = keyClient.getKey("keyName").value(); - * key.expires(OffsetDateTime.now().plusDays(60)); - * KeyBase updatedKeyBase = keyClient.updateKey(key, KeyOperation.ENCRYPT, KeyOperation.DECRYPT).value(); - * Key updatedKey = keyClient.getKey(updatedKeyBase.name()).value(); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.updateKeyWithResponse#KeyBase-keyOperations-Context} * * @param key The {@link KeyBase base key} object with updated properties. + * @param context Additional context that is passed through the Http pipeline during the service call. * @param keyOperations The updated key operations to associate with the key. * @throws NullPointerException if {@code key} is {@code null}. * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault. * @throws HttpRequestException if {@link KeyBase#name() name} or {@link KeyBase#version() version} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link KeyBase updated key}. */ - public ResponseupdateKey(KeyBase key, KeyOperation... keyOperations) { - return client.updateKey(key, keyOperations).block(); + public Response updateKeyWithResponse(KeyBase key, Context context, KeyOperation... keyOperations) { + return client.updateKey(key, context, keyOperations).block(); } /** @@ -335,18 +444,36 @@ public Response updateKey(KeyBase key, KeyOperation... keyOperations) { * * Code Samples
*Deletes the key from the keyvault. Prints out the recovery id of the deleted key returned in the response.
- *- * DeletedKey deletedKey = keyClient.deleteKey("keyName").value(); - * System.out.printf("Deleted Key's Recovery Id %s", deletedKey.recoveryId())); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.deleteKey#string} + * + * @param name The name of the key to be deleted. + * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a key with {@code name} is empty string. + * @return The {@link DeletedKey deleted key}. + */ + public DeletedKey deleteKey(String name) { + return this.deleteKeyWithResponse(name, Context.NONE).value(); + } + + /** + * Deletes a key of any type from the key vault. If soft-delete is enabled on the key vault then the key is placed in the deleted state + * and requires to be purged for permanent deletion else the key is permanently deleted. The delete operation applies to any key stored + * in Azure Key Vault but it cannot be applied to an individual version of a key. This operation removes the cryptographic material + * associated with the key, which means the key is not usable for Sign/Verify, Wrap/Unwrap or Encrypt/Decrypt operations. This operation + * requires the {@code keys/delete} permission. + * + *Code Samples
+ *Deletes the key from the keyvault. Prints out the recovery id of the deleted key returned in the response.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.deleteKeyWithResponse#string-Context} * * @param name The name of the key to be deleted. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. * @throws HttpRequestException when a key with {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedKey deleted key}. */ - public ResponsedeleteKey(String name) { - return client.deleteKey(name).block(); + public Response deleteKeyWithResponse(String name, Context context) { + return client.deleteKey(name, context).block(); } /** @@ -358,17 +485,37 @@ public Response deleteKey(String name) { * returned in the response. * * //Assuming key is deleted on a soft-delete enabled key vault. - * DeletedKey deletedKey = keyClient.getDeletedKey("keyName").value(); - * System.out.printf("Deleted Key with recovery Id %s \n", deletedKey.recoveryId()); + * {@codesnippet com.azure.keyvault.keys.keyclient.getDeletedKey#string} ** * @param name The name of the deleted key. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. * @throws HttpRequestException when a key with {@code name} is empty string. + * @return The {@link DeletedKey deleted key}. + */ + public DeletedKey getDeletedKey(String name) { + return this.getDeletedKeyWithResponse(name, Context.NONE).value(); + } + + /** + * Gets the public part of a deleted key. The Get Deleted Key operation is applicable for soft-delete enabled vaults. This operation + * requires the {@code keys/get} permission. + * + *Code Samples
+ *Gets the deleted key from the key vault enabled for soft-delete. Prints out the details of the deleted key + * returned in the response.
+ *+ * //Assuming key is deleted on a soft-delete enabled key vault. + * {@codesnippet com.azure.keyvault.keys.keyclient.getDeletedKeyWithResponse#string-Context} + * + * @param name The name of the deleted key. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a key with {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedKey deleted key}. */ - public ResponsegetDeletedKey(String name) { - return client.getDeletedKey(name).block(); + public Response getDeletedKeyWithResponse(String name, Context context) { + return client.getDeletedKey(name, context).block(); } /** @@ -377,11 +524,8 @@ public Response getDeletedKey(String name) { * * Code Samples
*Purges the deleted key from the key vault enabled for soft-delete. Prints out the status code from the server response.
- ** //Assuming key is deleted on a soft-delete enabled key vault. - * VoidResponse purgeResponse = keyClient.purgeDeletedKey("deletedKeyName"); - * System.out.printf("Purge Status Code: %rsaPrivateExponent", purgeResponse.statusCode()); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.purgeDeletedKey#string} * * @param name The name of the deleted key. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. @@ -389,7 +533,26 @@ public ResponsegetDeletedKey(String name) { * @return A {@link VoidResponse}. */ public VoidResponse purgeDeletedKey(String name) { - return client.purgeDeletedKey(name).block(); + return client.purgeDeletedKey(name, Context.NONE).block(); + } + + /** + * Permanently deletes the specified key without the possibility of recovery. The Purge Deleted Key operation is applicable for + * soft-delete enabled vaults. This operation requires the {@code keys/purge} permission. + * + * Code Samples
+ *Purges the deleted key from the key vault enabled for soft-delete. Prints out the status code from the server response.
+ * //Assuming key is deleted on a soft-delete enabled key vault. + * {@codesnippet com.azure.keyvault.keys.keyclient.purgeDeletedKey#string-Context} + * + * @param name The name of the deleted key. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a key with {@code name} is empty string. + * @return A {@link VoidResponse}. + */ + public VoidResponse purgeDeletedKey(String name, Context context) { + return client.purgeDeletedKey(name, context).block(); } /** @@ -399,19 +562,36 @@ public VoidResponse purgeDeletedKey(String name) { * *Code Samples
*Recovers the deleted key from the key vault enabled for soft-delete.
- ** //Assuming key is deleted on a soft-delete enabled key vault. - * Key recoveredKey = keyClient.recoverDeletedKey("deletedKeyName").value(); - * System.out.printf("Recovered key with name %s", recoveredKey.name()); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.recoverDeletedKey#string} + * + * @param name The name of the deleted key to be recovered. + * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a key with {@code name} is empty string. + * @return The {@link Key recovered key}. + */ + public Key recoverDeletedKey(String name) { + return this.recoverDeletedKeyWithResponse(name, Context.NONE).value(); + } + + /** + * Recovers the deleted key in the key vault to its latest version and can only be performed on a soft-delete enabled vault. An attempt + * to recover an non-deleted key will return an error. Consider this the inverse of the delete operation on soft-delete enabled vaults. + * This operation requires the {@code keys/recover} permission. + * + *Code Samples
+ *Recovers the deleted key from the key vault enabled for soft-delete.
+ * //Assuming key is deleted on a soft-delete enabled key vault. + * {@codesnippet com.azure.keyvault.keys.keyclient.recoverDeletedKeyWithResponse#string-Context} * * @param name The name of the deleted key to be recovered. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. * @throws HttpRequestException when a key with {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key recovered key}. */ - public ResponserecoverDeletedKey(String name) { - return client.recoverDeletedKey(name).block(); + public Response recoverDeletedKeyWithResponse(String name, Context context) { + return client.recoverDeletedKey(name, context).block(); } /** @@ -426,18 +606,39 @@ public Response recoverDeletedKey(String name) { * * Code Samples
*Backs up the key from the key vault and prints out the length of the key's backup byte array returned in the response
- *- * byte[] keyBackup = keyClient.backupKey("keyName").value(); - * System.out.printf("Key's Backup Byte array's length %s", keyBackup.length); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.backupKey#string} + * + * @param name The name of the key. + * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a key with {@code name} is empty string. + * @return The backed up key blob. + */ + public byte[] backupKey(String name) { + return this.backupKeyWithResponse(name, Context.NONE).value(); + } + + /** + * Requests a backup of the specified key be downloaded to the client. The Key Backup operation exports a key from Azure Key + * Vault in a protected form. Note that this operation does not return key material in a form that can be used outside the Azure Key + * Vault system, the returned key material is either protected to a Azure Key Vault HSM or to Azure Key Vault itself. The intent + * of this operation is to allow a client to generate a key in one Azure Key Vault instance, backup the key, and then restore it + * into another Azure Key Vault instance. The backup operation may be used to export, in protected form, any key type from Azure + * Key Vault. Individual versions of a key cannot be backed up. Backup / Restore can be performed within geographical boundaries only; + * meaning that a backup from one geographical area cannot be restored to another geographical area. For example, a backup + * from the US geographical area cannot be restored in an EU geographical area. This operation requires the {@code key/backup} permission. + * + *Code Samples
+ *Backs up the key from the key vault and prints out the length of the key's backup byte array returned in the response
+ * {@codesnippet com.azure.keyvault.keys.keyclient.backupKeyWithResponse#string-Context} * * @param name The name of the key. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. * @throws HttpRequestException when a key with {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the backed up key blob. */ - public ResponsebackupKey(String name) { - return client.backupKey(name).block(); + public Response backupKeyWithResponse(String name, Context context) { + return client.backupKey(name, context).block(); } /** @@ -451,18 +652,38 @@ public Response backupKey(String name) { * * Code Samples
*Restores the key in the key vault from its backup. Prints out the details of the restored key returned in the response.
- ** //Pass the Key Backup Byte array to the restore operation. - * KeyClient.restoreKey(keyBackupByteArray).subscribe(keyResponse -> - * System.out.printf("Restored Key with name %s and id %s \n", keyResponse.value().name(), keyResponse.value().id())); - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.restoreKey#byte} + * + * @param backup The backup blob associated with the key. + * @throws ResourceModifiedException when {@code backup} blob is malformed. + * @return The {@link Key restored key}. + */ + public Key restoreKey(byte[] backup) { + return this.restoreKeyWithResponse(backup, Context.NONE).value(); + } + + /** + * Restores a backed up key to a vault. Imports a previously backed up key into Azure Key Vault, restoring the key, its key identifier, + * attributes and access control policies. The restore operation may be used to import a previously backed up key. Individual versions of a + * key cannot be restored. The key is restored in its entirety with the same key name as it had when it was backed up. If the key name is not + * available in the target Key Vault, the restore operation will be rejected. While the key name is retained during restore, the final key identifier + * will change if the key is restored to a different vault. Restore will restore all versions and preserve version identifiers. The restore operation is subject + * to security constraints: The target Key Vault must be owned by the same Microsoft Azure Subscription as the source Key Vault The user must have restore permission in + * the target Key Vault. This operation requires the {@code keys/restore} permission. + * + *Code Samples
+ *Restores the key in the key vault from its backup. Prints out the details of the restored key returned in the response.
+ * //Pass the Key Backup Byte array to the restore operation. + * {@codesnippet com.azure.keyvault.keys.keyclient.restoreKeyWithResponse#byte-Context} * * @param backup The backup blob associated with the key. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws ResourceModifiedException when {@code backup} blob is malformed. * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key restored key}. */ - public ResponserestoreKey(byte[] backup) { - return client.restoreKey(backup).block(); + public Response restoreKeyWithResponse(byte[] backup, Context context) { + return client.restoreKey(backup, context).block(); } /** @@ -472,17 +693,28 @@ public Response restoreKey(byte[] backup) { * * It is possible to get full keys with key material from this information. Loop over the {@link KeyBase key} and * call {@link KeyClient#getKey(KeyBase baseKey)} . This will return the {@link Key key} with key material included of its latest version.
- *- * for (KeyBase key : keyClient.listKeys()) { - * Key keyWithMaterial = keyClient.getKey(key).value(); - * System.out.printf("Received key with name %s and type %s", keyWithMaterial.name(), keyWithMaterial.keyMaterial().kty()); - * } - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.listKeys} * * @return A {@link List} containing {@link KeyBase key} of all the keys in the vault. */ public IterablelistKeys() { - return client.listKeys().toIterable(); + return client.listKeys(Context.NONE).toIterable(); + } + + /** + * List keys in the key vault. Retrieves a list of the keys in the Key Vault as JSON Web Key structures that contain the public + * part of a stored key. The List operation is applicable to all key types and the individual key response in the list is represented by {@link KeyBase} as only the base key identifier, + * attributes and tags are provided in the response. The key material and individual key versions are not listed in the response. This operation requires the {@code keys/list} permission. + * + * It is possible to get full keys with key material from this information. Loop over the {@link KeyBase key} and + * call {@link KeyClient#getKey(KeyBase baseKey)} . This will return the {@link Key key} with key material included of its latest version.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.listKeys#Context} + * + * @param context Additional context that is passed through the Http pipeline during the service call. + * @return A {@link List} containing {@link KeyBase key} of all the keys in the vault. + */ + public IterablelistKeys(Context context) { + return client.listKeys(context).toIterable(); } /** @@ -492,11 +724,7 @@ public Iterable listKeys() { * * Code Samples
*Lists the deleted keys in the key vault and for each deleted key prints out its recovery id.
- *- * for (DeletedKey deletedKey : keyClient.listDeletedKeys()) { - * System.out.printf("Deleted key's recovery Id %s", deletedKey.recoveryId()); - * } - *+ * {@codesnippet com.azure.keyvault.keys.keyclient.listDeletedKeys} * * @return A {@link List} containing all of the {@link DeletedKey deleted keys} in the vault. */ @@ -504,6 +732,22 @@ public IterablelistDeletedKeys() { return client.listDeletedKeys().toIterable(); } + /** + * Lists {@link DeletedKey deleted keys} of the key vault. The deleted keys are retrieved as JSON Web Key structures + * that contain the public part of a deleted key. The Get Deleted Keys operation is applicable for vaults enabled + * for soft-delete. This operation requires the {@code keys/list} permission. + * + * Code Samples
+ *Lists the deleted keys in the key vault and for each deleted key prints out its recovery id.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.listDeletedKeys#Context} + * + * @param context Additional context that is passed through the Http pipeline during the service call. + * @return A {@link List} containing all of the {@link DeletedKey deleted keys} in the vault. + */ + public IterablelistDeletedKeys(Context context) { + return client.listDeletedKeys(context).toIterable(); + } + /** * List all versions of the specified key. The individual key response in the flux is represented by {@link KeyBase} * as only the base key identifier, attributes and tags are provided in the response. The key material values are @@ -521,4 +765,23 @@ public Iterable listDeletedKeys() { public Iterable listKeyVersions(String name) { return client.listKeyVersions(name).toIterable(); } + + /** + * List all versions of the specified key. The individual key response in the flux is represented by {@link KeyBase} + * as only the base key identifier, attributes and tags are provided in the response. The key material values are + * not provided in the response. This operation requires the {@code keys/list} permission. + * + * It is possible to get full keys with key material for each version from this information. Loop over the {@link KeyBase key} and + * call {@link KeyClient#getKey(KeyBase baseKey)} . This will return the {@link Key keys} with key material included of the specified versions.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.listKeyVersions} + * + * @param name The name of the key. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a key with {@code name} is empty string. + * @return A {@link List} containing {@link KeyBase key} of all the versions of the specified key in the vault. List is empty if key with {@code name} does not exist in key vault. + */ + public IterablelistKeyVersions(String name, Context context) { + return client.listKeyVersions(name, context).toIterable(); + } } diff --git a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClientBuilder.java b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClientBuilder.java index 63cf4e554a5f8..b5c9acfe8ee3c 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClientBuilder.java +++ b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClientBuilder.java @@ -3,6 +3,8 @@ package com.azure.security.keyvault.keys; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.implementation.http.policy.spi.HttpPolicyProviders; import com.azure.core.implementation.util.ImplUtils; import com.azure.core.util.configuration.Configuration; import com.azure.core.credentials.TokenCredential; @@ -88,6 +90,7 @@ public KeyClientBuilder() { public KeyClient buildClient() { return new KeyClient(buildAsyncClient()); } + /** * Creates a {@link KeyAsyncClient} based on options set in the builder. * Every time {@code buildAsyncClient()} is called, a new instance of {@link KeyAsyncClient} is created. @@ -121,12 +124,14 @@ public KeyAsyncClient buildAsyncClient() { // Closest to API goes first, closest to wire goes last. final List policies = new ArrayList<>(); policies.add(new UserAgentPolicy(AzureKeyVaultConfiguration.SDK_NAME, AzureKeyVaultConfiguration.SDK_VERSION, buildConfiguration)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); policies.add(retryPolicy); policies.add(new BearerTokenAuthenticationPolicy(credential, KeyAsyncClient.KEY_VAULT_SCOPE)); policies.addAll(this.policies); + HttpPolicyProviders.addAfterRetryPolicies(policies); policies.add(new HttpLoggingPolicy(httpLogDetailLevel)); - HttpPipeline pipeline = HttpPipeline.builder() + HttpPipeline pipeline = new HttpPipelineBuilder() .policies(policies.toArray(new HttpPipelinePolicy[0])) .httpClient(httpClient) .build(); diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/BackupAndRestoreOperations.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/BackupAndRestoreOperations.java index e54ebdad9d157..e35dcb2a91251 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/BackupAndRestoreOperations.java +++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/BackupAndRestoreOperations.java @@ -45,7 +45,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // Backups are good to have, if in case keys get accidentally deleted by you. // For long term storage, it is ideal to write the backup to a file. String backupFilePath = "YOUR_BACKUP_FILE_PATH"; - byte[] keyBackup = keyClient.backupKey("CloudRsaKey").value(); + byte[] keyBackup = keyClient.backupKey("CloudRsaKey"); writeBackupToFile(keyBackup, backupFilePath); // The Cloud Rsa key is no longer in use, so you delete it. @@ -62,7 +62,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // After sometime, the key is required again. We can use the backup value to restore it in the key vault. byte[] backupFromFile = Files.readAllBytes(new File(backupFilePath).toPath()); - Key restoredKey = keyClient.restoreKey(backupFromFile).value(); + Key restoredKey = keyClient.restoreKey(backupFromFile); } private static void writeBackupToFile(byte[] bytes, String filePath) { diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/BackupAndRestoreOperationsAsync.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/BackupAndRestoreOperationsAsync.java index c1b1191e861e9..9fa280a6d3558 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/BackupAndRestoreOperationsAsync.java +++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/BackupAndRestoreOperationsAsync.java @@ -41,7 +41,7 @@ public static void main(String[] args) throws IOException, InterruptedException, .expires(OffsetDateTime.now().plusYears(1)) .keySize(2048)) .subscribe(keyResponse -> - System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty())); + System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty())); Thread.sleep(2000); @@ -49,7 +49,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // For long term storage, it is ideal to write the backup to a file. String backupFilePath = "YOUR_BACKUP_FILE_PATH"; keyAsyncClient.backupKey("CloudRsaKey").subscribe(backupResponse -> { - byte[] backupBytes = backupResponse.value(); + byte[] backupBytes = backupResponse; writeBackupToFile(backupBytes, backupFilePath); }); @@ -57,7 +57,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // The Cloud Rsa key is no longer in use, so you delete it. keyAsyncClient.deleteKey("CloudRsaKey").subscribe(deletedKeyResponse -> - System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.value().recoveryId())); + System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.recoveryId())); //To ensure file is deleted on server side. Thread.sleep(30000); @@ -72,7 +72,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // After sometime, the key is required again. We can use the backup value to restore it in the key vault. byte[] backupFromFile = Files.readAllBytes(new File(backupFilePath).toPath()); keyAsyncClient.restoreKey(backupFromFile).subscribe(keyResponse -> - System.out.printf("Restored Key with name %s \n", keyResponse.value().name())); + System.out.printf("Restored Key with name %s \n", keyResponse.name())); //To ensure key is restored on server side. Thread.sleep(15000); diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorld.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorld.java index c9b3a3866ed80..50b5e387cf027 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorld.java +++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorld.java @@ -38,13 +38,14 @@ public static void main(String[] args) throws InterruptedException, IllegalArgum .keySize(2048)); // Let's Get the Cloud Rsa Key from the key vault. - Key cloudRsaKey = keyClient.getKey("CloudRsaKey").value(); - System.out.printf("Key is returned with name %s and type %s \n", cloudRsaKey.name(), cloudRsaKey.keyMaterial().kty()); + Key cloudRsaKey = keyClient.getKey("CloudRsaKey"); + System.out.printf("Key is returned with name %s and type %s \n", cloudRsaKey.name(), + cloudRsaKey.keyMaterial().kty()); // After one year, the Cloud Rsa Key is still required, we need to update the expiry time of the key. // The update method can be used to update the expiry attribute of the key. cloudRsaKey.expires(cloudRsaKey.expires().plusYears(1)); - Key updatedKey = keyClient.updateKey(cloudRsaKey).value(); + Key updatedKey = keyClient.updateKey(cloudRsaKey); System.out.printf("Key's updated expiry time %s \n", updatedKey.expires()); // We need the Cloud Rsa key with bigger key size, so you want to update the key in key vault to ensure it has the required size. diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorldAsync.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorldAsync.java index 257b79b48c500..922548455aecf 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorldAsync.java +++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorldAsync.java @@ -36,13 +36,13 @@ public static void main(String[] args) throws InterruptedException { .expires(OffsetDateTime.now().plusYears(1)) .keySize(2048)) .subscribe(keyResponse -> - System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty())); + System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty())); Thread.sleep(2000); // Let's Get the Cloud Rsa Key from the key vault. keyAsyncClient.getKey("CloudRsaKey").subscribe(keyResponse -> - System.out.printf("Key returned with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty())); + System.out.printf("Key returned with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty())); Thread.sleep(2000); @@ -50,11 +50,11 @@ public static void main(String[] args) throws InterruptedException { // After one year, the Cloud Rsa Key is still required, we need to update the expiry time of the key. // The update method can be used to update the expiry attribute of the key. keyAsyncClient.getKey("CloudRsaKey").subscribe(keyResponse -> { - Key key = keyResponse.value(); + Key key = keyResponse; //Update the expiry time of the key. key.expires(key.expires().plusYears(1)); keyAsyncClient.updateKey(key).subscribe(updatedKeyResponse -> - System.out.printf("Key's updated expiry time %s \n", updatedKeyResponse.value().expires().toString())); + System.out.printf("Key's updated expiry time %s \n", updatedKeyResponse.expires().toString())); }); Thread.sleep(2000); @@ -65,13 +65,13 @@ public static void main(String[] args) throws InterruptedException { .expires(OffsetDateTime.now().plusYears(1)) .keySize(4096)) .subscribe(keyResponse -> - System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty())); + System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty())); Thread.sleep(2000); // The Cloud Rsa Key is no longer needed, need to delete it from the key vault. keyAsyncClient.deleteKey("CloudRsaKey").subscribe(deletedKeyResponse -> - System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.value().recoveryId())); + System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.recoveryId())); //To ensure key is deleted on server side. Thread.sleep(30000); diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java new file mode 100644 index 0000000000000..12eacca66a16d --- /dev/null +++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java @@ -0,0 +1,496 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.security.keyvault.keys; + +import com.azure.core.credentials.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.test.models.RecordedData; +import com.azure.core.test.policy.RecordNetworkCallPolicy; +import com.azure.identity.credential.DefaultAzureCredential; +import com.azure.security.keyvault.keys.models.EcKeyCreateOptions; +import com.azure.security.keyvault.keys.models.Key; +import com.azure.security.keyvault.keys.models.KeyBase; +import com.azure.security.keyvault.keys.models.KeyCreateOptions; +import com.azure.security.keyvault.keys.models.RsaKeyCreateOptions; +import com.azure.security.keyvault.keys.models.webkey.KeyCurveName; +import com.azure.security.keyvault.keys.models.webkey.KeyOperation; +import com.azure.security.keyvault.keys.models.webkey.KeyType; +import reactor.util.context.Context; + +import java.time.OffsetDateTime; + +/** + * This class contains code samples for generating javadocs through doclets for {@link KeyAsyncClient} + */ +public final class KeyAsyncClientJavaDocCodeSnippets { + + private String key1 = "key1"; + private String key2 = "key2"; + private String value1 = "val1"; + private String value2 = "val2"; + + /** + * Generates code sample for creating a {@link KeyAsyncClient} + * @return An instance of {@link KeyAsyncClient} + */ + public KeyAsyncClient createAsyncClientWithHttpClient() { + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.withhttpclient.instantiation + RecordedData networkData = new RecordedData(); + KeyAsyncClient keyAsyncClient = new KeyClientBuilder() + .endpoint("https://myvault.azure.net/") + .credential(new DefaultAzureCredential()) + .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) + .addPolicy(new RecordNetworkCallPolicy(networkData)) + .httpClient(HttpClient.createDefault()) + .buildAsyncClient(); + // END: com.azure.security.keyvault.keys.async.keyclient.withhttpclient.instantiation + return keyAsyncClient; + } + + /** + * Generates code sample for creating a {@link KeyAsyncClient} + * @return An instance of {@link KeyAsyncClient} + */ + public KeyAsyncClient createAsyncClient() { + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.instantiation + KeyAsyncClient keyAsyncClient = new KeyClientBuilder() + .endpoint("https://myvault.azure.net/") + .credential(new DefaultAzureCredential()) + .buildAsyncClient(); + // END: com.azure.security.keyvault.keys.async.keyclient.instantiation + return keyAsyncClient; + } + + /** + * Generates code sample for creating a {@link KeyAsyncClient} + * @return An instance of {@link KeyAsyncClient} + */ + public KeyAsyncClient createAsyncClientWithPipeline() { + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.pipeline.instantiation + RecordedData networkData = new RecordedData(); + HttpPipeline pipeline = new HttpPipelineBuilder().policies(new RecordNetworkCallPolicy(networkData)).build(); + KeyAsyncClient keyAsyncClient = new KeyClientBuilder() + .pipeline(pipeline) + .endpoint("https://myvault.azure.net/") + .credential(new DefaultAzureCredential()) + .buildAsyncClient(); + // END: com.azure.security.keyvault.keys.async.keyclient.pipeline.instantiation + return keyAsyncClient; + } + + + /** + * Generates a code sample for using {@link KeyAsyncClient#createKey(String, KeyType)} + */ + public void createKey() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.createKey#string-keyType + keyAsyncClient.createKey("keyName", KeyType.EC) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", keyResponse.name(), keyResponse.id())); + // END: com.azure.security.keyvault.keys.async.keyclient.createKey#string-keyType + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.createKey#keyCreateOptions + KeyCreateOptions keyCreateOptions = new KeyCreateOptions("keyName", KeyType.RSA) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + keyAsyncClient.createKey(keyCreateOptions) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", keyResponse.name(), keyResponse.id())); + // END: com.azure.security.keyvault.keys.async.keyclient.createKey#keyCreateOptions + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.createRsaKey#RsaKeyCreateOptions + RsaKeyCreateOptions rsaKeyCreateOptions = new RsaKeyCreateOptions("keyName") + .keySize(2048) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + keyAsyncClient.createRsaKey(rsaKeyCreateOptions) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", keyResponse.name(), keyResponse.id())); + // END: com.azure.security.keyvault.keys.async.keyclient.createRsaKey#RsaKeyCreateOptions + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.createEcKey#EcKeyCreateOptions + EcKeyCreateOptions ecKeyCreateOptions = new EcKeyCreateOptions("keyName") + .curve(KeyCurveName.P_384) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + keyAsyncClient.createEcKey(ecKeyCreateOptions) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", keyResponse.name(), keyResponse.id())); + // END: com.azure.security.keyvault.keys.async.keyclient.createEcKey#EcKeyCreateOptions + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#deleteKey(String)} + */ + public void deleteKeySnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.deleteKey#string + keyAsyncClient.deleteKey("keyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Deleted Key's Recovery Id %s", keyResponse.recoveryId())); + // END: com.azure.security.keyvault.keys.async.keyclient.deleteKey#string + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#getDeletedKey(String)} + */ + public void getDeletedKeySnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getDeletedKey#string + keyAsyncClient.getDeletedKey("keyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Deleted Key's Recovery Id %s", keyResponse.recoveryId())); + // END: com.azure.security.keyvault.keys.async.keyclient.getDeletedKey#string + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#createKeyWithResponse(KeyCreateOptions)} + */ + public void createKeyWithResponses() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.createKeyWithResponse#keyCreateOptions + KeyCreateOptions keyCreateOptions = new KeyCreateOptions("keyName", KeyType.RSA) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + keyAsyncClient.createKeyWithResponse(keyCreateOptions) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", keyResponse.value().name(), + keyResponse.value().id())); + // END: com.azure.security.keyvault.keys.async.keyclient.createKeyWithResponse#keyCreateOptions + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.createRsaKeyWithResponse#RsaKeyCreateOptions + RsaKeyCreateOptions rsaKeyCreateOptions = new RsaKeyCreateOptions("keyName") + .keySize(2048) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + keyAsyncClient.createRsaKeyWithResponse(rsaKeyCreateOptions) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", keyResponse.value().name(), + keyResponse.value().id())); + // END: com.azure.security.keyvault.keys.async.keyclient.createRsaKeyWithResponse#RsaKeyCreateOptions + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.createEcKeyWithResponse#EcKeyCreateOptions + EcKeyCreateOptions ecKeyCreateOptions = new EcKeyCreateOptions("keyName") + .curve(KeyCurveName.P_384) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + keyAsyncClient.createEcKeyWithResponse(ecKeyCreateOptions) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", keyResponse.value().name(), + keyResponse.value().id())); + // END: com.azure.security.keyvault.keys.async.keyclient.createEcKeyWithResponse#EcKeyCreateOptions + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#getKeyWithResponse(String, String)} + */ + public void getKeyWithResponseSnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string-string + String keyVersion = "6A385B124DEF4096AF1361A85B16C204"; + keyAsyncClient.getKeyWithResponse("keyName", keyVersion) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", + keyResponse.value().name(), keyResponse.value().id())); + // END: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string-string + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string + keyAsyncClient.getKeyWithResponse("keyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", + keyResponse.value().name(), keyResponse.value().id())); + // END: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#KeyBase + keyAsyncClient.listKeys().subscribe(keyBase -> + keyAsyncClient.getKeyWithResponse(keyBase) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key with name %s and value %s \n", keyResponse.value().name(), + keyResponse.value().id()))); + // END: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#KeyBase + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#getKey(String, String)} + */ + public void getKeySnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKey#string-string + String keyVersion = "6A385B124DEF4096AF1361A85B16C204"; + keyAsyncClient.getKey("keyName", keyVersion) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", keyResponse.name(), keyResponse.id())); + // END: com.azure.security.keyvault.keys.async.keyclient.getKey#string-string + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKey#string + keyAsyncClient.getKey("keyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key is created with name %s and id %s \n", keyResponse.name(), keyResponse.id())); + // END: com.azure.security.keyvault.keys.async.keyclient.getKey#string + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKey#KeyBase + keyAsyncClient.listKeys().subscribe(keyBase -> + keyAsyncClient.getKey(keyBase) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Key with name %s and value %s \n", keyResponse.name(), keyResponse.id()))); + // END: com.azure.security.keyvault.keys.async.keyclient.getKey#KeyBase + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#updateKeyWithResponse(KeyBase, KeyOperation...)} + */ + public void updateKeyWithResponseSnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase-keyOperations + keyAsyncClient.getKeyWithResponse("keyName") + .subscribe(keyResponse -> { + Key key = keyResponse.value(); + //Update the not before time of the key. + key.notBefore(OffsetDateTime.now().plusDays(50)); + keyAsyncClient.updateKeyWithResponse(key, KeyOperation.ENCRYPT, KeyOperation.DECRYPT) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(updatedKeyResponse -> + System.out.printf("Key's updated not before time %s \n", + updatedKeyResponse.value().notBefore().toString())); + }); + // END: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase-keyOperations + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase + keyAsyncClient.getKeyWithResponse("keyName") + .subscribe(keyResponse -> { + Key key = keyResponse.value(); + //Update the not before time of the key. + key.notBefore(OffsetDateTime.now().plusDays(50)); + keyAsyncClient.updateKeyWithResponse(key) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(updatedKeyResponse -> + System.out.printf("Key's updated not before time %s \n", + updatedKeyResponse.value().notBefore().toString())); + }); + // END: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#updateKey(KeyBase, KeyOperation...)} + */ + public void updateKeySnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKey#KeyBase-keyOperations + keyAsyncClient.getKey("keyName") + .subscribe(keyResponse -> { + //Update the not before time of the key. + keyResponse.notBefore(OffsetDateTime.now().plusDays(50)); + keyAsyncClient.updateKey(keyResponse, KeyOperation.ENCRYPT, KeyOperation.DECRYPT) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(updatedKeyResponse -> + System.out.printf("Key's updated not before time %s \n", + updatedKeyResponse.notBefore().toString())); + }); + // END: com.azure.security.keyvault.keys.async.keyclient.updateKey#KeyBase-keyOperations + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKey#KeyBase + keyAsyncClient.getKey("keyName") + .subscribe(keyResponse -> { + //Update the not before time of the key. + keyResponse.notBefore(OffsetDateTime.now().plusDays(50)); + keyAsyncClient.updateKey(keyResponse) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(updatedKeyResponse -> + System.out.printf("Key's updated not before time %s \n", + updatedKeyResponse.notBefore().toString())); + }); + // END: com.azure.security.keyvault.keys.async.keyclient.updateKey#KeyBase + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#deleteKeyWithResponse(String)} + */ + public void deleteKeyWithResponseSnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.deleteKeyWithResponse#string + keyAsyncClient.deleteKeyWithResponse("keyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(deletedKeyResponse -> + System.out.printf("Deleted Key's Recovery Id %s", deletedKeyResponse.value().recoveryId())); + // END: com.azure.security.keyvault.keys.async.keyclient.deleteKeyWithResponse#string + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#getDeletedKeyWithResponse(String)} + */ + public void getDeleteKeyWithResponseSnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getDeletedKeyWithResponse#string + keyAsyncClient.getDeletedKeyWithResponse("keyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(deletedKeyResponse -> + System.out.printf("Deleted Key's Recovery Id %s", deletedKeyResponse.value().recoveryId())); + // END: com.azure.security.keyvault.keys.async.keyclient.getDeletedKeyWithResponse#string + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#purgeDeletedKey(String)} + */ + public void purgeDeletedKeySnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.purgeDeletedKey#string + keyAsyncClient.purgeDeletedKey("deletedKeyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(purgeResponse -> + System.out.printf("Purge Status response %rsaPrivateExponent \n", purgeResponse.statusCode())); + // END: com.azure.security.keyvault.keys.async.keyclient.purgeDeletedKey#string + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#recoverDeletedKeyWithResponse(String)} + */ + public void recoverDeletedKeyWithResponseSnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.recoverDeletedKeyWithResponse#string + keyAsyncClient.recoverDeletedKeyWithResponse("deletedKeyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(recoveredKeyResponse -> + System.out.printf("Recovered Key with name %s \n", recoveredKeyResponse.value().name())); + // END: com.azure.security.keyvault.keys.async.keyclient.recoverDeletedKeyWithResponse#string + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#recoverDeletedKey(String)} + */ + public void recoverDeletedKeySnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.recoverDeletedKey#string + keyAsyncClient.recoverDeletedKey("deletedKeyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(recoveredKeyResponse -> + System.out.printf("Recovered Key with name %s \n", recoveredKeyResponse.name())); + // END: com.azure.security.keyvault.keys.async.keyclient.recoverDeletedKey#string + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#backupKey(String)} + */ + public void backupKeySnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.backupKey#string + keyAsyncClient.backupKey("keyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyBackupResponse -> + System.out.printf("Key's Backup Byte array's length %s \n", keyBackupResponse.length)); + // END: com.azure.security.keyvault.keys.async.keyclient.backupKey#string + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#backupKeyWithResponse(String)} + */ + public void backupKeyWithResponseSnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.backupKeyWithResponse#string + keyAsyncClient.backupKeyWithResponse("keyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyBackupResponse -> + System.out.printf("Key's Backup Byte array's length %s \n", keyBackupResponse.value().length)); + // END: com.azure.security.keyvault.keys.async.keyclient.backupKeyWithResponse#string + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#restoreKey} + */ + public void restoreKeySnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.restoreKey#byte + byte[] keyBackupByteArray = {}; + keyAsyncClient.restoreKey(keyBackupByteArray) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Restored Key with name %s and id %s \n", keyResponse.name(), keyResponse.id())); + // END: com.azure.security.keyvault.keys.async.keyclient.restoreKey#byte + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#restoreKeyWithResponse(byte[])} + */ + public void restoreKeyWithResponseSnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.restoreKeyWithResponse#byte + byte[] keyBackupByteArray = {}; + keyAsyncClient.restoreKeyWithResponse(keyBackupByteArray) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyResponse -> + System.out.printf("Restored Key with name %s and id %s \n", keyResponse.value().name(), + keyResponse.value().id())); + // END: com.azure.security.keyvault.keys.async.keyclient.restoreKeyWithResponse#byte + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#listKeys} + */ + public void listKeySnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.listKeys + keyAsyncClient.listKeys() + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyBase -> keyAsyncClient.getKey(keyBase) + .subscribe(keyResponse -> System.out.printf("Received key with name %s and type %s", keyResponse.name(), + keyResponse.keyMaterial().kty()))); + // END: com.azure.security.keyvault.keys.async.keyclient.listKeys + } + + /** + * Generates a code sample for using {@link KeyAsyncClient#listDeletedKeys} + */ + public void listDeletedKeysSnippets() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.listDeletedKeys + keyAsyncClient.listDeletedKeys() + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(deletedKey -> System.out.printf("Deleted key's recovery Id %s", deletedKey.recoveryId())); + // END: com.azure.security.keyvault.keys.async.keyclient.listDeletedKeys + } + + /** + * Generates code sample for using {@link KeyAsyncClient#listKeyVersions(String)} + */ + public void listKeyVersions() { + KeyAsyncClient keyAsyncClient = createAsyncClient(); + // BEGIN: com.azure.security.keyvault.keys.async.keyclient.listKeyVersions + keyAsyncClient.listKeyVersions("keyName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(keyBase -> keyAsyncClient.getKey(keyBase) + .subscribe(keyResponse -> + System.out.printf("Received key's version with name %s, type %s and version %s", keyResponse.name(), + keyResponse.keyMaterial().kty(), keyResponse.version()))); + // END: com.azure.security.keyvault.keys.async.keyclient.listKeyVersions + } + + /** + * Implementation not provided for this method + * @return {@code null} + */ + private TokenCredential getKeyVaultCredential() { + return null; + } +} diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java index 6f63be8f59b68..c2e2caedfee11 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java +++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java @@ -6,36 +6,33 @@ import com.azure.core.credentials.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.HttpLogDetailLevel; -import com.azure.core.test.models.RecordedData; -import com.azure.core.test.policy.RecordNetworkCallPolicy; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.VoidResponse; +import com.azure.core.util.Context; import com.azure.identity.credential.DefaultAzureCredential; +import com.azure.security.keyvault.keys.models.DeletedKey; +import com.azure.security.keyvault.keys.models.EcKeyCreateOptions; import com.azure.security.keyvault.keys.models.Key; import com.azure.security.keyvault.keys.models.KeyBase; +import com.azure.security.keyvault.keys.models.KeyCreateOptions; +import com.azure.security.keyvault.keys.models.RsaKeyCreateOptions; +import com.azure.security.keyvault.keys.models.webkey.KeyCurveName; +import com.azure.security.keyvault.keys.models.webkey.KeyOperation; import com.azure.security.keyvault.keys.models.webkey.KeyType; +import java.time.OffsetDateTime; + /** * This class contains code samples for generating javadocs through doclets for {@link KeyClient} */ public final class KeyClientJavaDocCodeSnippets { - /** - * Generates code sample for creating a {@link KeyAsyncClient} - * @return An instance of {@link KeyAsyncClient} - */ - public KeyAsyncClient createAsyncClientWithHttpClient() { - // BEGIN: com.azure.security.keyvault.keys.async.keyclient.withhttpclient.instantiation - RecordedData networkData = new RecordedData(); - KeyAsyncClient keyClient = new KeyClientBuilder() - .endpoint("https://myvault.azure.net/") - .credential(new DefaultAzureCredential()) - .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) - .addPolicy(new RecordNetworkCallPolicy(networkData)) - .httpClient(HttpClient.createDefault()) - .buildAsyncClient(); - // END: com.azure.security.keyvault.keys.async.keyclient.withhttpclient.instantiation - return keyClient; - } + private String key1 = "key1"; + private String key2 = "key2"; + private String value1 = "val1"; + private String value2 = "val2"; /** * Generates code sample for creating a {@link KeyClient} @@ -52,46 +49,323 @@ public KeyClient createClient() { } /** - * Generates code sample for creating a {@link KeyAsyncClient} - * @return An instance of {@link KeyAsyncClient} + * Generates a code sample for using {@link KeyClient#createKey(String, KeyType)} */ - public KeyAsyncClient createAsyncClient() { - // BEGIN: com.azure.security.keyvault.keys.async.keyclient.instantiation - KeyAsyncClient keyClient = new KeyClientBuilder() - .endpoint("https://myvault.azure.net/") - .credential(new DefaultAzureCredential()) - .buildAsyncClient(); - // END: com.azure.security.keyvault.keys.async.keyclient.instantiation - return keyClient; + public void createKey() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.createKey#string-keyType + Key key = keyClient.createKey("keyName", KeyType.EC); + System.out.printf("Key is created with name %s and id %s %n", key.name(), key.id()); + // END: com.azure.keyvault.keys.keyclient.createKey#string-keyType + + // BEGIN: com.azure.keyvault.keys.keyclient.createKey#keyOptions + KeyCreateOptions keyCreateOptions = new KeyCreateOptions("keyName", KeyType.RSA) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + Key optionsKey = keyClient.createKey(keyCreateOptions); + System.out.printf("Key is created with name %s and id %s \n", optionsKey.name(), optionsKey.id()); + // END: com.azure.keyvault.keys.keyclient.createKey#keyOptions + + // BEGIN: com.azure.keyvault.keys.keyclient.createRsaKey#keyOptions + RsaKeyCreateOptions rsaKeyCreateOptions = new RsaKeyCreateOptions("keyName") + .keySize(2048) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + Key rsaKey = keyClient.createRsaKey(rsaKeyCreateOptions); + System.out.printf("Key is created with name %s and id %s \n", rsaKey.name(), rsaKey.id()); + // END: com.azure.keyvault.keys.keyclient.createRsaKey#keyOptions + + // BEGIN: com.azure.keyvault.keys.keyclient.createEcKey#keyOptions + EcKeyCreateOptions ecKeyCreateOptions = new EcKeyCreateOptions("keyName") + .curve(KeyCurveName.P_384) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + Key ecKey = keyClient.createEcKey(ecKeyCreateOptions); + System.out.printf("Key is created with name %s and id %s \n", ecKey.name(), ecKey.id()); + // END: com.azure.keyvault.keys.keyclient.createEcKey#keyOptions + + } /** - * Generates code sample for creating a {@link KeyAsyncClient} - * @return An instance of {@link KeyAsyncClient} + * Generates a code sample for using {@link KeyClient#deleteKey(String)} */ - public KeyAsyncClient createAsyncClientWithPipeline() { - // BEGIN: com.azure.security.keyvault.keys.async.keyclient.pipeline.instantiation - RecordedData networkData = new RecordedData(); - HttpPipeline pipeline = HttpPipeline.builder().policies(new RecordNetworkCallPolicy(networkData)).build(); - KeyAsyncClient keyClient = new KeyClientBuilder() - .pipeline(pipeline) - .endpoint("https://myvault.azure.net/") - .credential(new DefaultAzureCredential()) - .buildAsyncClient(); - // END: com.azure.security.keyvault.keys.async.keyclient.pipeline.instantiation - return keyClient; + public void deleteKeySnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.deleteKey#string + Key key = keyClient.getKey("keyName"); + DeletedKey deletedKey = keyClient.deleteKey("keyName"); + System.out.printf("Deleted Key's Recovery Id %s", deletedKey.recoveryId()); + // END: com.azure.keyvault.keys.keyclient.deleteKey#string } + /** + * Generates a code sample for using {@link KeyClient#getDeletedKey(String)} + */ + public void getDeletedKeySnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.getDeletedKey#string + DeletedKey deletedKey = keyClient.getDeletedKey("keyName"); + System.out.printf("Deleted Key's Recovery Id %s", deletedKey.recoveryId()); + // END: com.azure.keyvault.keys.keyclient.getDeletedKey#string + } /** - * Generates a code sample for using {@link KeyClient#createKey(String, KeyType)} + * Generates a code sample for using {@link KeyClient#createKeyWithResponse(KeyCreateOptions, Context)} */ - public void createKey() { + public void createKeyWithResponses() { KeyClient keyClient = createClient(); - // BEGIN: com.azure.keyvault.keys.keyclient.createKey#string-keyType - Key retKey = keyClient.createKey("keyName", KeyType.EC).value(); - System.out.printf("Key is created with name %s and id %s %n", retKey.name(), retKey.id()); - // END: com.azure.keyvault.keys.keyclient.createKey#string-keyType + // BEGIN: com.azure.keyvault.keys.keyclient.createKeyWithResponse#keyCreateOptions-Context + KeyCreateOptions keyCreateOptions = new KeyCreateOptions("keyName", KeyType.RSA) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + Key optionsKey = keyClient.createKeyWithResponse(keyCreateOptions, new Context(key1, value1)).value(); + System.out.printf("Key is created with name %s and id %s \n", optionsKey.name(), optionsKey.id()); + // END: com.azure.keyvault.keys.keyclient.createKeyWithResponse#keyCreateOptions-Context + + // BEGIN: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions + RsaKeyCreateOptions rsaKeyCreateOptions = new RsaKeyCreateOptions("keyName") + .keySize(2048) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + Key rsaKey = keyClient.createRsaKeyWithResponse(rsaKeyCreateOptions, new Context(key1, value1)).value(); + System.out.printf("Key is created with name %s and id %s \n", rsaKey.name(), rsaKey.id()); + // END: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions + + // BEGIN: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions + EcKeyCreateOptions ecKeyCreateOptions = new EcKeyCreateOptions("keyName") + .curve(KeyCurveName.P_384) + .notBefore(OffsetDateTime.now().plusDays(1)) + .expires(OffsetDateTime.now().plusYears(1)); + Key ecKey = keyClient.createEcKeyWithResponse(ecKeyCreateOptions, new Context(key1, value1)).value(); + System.out.printf("Key is created with name %s and id %s \n", ecKey.name(), ecKey.id()); + // END: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions + } + + /** + * Generates a code sample for using {@link KeyClient#getKeyWithResponse(String, String, Context)} + */ + public void getKeyWithResponseSnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.getKeyWithResponse#string-string-Context + String keyVersion = "6A385B124DEF4096AF1361A85B16C204"; + Key keyWithVersion = keyClient.getKeyWithResponse("keyName", keyVersion, + new Context(key1, value1)).value(); + System.out.printf("Key is returned with name %s and id %s \n", keyWithVersion.name(), keyWithVersion.id()); + // END: com.azure.keyvault.keys.keyclient.getKeyWithResponse#string-string-Context + } + + /** + * Generates a code sample for using {@link KeyClient#getKey(String, String)} + */ + public void getKeySnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.getKey#string-string + String keyVersion = "6A385B124DEF4096AF1361A85B16C204"; + Key keyWithVersion = keyClient.getKey("keyName", keyVersion); + System.out.printf("Key is returned with name %s and id %s \n", keyWithVersion.name(), keyWithVersion.id()); + // END: com.azure.keyvault.keys.keyclient.getKey#string-string + + // BEGIN: com.azure.keyvault.keys.keyclient.getKey#string + Key keyWithVersionValue = keyClient.getKey("keyName"); + System.out.printf("Key is returned with name %s and id %s \n", keyWithVersionValue.name(), keyWithVersionValue.id()); + // END: com.azure.keyvault.keys.keyclient.getKey#string + + // BEGIN: com.azure.keyvault.keys.keyclient.getKey#KeyBase + for (KeyBase key : keyClient.listKeys()) { + Key keyResponse = keyClient.getKey(key); + System.out.printf("Received key with name %s and type %s", keyResponse.name(), + keyResponse.keyMaterial().kty()); + } + // END: com.azure.keyvault.keys.keyclient.getKey#KeyBase + } + + /** + * Generates a code sample for using {@link KeyClient#updateKeyWithResponse(KeyBase, Context, KeyOperation...)} + */ + public void updateKeyWithResponseSnippets() { + KeyClient keyClient = createClient(); + + // BEGIN: com.azure.keyvault.keys.keyclient.updateKeyWithResponse#KeyBase-keyOperations-Context + Key key = keyClient.getKey("keyName"); + key.expires(OffsetDateTime.now().plusDays(60)); + KeyBase updatedKeyBase = keyClient.updateKeyWithResponse(key, + new Context(key1, value1), KeyOperation.ENCRYPT, KeyOperation.DECRYPT).value(); + Key updatedKey = keyClient.getKey(updatedKeyBase.name()); + System.out.printf("Key is updated with name %s and id %s \n", updatedKey.name(), updatedKey.id()); + // END: com.azure.keyvault.keys.keyclient.updateKeyWithResponse#KeyBase-keyOperations-Context + } + + /** + * Generates a code sample for using {@link KeyClient#updateKey(KeyBase, KeyOperation...)} + */ + public void updateKeySnippets() { + KeyClient keyClient = createClient(); + + // BEGIN: com.azure.keyvault.keys.keyclient.updateKey#KeyBase-keyOperations + Key key = keyClient.getKey("keyName"); + key.expires(OffsetDateTime.now().plusDays(60)); + KeyBase updatedKeyBase = keyClient.updateKey(key, KeyOperation.ENCRYPT, KeyOperation.DECRYPT); + Key updatedKey = keyClient.getKey(updatedKeyBase.name()); + System.out.printf("Key is updated with name %s and id %s \n", updatedKey.name(), updatedKey.id()); + // END: com.azure.keyvault.keys.keyclient.updateKey#KeyBase-keyOperations + + // BEGIN: com.azure.keyvault.keys.keyclient.updateKey#KeyBase + Key updateKey = keyClient.getKey("keyName"); + key.expires(OffsetDateTime.now().plusDays(60)); + KeyBase updatedKeyBaseValue = keyClient.updateKey(updateKey); + Key updatedKeyValue = keyClient.getKey(updatedKeyBaseValue.name()); + System.out.printf("Key is updated with name %s and id %s \n", updatedKeyValue.name(), updatedKeyValue.id()); + // END: com.azure.keyvault.keys.keyclient.updateKey#KeyBase + } + + /** + * Generates a code sample for using {@link KeyClient#deleteKeyWithResponse(String, Context)} + */ + public void deleteKeyWithResponseSnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.deleteKeyWithResponse#string-Context + Key key = keyClient.getKey("keyName"); + DeletedKey deletedKey = keyClient.deleteKeyWithResponse("keyName", new Context(key1, value1)).value(); + System.out.printf("Deleted Key's Recovery Id %s", deletedKey.recoveryId()); + // END: com.azure.keyvault.keys.keyclient.deleteKeyWithResponse#string-Context + } + + /** + * Generates a code sample for using {@link KeyClient#getDeletedKeyWithResponse(String, Context)} + */ + public void getDeleteKeyWithResponseSnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.getDeletedKeyWithResponse#string-Context + DeletedKey deletedKey = keyClient.getDeletedKeyWithResponse("keyName", new Context(key1, value1)).value(); + System.out.printf("Deleted Key with recovery Id %s \n", deletedKey.recoveryId()); + // END: com.azure.keyvault.keys.keyclient.getDeletedKeyWithResponse#string-Context + } + + /** + * Generates a code sample for using {@link KeyClient#purgeDeletedKey(String)} + */ + public void purgeDeletedKeySnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.purgeDeletedKey#string + VoidResponse purgeResponse = keyClient.purgeDeletedKey("deletedKeyName"); + System.out.printf("Purge Status Code: %rsaPrivateExponent", purgeResponse.statusCode()); + // END: com.azure.keyvault.keys.keyclient.purgeDeletedKey#string + + // BEGIN: com.azure.keyvault.keys.keyclient.purgeDeletedKey#string-Context + VoidResponse purgedResponse = keyClient.purgeDeletedKey("deletedKeyName", new Context(key2, value2)); + System.out.printf("Purge Status Code: %rsaPrivateExponent", purgedResponse.statusCode()); + // END: com.azure.keyvault.keys.keyclient.purgeDeletedKey#string-Context + } + + /** + * Generates a code sample for using {@link KeyClient#recoverDeletedKeyWithResponse(String, Context)} + */ + public void recoverDeletedKeyWithResponseSnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.recoverDeletedKeyWithResponse#string-Context + Key recoveredKey = keyClient.recoverDeletedKeyWithResponse("deletedKeyName", + new Context(key2, value2)).value(); + System.out.printf("Recovered key with name %s", recoveredKey.name()); + // END: com.azure.keyvault.keys.keyclient.recoverDeletedKeyWithResponse#string-Context + } + + /** + * Generates a code sample for using {@link KeyClient#recoverDeletedKey(String)} + */ + public void recoverDeletedKeySnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.recoverDeletedKey#string + Key recoveredKey = keyClient.recoverDeletedKey("deletedKeyName"); + System.out.printf("Recovered key with name %s", recoveredKey.name()); + // END: com.azure.keyvault.keys.keyclient.recoverDeletedKey#string + } + + /** + * Generates a code sample for using {@link KeyClient#backupKey(String)} + */ + public void backupKeySnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.backupKey#string + byte[] keyBackup = keyClient.backupKey("keyName"); + System.out.printf("Key's Backup Byte array's length %s", keyBackup.length); + // END: com.azure.keyvault.keys.keyclient.backupKey#string + } + + /** + * Generates a code sample for using {@link KeyClient#backupKeyWithResponse(String, Context)} + */ + public void backupKeyWithResponseSnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.backupKeyWithResponse#string-Context + byte[] keyBackup = keyClient.backupKeyWithResponse("keyName", new Context(key2, value2)).value(); + System.out.printf("Key's Backup Byte array's length %s", keyBackup.length); + // END: com.azure.keyvault.keys.keyclient.backupKeyWithResponse#string-Context + } + + /** + * Generates a code sample for using {@link KeyClient#restoreKey} + */ + public void restoreKeySnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.restoreKey#byte + byte[] keyBackupByteArray = {}; + Key keyResponse = keyClient.restoreKey(keyBackupByteArray); + System.out.printf("Restored Key with name %s and id %s \n", keyResponse.name(), keyResponse.id()); + // END: com.azure.keyvault.keys.keyclient.restoreKey#byte + } + + /** + * Generates a code sample for using {@link KeyClient#restoreKeyWithResponse(byte[], Context)} + */ + public void restoreKeyWithResponseSnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.restoreKeyWithResponse#byte-Context + byte[] keyBackupByteArray = {}; + Response keyResponse = keyClient.restoreKeyWithResponse(keyBackupByteArray, new Context(key1, value1)); + System.out.printf("Restored Key with name %s and id %s \n", + keyResponse.value().name(), keyResponse.value().id()); + // END: com.azure.keyvault.keys.keyclient.restoreKeyWithResponse#byte-Context + } + + /** + * Generates a code sample for using {@link KeyClient#listKeys} + */ + public void listKeySnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.listKeys + for (KeyBase key : keyClient.listKeys()) { + Key keyWithMaterial = keyClient.getKey(key); + System.out.printf("Received key with name %s and type %s", keyWithMaterial.name(), + keyWithMaterial.keyMaterial().kty()); + } + // END: com.azure.keyvault.keys.keyclient.listKeys + + // BEGIN: com.azure.keyvault.keys.keyclient.listKeys#Context + for (KeyBase key : keyClient.listKeys(new Context(key2, value2))) { + Key keyWithMaterial = keyClient.getKey(key); + System.out.printf("Received key with name %s and type %s", keyWithMaterial.name(), + keyWithMaterial.keyMaterial().kty()); + } + // END: com.azure.keyvault.keys.keyclient.listKeys#Context + } + + /** + * Generates a code sample for using {@link KeyClient#listDeletedKeys} + */ + public void listDeletedKeysSnippets() { + KeyClient keyClient = createClient(); + // BEGIN: com.azure.keyvault.keys.keyclient.listDeletedKeys + for (DeletedKey deletedKey : keyClient.listDeletedKeys()) { + System.out.printf("Deleted key's recovery Id %s", deletedKey.recoveryId()); + } + // END: com.azure.keyvault.keys.keyclient.listDeletedKeys + + // BEGIN: com.azure.keyvault.keys.keyclient.listDeletedKeys#Context + for (DeletedKey deletedKey : keyClient.listDeletedKeys(new Context(key2, value2))) { + System.out.printf("Deleted key's recovery Id %s", deletedKey.recoveryId()); + } + // END: com.azure.keyvault.keys.keyclient.listDeletedKeys#Context } /** @@ -101,11 +375,19 @@ public void listKeyVersions() { KeyClient keyClient = createClient(); // BEGIN: com.azure.keyvault.keys.keyclient.listKeyVersions for (KeyBase key : keyClient.listKeyVersions("keyName")) { - Key keyWithMaterial = keyClient.getKey(key).value(); + Key keyWithMaterial = keyClient.getKey(key); System.out.printf("Received key's version with name %s, type %s and version %s", keyWithMaterial.name(), keyWithMaterial.keyMaterial().kty(), keyWithMaterial.version()); } // END: com.azure.keyvault.keys.keyclient.listKeyVersions + + // BEGIN: com.azure.keyvault.keys.keyclient.listKeyVersions#Context + for (KeyBase key : keyClient.listKeyVersions("keyName", new Context(key2, value2))) { + Key keyWithMaterial = keyClient.getKey(key); + System.out.printf("Received key's version with name %s, type %s and version %s", keyWithMaterial.name(), + keyWithMaterial.keyMaterial().kty(), keyWithMaterial.version()); + } + // END: com.azure.keyvault.keys.keyclient.listKeyVersions#Context } /** diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperations.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperations.java index b719d6970856f..400fe84a2a054 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperations.java +++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperations.java @@ -43,7 +43,7 @@ public static void main(String[] args) throws IllegalArgumentException { // You need to check te type of keys already exist in your key vault. Let's list the keys and print their types. // List operations don't return the keys with key material information. So, for each returned key we call getKey to get the key with its key material information. for (KeyBase key : keyClient.listKeys()) { - Key keyWithMaterial = keyClient.getKey(key).value(); + Key keyWithMaterial = keyClient.getKey(key); System.out.printf("Received key with name %s and type %s", keyWithMaterial.name(), keyWithMaterial.keyMaterial().kty()); } @@ -55,7 +55,7 @@ public static void main(String[] args) throws IllegalArgumentException { // You need to check all the different versions Cloud Rsa key had previously. Lets print all the versions of this key. for (KeyBase key : keyClient.listKeyVersions("CloudRsaKey")) { - Key keyWithMaterial = keyClient.getKey(key).value(); + Key keyWithMaterial = keyClient.getKey(key); System.out.printf("Received key's version with name %s, type %s and version %s", keyWithMaterial.name(), keyWithMaterial.keyMaterial().kty(), keyWithMaterial.version()); } } diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java index f82d562845589..35ab9c7b1902f 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java +++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java @@ -35,11 +35,11 @@ public static void main(String[] args) throws InterruptedException { keyAsyncClient.createEcKey(new EcKeyCreateOptions("CloudEcKey") .expires(OffsetDateTime.now().plusYears(1))) .subscribe(keyResponse -> - System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty())); + System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty())); Thread.sleep(2000); - keyAsyncClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey") + keyAsyncClient.createRsaKeyWithResponse(new RsaKeyCreateOptions("CloudRsaKey") .expires(OffsetDateTime.now().plusYears(1))) .subscribe(keyResponse -> System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty())); @@ -51,7 +51,7 @@ public static void main(String[] args) throws InterruptedException { keyAsyncClient.listKeys() .subscribe(keyBase -> keyAsyncClient.getKey(keyBase).subscribe(keyResponse -> - System.out.printf("Received key with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty()))); + System.out.printf("Received key with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty()))); Thread.sleep(15000); @@ -60,15 +60,15 @@ public static void main(String[] args) throws InterruptedException { keyAsyncClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey") .keySize(4096) .expires(OffsetDateTime.now().plusYears(1))).subscribe(keyResponse -> - System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty())); + System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty())); Thread.sleep(2000); // You need to check all the different versions Cloud Rsa key had previously. Lets print all the versions of this key. keyAsyncClient.listKeyVersions("CloudRsaKey").subscribe(keyBase -> keyAsyncClient.getKey(keyBase).subscribe(keyResponse -> - System.out.printf("Received key's version with name %s, type %s and version %s \n", keyResponse.value().name(), - keyResponse.value().keyMaterial().kty(), keyResponse.value().version()))); + System.out.printf("Received key's version with name %s, type %s and version %s \n", keyResponse.name(), + keyResponse.keyMaterial().kty(), keyResponse.version()))); Thread.sleep(15000); } diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ManagingDeletedKeysAsync.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ManagingDeletedKeysAsync.java index a9a206453ba8e..a88635df02911 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ManagingDeletedKeysAsync.java +++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ManagingDeletedKeysAsync.java @@ -39,20 +39,20 @@ public static void main(String[] args) throws InterruptedException { keyAsyncClient.createEcKey(new EcKeyCreateOptions("CloudEcKey") .expires(OffsetDateTime.now().plusYears(1))) .subscribe(keyResponse -> - System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty())); + System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty())); Thread.sleep(2000); keyAsyncClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey") .expires(OffsetDateTime.now().plusYears(1))) .subscribe(keyResponse -> - System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty())); + System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty())); Thread.sleep(2000); // The Cloud Rsa Key is no longer needed, need to delete it from the key vault. keyAsyncClient.deleteKey("CloudEcKey").subscribe(deletedKeyResponse -> - System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.value().recoveryId())); + System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.recoveryId())); //To ensure key is deleted on server side. Thread.sleep(30000); @@ -60,17 +60,17 @@ public static void main(String[] args) throws InterruptedException { // We accidentally deleted Cloud Ec key. Let's recover it. // A deleted key can only be recovered if the key vault is soft-delete enabled. keyAsyncClient.recoverDeletedKey("CloudEcKey").subscribe(recoveredKeyResponse -> - System.out.printf("Recovered Key with name %s \n", recoveredKeyResponse.value().name())); + System.out.printf("Recovered Key with name %s \n", recoveredKeyResponse.name())); //To ensure key is recovered on server side. Thread.sleep(10000); // The Cloud Ec and Rsa keys are no longer needed, need to delete them from the key vault. keyAsyncClient.deleteKey("CloudEcKey").subscribe(deletedKeyResponse -> - System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.value().recoveryId())); + System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.recoveryId())); keyAsyncClient.deleteKey("CloudRsaKey").subscribe(deletedKeyResponse -> - System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.value().recoveryId())); + System.out.printf("Deleted Key's Recovery Id %s \n", deletedKeyResponse.recoveryId())); // To ensure key is deleted on server side. Thread.sleep(30000); diff --git a/sdk/keyvault/azure-keyvault-keys/src/test/java/com/azure/security/keyvault/keys/KeyAsyncClientTest.java b/sdk/keyvault/azure-keyvault-keys/src/test/java/com/azure/security/keyvault/keys/KeyAsyncClientTest.java index 4e21a1d56a9d4..c8b8acb7bb08c 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/test/java/com/azure/security/keyvault/keys/KeyAsyncClientTest.java +++ b/sdk/keyvault/azure-keyvault-keys/src/test/java/com/azure/security/keyvault/keys/KeyAsyncClientTest.java @@ -14,10 +14,10 @@ import com.azure.security.keyvault.keys.models.KeyCreateOptions; import com.azure.security.keyvault.keys.models.webkey.KeyType; import io.netty.handler.codec.http.HttpResponseStatus; +import org.junit.Assert; import reactor.test.StepVerifier; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import static org.junit.Assert.assertEquals; @@ -34,20 +34,20 @@ protected void beforeTest() { if (interceptorManager.isPlaybackMode()) { client = clientSetup(credentials -> new KeyClientBuilder() - .credential(credentials) - .endpoint(getEndpoint()) - .httpClient(interceptorManager.getPlaybackClient()) - .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) - .buildAsyncClient()); + .credential(credentials) + .endpoint(getEndpoint()) + .httpClient(interceptorManager.getPlaybackClient()) + .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) + .buildAsyncClient()); } else { client = clientSetup(credentials -> new KeyClientBuilder() - .credential(credentials) - .endpoint(getEndpoint()) - .httpClient(HttpClient.createDefault().wiretap(true)) - .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) - .addPolicy(interceptorManager.getRecordPolicy()) - .addPolicy(new RetryPolicy()) - .buildAsyncClient()); + .credential(credentials) + .endpoint(getEndpoint()) + .httpClient(HttpClient.createDefault().wiretap(true)) + .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) + .addPolicy(interceptorManager.getRecordPolicy()) + .addPolicy(new RetryPolicy()) + .buildAsyncClient()); } } @@ -57,8 +57,8 @@ protected void beforeTest() { public void setKey() { setKeyRunner((expected) -> StepVerifier.create(client.createKey(expected)) - .assertNext(response -> assertKeyEquals(expected, response)) - .verifyComplete()); + .assertNext(response -> assertKeyEquals(expected, response)) + .verifyComplete()); } /** @@ -66,19 +66,17 @@ public void setKey() { */ public void setKeyEmptyName() { StepVerifier.create(client.createKey("", KeyType.RSA)) - .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceModifiedException.class, HttpResponseStatus.BAD_REQUEST.code())); + .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceModifiedException.class, + HttpResponseStatus.BAD_REQUEST.code())); } /** * Tests that we can create keys when value is not null or an empty string. */ public void setKeyNullType() { - setKeyEmptyValueRunner((key) -> { - - StepVerifier.create(client.createKey(key)) - .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceModifiedException.class, HttpResponseStatus.BAD_REQUEST.code())); - - }); + setKeyEmptyValueRunner((key) -> StepVerifier.create(client.createKey(key)) + .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceModifiedException.class, + HttpResponseStatus.BAD_REQUEST.code()))); } /** @@ -94,19 +92,19 @@ public void setKeyNull() { public void updateKey() { updateKeyRunner((original, updated) -> { StepVerifier.create(client.createKey(original)) - .assertNext(response -> assertKeyEquals(original, response)) - .verifyComplete(); - Key keyToUpdate = client.getKey(original.name()).block().value(); + .assertNext(response -> assertKeyEquals(original, response)) + .verifyComplete(); + Key keyToUpdate = client.getKey(original.name()).block(); StepVerifier.create(client.updateKey(keyToUpdate.expires(updated.expires()))) - .assertNext(response -> { - assertNotNull(response.value()); - assertEquals(original.name(), response.value().name()); - }).verifyComplete(); + .assertNext(response -> { + assertNotNull(response); + assertEquals(original.name(), response.name()); + }).verifyComplete(); StepVerifier.create(client.getKey(original.name())) - .assertNext(updatedKeyResponse -> assertKeyEquals(updated, updatedKeyResponse)) - .verifyComplete(); + .assertNext(updatedKeyResponse -> assertKeyEquals(updated, updatedKeyResponse)) + .verifyComplete(); }); } @@ -116,19 +114,19 @@ public void updateKey() { public void updateDisabledKey() { updateDisabledKeyRunner((original, updated) -> { StepVerifier.create(client.createKey(original)) - .assertNext(response -> assertKeyEquals(original, response)) - .verifyComplete(); - Key keyToUpdate = client.getKey(original.name()).block().value(); + .assertNext(response -> assertKeyEquals(original, response)) + .verifyComplete(); + Key keyToUpdate = client.getKey(original.name()).block(); StepVerifier.create(client.updateKey(keyToUpdate.expires(updated.expires()))) - .assertNext(response -> { - assertNotNull(response.value()); - assertEquals(original.name(), response.value().name()); - }).verifyComplete(); + .assertNext(response -> { + assertNotNull(response); + assertEquals(original.name(), response.name()); + }).verifyComplete(); StepVerifier.create(client.getKey(original.name())) - .assertNext(updatedKeyResponse -> assertKeyEquals(updated, updatedKeyResponse)) - .verifyComplete(); + .assertNext(updatedKeyResponse -> assertKeyEquals(updated, updatedKeyResponse)) + .verifyComplete(); }); } @@ -140,8 +138,8 @@ public void getKey() { getKeyRunner((original) -> { client.createKey(original); StepVerifier.create(client.getKey(original.name())) - .assertNext(response -> assertKeyEquals(original, response)) - .verifyComplete(); + .assertNext(response -> assertKeyEquals(original, response)) + .verifyComplete(); }); } @@ -150,16 +148,16 @@ public void getKey() { */ public void getKeySpecificVersion() { getKeySpecificVersionRunner((key, keyWithNewVal) -> { - final Key keyVersionOne = client.createKey(key).block().value(); - final Key keyVersionTwo = client.createKey(keyWithNewVal).block().value(); + final Key keyVersionOne = client.createKey(key).block(); + final Key keyVersionTwo = client.createKey(keyWithNewVal).block(); StepVerifier.create(client.getKey(key.name(), keyVersionOne.version())) - .assertNext(response -> assertKeyEquals(key, response)) - .verifyComplete(); + .assertNext(response -> assertKeyEquals(key, response)) + .verifyComplete(); StepVerifier.create(client.getKey(keyWithNewVal.name(), keyVersionTwo.version())) - .assertNext(response -> assertKeyEquals(keyWithNewVal, response)) - .verifyComplete(); + .assertNext(response -> assertKeyEquals(keyWithNewVal, response)) + .verifyComplete(); }); } @@ -168,7 +166,7 @@ public void getKeySpecificVersion() { */ public void getKeyNotFound() { StepVerifier.create(client.getKey("non-existing")) - .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); + .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); } @@ -178,31 +176,27 @@ public void getKeyNotFound() { public void deleteKey() { deleteKeyRunner((keyToDelete) -> { StepVerifier.create(client.createKey(keyToDelete)) - .assertNext(keyResponse -> { - assertKeyEquals(keyToDelete, keyResponse.value()); - }).verifyComplete(); + .assertNext(keyResponse -> assertKeyEquals(keyToDelete, keyResponse)).verifyComplete(); StepVerifier.create(client.deleteKey(keyToDelete.name())) - .assertNext(deletedKeyResponse -> { - DeletedKey deletedKey = deletedKeyResponse.value(); - assertNotNull(deletedKey.deletedDate()); - assertNotNull(deletedKey.recoveryId()); - assertNotNull(deletedKey.scheduledPurgeDate()); - assertEquals(keyToDelete.name(), deletedKey.name()); - }).verifyComplete(); + .assertNext(deletedKeyResponse -> { + assertNotNull(deletedKeyResponse.deletedDate()); + assertNotNull(deletedKeyResponse.recoveryId()); + assertNotNull(deletedKeyResponse.scheduledPurgeDate()); + assertEquals(keyToDelete.name(), deletedKeyResponse.name()); + }).verifyComplete(); sleepInRecordMode(30000); StepVerifier.create(client.purgeDeletedKey(keyToDelete.name())) - .assertNext(voidResponse -> { - assertEquals(HttpResponseStatus.NO_CONTENT.code(), voidResponse.statusCode()); - }).verifyComplete(); + .assertNext(voidResponse -> assertEquals(HttpResponseStatus.NO_CONTENT.code(), + voidResponse.statusCode())).verifyComplete(); sleepInRecordMode(15000); }); } public void deleteKeyNotFound() { StepVerifier.create(client.deleteKey("non-existing")) - .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); + .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); } /** @@ -210,7 +204,7 @@ public void deleteKeyNotFound() { */ public void getDeletedKeyNotFound() { StepVerifier.create(client.getDeletedKey("non-existing")) - .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); + .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); } /** @@ -219,24 +213,18 @@ public void getDeletedKeyNotFound() { public void recoverDeletedKey() { recoverDeletedKeyRunner((keyToDeleteAndRecover) -> { StepVerifier.create(client.createKey(keyToDeleteAndRecover)) - .assertNext(keyResponse -> { - assertKeyEquals(keyToDeleteAndRecover, keyResponse.value()); - }).verifyComplete(); + .assertNext(keyResponse -> assertKeyEquals(keyToDeleteAndRecover, keyResponse)).verifyComplete(); StepVerifier.create(client.deleteKey(keyToDeleteAndRecover.name())) - .assertNext(deletedKeyResponse -> { - DeletedKey deletedKey = deletedKeyResponse.value(); - assertNotNull(deletedKey); - }).verifyComplete(); + .assertNext(Assert::assertNotNull).verifyComplete(); sleepInRecordMode(30000); StepVerifier.create(client.recoverDeletedKey(keyToDeleteAndRecover.name())) - .assertNext(keyResponse -> { - Key recoveredKey = keyResponse.value(); - assertEquals(keyToDeleteAndRecover.name(), recoveredKey.name()); - assertEquals(keyToDeleteAndRecover.notBefore(), recoveredKey.notBefore()); - assertEquals(keyToDeleteAndRecover.expires(), recoveredKey.expires()); - }).verifyComplete(); + .assertNext(keyResponse -> { + assertEquals(keyToDeleteAndRecover.name(), keyResponse.name()); + assertEquals(keyToDeleteAndRecover.notBefore(), keyResponse.notBefore()); + assertEquals(keyToDeleteAndRecover.expires(), keyResponse.expires()); + }).verifyComplete(); }); } @@ -245,7 +233,7 @@ public void recoverDeletedKey() { */ public void recoverDeletedKeyNotFound() { StepVerifier.create(client.recoverDeletedKey("non-existing")) - .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); + .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); } /** @@ -254,16 +242,13 @@ public void recoverDeletedKeyNotFound() { public void backupKey() { backupKeyRunner((keyToBackup) -> { StepVerifier.create(client.createKey(keyToBackup)) - .assertNext(keyResponse -> { - assertKeyEquals(keyToBackup, keyResponse.value()); - }).verifyComplete(); + .assertNext(keyResponse -> assertKeyEquals(keyToBackup, keyResponse)).verifyComplete(); StepVerifier.create(client.backupKey(keyToBackup.name())) - .assertNext(response -> { - byte[] backupBytes = response.value(); - assertNotNull(backupBytes); - assertTrue(backupBytes.length > 0); - }).verifyComplete(); + .assertNext(response -> { + assertNotNull(response); + assertTrue(response.length > 0); + }).verifyComplete(); }); } @@ -272,7 +257,7 @@ public void backupKey() { */ public void backupKeyNotFound() { StepVerifier.create(client.backupKey("non-existing")) - .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); + .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceNotFoundException.class, HttpResponseStatus.NOT_FOUND.code())); } /** @@ -281,33 +266,26 @@ public void backupKeyNotFound() { public void restoreKey() { restoreKeyRunner((keyToBackupAndRestore) -> { StepVerifier.create(client.createKey(keyToBackupAndRestore)) - .assertNext(keyResponse -> { - assertKeyEquals(keyToBackupAndRestore, keyResponse.value()); - }).verifyComplete(); - byte[] backup = client.backupKey(keyToBackupAndRestore.name()).block().value(); + .assertNext(keyResponse -> assertKeyEquals(keyToBackupAndRestore, keyResponse)).verifyComplete(); + byte[] backup = client.backupKey(keyToBackupAndRestore.name()).block(); StepVerifier.create(client.deleteKey(keyToBackupAndRestore.name())) - .assertNext(deletedKeyResponse -> { - DeletedKey deletedKey = deletedKeyResponse.value(); - assertNotNull(deletedKey); - }).verifyComplete(); + .assertNext(Assert::assertNotNull).verifyComplete(); pollOnKeyDeletion(keyToBackupAndRestore.name()); StepVerifier.create(client.purgeDeletedKey(keyToBackupAndRestore.name())) - .assertNext(voidResponse -> { - assertEquals(HttpResponseStatus.NO_CONTENT.code(), voidResponse.statusCode()); - }).verifyComplete(); + .assertNext(voidResponse -> assertEquals(HttpResponseStatus.NO_CONTENT.code(), + voidResponse.statusCode())).verifyComplete(); pollOnKeyPurge(keyToBackupAndRestore.name()); sleepInRecordMode(60000); StepVerifier.create(client.restoreKey(backup)) - .assertNext(response -> { - Key restoredKey = response.value(); - assertEquals(keyToBackupAndRestore.name(), restoredKey.name()); - assertEquals(keyToBackupAndRestore.notBefore(), restoredKey.notBefore()); - assertEquals(keyToBackupAndRestore.expires(), restoredKey.expires()); - }).verifyComplete(); + .assertNext(response -> { + assertEquals(keyToBackupAndRestore.name(), response.name()); + assertEquals(keyToBackupAndRestore.notBefore(), response.notBefore()); + assertEquals(keyToBackupAndRestore.expires(), response.expires()); + }).verifyComplete(); }); } @@ -317,7 +295,7 @@ public void restoreKey() { public void restoreKeyFromMalformedBackup() { byte[] keyBackupBytes = "non-existing".getBytes(); StepVerifier.create(client.restoreKey(keyBackupBytes)) - .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceModifiedException.class, HttpResponseStatus.BAD_REQUEST.code())); + .verifyErrorSatisfies(ex -> assertRestException(ex, ResourceModifiedException.class, HttpResponseStatus.BAD_REQUEST.code())); } /** @@ -327,31 +305,24 @@ public void getDeletedKey() { getDeletedKeyRunner((keyToDeleteAndGet) -> { StepVerifier.create(client.createKey(keyToDeleteAndGet)) - .assertNext(keyResponse -> { - assertKeyEquals(keyToDeleteAndGet, keyResponse.value()); - }).verifyComplete(); + .assertNext(keyResponse -> assertKeyEquals(keyToDeleteAndGet, keyResponse)).verifyComplete(); StepVerifier.create(client.deleteKey(keyToDeleteAndGet.name())) - .assertNext(deletedKeyResponse -> { - DeletedKey deletedKey = deletedKeyResponse.value(); - assertNotNull(deletedKey); - }).verifyComplete(); + .assertNext(Assert::assertNotNull).verifyComplete(); pollOnKeyDeletion(keyToDeleteAndGet.name()); sleepInRecordMode(30000); StepVerifier.create(client.getDeletedKey(keyToDeleteAndGet.name())) - .assertNext(deletedKeyResponse -> { - DeletedKey deletedKey = deletedKeyResponse.value(); - assertNotNull(deletedKey.deletedDate()); - assertNotNull(deletedKey.recoveryId()); - assertNotNull(deletedKey.scheduledPurgeDate()); - assertEquals(keyToDeleteAndGet.name(), deletedKey.name()); - }).verifyComplete(); + .assertNext(deletedKeyResponse -> { + assertNotNull(deletedKeyResponse.deletedDate()); + assertNotNull(deletedKeyResponse.recoveryId()); + assertNotNull(deletedKeyResponse.scheduledPurgeDate()); + assertEquals(keyToDeleteAndGet.name(), deletedKeyResponse.name()); + }).verifyComplete(); StepVerifier.create(client.purgeDeletedKey(keyToDeleteAndGet.name())) - .assertNext(voidResponse -> { - assertEquals(HttpResponseStatus.NO_CONTENT.code(), voidResponse.statusCode()); - }).verifyComplete(); + .assertNext(voidResponse -> assertEquals(HttpResponseStatus.NO_CONTENT.code(), + voidResponse.statusCode())).verifyComplete(); pollOnKeyPurge(keyToDeleteAndGet.name()); sleepInRecordMode(15000); }); @@ -364,22 +335,16 @@ public void getDeletedKey() { public void listDeletedKeys() { listDeletedKeysRunner((keys) -> { - HashMap keysToDelete = keys; List deletedKeys = new ArrayList<>(); - for (KeyCreateOptions key : keysToDelete.values()) { + for (KeyCreateOptions key : keys.values()) { StepVerifier.create(client.createKey(key)) - .assertNext(keyResponse -> { - assertKeyEquals(key, keyResponse.value()); - }).verifyComplete(); + .assertNext(keyResponse -> assertKeyEquals(key, keyResponse)).verifyComplete(); } sleepInRecordMode(10000); - for (KeyCreateOptions key : keysToDelete.values()) { + for (KeyCreateOptions key : keys.values()) { StepVerifier.create(client.deleteKey(key.name())) - .assertNext(deletedKeyResponse -> { - DeletedKey deletedKey = deletedKeyResponse.value(); - assertNotNull(deletedKey); - }).verifyComplete(); + .assertNext(Assert::assertNotNull).verifyComplete(); pollOnKeyDeletion(key.name()); } @@ -388,20 +353,19 @@ public void listDeletedKeys() { sleepInRecordMode(30000); for (DeletedKey actualKey : deletedKeys) { - if (keysToDelete.containsKey(actualKey.name())) { + if (keys.containsKey(actualKey.name())) { assertNotNull(actualKey.deletedDate()); assertNotNull(actualKey.recoveryId()); - keysToDelete.remove(actualKey.name()); + keys.remove(actualKey.name()); } } - assertEquals(0, keysToDelete.size()); + assertEquals(0, keys.size()); for (DeletedKey deletedKey : deletedKeys) { StepVerifier.create(client.purgeDeletedKey(deletedKey.name())) - .assertNext(voidResponse -> { - assertEquals(HttpResponseStatus.NO_CONTENT.code(), voidResponse.statusCode()); - }).verifyComplete(); + .assertNext(voidResponse -> assertEquals(HttpResponseStatus.NO_CONTENT.code(), + voidResponse.statusCode())).verifyComplete(); pollOnKeyPurge(deletedKey.name()); } }); @@ -413,32 +377,27 @@ public void listDeletedKeys() { @Override public void listKeyVersions() { listKeyVersionsRunner((keys) -> { - List keyVersions = keys; List output = new ArrayList<>(); String keyName = null; - for (KeyCreateOptions key : keyVersions) { + for (KeyCreateOptions key : keys) { keyName = key.name(); - client.createKey(key).subscribe(keyResponse -> assertKeyEquals(key, keyResponse.value())); + client.createKey(key).subscribe(keyResponse -> assertKeyEquals(key, keyResponse)); sleepInRecordMode(1000); } sleepInRecordMode(30000); client.listKeyVersions(keyName).subscribe(output::add); sleepInRecordMode(30000); - assertEquals(keyVersions.size(), output.size()); + assertEquals(keys.size(), output.size()); StepVerifier.create(client.deleteKey(keyName)) - .assertNext(deletedKeyResponse -> { - DeletedKey deletedKey = deletedKeyResponse.value(); - assertNotNull(deletedKey); - }).verifyComplete(); + .assertNext(Assert::assertNotNull).verifyComplete(); pollOnKeyDeletion(keyName); StepVerifier.create(client.purgeDeletedKey(keyName)) - .assertNext(voidResponse -> { - assertEquals(HttpResponseStatus.NO_CONTENT.code(), voidResponse.statusCode()); - }).verifyComplete(); + .assertNext(voidResponse -> assertEquals(HttpResponseStatus.NO_CONTENT.code(), + voidResponse.statusCode())).verifyComplete(); pollOnKeyPurge(keyName); }); @@ -449,10 +408,9 @@ public void listKeyVersions() { */ public void listKeys() { listKeysRunner((keys) -> { - HashMap keysToList = keys; List output = new ArrayList<>(); - for (KeyCreateOptions key : keysToList.values()) { - client.createKey(key).subscribe(keyResponse -> assertKeyEquals(key, keyResponse.value())); + for (KeyCreateOptions key : keys.values()) { + client.createKey(key).subscribe(keyResponse -> assertKeyEquals(key, keyResponse)); sleepInRecordMode(1000); } sleepInRecordMode(30000); @@ -471,43 +429,40 @@ public void listKeys() { }); } - private DeletedKey pollOnKeyDeletion(String keyName) { + private void pollOnKeyDeletion(String keyName) { int pendingPollCount = 0; while (pendingPollCount < 30) { DeletedKey deletedKey = null; try { - deletedKey = client.getDeletedKey(keyName).block().value(); + deletedKey = client.getDeletedKeyWithResponse(keyName).block().value(); } catch (ResourceNotFoundException e) { } if (deletedKey == null) { sleepInRecordMode(2000); pendingPollCount += 1; - continue; } else { - return deletedKey; + return; } } System.err.printf("Deleted Key %s not found \n", keyName); - return null; } - private DeletedKey pollOnKeyPurge(String keyName) { + private void pollOnKeyPurge(String keyName) { int pendingPollCount = 0; while (pendingPollCount < 10) { DeletedKey deletedKey = null; try { - deletedKey = client.getDeletedKey(keyName).block().value(); + deletedKey = client.getDeletedKeyWithResponse(keyName).block().value(); } catch (ResourceNotFoundException e) { } if (deletedKey != null) { sleepInRecordMode(2000); pendingPollCount += 1; - continue; } else { - return deletedKey; + return; } } System.err.printf("Deleted Key %s was not purged \n", keyName); - return null; } } + diff --git a/sdk/keyvault/azure-keyvault-keys/src/test/java/com/azure/security/keyvault/keys/KeyClientTest.java b/sdk/keyvault/azure-keyvault-keys/src/test/java/com/azure/security/keyvault/keys/KeyClientTest.java index a07fa17a52de8..bb1a6858fdc82 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/test/java/com/azure/security/keyvault/keys/KeyClientTest.java +++ b/sdk/keyvault/azure-keyvault-keys/src/test/java/com/azure/security/keyvault/keys/KeyClientTest.java @@ -86,7 +86,7 @@ public void setKeyNull() { public void updateKey() { updateKeyRunner((original, updated) -> { assertKeyEquals(original, client.createKey(original)); - Key keyToUpdate = client.getKey(original.name()).value(); + Key keyToUpdate = client.getKey(original.name()); client.updateKey(keyToUpdate.expires(updated.expires())); assertKeyEquals(updated, client.getKey(original.name())); }); @@ -98,7 +98,7 @@ public void updateKey() { public void updateDisabledKey() { updateDisabledKeyRunner((original, updated) -> { assertKeyEquals(original, client.createKey(original)); - Key keyToUpdate = client.getKey(original.name()).value(); + Key keyToUpdate = client.getKey(original.name()); client.updateKey(keyToUpdate.expires(updated.expires())); assertKeyEquals(updated, client.getKey(original.name())); }); @@ -119,8 +119,8 @@ public void getKey() { */ public void getKeySpecificVersion() { getKeySpecificVersionRunner((key, keyWithNewVal) -> { - Key keyVersionOne = client.createKey(key).value(); - Key keyVersionTwo = client.createKey(keyWithNewVal).value(); + Key keyVersionOne = client.createKey(key); + Key keyVersionTwo = client.createKey(keyWithNewVal); assertKeyEquals(key, client.getKey(keyVersionOne.name(), keyVersionOne.version())); assertKeyEquals(keyWithNewVal, client.getKey(keyVersionTwo.name(), keyVersionTwo.version())); }); @@ -139,7 +139,7 @@ public void getKeyNotFound() { public void deleteKey() { deleteKeyRunner((keyToDelete) -> { assertKeyEquals(keyToDelete, client.createKey(keyToDelete)); - DeletedKey deletedKey = client.deleteKey(keyToDelete.name()).value(); + DeletedKey deletedKey = client.deleteKey(keyToDelete.name()); pollOnKeyDeletion(keyToDelete.name()); assertNotNull(deletedKey.deletedDate()); assertNotNull(deletedKey.recoveryId()); @@ -169,9 +169,9 @@ public void getDeletedKeyNotFound() { public void recoverDeletedKey() { recoverDeletedKeyRunner((keyToDeleteAndRecover) -> { assertKeyEquals(keyToDeleteAndRecover, client.createKey(keyToDeleteAndRecover)); - assertNotNull(client.deleteKey(keyToDeleteAndRecover.name()).value()); + assertNotNull(client.deleteKey(keyToDeleteAndRecover.name())); pollOnKeyDeletion(keyToDeleteAndRecover.name()); - Key recoveredKey = client.recoverDeletedKey(keyToDeleteAndRecover.name()).value(); + Key recoveredKey = client.recoverDeletedKey(keyToDeleteAndRecover.name()); assertEquals(keyToDeleteAndRecover.name(), recoveredKey.name()); assertEquals(keyToDeleteAndRecover.notBefore(), recoveredKey.notBefore()); assertEquals(keyToDeleteAndRecover.expires(), recoveredKey.expires()); @@ -191,7 +191,7 @@ public void recoverDeletedKeyNotFound() { public void backupKey() { backupKeyRunner((keyToBackup) -> { assertKeyEquals(keyToBackup, client.createKey(keyToBackup)); - byte[] backupBytes = (client.backupKey(keyToBackup.name()).value()); + byte[] backupBytes = (client.backupKey(keyToBackup.name())); assertNotNull(backupBytes); assertTrue(backupBytes.length > 0); }); @@ -210,7 +210,7 @@ public void backupKeyNotFound() { public void restoreKey() { restoreKeyRunner((keyToBackupAndRestore) -> { assertKeyEquals(keyToBackupAndRestore, client.createKey(keyToBackupAndRestore)); - byte[] backupBytes = (client.backupKey(keyToBackupAndRestore.name()).value()); + byte[] backupBytes = (client.backupKey(keyToBackupAndRestore.name())); assertNotNull(backupBytes); assertTrue(backupBytes.length > 0); client.deleteKey(keyToBackupAndRestore.name()); @@ -218,7 +218,7 @@ public void restoreKey() { client.purgeDeletedKey(keyToBackupAndRestore.name()); pollOnKeyPurge(keyToBackupAndRestore.name()); sleepInRecordMode(60000); - Key restoredKey = client.restoreKey(backupBytes).value(); + Key restoredKey = client.restoreKey(backupBytes); assertEquals(keyToBackupAndRestore.name(), restoredKey.name()); assertEquals(keyToBackupAndRestore.expires(), restoredKey.expires()); }); @@ -261,10 +261,10 @@ public void listKeys() { public void getDeletedKey() { getDeletedKeyRunner((keyToDeleteAndGet) -> { assertKeyEquals(keyToDeleteAndGet, client.createKey(keyToDeleteAndGet)); - assertNotNull(client.deleteKey(keyToDeleteAndGet.name()).value()); + assertNotNull(client.deleteKey(keyToDeleteAndGet.name())); pollOnKeyDeletion(keyToDeleteAndGet.name()); sleepInRecordMode(30000); - DeletedKey deletedKey = client.getDeletedKey(keyToDeleteAndGet.name()).value(); + DeletedKey deletedKey = client.getDeletedKey(keyToDeleteAndGet.name()); assertNotNull(deletedKey.deletedDate()); assertNotNull(deletedKey.recoveryId()); assertNotNull(deletedKey.scheduledPurgeDate()); @@ -343,7 +343,7 @@ private DeletedKey pollOnKeyDeletion(String keyName) { while (pendingPollCount < 30) { DeletedKey deletedKey = null; try { - deletedKey = client.getDeletedKey(keyName).value(); + deletedKey = client.getDeletedKey(keyName); } catch (ResourceNotFoundException e) { } if (deletedKey == null) { @@ -363,7 +363,7 @@ private DeletedKey pollOnKeyPurge(String keyName) { while (pendingPollCount < 10) { DeletedKey deletedKey = null; try { - deletedKey = client.getDeletedKey(keyName).value(); + deletedKey = client.getDeletedKey(keyName); } catch (ResourceNotFoundException e) { } if (deletedKey != null) { diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java index 5d51121fb007c..2cbd05b7b2607 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java @@ -3,6 +3,7 @@ package com.azure.security.keyvault.secrets; +import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.implementation.annotation.ServiceClientBuilder; import com.azure.core.util.configuration.ConfigurationManager; import com.azure.core.util.configuration.Configuration; @@ -126,7 +127,7 @@ public SecretAsyncClient buildAsyncClient() { policies.addAll(this.policies); policies.add(new HttpLoggingPolicy(httpLogDetailLevel)); - HttpPipeline pipeline = HttpPipeline.builder() + HttpPipeline pipeline = new HttpPipelineBuilder() .policies(policies.toArray(new HttpPipelinePolicy[0])) .httpClient(httpClient) .build(); diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretClientJavaDocCodeSnippets.java index 3b71f4e882ccc..7b92e5986b42e 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretClientJavaDocCodeSnippets.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretClientJavaDocCodeSnippets.java @@ -5,6 +5,7 @@ import com.azure.core.http.HttpClient; import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.test.models.RecordedData; import com.azure.core.test.policy.RecordNetworkCallPolicy; @@ -24,7 +25,7 @@ public final class SecretClientJavaDocCodeSnippets { public SecretAsyncClient createAsyncClientWithHttpclient() { // BEGIN: com.azure.security.keyvault.keys.async.secretclient.withhttpclient.instantiation RecordedData networkData = new RecordedData(); - HttpPipeline pipeline = HttpPipeline.builder().policies(new RecordNetworkCallPolicy(networkData)).build(); + HttpPipeline pipeline = new HttpPipelineBuilder().policies(new RecordNetworkCallPolicy(networkData)).build(); SecretAsyncClient keyClient = new SecretClientBuilder() .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) .endpoint("https://myvault.azure.net/") @@ -89,7 +90,7 @@ private SecretClient getSyncSecretClient() { public SecretAsyncClient createAsyncClientWithPipeline() { // BEGIN: com.azure.security.keyvault.keys.async.secretclient.pipeline.instantiation RecordedData networkData = new RecordedData(); - HttpPipeline pipeline = HttpPipeline.builder().policies(new RecordNetworkCallPolicy(networkData)).build(); + HttpPipeline pipeline = new HttpPipelineBuilder().policies(new RecordNetworkCallPolicy(networkData)).build(); SecretAsyncClient keyClient = new SecretClientBuilder() .pipeline(pipeline) .endpoint("https://myvault.azure.net/") diff --git a/storage/client/blob/pom.xml b/storage/client/blob/pom.xml index b661ff0ad7e2d..00132d720cd8c 100644 --- a/storage/client/blob/pom.xml +++ b/storage/client/blob/pom.xml @@ -49,7 +49,7 @@ com.azure azure-core -1.0.0-preview.2 +1.0.0-preview.3 org.slf4j @@ -69,7 +69,7 @@com.azure azure-core-test -1.0.0-preview.2 +1.0.0-preview.3 test diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java index c8ceb3f311d3f..1e5f741d3b8a6 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java @@ -98,7 +98,7 @@ public class BlobAsyncClient { public BlockBlobAsyncClient asBlockBlobAsyncClient() { return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() .url(getBlobUrl().toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); } /** @@ -110,7 +110,7 @@ public BlockBlobAsyncClient asBlockBlobAsyncClient() { public AppendBlobAsyncClient asAppendBlobAsyncClient() { return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() .url(getBlobUrl().toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); } /** @@ -122,7 +122,7 @@ public AppendBlobAsyncClient asAppendBlobAsyncClient() { public PageBlobAsyncClient asPageBlobAsyncClient() { return new PageBlobAsyncClient(new AzureBlobStorageBuilder() .url(getBlobUrl().toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); } /** @@ -136,7 +136,7 @@ public ContainerAsyncClient getContainerAsyncClient() { BlobURLParts parts = URLParser.parse(getBlobUrl()); return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(String.format("%s://%s/%s", parts.scheme(), parts.host(), parts.containerName())) - .pipeline(azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.getHttpPipeline())); } /** @@ -147,13 +147,13 @@ public ContainerAsyncClient getContainerAsyncClient() { */ public URL getBlobUrl() { try { - UrlBuilder urlBuilder = UrlBuilder.parse(azureBlobStorage.url()); + UrlBuilder urlBuilder = UrlBuilder.parse(azureBlobStorage.getUrl()); if (snapshot != null) { urlBuilder.query("snapshot=" + snapshot); } return urlBuilder.toURL(); } catch (MalformedURLException e) { - throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.url()), e); + throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.getUrl()), e); } } @@ -925,7 +925,7 @@ public String generateSAS(String identifier, BlobSASPermission permissions, Offs cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); SharedKeyCredential sharedKeyCredential = - Utility.getSharedKeyCredential(this.azureBlobStorage.httpPipeline()); + Utility.getSharedKeyCredential(this.azureBlobStorage.getHttpPipeline()); Utility.assertNotNull("sharedKeyCredential", sharedKeyCredential); @@ -944,7 +944,7 @@ ServiceSASSignatureValues configureServiceSASSignatureValues(ServiceSASSignature String accountName) { // Set canonical name - serviceSASSignatureValues.canonicalName(this.azureBlobStorage.url(), accountName); + serviceSASSignatureValues.canonicalName(this.azureBlobStorage.getUrl(), accountName); // Set snapshotId serviceSASSignatureValues.snapshotId(getSnapshotId()); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java index b0e3c98d8904a..4467ea5f6a01a 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java @@ -6,6 +6,7 @@ import com.azure.core.credentials.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.AddDatePolicy; import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; import com.azure.core.http.policy.HttpLogDetailLevel; @@ -120,7 +121,7 @@ private AzureBlobStorageBuilder buildImpl() { policies.addAll(this.policies); policies.add(new HttpLoggingPolicy(logLevel)); - HttpPipeline pipeline = HttpPipeline.builder() + HttpPipeline pipeline = new HttpPipelineBuilder() .policies(policies.toArray(new HttpPipelinePolicy[0])) .httpClient(httpClient) .build(); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java index 936bab6932528..f9cf29c3e79f0 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java @@ -107,7 +107,7 @@ public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName) { public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName, String snapshot) { return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); } /** @@ -140,7 +140,7 @@ public PageBlobAsyncClient getPageBlobAsyncClient(String blobName) { public PageBlobAsyncClient getPageBlobAsyncClient(String blobName, String snapshot) { return new PageBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); } /** @@ -173,7 +173,7 @@ public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName) { public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName, String snapshot) { return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); } /** @@ -202,7 +202,7 @@ public BlobAsyncClient getBlobAsyncClient(String blobName) { public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) { return new BlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.getHttpPipeline()), snapshot); } /** @@ -213,7 +213,7 @@ public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) { public StorageAsyncClient getStorageAsyncClient() { return new StorageAsyncClient(new AzureBlobStorageBuilder() .url(Utility.stripLastPathSegment(getContainerUrl()).toString()) - .pipeline(azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.getHttpPipeline())); } /** @@ -224,9 +224,9 @@ public StorageAsyncClient getStorageAsyncClient() { */ public URL getContainerUrl() { try { - return new URL(azureBlobStorage.url()); + return new URL(azureBlobStorage.getUrl()); } catch (MalformedURLException e) { - throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.url()), e); + throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.getUrl()), e); } } @@ -681,7 +681,7 @@ private Flux listBlobsHierarchyHelper(String delimiter, ListBlobsOptio } else { prefixes = Flux.empty(); } - Flux result = blobs.concatWith(prefixes.map(prefix -> new BlobItem().name(prefix.name()).isPrefix(true))); + Flux result = blobs.map(item -> item.isPrefix(false)).concatWith(prefixes.map(prefix -> new BlobItem().name(prefix.name()).isPrefix(true))); if (response.value().nextMarker() != null) { // Recursively add the continuation items to the observable. @@ -1102,7 +1102,7 @@ public String generateSAS(String identifier, ContainerSASPermission permissions, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); SharedKeyCredential sharedKeyCredential = - Utility.getSharedKeyCredential(this.azureBlobStorage.httpPipeline()); + Utility.getSharedKeyCredential(this.azureBlobStorage.getHttpPipeline()); Utility.assertNotNull("sharedKeyCredential", sharedKeyCredential); @@ -1119,7 +1119,7 @@ public String generateSAS(String identifier, ContainerSASPermission permissions, */ private ServiceSASSignatureValues configureServiceSASSignatureValues(ServiceSASSignatureValues serviceSASSignatureValues, String accountName) { // Set canonical name - serviceSASSignatureValues.canonicalName(this.azureBlobStorage.url(), accountName); + serviceSASSignatureValues.canonicalName(this.azureBlobStorage.getUrl(), accountName); // Set snapshotId to null serviceSASSignatureValues.snapshotId(null); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java index 7c9e9543ffd94..97a05be2ed254 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java @@ -6,6 +6,7 @@ import com.azure.core.credentials.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.AddDatePolicy; import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; import com.azure.core.http.policy.HttpLogDetailLevel; @@ -110,7 +111,7 @@ private AzureBlobStorageBuilder buildImpl() { policies.addAll(this.policies); policies.add(new HttpLoggingPolicy(logLevel)); - HttpPipeline pipeline = HttpPipeline.builder() + HttpPipeline pipeline = new HttpPipelineBuilder() .policies(policies.toArray(new HttpPipelinePolicy[0])) .httpClient(httpClient) .build(); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java index 9e4d0fb2140f5..e84d23ee1dbe0 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java @@ -73,7 +73,7 @@ public final class StorageAsyncClient { public ContainerAsyncClient getContainerAsyncClient(String containerName) { return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getAccountUrl(), containerName).toString()) - .pipeline(azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.getHttpPipeline())); } /** @@ -125,9 +125,9 @@ public Mono deleteContainer(String containerName) { */ public URL getAccountUrl() { try { - return new URL(azureBlobStorage.url()); + return new URL(azureBlobStorage.getUrl()); } catch (MalformedURLException e) { - throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.url()), e); + throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.getUrl()), e); } } @@ -318,7 +318,7 @@ public String generateAccountSAS(AccountSASService accountSASService, AccountSAS accountSASSignatureValues.ipRange(ipRange); accountSASSignatureValues.protocol(sasProtocol); - SharedKeyCredential sharedKeyCredential = Utility.getSharedKeyCredential(this.azureBlobStorage.httpPipeline()); + SharedKeyCredential sharedKeyCredential = Utility.getSharedKeyCredential(this.azureBlobStorage.getHttpPipeline()); SASQueryParameters sasQueryParameters = accountSASSignatureValues.generateSASQueryParameters(sharedKeyCredential); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClientBuilder.java index fbbdc0f438ac0..a73249dec8f70 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClientBuilder.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClientBuilder.java @@ -6,6 +6,7 @@ import com.azure.core.credentials.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.AddDatePolicy; import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; import com.azure.core.http.policy.HttpLogDetailLevel; @@ -104,7 +105,7 @@ private AzureBlobStorageBuilder buildImpl() { policies.addAll(this.policies); policies.add(new HttpLoggingPolicy(logLevel)); - HttpPipeline pipeline = HttpPipeline.builder() + HttpPipeline pipeline = new HttpPipelineBuilder() .policies(policies.toArray(new HttpPipelinePolicy[0])) .httpClient(httpClient) .build(); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AppendBlobsImpl.java b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AppendBlobsImpl.java index a6f486ff075f7..3439bb917017e 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AppendBlobsImpl.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AppendBlobsImpl.java @@ -4,18 +4,20 @@ package com.azure.storage.blob.implementation; -import com.azure.core.annotations.BodyParam; -import com.azure.core.annotations.ExpectedResponses; -import com.azure.core.annotations.HeaderParam; -import com.azure.core.annotations.Host; -import com.azure.core.annotations.HostParam; -import com.azure.core.annotations.PUT; -import com.azure.core.annotations.PathParam; -import com.azure.core.annotations.QueryParam; -import com.azure.core.annotations.Service; -import com.azure.core.annotations.UnexpectedResponseExceptionType; import com.azure.core.implementation.DateTimeRfc1123; import com.azure.core.implementation.RestProxy; +import com.azure.core.implementation.annotation.BodyParam; +import com.azure.core.implementation.annotation.ExpectedResponses; +import com.azure.core.implementation.annotation.HeaderParam; +import com.azure.core.implementation.annotation.Host; +import com.azure.core.implementation.annotation.HostParam; +import com.azure.core.implementation.annotation.PathParam; +import com.azure.core.implementation.annotation.Put; +import com.azure.core.implementation.annotation.QueryParam; +import com.azure.core.implementation.annotation.ReturnType; +import com.azure.core.implementation.annotation.ServiceInterface; +import com.azure.core.implementation.annotation.ServiceMethod; +import com.azure.core.implementation.annotation.UnexpectedResponseExceptionType; import com.azure.core.implementation.util.Base64Util; import com.azure.core.util.Context; import com.azure.storage.blob.models.AppendBlobsAppendBlockFromUrlResponse; @@ -56,28 +58,28 @@ public final class AppendBlobsImpl { * @param client the instance of the service client containing this operation class. */ public AppendBlobsImpl(AzureBlobStorageImpl client) { - this.service = RestProxy.create(AppendBlobsService.class, client); + this.service = RestProxy.create(AppendBlobsService.class, client.getHttpPipeline()); this.client = client; } /** - * The interface defining all the services for AppendBlobs to be used by - * the proxy service to perform REST calls. + * The interface defining all the services for AzureBlobStorageAppendBlobs + * to be used by the proxy service to perform REST calls. */ @Host("{url}") - @Service("Storage Blobs AppendBlob") + @ServiceInterface(name = "AzureBlobStorageAppendBlobs") private interface AppendBlobsService { - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono create(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("Content-Length") long contentLength, @HeaderParam("x-ms-meta-") Map metadata, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @HeaderParam("x-ms-blob-type") String blobType, @HeaderParam("x-ms-blob-content-type") String blobContentType, @HeaderParam("x-ms-blob-content-encoding") String blobContentEncoding, @HeaderParam("x-ms-blob-content-language") String blobContentLanguage, @HeaderParam("x-ms-blob-content-md5") String blobContentMD5, @HeaderParam("x-ms-blob-cache-control") String blobCacheControl, @HeaderParam("x-ms-blob-content-disposition") String blobContentDisposition, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono appendBlock(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @BodyParam("application/octet-stream") Flux body, @QueryParam("timeout") Integer timeout, @HeaderParam("Content-Length") long contentLength, @HeaderParam("Content-MD5") String transactionalContentMD5, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("x-ms-blob-condition-maxsize") Long maxSize, @HeaderParam("x-ms-blob-condition-appendpos") Long appendPosition, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono appendBlockFromUrl(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @HeaderParam("x-ms-copy-source") URL copySource, @HeaderParam("x-ms-source-range") String sourceRange, @HeaderParam("x-ms-source-content-md5") String sourceContentMD5, @QueryParam("timeout") Integer timeout, @HeaderParam("Content-Length") long contentLength, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("x-ms-blob-condition-maxsize") Long maxSize, @HeaderParam("x-ms-blob-condition-appendpos") Long appendPosition, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, @HeaderParam("x-ms-source-if-modified-since") DateTimeRfc1123 sourceIfModifiedSince, @HeaderParam("x-ms-source-if-unmodified-since") DateTimeRfc1123 sourceIfUnmodifiedSince, @HeaderParam("x-ms-source-if-match") String sourceIfMatch, @HeaderParam("x-ms-source-if-none-match") String sourceIfNoneMatch, Context context); @@ -93,6 +95,7 @@ private interface AppendBlobsService { * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono createWithRestResponseAsync(String containerName, String blob, long contentLength, Context context) { final Integer timeout = null; final Map metadata = null; @@ -112,7 +115,7 @@ public Mono createWithRestResponseAsync(String contai String blobContentMD5Converted = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.create(containerName, blob, this.client.url(), timeout, contentLength, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, blobType, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5Converted, blobCacheControl, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.create(containerName, blob, this.client.getUrl(), timeout, contentLength, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, blobType, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5Converted, blobCacheControl, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -134,6 +137,7 @@ public Mono createWithRestResponseAsync(String contai * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono createWithRestResponseAsync(String containerName, String blob, long contentLength, Integer timeout, Map metadata, String encryptionKey, String encryptionKeySha256, EncryptionAlgorithmType encryptionAlgorithm, String requestId, BlobHTTPHeaders blobHTTPHeaders, LeaseAccessConditions leaseAccessConditions, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String blobType = "AppendBlob"; String blobContentType = null; @@ -183,7 +187,7 @@ public Mono createWithRestResponseAsync(String contai String blobContentMD5Converted = Base64Util.encodeToString(blobContentMD5); DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.create(containerName, blob, this.client.url(), timeout, contentLength, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, blobType, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5Converted, blobCacheControl, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.create(containerName, blob, this.client.getUrl(), timeout, contentLength, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, blobType, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5Converted, blobCacheControl, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -197,6 +201,7 @@ public Mono createWithRestResponseAsync(String contai * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono appendBlockWithRestResponseAsync(String containerName, String blob, Flux body, long contentLength, Context context) { final Integer timeout = null; final String encryptionKey = null; @@ -212,7 +217,7 @@ public Mono appendBlockWithRestResponseAsync(Str String transactionalContentMD5Converted = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.appendBlock(containerName, blob, this.client.url(), body, timeout, contentLength, transactionalContentMD5Converted, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, leaseId, maxSize, appendPosition, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.appendBlock(containerName, blob, this.client.getUrl(), body, timeout, contentLength, transactionalContentMD5Converted, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, leaseId, maxSize, appendPosition, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -235,6 +240,7 @@ public Mono appendBlockWithRestResponseAsync(Str * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono appendBlockWithRestResponseAsync(String containerName, String blob, Flux body, long contentLength, Integer timeout, byte[] transactionalContentMD5, String encryptionKey, String encryptionKeySha256, EncryptionAlgorithmType encryptionAlgorithm, String requestId, LeaseAccessConditions leaseAccessConditions, AppendPositionAccessConditions appendPositionAccessConditions, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String comp = "appendblock"; String leaseId = null; @@ -268,7 +274,7 @@ public Mono appendBlockWithRestResponseAsync(Str String transactionalContentMD5Converted = Base64Util.encodeToString(transactionalContentMD5); DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.appendBlock(containerName, blob, this.client.url(), body, timeout, contentLength, transactionalContentMD5Converted, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, leaseId, maxSize, appendPosition, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.appendBlock(containerName, blob, this.client.getUrl(), body, timeout, contentLength, transactionalContentMD5Converted, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, leaseId, maxSize, appendPosition, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -282,6 +288,7 @@ public Mono appendBlockWithRestResponseAsync(Str * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono appendBlockFromUrlWithRestResponseAsync(String containerName, String blob, URL sourceUrl, long contentLength, Context context) { final String sourceRange = null; final Integer timeout = null; @@ -299,7 +306,7 @@ public Mono appendBlockFromUrlWithRestRes DateTimeRfc1123 ifUnmodifiedSinceConverted = null; DateTimeRfc1123 sourceIfModifiedSinceConverted = null; DateTimeRfc1123 sourceIfUnmodifiedSinceConverted = null; - return service.appendBlockFromUrl(containerName, blob, this.client.url(), sourceUrl, sourceRange, sourceContentMD5Converted, timeout, contentLength, this.client.version(), requestId, comp, leaseId, maxSize, appendPosition, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, context); + return service.appendBlockFromUrl(containerName, blob, this.client.getUrl(), sourceUrl, sourceRange, sourceContentMD5Converted, timeout, contentLength, this.client.getVersion(), requestId, comp, leaseId, maxSize, appendPosition, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, context); } /** @@ -321,6 +328,7 @@ public Mono appendBlockFromUrlWithRestRes * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono appendBlockFromUrlWithRestResponseAsync(String containerName, String blob, URL sourceUrl, long contentLength, String sourceRange, byte[] sourceContentMD5, Integer timeout, String requestId, LeaseAccessConditions leaseAccessConditions, AppendPositionAccessConditions appendPositionAccessConditions, ModifiedAccessConditions modifiedAccessConditions, SourceModifiedAccessConditions sourceModifiedAccessConditions, Context context) { final String comp = "appendblock"; String leaseId = null; @@ -372,6 +380,6 @@ public Mono appendBlockFromUrlWithRestRes DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); DateTimeRfc1123 sourceIfModifiedSinceConverted = sourceIfModifiedSince == null ? null : new DateTimeRfc1123(sourceIfModifiedSince); DateTimeRfc1123 sourceIfUnmodifiedSinceConverted = sourceIfUnmodifiedSince == null ? null : new DateTimeRfc1123(sourceIfUnmodifiedSince); - return service.appendBlockFromUrl(containerName, blob, this.client.url(), sourceUrl, sourceRange, sourceContentMD5Converted, timeout, contentLength, this.client.version(), requestId, comp, leaseId, maxSize, appendPosition, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, context); + return service.appendBlockFromUrl(containerName, blob, this.client.getUrl(), sourceUrl, sourceRange, sourceContentMD5Converted, timeout, contentLength, this.client.getVersion(), requestId, comp, leaseId, maxSize, appendPosition, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, context); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AzureBlobStorageBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AzureBlobStorageBuilder.java index c77d984c4e928..95eccfcca197c 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AzureBlobStorageBuilder.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AzureBlobStorageBuilder.java @@ -6,10 +6,12 @@ import com.azure.core.http.HttpPipeline; import com.azure.core.implementation.RestProxy; +import com.azure.core.implementation.annotation.ServiceClientBuilder; /** * A builder for creating a new instance of the AzureBlobStorage type. */ +@ServiceClientBuilder(serviceClients = AzureBlobStorageImpl.class) public final class AzureBlobStorageBuilder { /* * The URL of the service account, container, or blob that is the targe of the desired operation. @@ -73,10 +75,10 @@ public AzureBlobStorageImpl build() { } AzureBlobStorageImpl client = new AzureBlobStorageImpl(pipeline); if (this.url != null) { - client.url(this.url); + client.setUrl(this.url); } if (this.version != null) { - client.version(this.version); + client.setVersion(this.version); } return client; } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AzureBlobStorageImpl.java b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AzureBlobStorageImpl.java index 6702b82da14ea..6df6ced959bcd 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AzureBlobStorageImpl.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/AzureBlobStorageImpl.java @@ -4,14 +4,13 @@ package com.azure.storage.blob.implementation; -import com.azure.core.ServiceClient; import com.azure.core.http.HttpPipeline; import com.azure.core.implementation.RestProxy; /** * Initializes a new instance of the AzureBlobStorage type. */ -public final class AzureBlobStorageImpl extends ServiceClient { +public final class AzureBlobStorageImpl { /** * The URL of the service account, container, or blob that is the targe of the desired operation. */ @@ -22,7 +21,7 @@ public final class AzureBlobStorageImpl extends ServiceClient { * * @return the url value. */ - public String url() { + public String getUrl() { return this.url; } @@ -32,7 +31,7 @@ public String url() { * @param url the url value. * @return the service client itself. */ - AzureBlobStorageImpl url(String url) { + AzureBlobStorageImpl setUrl(String url) { this.url = url; return this; } @@ -47,7 +46,7 @@ AzureBlobStorageImpl url(String url) { * * @return the version value. */ - public String version() { + public String getVersion() { return this.version; } @@ -57,11 +56,25 @@ public String version() { * @param version the version value. * @return the service client itself. */ - AzureBlobStorageImpl version(String version) { + AzureBlobStorageImpl setVersion(String version) { this.version = version; return this; } + /** + * The HTTP pipeline to send requests through. + */ + private HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + /** * The ServicesImpl object to access its operations. */ @@ -159,7 +172,7 @@ public AzureBlobStorageImpl() { * @param httpPipeline The HTTP pipeline to send requests through. */ public AzureBlobStorageImpl(HttpPipeline httpPipeline) { - super(httpPipeline); + this.httpPipeline = httpPipeline; this.services = new ServicesImpl(this); this.containers = new ContainersImpl(this); this.blobs = new BlobsImpl(this); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/BlobsImpl.java b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/BlobsImpl.java index e89e8972aed35..eba1efa297e4b 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/BlobsImpl.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/BlobsImpl.java @@ -4,20 +4,22 @@ package com.azure.storage.blob.implementation; -import com.azure.core.annotations.DELETE; -import com.azure.core.annotations.ExpectedResponses; -import com.azure.core.annotations.GET; -import com.azure.core.annotations.HEAD; -import com.azure.core.annotations.HeaderParam; -import com.azure.core.annotations.Host; -import com.azure.core.annotations.HostParam; -import com.azure.core.annotations.PUT; -import com.azure.core.annotations.PathParam; -import com.azure.core.annotations.QueryParam; -import com.azure.core.annotations.Service; -import com.azure.core.annotations.UnexpectedResponseExceptionType; import com.azure.core.implementation.DateTimeRfc1123; import com.azure.core.implementation.RestProxy; +import com.azure.core.implementation.annotation.Delete; +import com.azure.core.implementation.annotation.ExpectedResponses; +import com.azure.core.implementation.annotation.Get; +import com.azure.core.implementation.annotation.Head; +import com.azure.core.implementation.annotation.HeaderParam; +import com.azure.core.implementation.annotation.Host; +import com.azure.core.implementation.annotation.HostParam; +import com.azure.core.implementation.annotation.PathParam; +import com.azure.core.implementation.annotation.Put; +import com.azure.core.implementation.annotation.QueryParam; +import com.azure.core.implementation.annotation.ReturnType; +import com.azure.core.implementation.annotation.ServiceInterface; +import com.azure.core.implementation.annotation.ServiceMethod; +import com.azure.core.implementation.annotation.UnexpectedResponseExceptionType; import com.azure.core.implementation.util.Base64Util; import com.azure.core.util.Context; import com.azure.storage.blob.models.AccessTier; @@ -71,98 +73,98 @@ public final class BlobsImpl { * @param client the instance of the service client containing this operation class. */ public BlobsImpl(AzureBlobStorageImpl client) { - this.service = RestProxy.create(BlobsService.class, client); + this.service = RestProxy.create(BlobsService.class, client.getHttpPipeline()); this.client = client; } /** - * The interface defining all the services for Blobs to be used by the - * proxy service to perform REST calls. + * The interface defining all the services for AzureBlobStorageBlobs to be + * used by the proxy service to perform REST calls. */ @Host("{url}") - @Service("Storage Blobs") + @ServiceInterface(name = "AzureBlobStorageBlobs") private interface BlobsService { - @GET("{containerName}/{blob}") + @Get("{containerName}/{blob}") @ExpectedResponses({200, 206}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono download(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("snapshot") String snapshot, @QueryParam("versionid") String versionId, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-range") String range, @HeaderParam("x-ms-range-get-content-md5") Boolean rangeGetContentMD5, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @HEAD("{containerName}/{blob}") + @Head("{containerName}/{blob}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono getProperties(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("snapshot") String snapshot, @QueryParam("versionid") String versionId, @QueryParam("timeout") Integer timeout, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @DELETE("{containerName}/{blob}") + @Delete("{containerName}/{blob}") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono delete(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("snapshot") String snapshot, @QueryParam("versionid") String versionId, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-delete-snapshots") DeleteSnapshotsOptionType deleteSnapshots, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono undelete(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono setHTTPHeaders(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-blob-cache-control") String blobCacheControl, @HeaderParam("x-ms-blob-content-type") String blobContentType, @HeaderParam("x-ms-blob-content-md5") String blobContentMD5, @HeaderParam("x-ms-blob-content-encoding") String blobContentEncoding, @HeaderParam("x-ms-blob-content-language") String blobContentLanguage, @HeaderParam("x-ms-blob-content-disposition") String blobContentDisposition, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono setMetadata(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-meta-") Map metadata, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono acquireLease(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-lease-duration") Integer duration, @HeaderParam("x-ms-proposed-lease-id") String proposedLeaseId, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-action") String action, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono releaseLease(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-action") String action, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono renewLease(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-action") String action, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono changeLease(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("x-ms-proposed-lease-id") String proposedLeaseId, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-action") String action, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono breakLease(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-lease-break-period") Integer breakPeriod, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-action") String action, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono createSnapshot(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-meta-") Map metadata, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, @HeaderParam("x-ms-lease-id") String leaseId, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono startCopyFromURL(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-meta-") Map metadata, @HeaderParam("x-ms-copy-source") URL copySource, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @HeaderParam("x-ms-source-if-modified-since") DateTimeRfc1123 sourceIfModifiedSince, @HeaderParam("x-ms-source-if-unmodified-since") DateTimeRfc1123 sourceIfUnmodifiedSince, @HeaderParam("x-ms-source-if-match") String sourceIfMatch, @HeaderParam("x-ms-source-if-none-match") String sourceIfNoneMatch, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, @HeaderParam("x-ms-lease-id") String leaseId, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({202}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono copyFromURL(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-meta-") Map metadata, @HeaderParam("x-ms-copy-source") URL copySource, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @HeaderParam("x-ms-requires-sync") String xMsRequiresSync, @HeaderParam("x-ms-source-if-modified-since") DateTimeRfc1123 sourceIfModifiedSince, @HeaderParam("x-ms-source-if-unmodified-since") DateTimeRfc1123 sourceIfUnmodifiedSince, @HeaderParam("x-ms-source-if-match") String sourceIfMatch, @HeaderParam("x-ms-source-if-none-match") String sourceIfNoneMatch, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, @HeaderParam("x-ms-lease-id") String leaseId, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({204}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono abortCopyFromURL(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("copyid") String copyId, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-copy-action") String copyActionAbortConstant, @HeaderParam("x-ms-lease-id") String leaseId, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({200, 202}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono setTier(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-access-tier") AccessTier tier, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-id") String leaseId, Context context); - @GET("{containerName}/{blob}") + @Get("{containerName}/{blob}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono getAccountInfo(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @HeaderParam("x-ms-version") String version, @QueryParam("restype") String restype, @QueryParam("comp") String comp, Context context); @@ -177,6 +179,7 @@ private interface BlobsService { * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono downloadWithRestResponseAsync(String containerName, String blob, Context context) { final String snapshot = null; final String versionId = null; @@ -192,7 +195,7 @@ public Mono downloadWithRestResponseAsync(String containe final String ifNoneMatch = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.download(containerName, blob, this.client.url(), snapshot, versionId, timeout, range, rangeGetContentMD5, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.download(containerName, blob, this.client.getUrl(), snapshot, versionId, timeout, range, rangeGetContentMD5, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -215,6 +218,7 @@ public Mono downloadWithRestResponseAsync(String containe * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono downloadWithRestResponseAsync(String containerName, String blob, String snapshot, String versionId, Integer timeout, String range, Boolean rangeGetContentMD5, String encryptionKey, String encryptionKeySha256, EncryptionAlgorithmType encryptionAlgorithm, String requestId, LeaseAccessConditions leaseAccessConditions, ModifiedAccessConditions modifiedAccessConditions, Context context) { String leaseId = null; if (leaseAccessConditions != null) { @@ -238,7 +242,7 @@ public Mono downloadWithRestResponseAsync(String containe } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.download(containerName, blob, this.client.url(), snapshot, versionId, timeout, range, rangeGetContentMD5, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.download(containerName, blob, this.client.getUrl(), snapshot, versionId, timeout, range, rangeGetContentMD5, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -250,6 +254,7 @@ public Mono downloadWithRestResponseAsync(String containe * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono getPropertiesWithRestResponseAsync(String containerName, String blob, Context context) { final String snapshot = null; final String versionId = null; @@ -263,7 +268,7 @@ public Mono getPropertiesWithRestResponseAsync(Strin final String ifNoneMatch = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.getProperties(containerName, blob, this.client.url(), snapshot, versionId, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.getProperties(containerName, blob, this.client.getUrl(), snapshot, versionId, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -284,6 +289,7 @@ public Mono getPropertiesWithRestResponseAsync(Strin * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono getPropertiesWithRestResponseAsync(String containerName, String blob, String snapshot, String versionId, Integer timeout, String encryptionKey, String encryptionKeySha256, EncryptionAlgorithmType encryptionAlgorithm, String requestId, LeaseAccessConditions leaseAccessConditions, ModifiedAccessConditions modifiedAccessConditions, Context context) { String leaseId = null; if (leaseAccessConditions != null) { @@ -307,11 +313,11 @@ public Mono getPropertiesWithRestResponseAsync(Strin } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.getProperties(containerName, blob, this.client.url(), snapshot, versionId, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.getProperties(containerName, blob, this.client.getUrl(), snapshot, versionId, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** - * If the storage account's soft delete feature is disabled then, when a blob is deleted, it is permanently removed from the storage account. If the storage account's soft delete feature is enabled, then, when a blob is deleted, it is marked for deletion and becomes inaccessible immediately. However, the storage service retains the blob or snapshot for the number of days specified by the DeleteRetentionPolicy section of [Storage service properties] (Set-Blob-Service-Properties.md). After the specified number of days has passed, the blob's data is permanently removed from the storage account. Note that you continue to be charged for the soft-deleted blob's storage until it is permanently removed. Use the List Blobs API and specify the "include=deleted" query parameter to discover which blobs and snapshots have been soft deleted. You can then use the Undelete Blob API to restore a soft-deleted blob. All other operations on a soft-deleted blob or snapshot causes the service to return an HTTP status code of 404 (ResourceNotFound). If the storage account's automatic snapshot feature is enabled, then, when a blob is deleted, an automatic snapshot is created. The blob becomes inaccessible immediately. All other operations on the blob causes the service to return an HTTP status code of 404 (ResourceNotFound). You can access automatic snapshot using snapshot timestamp or version id. You can restore the blob by calling Put or Copy Blob API with automatic snapshot as source. Deleting automatic snapshot requires shared key or special SAS/RBAC permissions. + * If the storage account's soft delete feature is disabled then, when a blob is deleted, it is permanently removed from the storage account. If the storage account's soft delete feature is enabled, then, when a blob is deleted, it is marked for deletion and becomes inaccessible immediately. However, the blob service retains the blob or snapshot for the number of days specified by the DeleteRetentionPolicy section of [Storage service properties] (Set-Blob-Service-Properties.md). After the specified number of days has passed, the blob's data is permanently removed from the storage account. Note that you continue to be charged for the soft-deleted blob's storage until it is permanently removed. Use the List Blobs API and specify the "include=deleted" query parameter to discover which blobs and snapshots have been soft deleted. You can then use the Undelete Blob API to restore a soft-deleted blob. All other operations on a soft-deleted blob or snapshot causes the service to return an HTTP status code of 404 (ResourceNotFound). If the storage account's automatic snapshot feature is enabled, then, when a blob is deleted, an automatic snapshot is created. The blob becomes inaccessible immediately. All other operations on the blob causes the service to return an HTTP status code of 404 (ResourceNotFound). You can access automatic snapshot using snapshot timestamp or version id. You can restore the blob by calling Put or Copy Blob API with automatic snapshot as source. Deleting automatic snapshot requires shared key or special SAS/RBAC permissions. * * @param containerName The container name. * @param blob The blob name. @@ -319,6 +325,7 @@ public Mono getPropertiesWithRestResponseAsync(Strin * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteWithRestResponseAsync(String containerName, String blob, Context context) { final String snapshot = null; final String versionId = null; @@ -330,11 +337,11 @@ public Mono deleteWithRestResponseAsync(String containerNam final String ifNoneMatch = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.delete(containerName, blob, this.client.url(), snapshot, versionId, timeout, deleteSnapshots, this.client.version(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.delete(containerName, blob, this.client.getUrl(), snapshot, versionId, timeout, deleteSnapshots, this.client.getVersion(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** - * If the storage account's soft delete feature is disabled then, when a blob is deleted, it is permanently removed from the storage account. If the storage account's soft delete feature is enabled, then, when a blob is deleted, it is marked for deletion and becomes inaccessible immediately. However, the storage service retains the blob or snapshot for the number of days specified by the DeleteRetentionPolicy section of [Storage service properties] (Set-Blob-Service-Properties.md). After the specified number of days has passed, the blob's data is permanently removed from the storage account. Note that you continue to be charged for the soft-deleted blob's storage until it is permanently removed. Use the List Blobs API and specify the "include=deleted" query parameter to discover which blobs and snapshots have been soft deleted. You can then use the Undelete Blob API to restore a soft-deleted blob. All other operations on a soft-deleted blob or snapshot causes the service to return an HTTP status code of 404 (ResourceNotFound). If the storage account's automatic snapshot feature is enabled, then, when a blob is deleted, an automatic snapshot is created. The blob becomes inaccessible immediately. All other operations on the blob causes the service to return an HTTP status code of 404 (ResourceNotFound). You can access automatic snapshot using snapshot timestamp or version id. You can restore the blob by calling Put or Copy Blob API with automatic snapshot as source. Deleting automatic snapshot requires shared key or special SAS/RBAC permissions. + * If the storage account's soft delete feature is disabled then, when a blob is deleted, it is permanently removed from the storage account. If the storage account's soft delete feature is enabled, then, when a blob is deleted, it is marked for deletion and becomes inaccessible immediately. However, the blob service retains the blob or snapshot for the number of days specified by the DeleteRetentionPolicy section of [Storage service properties] (Set-Blob-Service-Properties.md). After the specified number of days has passed, the blob's data is permanently removed from the storage account. Note that you continue to be charged for the soft-deleted blob's storage until it is permanently removed. Use the List Blobs API and specify the "include=deleted" query parameter to discover which blobs and snapshots have been soft deleted. You can then use the Undelete Blob API to restore a soft-deleted blob. All other operations on a soft-deleted blob or snapshot causes the service to return an HTTP status code of 404 (ResourceNotFound). If the storage account's automatic snapshot feature is enabled, then, when a blob is deleted, an automatic snapshot is created. The blob becomes inaccessible immediately. All other operations on the blob causes the service to return an HTTP status code of 404 (ResourceNotFound). You can access automatic snapshot using snapshot timestamp or version id. You can restore the blob by calling Put or Copy Blob API with automatic snapshot as source. Deleting automatic snapshot requires shared key or special SAS/RBAC permissions. * * @param containerName The container name. * @param blob The blob name. @@ -349,6 +356,7 @@ public Mono deleteWithRestResponseAsync(String containerNam * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteWithRestResponseAsync(String containerName, String blob, String snapshot, String versionId, Integer timeout, DeleteSnapshotsOptionType deleteSnapshots, String requestId, LeaseAccessConditions leaseAccessConditions, ModifiedAccessConditions modifiedAccessConditions, Context context) { String leaseId = null; if (leaseAccessConditions != null) { @@ -372,7 +380,7 @@ public Mono deleteWithRestResponseAsync(String containerNam } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.delete(containerName, blob, this.client.url(), snapshot, versionId, timeout, deleteSnapshots, this.client.version(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.delete(containerName, blob, this.client.getUrl(), snapshot, versionId, timeout, deleteSnapshots, this.client.getVersion(), requestId, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -384,11 +392,12 @@ public Mono deleteWithRestResponseAsync(String containerNam * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono undeleteWithRestResponseAsync(String containerName, String blob, Context context) { final Integer timeout = null; final String requestId = null; final String comp = "undelete"; - return service.undelete(containerName, blob, this.client.url(), timeout, this.client.version(), requestId, comp, context); + return service.undelete(containerName, blob, this.client.getUrl(), timeout, this.client.getVersion(), requestId, comp, context); } /** @@ -402,9 +411,10 @@ public Mono undeleteWithRestResponseAsync(String containe * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono undeleteWithRestResponseAsync(String containerName, String blob, Integer timeout, String requestId, Context context) { final String comp = "undelete"; - return service.undelete(containerName, blob, this.client.url(), timeout, this.client.version(), requestId, comp, context); + return service.undelete(containerName, blob, this.client.getUrl(), timeout, this.client.getVersion(), requestId, comp, context); } /** @@ -416,6 +426,7 @@ public Mono undeleteWithRestResponseAsync(String containe * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono setHTTPHeadersWithRestResponseAsync(String containerName, String blob, Context context) { final Integer timeout = null; final String requestId = null; @@ -431,7 +442,7 @@ public Mono setHTTPHeadersWithRestResponseAsync(Str String blobContentMD5Converted = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.setHTTPHeaders(containerName, blob, this.client.url(), timeout, this.client.version(), requestId, comp, blobCacheControl, blobContentType, blobContentMD5Converted, blobContentEncoding, blobContentLanguage, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.setHTTPHeaders(containerName, blob, this.client.getUrl(), timeout, this.client.getVersion(), requestId, comp, blobCacheControl, blobContentType, blobContentMD5Converted, blobContentEncoding, blobContentLanguage, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -448,6 +459,7 @@ public Mono setHTTPHeadersWithRestResponseAsync(Str * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono setHTTPHeadersWithRestResponseAsync(String containerName, String blob, Integer timeout, String requestId, BlobHTTPHeaders blobHTTPHeaders, LeaseAccessConditions leaseAccessConditions, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String comp = "properties"; String blobCacheControl = null; @@ -497,7 +509,7 @@ public Mono setHTTPHeadersWithRestResponseAsync(Str String blobContentMD5Converted = Base64Util.encodeToString(blobContentMD5); DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.setHTTPHeaders(containerName, blob, this.client.url(), timeout, this.client.version(), requestId, comp, blobCacheControl, blobContentType, blobContentMD5Converted, blobContentEncoding, blobContentLanguage, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.setHTTPHeaders(containerName, blob, this.client.getUrl(), timeout, this.client.getVersion(), requestId, comp, blobCacheControl, blobContentType, blobContentMD5Converted, blobContentEncoding, blobContentLanguage, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -509,6 +521,7 @@ public Mono setHTTPHeadersWithRestResponseAsync(Str * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono setMetadataWithRestResponseAsync(String containerName, String blob, Context context) { final Integer timeout = null; final Map metadata = null; @@ -522,7 +535,7 @@ public Mono setMetadataWithRestResponseAsync(String co final String ifNoneMatch = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.setMetadata(containerName, blob, this.client.url(), timeout, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.setMetadata(containerName, blob, this.client.getUrl(), timeout, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -542,6 +555,7 @@ public Mono setMetadataWithRestResponseAsync(String co * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono setMetadataWithRestResponseAsync(String containerName, String blob, Integer timeout, Map metadata, String encryptionKey, String encryptionKeySha256, EncryptionAlgorithmType encryptionAlgorithm, String requestId, LeaseAccessConditions leaseAccessConditions, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String comp = "metadata"; String leaseId = null; @@ -566,7 +580,7 @@ public Mono setMetadataWithRestResponseAsync(String co } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.setMetadata(containerName, blob, this.client.url(), timeout, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.setMetadata(containerName, blob, this.client.getUrl(), timeout, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -578,6 +592,7 @@ public Mono setMetadataWithRestResponseAsync(String co * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono acquireLeaseWithRestResponseAsync(String containerName, String blob, Context context) { final Integer timeout = null; final Integer duration = null; @@ -589,7 +604,7 @@ public Mono acquireLeaseWithRestResponseAsync(String final String ifNoneMatch = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.acquireLease(containerName, blob, this.client.url(), timeout, duration, proposedLeaseId, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.acquireLease(containerName, blob, this.client.getUrl(), timeout, duration, proposedLeaseId, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -606,6 +621,7 @@ public Mono acquireLeaseWithRestResponseAsync(String * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono acquireLeaseWithRestResponseAsync(String containerName, String blob, Integer timeout, Integer duration, String proposedLeaseId, String requestId, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String comp = "lease"; final String action = "acquire"; @@ -627,7 +643,7 @@ public Mono acquireLeaseWithRestResponseAsync(String } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.acquireLease(containerName, blob, this.client.url(), timeout, duration, proposedLeaseId, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.acquireLease(containerName, blob, this.client.getUrl(), timeout, duration, proposedLeaseId, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -640,6 +656,7 @@ public Mono acquireLeaseWithRestResponseAsync(String * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono releaseLeaseWithRestResponseAsync(String containerName, String blob, String leaseId, Context context) { final Integer timeout = null; final String requestId = null; @@ -649,7 +666,7 @@ public Mono releaseLeaseWithRestResponseAsync(String final String ifNoneMatch = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.releaseLease(containerName, blob, this.client.url(), timeout, leaseId, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.releaseLease(containerName, blob, this.client.getUrl(), timeout, leaseId, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -665,6 +682,7 @@ public Mono releaseLeaseWithRestResponseAsync(String * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono releaseLeaseWithRestResponseAsync(String containerName, String blob, String leaseId, Integer timeout, String requestId, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String comp = "lease"; final String action = "release"; @@ -686,7 +704,7 @@ public Mono releaseLeaseWithRestResponseAsync(String } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.releaseLease(containerName, blob, this.client.url(), timeout, leaseId, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.releaseLease(containerName, blob, this.client.getUrl(), timeout, leaseId, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -699,6 +717,7 @@ public Mono releaseLeaseWithRestResponseAsync(String * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono renewLeaseWithRestResponseAsync(String containerName, String blob, String leaseId, Context context) { final Integer timeout = null; final String requestId = null; @@ -708,7 +727,7 @@ public Mono renewLeaseWithRestResponseAsync(String cont final String ifNoneMatch = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.renewLease(containerName, blob, this.client.url(), timeout, leaseId, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.renewLease(containerName, blob, this.client.getUrl(), timeout, leaseId, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -724,6 +743,7 @@ public Mono renewLeaseWithRestResponseAsync(String cont * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono renewLeaseWithRestResponseAsync(String containerName, String blob, String leaseId, Integer timeout, String requestId, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String comp = "lease"; final String action = "renew"; @@ -745,7 +765,7 @@ public Mono renewLeaseWithRestResponseAsync(String cont } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.renewLease(containerName, blob, this.client.url(), timeout, leaseId, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.renewLease(containerName, blob, this.client.getUrl(), timeout, leaseId, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -759,6 +779,7 @@ public Mono renewLeaseWithRestResponseAsync(String cont * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono changeLeaseWithRestResponseAsync(String containerName, String blob, String leaseId, String proposedLeaseId, Context context) { final Integer timeout = null; final String requestId = null; @@ -768,7 +789,7 @@ public Mono changeLeaseWithRestResponseAsync(String co final String ifNoneMatch = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.changeLease(containerName, blob, this.client.url(), timeout, leaseId, proposedLeaseId, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.changeLease(containerName, blob, this.client.getUrl(), timeout, leaseId, proposedLeaseId, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -785,6 +806,7 @@ public Mono changeLeaseWithRestResponseAsync(String co * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono changeLeaseWithRestResponseAsync(String containerName, String blob, String leaseId, String proposedLeaseId, Integer timeout, String requestId, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String comp = "lease"; final String action = "change"; @@ -806,7 +828,7 @@ public Mono changeLeaseWithRestResponseAsync(String co } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.changeLease(containerName, blob, this.client.url(), timeout, leaseId, proposedLeaseId, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.changeLease(containerName, blob, this.client.getUrl(), timeout, leaseId, proposedLeaseId, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -818,6 +840,7 @@ public Mono changeLeaseWithRestResponseAsync(String co * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono breakLeaseWithRestResponseAsync(String containerName, String blob, Context context) { final Integer timeout = null; final Integer breakPeriod = null; @@ -828,7 +851,7 @@ public Mono breakLeaseWithRestResponseAsync(String cont final String ifNoneMatch = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.breakLease(containerName, blob, this.client.url(), timeout, breakPeriod, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.breakLease(containerName, blob, this.client.getUrl(), timeout, breakPeriod, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -844,6 +867,7 @@ public Mono breakLeaseWithRestResponseAsync(String cont * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono breakLeaseWithRestResponseAsync(String containerName, String blob, Integer timeout, Integer breakPeriod, String requestId, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String comp = "lease"; final String action = "break"; @@ -865,7 +889,7 @@ public Mono breakLeaseWithRestResponseAsync(String cont } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.breakLease(containerName, blob, this.client.url(), timeout, breakPeriod, this.client.version(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.breakLease(containerName, blob, this.client.getUrl(), timeout, breakPeriod, this.client.getVersion(), requestId, comp, action, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -877,6 +901,7 @@ public Mono breakLeaseWithRestResponseAsync(String cont * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono createSnapshotWithRestResponseAsync(String containerName, String blob, Context context) { final Integer timeout = null; final Map metadata = null; @@ -890,7 +915,7 @@ public Mono createSnapshotWithRestResponseAsync(Str final String leaseId = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.createSnapshot(containerName, blob, this.client.url(), timeout, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); + return service.createSnapshot(containerName, blob, this.client.getUrl(), timeout, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); } /** @@ -910,6 +935,7 @@ public Mono createSnapshotWithRestResponseAsync(Str * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono createSnapshotWithRestResponseAsync(String containerName, String blob, Integer timeout, Map metadata, String encryptionKey, String encryptionKeySha256, EncryptionAlgorithmType encryptionAlgorithm, String requestId, ModifiedAccessConditions modifiedAccessConditions, LeaseAccessConditions leaseAccessConditions, Context context) { final String comp = "snapshot"; OffsetDateTime ifModifiedSince = null; @@ -934,7 +960,7 @@ public Mono createSnapshotWithRestResponseAsync(Str } DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.createSnapshot(containerName, blob, this.client.url(), timeout, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); + return service.createSnapshot(containerName, blob, this.client.getUrl(), timeout, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); } /** @@ -947,6 +973,7 @@ public Mono createSnapshotWithRestResponseAsync(Str * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono startCopyFromURLWithRestResponseAsync(String containerName, String blob, URL copySource, Context context) { final Integer timeout = null; final Map metadata = null; @@ -960,7 +987,7 @@ public Mono startCopyFromURLWithRestResponseAsync DateTimeRfc1123 sourceIfUnmodifiedSinceConverted = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.startCopyFromURL(containerName, blob, this.client.url(), timeout, metadata, copySource, this.client.version(), requestId, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); + return service.startCopyFromURL(containerName, blob, this.client.getUrl(), timeout, metadata, copySource, this.client.getVersion(), requestId, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); } /** @@ -979,6 +1006,7 @@ public Mono startCopyFromURLWithRestResponseAsync * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono startCopyFromURLWithRestResponseAsync(String containerName, String blob, URL copySource, Integer timeout, Map metadata, String requestId, SourceModifiedAccessConditions sourceModifiedAccessConditions, ModifiedAccessConditions modifiedAccessConditions, LeaseAccessConditions leaseAccessConditions, Context context) { OffsetDateTime sourceIfModifiedSince = null; if (sourceModifiedAccessConditions != null) { @@ -1020,7 +1048,7 @@ public Mono startCopyFromURLWithRestResponseAsync DateTimeRfc1123 sourceIfUnmodifiedSinceConverted = sourceIfUnmodifiedSince == null ? null : new DateTimeRfc1123(sourceIfUnmodifiedSince); DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.startCopyFromURL(containerName, blob, this.client.url(), timeout, metadata, copySource, this.client.version(), requestId, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); + return service.startCopyFromURL(containerName, blob, this.client.getUrl(), timeout, metadata, copySource, this.client.getVersion(), requestId, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); } /** @@ -1033,6 +1061,7 @@ public Mono startCopyFromURLWithRestResponseAsync * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono copyFromURLWithRestResponseAsync(String containerName, String blob, URL copySource, Context context) { final Integer timeout = null; final Map metadata = null; @@ -1047,7 +1076,7 @@ public Mono copyFromURLWithRestResponseAsync(String co DateTimeRfc1123 sourceIfUnmodifiedSinceConverted = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.copyFromURL(containerName, blob, this.client.url(), timeout, metadata, copySource, this.client.version(), requestId, xMsRequiresSync, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); + return service.copyFromURL(containerName, blob, this.client.getUrl(), timeout, metadata, copySource, this.client.getVersion(), requestId, xMsRequiresSync, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); } /** @@ -1066,6 +1095,7 @@ public Mono copyFromURLWithRestResponseAsync(String co * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono copyFromURLWithRestResponseAsync(String containerName, String blob, URL copySource, Integer timeout, Map metadata, String requestId, SourceModifiedAccessConditions sourceModifiedAccessConditions, ModifiedAccessConditions modifiedAccessConditions, LeaseAccessConditions leaseAccessConditions, Context context) { final String xMsRequiresSync = "true"; OffsetDateTime sourceIfModifiedSince = null; @@ -1108,7 +1138,7 @@ public Mono copyFromURLWithRestResponseAsync(String co DateTimeRfc1123 sourceIfUnmodifiedSinceConverted = sourceIfUnmodifiedSince == null ? null : new DateTimeRfc1123(sourceIfUnmodifiedSince); DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.copyFromURL(containerName, blob, this.client.url(), timeout, metadata, copySource, this.client.version(), requestId, xMsRequiresSync, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); + return service.copyFromURL(containerName, blob, this.client.getUrl(), timeout, metadata, copySource, this.client.getVersion(), requestId, xMsRequiresSync, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, leaseId, context); } /** @@ -1121,13 +1151,14 @@ public Mono copyFromURLWithRestResponseAsync(String co * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono abortCopyFromURLWithRestResponseAsync(String containerName, String blob, String copyId, Context context) { final Integer timeout = null; final String requestId = null; final String comp = "copy"; final String copyActionAbortConstant = "abort"; final String leaseId = null; - return service.abortCopyFromURL(containerName, blob, this.client.url(), copyId, timeout, this.client.version(), requestId, comp, copyActionAbortConstant, leaseId, context); + return service.abortCopyFromURL(containerName, blob, this.client.getUrl(), copyId, timeout, this.client.getVersion(), requestId, comp, copyActionAbortConstant, leaseId, context); } /** @@ -1143,6 +1174,7 @@ public Mono abortCopyFromURLWithRestResponseAsync * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono abortCopyFromURLWithRestResponseAsync(String containerName, String blob, String copyId, Integer timeout, String requestId, LeaseAccessConditions leaseAccessConditions, Context context) { final String comp = "copy"; final String copyActionAbortConstant = "abort"; @@ -1150,7 +1182,7 @@ public Mono abortCopyFromURLWithRestResponseAsync if (leaseAccessConditions != null) { leaseId = leaseAccessConditions.leaseId(); } - return service.abortCopyFromURL(containerName, blob, this.client.url(), copyId, timeout, this.client.version(), requestId, comp, copyActionAbortConstant, leaseId, context); + return service.abortCopyFromURL(containerName, blob, this.client.getUrl(), copyId, timeout, this.client.getVersion(), requestId, comp, copyActionAbortConstant, leaseId, context); } /** @@ -1163,12 +1195,13 @@ public Mono abortCopyFromURLWithRestResponseAsync * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono setTierWithRestResponseAsync(String containerName, String blob, AccessTier tier, Context context) { final Integer timeout = null; final String requestId = null; final String comp = "tier"; final String leaseId = null; - return service.setTier(containerName, blob, this.client.url(), timeout, tier, this.client.version(), requestId, comp, leaseId, context); + return service.setTier(containerName, blob, this.client.getUrl(), timeout, tier, this.client.getVersion(), requestId, comp, leaseId, context); } /** @@ -1184,13 +1217,14 @@ public Mono setTierWithRestResponseAsync(String containerN * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono setTierWithRestResponseAsync(String containerName, String blob, AccessTier tier, Integer timeout, String requestId, LeaseAccessConditions leaseAccessConditions, Context context) { final String comp = "tier"; String leaseId = null; if (leaseAccessConditions != null) { leaseId = leaseAccessConditions.leaseId(); } - return service.setTier(containerName, blob, this.client.url(), timeout, tier, this.client.version(), requestId, comp, leaseId, context); + return service.setTier(containerName, blob, this.client.getUrl(), timeout, tier, this.client.getVersion(), requestId, comp, leaseId, context); } /** @@ -1202,9 +1236,10 @@ public Mono setTierWithRestResponseAsync(String containerN * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono getAccountInfoWithRestResponseAsync(String containerName, String blob, Context context) { final String restype = "account"; final String comp = "properties"; - return service.getAccountInfo(containerName, blob, this.client.url(), this.client.version(), restype, comp, context); + return service.getAccountInfo(containerName, blob, this.client.getUrl(), this.client.getVersion(), restype, comp, context); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/BlockBlobsImpl.java b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/BlockBlobsImpl.java index 2c4645d2bd4bc..390c2436de9a3 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/BlockBlobsImpl.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/implementation/BlockBlobsImpl.java @@ -4,19 +4,21 @@ package com.azure.storage.blob.implementation; -import com.azure.core.annotations.BodyParam; -import com.azure.core.annotations.ExpectedResponses; -import com.azure.core.annotations.GET; -import com.azure.core.annotations.HeaderParam; -import com.azure.core.annotations.Host; -import com.azure.core.annotations.HostParam; -import com.azure.core.annotations.PUT; -import com.azure.core.annotations.PathParam; -import com.azure.core.annotations.QueryParam; -import com.azure.core.annotations.Service; -import com.azure.core.annotations.UnexpectedResponseExceptionType; import com.azure.core.implementation.DateTimeRfc1123; import com.azure.core.implementation.RestProxy; +import com.azure.core.implementation.annotation.BodyParam; +import com.azure.core.implementation.annotation.ExpectedResponses; +import com.azure.core.implementation.annotation.Get; +import com.azure.core.implementation.annotation.HeaderParam; +import com.azure.core.implementation.annotation.Host; +import com.azure.core.implementation.annotation.HostParam; +import com.azure.core.implementation.annotation.PathParam; +import com.azure.core.implementation.annotation.Put; +import com.azure.core.implementation.annotation.QueryParam; +import com.azure.core.implementation.annotation.ReturnType; +import com.azure.core.implementation.annotation.ServiceInterface; +import com.azure.core.implementation.annotation.ServiceMethod; +import com.azure.core.implementation.annotation.UnexpectedResponseExceptionType; import com.azure.core.implementation.util.Base64Util; import com.azure.core.util.Context; import com.azure.storage.blob.models.BlobHTTPHeaders; @@ -33,12 +35,11 @@ import com.azure.storage.blob.models.SourceModifiedAccessConditions; import com.azure.storage.blob.models.StorageErrorException; import io.netty.buffer.ByteBuf; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - import java.net.URL; import java.time.OffsetDateTime; import java.util.Map; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; /** * An instance of this class provides access to all the operations defined in @@ -61,38 +62,38 @@ public final class BlockBlobsImpl { * @param client the instance of the service client containing this operation class. */ public BlockBlobsImpl(AzureBlobStorageImpl client) { - this.service = RestProxy.create(BlockBlobsService.class, client); + this.service = RestProxy.create(BlockBlobsService.class, client.getHttpPipeline()); this.client = client; } /** - * The interface defining all the services for BlockBlobs to be used by the - * proxy service to perform REST calls. + * The interface defining all the services for AzureBlobStorageBlockBlobs + * to be used by the proxy service to perform REST calls. */ @Host("{url}") - @Service("Storage Blobs BlockBlob") + @ServiceInterface(name = "AzureBlobStorageBlockBlobs") private interface BlockBlobsService { - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono upload(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @BodyParam("application/octet-stream") Flux body, @QueryParam("timeout") Integer timeout, @HeaderParam("Content-Length") long contentLength, @HeaderParam("x-ms-meta-") Map metadata, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @HeaderParam("x-ms-blob-type") String blobType, @HeaderParam("x-ms-blob-content-type") String blobContentType, @HeaderParam("x-ms-blob-content-encoding") String blobContentEncoding, @HeaderParam("x-ms-blob-content-language") String blobContentLanguage, @HeaderParam("x-ms-blob-content-md5") String blobContentMD5, @HeaderParam("x-ms-blob-cache-control") String blobCacheControl, @HeaderParam("x-ms-blob-content-disposition") String blobContentDisposition, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono stageBlock(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("blockid") String blockId, @HeaderParam("Content-Length") long contentLength, @HeaderParam("Content-MD5") String transactionalContentMD5, @BodyParam("application/octet-stream") Flux body, @QueryParam("timeout") Integer timeout, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-id") String leaseId, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono stageBlockFromURL(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("blockid") String blockId, @HeaderParam("Content-Length") long contentLength, @HeaderParam("x-ms-copy-source") URL copySource, @HeaderParam("x-ms-source-range") String sourceRange, @HeaderParam("x-ms-source-content-md5") String sourceContentMD5, @QueryParam("timeout") Integer timeout, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("x-ms-source-if-modified-since") DateTimeRfc1123 sourceIfModifiedSince, @HeaderParam("x-ms-source-if-unmodified-since") DateTimeRfc1123 sourceIfUnmodifiedSince, @HeaderParam("x-ms-source-if-match") String sourceIfMatch, @HeaderParam("x-ms-source-if-none-match") String sourceIfNoneMatch, Context context); - @PUT("{containerName}/{blob}") + @Put("{containerName}/{blob}") @ExpectedResponses({201}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono commitBlockList(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-meta-") Map metadata, @QueryParam("x-ms-encryption-key") String encryptionKey, @QueryParam("x-ms-encryption-key-sha256") String encryptionKeySha256, @QueryParam("x-ms-encryption-algorithm") EncryptionAlgorithmType encryptionAlgorithm, @BodyParam("application/xml; charset=utf-8") BlockLookupList blocks, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-blob-cache-control") String blobCacheControl, @HeaderParam("x-ms-blob-content-type") String blobContentType, @HeaderParam("x-ms-blob-content-encoding") String blobContentEncoding, @HeaderParam("x-ms-blob-content-language") String blobContentLanguage, @HeaderParam("x-ms-blob-content-md5") String blobContentMD5, @HeaderParam("x-ms-blob-content-disposition") String blobContentDisposition, @HeaderParam("x-ms-lease-id") String leaseId, @HeaderParam("If-Modified-Since") DateTimeRfc1123 ifModifiedSince, @HeaderParam("If-Unmodified-Since") DateTimeRfc1123 ifUnmodifiedSince, @HeaderParam("If-Match") String ifMatch, @HeaderParam("If-None-Match") String ifNoneMatch, Context context); - @GET("{containerName}/{blob}") + @Get("{containerName}/{blob}") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Mono getBlockList(@PathParam("containerName") String containerName, @PathParam("blob") String blob, @HostParam("url") String url, @QueryParam("snapshot") String snapshot, @QueryParam("versionid") String versionId, @QueryParam("blocklisttype") BlockListType listType, @QueryParam("timeout") Integer timeout, @HeaderParam("x-ms-version") String version, @HeaderParam("x-ms-client-request-id") String requestId, @QueryParam("comp") String comp, @HeaderParam("x-ms-lease-id") String leaseId, Context context); @@ -109,6 +110,7 @@ private interface BlockBlobsService { * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono uploadWithRestResponseAsync(String containerName, String blob, Flux body, long contentLength, Context context) { final Integer timeout = null; final Map metadata = null; @@ -128,7 +130,7 @@ public Mono uploadWithRestResponseAsync(String contain String blobContentMD5Converted = null; DateTimeRfc1123 ifModifiedSinceConverted = null; DateTimeRfc1123 ifUnmodifiedSinceConverted = null; - return service.upload(containerName, blob, this.client.url(), body, timeout, contentLength, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, blobType, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5Converted, blobCacheControl, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.upload(containerName, blob, this.client.getUrl(), body, timeout, contentLength, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, blobType, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5Converted, blobCacheControl, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -151,6 +153,7 @@ public Mono uploadWithRestResponseAsync(String contain * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono uploadWithRestResponseAsync(String containerName, String blob, Flux body, long contentLength, Integer timeout, Map metadata, String encryptionKey, String encryptionKeySha256, EncryptionAlgorithmType encryptionAlgorithm, String requestId, BlobHTTPHeaders blobHTTPHeaders, LeaseAccessConditions leaseAccessConditions, ModifiedAccessConditions modifiedAccessConditions, Context context) { final String blobType = "BlockBlob"; String blobContentType = null; @@ -200,7 +203,7 @@ public Mono uploadWithRestResponseAsync(String contain String blobContentMD5Converted = Base64Util.encodeToString(blobContentMD5); DateTimeRfc1123 ifModifiedSinceConverted = ifModifiedSince == null ? null : new DateTimeRfc1123(ifModifiedSince); DateTimeRfc1123 ifUnmodifiedSinceConverted = ifUnmodifiedSince == null ? null : new DateTimeRfc1123(ifUnmodifiedSince); - return service.upload(containerName, blob, this.client.url(), body, timeout, contentLength, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, blobType, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5Converted, blobCacheControl, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); + return service.upload(containerName, blob, this.client.getUrl(), body, timeout, contentLength, metadata, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, blobType, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5Converted, blobCacheControl, blobContentDisposition, leaseId, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, ifMatch, ifNoneMatch, context); } /** @@ -215,6 +218,7 @@ public Mono uploadWithRestResponseAsync(String contain * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono stageBlockWithRestResponseAsync(String containerName, String blob, String blockId, long contentLength, Flux body, Context context) { final Integer timeout = null; final String encryptionKey = null; @@ -224,7 +228,7 @@ public Mono stageBlockWithRestResponseAsync(String final String comp = "block"; final String leaseId = null; String transactionalContentMD5Converted = null; - return service.stageBlock(containerName, blob, this.client.url(), blockId, contentLength, transactionalContentMD5Converted, body, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, leaseId, context); + return service.stageBlock(containerName, blob, this.client.getUrl(), blockId, contentLength, transactionalContentMD5Converted, body, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, leaseId, context); } /** @@ -246,6 +250,7 @@ public Mono stageBlockWithRestResponseAsync(String * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono stageBlockWithRestResponseAsync(String containerName, String blob, String blockId, long contentLength, Flux body, byte[] transactionalContentMD5, Integer timeout, String encryptionKey, String encryptionKeySha256, EncryptionAlgorithmType encryptionAlgorithm, String requestId, LeaseAccessConditions leaseAccessConditions, Context context) { final String comp = "block"; String leaseId = null; @@ -253,7 +258,7 @@ public Mono stageBlockWithRestResponseAsync(String leaseId = leaseAccessConditions.leaseId(); } String transactionalContentMD5Converted = Base64Util.encodeToString(transactionalContentMD5); - return service.stageBlock(containerName, blob, this.client.url(), blockId, contentLength, transactionalContentMD5Converted, body, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, leaseId, context); + return service.stageBlock(containerName, blob, this.client.getUrl(), blockId, contentLength, transactionalContentMD5Converted, body, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, leaseId, context); } /** @@ -268,6 +273,7 @@ public Mono stageBlockWithRestResponseAsync(String * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono stageBlockFromURLWithRestResponseAsync(String containerName, String blob, String blockId, long contentLength, URL sourceUrl, Context context) { final String sourceRange = null; final Integer timeout = null; @@ -282,7 +288,7 @@ public Mono stageBlockFromURLWithRestRespon String sourceContentMD5Converted = null; DateTimeRfc1123 sourceIfModifiedSinceConverted = null; DateTimeRfc1123 sourceIfUnmodifiedSinceConverted = null; - return service.stageBlockFromURL(containerName, blob, this.client.url(), blockId, contentLength, sourceUrl, sourceRange, sourceContentMD5Converted, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, leaseId, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, context); + return service.stageBlockFromURL(containerName, blob, this.client.getUrl(), blockId, contentLength, sourceUrl, sourceRange, sourceContentMD5Converted, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, leaseId, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, context); } /** @@ -306,6 +312,7 @@ public Mono stageBlockFromURLWithRestRespon * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono stageBlockFromURLWithRestResponseAsync(String containerName, String blob, String blockId, long contentLength, URL sourceUrl, String sourceRange, byte[] sourceContentMD5, Integer timeout, String encryptionKey, String encryptionKeySha256, EncryptionAlgorithmType encryptionAlgorithm, String requestId, LeaseAccessConditions leaseAccessConditions, SourceModifiedAccessConditions sourceModifiedAccessConditions, Context context) { final String comp = "block"; String leaseId = null; @@ -331,7 +338,7 @@ public Mono stageBlockFromURLWithRestRespon String sourceContentMD5Converted = Base64Util.encodeToString(sourceContentMD5); DateTimeRfc1123 sourceIfModifiedSinceConverted = sourceIfModifiedSince == null ? null : new DateTimeRfc1123(sourceIfModifiedSince); DateTimeRfc1123 sourceIfUnmodifiedSinceConverted = sourceIfUnmodifiedSince == null ? null : new DateTimeRfc1123(sourceIfUnmodifiedSince); - return service.stageBlockFromURL(containerName, blob, this.client.url(), blockId, contentLength, sourceUrl, sourceRange, sourceContentMD5Converted, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.version(), requestId, comp, leaseId, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, context); + return service.stageBlockFromURL(containerName, blob, this.client.getUrl(), blockId, contentLength, sourceUrl, sourceRange, sourceContentMD5Converted, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, this.client.getVersion(), requestId, comp, leaseId, sourceIfModifiedSinceConverted, sourceIfUnmodifiedSinceConverted, sourceIfMatch, sourceIfNoneMatch, context); } /** @@ -344,6 +351,7 @@ public Mono stageBlockFromURLWithRestRespon * @throws IllegalArgumentException thrown if parameters fail the validation. * @return a Mono which performs the network request upon subscription. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Mono commitBlockListWithRestResponseAsync(String containerName, String blob, BlockLookupList blocks, Context context) { final Integer timeout = null; final Map metadata = null; @@ -363,7 +371,7 @@ public Mono