From 631d07bfc58e51ff473c08c8f1426a238d6bb6ea Mon Sep 17 00:00:00 2001 From: anuchan Date: Fri, 17 Jun 2016 12:05:53 -0700 Subject: [PATCH 1/2] Fixing 845 --- .../management/storage/StorageAccount.java | 4 ++-- .../implementation/StorageAccountImpl.java | 5 ++--- .../StorageAccountOperationsTests.java | 21 +++++++++++++++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccount.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccount.java index 57c84a09828f7..8319c71f67bf4 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccount.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccount.java @@ -130,12 +130,12 @@ public interface StorageAccount extends /** * Regenerates the access keys for this storage account. * - * @param keyType if the key is primary or secondary + * @param keyName if the key name * @return the generated access keys for this storage account * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization */ - List regenerateKey(KeyType keyType) throws CloudException, IOException; + List regenerateKey(String keyName) throws CloudException, IOException; /************************************************************** * Fluent interfaces to provision a StorageAccount diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java index 61036d6561ad4..6bd079fda40b6 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java @@ -9,7 +9,6 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; import com.microsoft.azure.management.resources.implementation.ResourceManager; -import com.microsoft.azure.management.storage.KeyType; import com.microsoft.azure.management.storage.StorageAccount; import com.microsoft.azure.management.storage.implementation.api.AccessTier; import com.microsoft.azure.management.storage.implementation.api.CustomDomain; @@ -138,9 +137,9 @@ public List refreshKeys() throws CloudException, IOException } @Override - public List regenerateKey(KeyType keyType) throws CloudException, IOException { + public List regenerateKey(String keyName) throws CloudException, IOException { ServiceResponse response = - this.client.regenerateKey(this.resourceGroupName(), this.key, keyType.toString()); + this.client.regenerateKey(this.resourceGroupName(), this.key, keyName); StorageAccountListKeysResultInner resultInner = response.getBody(); cachedAccountKeys = resultInner.keys(); return cachedAccountKeys; diff --git a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageAccountOperationsTests.java b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageAccountOperationsTests.java index 0b105f90def29..6e072060bc49d 100644 --- a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageAccountOperationsTests.java +++ b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageAccountOperationsTests.java @@ -11,6 +11,7 @@ import com.microsoft.azure.management.storage.implementation.CheckNameAvailabilityResult; import com.microsoft.azure.management.storage.implementation.api.AccessTier; import com.microsoft.azure.management.storage.implementation.api.SkuName; +import com.microsoft.azure.management.storage.implementation.api.StorageAccountKey; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -21,8 +22,8 @@ import static org.junit.Assert.fail; public class StorageAccountOperationsTests extends StorageManagementTestBase { - private static final String RG_NAME = "javacsmrg7"; - private static final String SA_NAME = "javacsmsa2"; + private static final String RG_NAME = "javacsmrg9"; + private static final String SA_NAME = "javacsmsa4"; private static ResourceGroup resourceGroup; @BeforeClass @@ -61,6 +62,22 @@ public void canCRUDStorageAccount() throws Exception { // Get storageAccount = storageManager.storageAccounts().getByGroup(RG_NAME, SA_NAME); Assert.assertNotNull(storageAccount); + + // Get Keys + List keys = storageAccount.keys(); + Assert.assertTrue(keys.size() > 0); + + // Regen key + StorageAccountKey oldKey = keys.get(0); + List updatedKeys = storageAccount.regenerateKey(oldKey.keyName()); + Assert.assertTrue(updatedKeys.size() > 0); + for (StorageAccountKey updatedKey : updatedKeys) { + if (updatedKey.keyName().equalsIgnoreCase(oldKey.keyName())) { + Assert.assertNotEquals(oldKey.value(), updatedKey.value()); + break; + } + } + // Update try { storageAccount.update() From e36af5f99b0935afeb4f75c62412920195064353 Mon Sep 17 00:00:00 2001 From: anuchan Date: Fri, 17 Jun 2016 12:08:08 -0700 Subject: [PATCH 2/2] removing the keyType class and fixing sample --- .../azure/management/storage/KeyType.java | 29 ------------------- .../storage/samples/ManageStorageAccount.java | 5 ++-- 2 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/KeyType.java diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/KeyType.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/KeyType.java deleted file mode 100644 index b60112e84a968..0000000000000 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/KeyType.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. - */ - -package com.microsoft.azure.management.storage; - -/** - * Indicates whether the access key is primary or secondary. - */ -public enum KeyType { - /** The access key is a primary key. */ - PRIMARY("Primary"), - - /** The access key is a secondary key. */ - SECONDARY("Secondary"); - - private String value; - - KeyType(String value) { - this.value = value; - } - - @Override - public String toString() { - return this.value; - } -} diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/storage/samples/ManageStorageAccount.java b/azure-samples/src/main/java/com/microsoft/azure/management/storage/samples/ManageStorageAccount.java index 1af5e815a6c69..08d7da983e62e 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/storage/samples/ManageStorageAccount.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/storage/samples/ManageStorageAccount.java @@ -10,7 +10,6 @@ import com.microsoft.azure.Azure; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import com.microsoft.azure.management.samples.Utils; -import com.microsoft.azure.management.storage.KeyType; import com.microsoft.azure.management.storage.StorageAccount; import com.microsoft.azure.management.storage.StorageAccounts; import com.microsoft.azure.management.storage.implementation.api.StorageAccountKey; @@ -78,9 +77,9 @@ public static void main(String[] args) { Utils.print(storageAccountKeys); - System.out.println("Regenerating primary storage account access key"); + System.out.println("Regenerating first storage account access key"); - storageAccountKeys = storageAccount.regenerateKey(KeyType.PRIMARY); + storageAccountKeys = storageAccount.regenerateKey(storageAccountKeys.get(0).keyName()); Utils.print(storageAccountKeys);