diff --git a/sdk/appservice/mgmt/src/main/java/com/azure/resourcemanager/appservice/implementation/KuduClient.java b/sdk/appservice/mgmt/src/main/java/com/azure/resourcemanager/appservice/implementation/KuduClient.java index 4e7f2dd423f70..2f704de4c5d9e 100644 --- a/sdk/appservice/mgmt/src/main/java/com/azure/resourcemanager/appservice/implementation/KuduClient.java +++ b/sdk/appservice/mgmt/src/main/java/com/azure/resourcemanager/appservice/implementation/KuduClient.java @@ -24,8 +24,11 @@ import com.azure.resourcemanager.appservice.models.KuduAuthenticationPolicy; import com.azure.resourcemanager.appservice.models.WebAppBase; import com.fasterxml.jackson.core.JsonParseException; + +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -140,7 +143,9 @@ Mono warDeploy( "x-ms-body-logging: false" }) @Post("api/zipdeploy") - Mono zipDeploy(@HostParam("$host") String host, @BodyParam("application/octet-stream") byte[] zipFile); + Mono zipDeploy( + @HostParam("$host") String host, + @BodyParam("application/octet-stream") byte[] zipFile); @Headers({ "Content-Type: application/octet-stream", @@ -243,7 +248,12 @@ private static int findByte(ByteBuffer byteBuffer, byte b) { } Mono warDeployAsync(InputStream warFile, String appName) { - return withRetry(service.warDeploy(host, byteArrayFromInputStream(warFile), appName)); + InputStreamFlux flux = fluxFromInputStream(warFile); + if (flux.flux != null) { + return withRetry(service.warDeploy(host, flux.flux, flux.size, appName)); + } else { + return withRetry(service.warDeploy(host, flux.bytes, appName)); + } } Mono warDeployAsync(File warFile, String appName) throws IOException { @@ -259,7 +269,12 @@ Mono warDeployAsync(File warFile, String appName) throws IOException { } Mono zipDeployAsync(InputStream zipFile) { - return withRetry(service.zipDeploy(host, byteArrayFromInputStream(zipFile))); + InputStreamFlux flux = fluxFromInputStream(zipFile); + if (flux.flux != null) { + return withRetry(service.zipDeploy(host, flux.flux, flux.size)); + } else { + return withRetry(service.zipDeploy(host, flux.bytes)); + } } Mono zipDeployAsync(File zipFile) throws IOException { @@ -274,21 +289,37 @@ Mono zipDeployAsync(File zipFile) throws IOException { })); } - private byte[] byteArrayFromInputStream(InputStream inputStream) { - // TODO (weidxu) core does not yet support InputStream as @BodyParam + private InputStreamFlux fluxFromInputStream(InputStream inputStream) { try { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - int nRead; - byte[] data = new byte[16384]; - while ((nRead = inputStream.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, nRead); + InputStreamFlux inputStreamFlux = new InputStreamFlux(); + if (inputStream instanceof FileInputStream) { + inputStreamFlux.size = ((FileInputStream) inputStream).getChannel().size(); + inputStreamFlux.flux = FluxUtil.toFluxByteBuffer(inputStream); + } else if (inputStream instanceof ByteArrayInputStream) { + inputStreamFlux.size = inputStream.available(); + inputStreamFlux.flux = FluxUtil.toFluxByteBuffer(inputStream); + } else { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int nRead; + byte[] data = new byte[16384]; + while ((nRead = inputStream.read(data, 0, data.length)) != -1) { + buffer.write(data, 0, nRead); + } + inputStreamFlux.bytes = buffer.toByteArray(); + inputStreamFlux.size = inputStreamFlux.bytes.length; } - return buffer.toByteArray(); + return inputStreamFlux; } catch (IOException e) { throw logger.logExceptionAsError(new IllegalStateException(e)); } } + private static class InputStreamFlux { + private Flux flux; + private byte[] bytes; + private long size; + } + private Mono withRetry(Mono observable) { return observable .retryWhen( diff --git a/sdk/appservice/mgmt/src/test/java/com/azure/resourcemanager/appservice/WarDeployTests.java b/sdk/appservice/mgmt/src/test/java/com/azure/resourcemanager/appservice/WarDeployTests.java index dcec739397fa5..7b3f0ce8994ed 100644 --- a/sdk/appservice/mgmt/src/test/java/com/azure/resourcemanager/appservice/WarDeployTests.java +++ b/sdk/appservice/mgmt/src/test/java/com/azure/resourcemanager/appservice/WarDeployTests.java @@ -11,6 +11,8 @@ import com.azure.resourcemanager.appservice.models.WebContainer; import com.azure.resourcemanager.resources.fluentcore.arm.Region; import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; import com.azure.resourcemanager.resources.fluentcore.profile.AzureProfile; import org.junit.jupiter.api.Assertions; @@ -75,7 +77,9 @@ public void canDeployMultipleWars() throws Exception { if (!isPlaybackMode()) { webApp.warDeploy(new File(WarDeployTests.class.getResource("/helloworld.war").getPath())); - webApp.warDeploy(new File(WarDeployTests.class.getResource("/helloworld.war").getPath()), "app2"); + try (InputStream is = new FileInputStream(new File(WarDeployTests.class.getResource("/helloworld.war").getPath()))) { + webApp.warDeploy(is, "app2"); + } Response response = curl("http://" + webappName + "." + "azurewebsites.net"); Assertions.assertEquals(200, response.getStatusCode()); diff --git a/sdk/keyvault/mgmt/src/main/java/com/azure/resourcemanager/keyvault/implementation/KeyImpl.java b/sdk/keyvault/mgmt/src/main/java/com/azure/resourcemanager/keyvault/implementation/KeyImpl.java index bbc6140963cfd..e2f10cf60ac1b 100644 --- a/sdk/keyvault/mgmt/src/main/java/com/azure/resourcemanager/keyvault/implementation/KeyImpl.java +++ b/sdk/keyvault/mgmt/src/main/java/com/azure/resourcemanager/keyvault/implementation/KeyImpl.java @@ -23,6 +23,7 @@ import com.azure.security.keyvault.keys.models.CreateRsaKeyOptions; import com.azure.security.keyvault.keys.models.ImportKeyOptions; import com.azure.security.keyvault.keys.models.JsonWebKey; +import com.azure.security.keyvault.keys.models.KeyCurveName; import com.azure.security.keyvault.keys.models.KeyOperation; import com.azure.security.keyvault.keys.models.KeyProperties; import com.azure.security.keyvault.keys.models.KeyType; @@ -345,13 +346,17 @@ public KeyImpl withHsm(boolean isHsm) { @Override public KeyImpl withKeySize(int size) { - // TODO (weidxu) currently no setKeySize in CreateEcKeyOptions - /*if (createKeyRequest instanceof CreateEcKeyOptions) { - ((CreateEcKeyOptions) createKeyRequest).setKeySize(size); - } else */ if (createKeyRequest instanceof CreateRsaKeyOptions) { ((CreateRsaKeyOptions) createKeyRequest).setKeySize(size); } return this; } + + @Override + public DefinitionStages.WithCreate withKeyCurveName(KeyCurveName keyCurveName) { + if (createKeyRequest instanceof CreateEcKeyOptions) { + ((CreateEcKeyOptions) createKeyRequest).setCurveName(keyCurveName); + } + return this; + } } diff --git a/sdk/keyvault/mgmt/src/main/java/com/azure/resourcemanager/keyvault/models/Key.java b/sdk/keyvault/mgmt/src/main/java/com/azure/resourcemanager/keyvault/models/Key.java index 2dd3bf31377c8..6f97cf97f0639 100644 --- a/sdk/keyvault/mgmt/src/main/java/com/azure/resourcemanager/keyvault/models/Key.java +++ b/sdk/keyvault/mgmt/src/main/java/com/azure/resourcemanager/keyvault/models/Key.java @@ -16,6 +16,7 @@ import com.azure.security.keyvault.keys.cryptography.models.KeyWrapAlgorithm; import com.azure.security.keyvault.keys.cryptography.models.SignatureAlgorithm; import com.azure.security.keyvault.keys.models.JsonWebKey; +import com.azure.security.keyvault.keys.models.KeyCurveName; import com.azure.security.keyvault.keys.models.KeyOperation; import com.azure.security.keyvault.keys.models.KeyProperties; import com.azure.security.keyvault.keys.models.KeyType; @@ -198,12 +199,20 @@ interface WithKey { /** The stage of a key definition allowing to specify the key size. */ interface WithKeySize { /** - * Specifies the size of the key to create. + * Specifies the size of the RSA key to create. * * @param size the size of the key in integer * @return the next stage of the definition */ WithCreate withKeySize(int size); + + /** + * Specifies the name of the key curve for elliptic-curve key to create. + * + * @param keyCurveName name of the key curve + * @return the next stage of the definition + */ + WithCreate withKeyCurveName(KeyCurveName keyCurveName); } /** The stage of a key definition allowing to specify the allowed operations for the key. */ diff --git a/sdk/keyvault/mgmt/src/test/java/com/azure/resourcemanager/keyvault/KeyTests.java b/sdk/keyvault/mgmt/src/test/java/com/azure/resourcemanager/keyvault/KeyTests.java index fad99351bd84a..032e5acec18c9 100644 --- a/sdk/keyvault/mgmt/src/test/java/com/azure/resourcemanager/keyvault/KeyTests.java +++ b/sdk/keyvault/mgmt/src/test/java/com/azure/resourcemanager/keyvault/KeyTests.java @@ -14,6 +14,7 @@ import com.azure.security.keyvault.keys.cryptography.models.KeyWrapAlgorithm; import com.azure.security.keyvault.keys.cryptography.models.SignatureAlgorithm; import com.azure.security.keyvault.keys.models.JsonWebKey; +import com.azure.security.keyvault.keys.models.KeyCurveName; import com.azure.security.keyvault.keys.models.KeyOperation; import com.azure.security.keyvault.keys.models.KeyType; import java.security.KeyPair; @@ -74,6 +75,33 @@ public void canCRUDKey() throws Exception { // List versions Iterable keys = key.listVersions(); Assertions.assertEquals(2, TestUtilities.getSize(keys)); + + // Create RSA key with size + key = vault + .keys() + .define(keyName) + .withKeyTypeToCreate(KeyType.RSA) + .withKeyOperations(KeyOperation.SIGN, KeyOperation.VERIFY) + .withKeySize(2048) + .create(); + + Assertions.assertNotNull(key); + Assertions.assertNotNull(key.id()); + Assertions.assertEquals(KeyType.RSA, key.getJsonWebKey().getKeyType()); + + // Create EC key with curve + key = vault + .keys() + .define(keyName) + .withKeyTypeToCreate(KeyType.EC) + .withKeyOperations(KeyOperation.SIGN, KeyOperation.VERIFY) + .withKeyCurveName(KeyCurveName.P_521) + .create(); + + Assertions.assertNotNull(key); + Assertions.assertNotNull(key.id()); + Assertions.assertEquals(KeyType.EC, key.getJsonWebKey().getKeyType()); + Assertions.assertEquals(KeyCurveName.P_521, key.getJsonWebKey().getCurveName()); } @Test