Skip to content

Commit

Permalink
Merge pull request #846 from anuchandy/fix845
Browse files Browse the repository at this point in the history
Removing StorageAccount.KeyType and adding test for regen key
  • Loading branch information
selvasingh authored Jun 17, 2016
2 parents 80f1616 + e36af5f commit 71b4f35
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 39 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<StorageAccountKey> regenerateKey(KeyType keyType) throws CloudException, IOException;
List<StorageAccountKey> regenerateKey(String keyName) throws CloudException, IOException;

/**************************************************************
* Fluent interfaces to provision a StorageAccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
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;
Expand Down Expand Up @@ -141,9 +140,9 @@ public List<StorageAccountKey> refreshKeys() throws CloudException, IOException
}

@Override
public List<StorageAccountKey> regenerateKey(KeyType keyType) throws CloudException, IOException {
public List<StorageAccountKey> regenerateKey(String keyName) throws CloudException, IOException {
ServiceResponse<StorageAccountListKeysResultInner> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -61,6 +62,22 @@ public void canCRUDStorageAccount() throws Exception {
// Get
storageAccount = storageManager.storageAccounts().getByGroup(RG_NAME, SA_NAME);
Assert.assertNotNull(storageAccount);

// Get Keys
List<StorageAccountKey> keys = storageAccount.keys();
Assert.assertTrue(keys.size() > 0);

// Regen key
StorageAccountKey oldKey = keys.get(0);
List<StorageAccountKey> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 71b4f35

Please sign in to comment.