Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 0bd50d4

Browse files
committed
Added support for getAccountInfo
1 parent 09772c2 commit 0bd50d4

File tree

11 files changed

+444
-146
lines changed

11 files changed

+444
-146
lines changed

ChangeLog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
XXXX.XX.XX Version X.X.X
22
* Support for 2018-03-28 REST version. Please see our REST API documentation and blogs for information about the related added features.
33
* Added support for static website properties.
4+
* Added support for the getAccountInfo feature. Sku name and account kind may be retrieved using a CloudBlobClient, CloudBlobContainer, or CloudBlob with SharedKey or SAS.
45

56
2018.05.22 Version 7.1.0
67
* Support for 2017-11-09 REST version. Please see our REST API documentation and blogs for information about the related added features.

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobClientTests.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,14 @@
1919
import java.io.FileOutputStream;
2020
import java.io.IOException;
2121
import java.net.URISyntaxException;
22-
import java.util.ArrayList;
23-
import java.util.Iterator;
24-
import java.util.UUID;
22+
import java.security.InvalidKeyException;
23+
import java.util.*;
2524

25+
import com.microsoft.azure.storage.*;
2626
import org.junit.Test;
2727
import org.junit.experimental.categories.Category;
2828

29-
import com.microsoft.azure.storage.Constants;
3029
import com.microsoft.azure.storage.core.SR;
31-
import com.microsoft.azure.storage.LocationMode;
32-
import com.microsoft.azure.storage.OperationContext;
33-
import com.microsoft.azure.storage.ResultContinuation;
34-
import com.microsoft.azure.storage.ResultSegment;
35-
import com.microsoft.azure.storage.SendingRequestEvent;
36-
import com.microsoft.azure.storage.StorageEvent;
37-
import com.microsoft.azure.storage.StorageException;
3830
import com.microsoft.azure.storage.TestRunners.CloudTests;
3931
import com.microsoft.azure.storage.TestRunners.DevFabricTests;
4032
import com.microsoft.azure.storage.TestRunners.DevStoreTests;
@@ -245,6 +237,33 @@ public void testGetServiceStats() throws StorageException {
245237
BlobTestHelper.verifyServiceStats(bClient.getServiceStats());
246238
}
247239

240+
@Test
241+
@Category({ CloudTests.class})
242+
public void testGetAccountInformation() throws StorageException, URISyntaxException, InvalidKeyException {
243+
// Shared key
244+
CloudBlobClient bClient = BlobTestHelper.createCloudBlobClient();
245+
bClient.getDefaultRequestOptions().setLocationMode(LocationMode.PRIMARY_ONLY);
246+
247+
AccountInformation accountInformation = bClient.downloadAccountInfo();
248+
assertNotNull(accountInformation.getAccountKind());
249+
assertNotNull(accountInformation.getSkuName());
250+
251+
// SAS
252+
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
253+
cal.setTime(new Date());
254+
cal.add(Calendar.SECOND, 60);
255+
SharedAccessAccountPolicy policy = new SharedAccessAccountPolicy();
256+
policy.setSharedAccessExpiryTime(cal.getTime());
257+
policy.setPermissionsFromString("r");
258+
policy.setResourceTypes(EnumSet.of(SharedAccessAccountResourceType.SERVICE));
259+
policy.setServiceFromString("b");
260+
CloudBlobClient sasClient = TestHelper.createCloudBlobClient(policy, false);
261+
262+
accountInformation = sasClient.downloadAccountInfo();
263+
assertNotNull(accountInformation.getAccountKind());
264+
assertNotNull(accountInformation.getSkuName());
265+
}
266+
248267
@Test
249268
@Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class })
250269
public void testSingleBlobPutThresholdInBytes() throws URISyntaxException, StorageException, IOException {

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobContainerTests.java

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,14 @@
2323
import java.security.InvalidKeyException;
2424
import java.util.*;
2525

26+
import com.microsoft.azure.storage.*;
2627
import org.junit.After;
2728
import org.junit.Before;
2829
import org.junit.Test;
2930
import org.junit.experimental.categories.Category;
3031

31-
import com.microsoft.azure.storage.Constants;
3232
import com.microsoft.azure.storage.core.SR;
3333
import com.microsoft.azure.storage.core.UriQueryBuilder;
34-
import com.microsoft.azure.storage.NameValidator;
35-
import com.microsoft.azure.storage.OperationContext;
36-
import com.microsoft.azure.storage.ResultContinuation;
37-
import com.microsoft.azure.storage.ResultSegment;
38-
import com.microsoft.azure.storage.SendingRequestEvent;
39-
import com.microsoft.azure.storage.SharedAccessAccountPermissions;
40-
import com.microsoft.azure.storage.SharedAccessAccountPolicy;
41-
import com.microsoft.azure.storage.SharedAccessAccountResourceType;
42-
import com.microsoft.azure.storage.SharedAccessAccountService;
43-
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
44-
import com.microsoft.azure.storage.StorageErrorCodeStrings;
45-
import com.microsoft.azure.storage.StorageEvent;
46-
import com.microsoft.azure.storage.StorageException;
47-
import com.microsoft.azure.storage.TestHelper;
4834
import com.microsoft.azure.storage.TestRunners.CloudTests;
4935
import com.microsoft.azure.storage.TestRunners.DevFabricTests;
5036
import com.microsoft.azure.storage.TestRunners.DevStoreTests;
@@ -909,7 +895,7 @@ private static void assertCreatedAndListedBlobsEquivalent(CloudBlockBlob created
909895
assertEquals(Long.valueOf(length), state2.getTotalBytes());
910896
}
911897
}
912-
898+
913899
private void validateWebContainer(CloudBlobContainer webContainer) throws URISyntaxException, StorageException, IOException {
914900
CloudBlockBlob blob0 = webContainer.getBlockBlobReference("blob");
915901
// Content type is important for the $web container
@@ -947,19 +933,18 @@ public void testCloudBlobContainerWebContainer() throws StorageException, URISyn
947933
assertFalse(webContainer.exists());
948934
long now = System.currentTimeMillis();
949935

950-
while(true) {
951-
try{
952-
if (webContainer.createIfNotExists() || (System.currentTimeMillis()-now)/1000 < 30) {
936+
while (true) {
937+
try {
938+
if (webContainer.createIfNotExists() || (System.currentTimeMillis() - now) / 1000 < 30) {
953939
break;
954940
}
955-
}
956-
catch (Exception e){
941+
} catch (Exception e) {
957942
Thread.sleep(1000);
958943
}
959944
}
960945
assertTrue(webContainer.exists());
961946
boolean webContainerFound = false;
962-
for(CloudBlobContainer container :blobClient.listContainers("$")) {
947+
for (CloudBlobContainer container : blobClient.listContainers("$")) {
963948
if (container.getName().equals(webContainer.getName())) {
964949
webContainerFound = true;
965950
}
@@ -970,7 +955,7 @@ public void testCloudBlobContainerWebContainer() throws StorageException, URISyn
970955

971956
// Clearing out the old data is faster than deleting/recreating.
972957
for (ListBlobItem blob : webContainer.listBlobs("", true)) {
973-
CloudBlob cloudBlob = (CloudBlob)blob;
958+
CloudBlob cloudBlob = (CloudBlob) blob;
974959
cloudBlob.delete();
975960
}
976961

@@ -988,15 +973,36 @@ public void testCloudBlobContainerWebContainer() throws StorageException, URISyn
988973
webContainer.delete();
989974

990975
webContainerFound = false;
991-
for(CloudBlobContainer container :blobClient.listContainers("$")) {
976+
for (CloudBlobContainer container : blobClient.listContainers("$")) {
992977
if (container.getName().equals(webContainer.getName())) {
993978
webContainerFound = true;
994979
}
995980
}
996981
assertFalse(webContainerFound);
997-
}
998-
finally {
982+
} finally {
999983
webContainer.deleteIfExists();
1000984
}
1001985
}
986+
987+
@Test
988+
@Category({ DevFabricTests.class, DevStoreTests.class })
989+
public void testGetAccountInfo() throws StorageException, InvalidKeyException, URISyntaxException {
990+
// Test using Shared Key.
991+
AccountInformation accountInformation = this.container.downloadAccountInfo();
992+
assertNotNull(accountInformation.getAccountKind());
993+
assertNotNull(accountInformation.getSkuName());
994+
995+
// Test using SAS.
996+
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
997+
cal.setTime(new Date());
998+
cal.add(Calendar.SECOND, 60);
999+
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
1000+
policy.setSharedAccessExpiryTime(cal.getTime());
1001+
policy.setPermissionsFromString("r");
1002+
String sas = container.generateSharedAccessSignature(policy, null);
1003+
CloudBlobContainer sasContainer = new CloudBlobContainer(container.getUri(), new StorageCredentialsSharedAccessSignature(sas));
1004+
accountInformation = sasContainer.downloadAccountInfo();
1005+
assertNotNull(accountInformation.getAccountKind());
1006+
assertNotNull(accountInformation.getSkuName());
1007+
}
10021008
}

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@
1414
*/
1515
package com.microsoft.azure.storage.blob;
1616

17-
import com.microsoft.azure.storage.AccessCondition;
18-
import com.microsoft.azure.storage.Constants;
19-
import com.microsoft.azure.storage.NameValidator;
20-
import com.microsoft.azure.storage.OperationContext;
21-
import com.microsoft.azure.storage.RetryNoRetry;
22-
import com.microsoft.azure.storage.SendingRequestEvent;
23-
import com.microsoft.azure.storage.StorageCredentialsAnonymous;
24-
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
25-
import com.microsoft.azure.storage.StorageEvent;
26-
import com.microsoft.azure.storage.StorageException;
17+
import com.microsoft.azure.storage.*;
2718
import com.microsoft.azure.storage.core.Utility;
2819
import com.microsoft.azure.storage.file.CloudFile;
2920
import com.microsoft.azure.storage.file.CloudFileShare;
@@ -50,7 +41,6 @@
5041
import java.security.InvalidKeyException;
5142
import java.util.*;
5243

53-
import com.microsoft.azure.storage.StorageErrorCodeStrings;
5444
import com.microsoft.azure.storage.TestRunners.CloudTests;
5545
import com.microsoft.azure.storage.TestRunners.DevFabricTests;
5646
import com.microsoft.azure.storage.TestRunners.DevStoreTests;
@@ -2451,4 +2441,27 @@ public void testCloudBlockBlobRehydrateBlob() throws StorageException, IOExcepti
24512441
assertNull(listBlob2.getProperties().getPremiumPageBlobTier());
24522442
assertNotNull(listBlob2.getProperties().getTierChangeTime());
24532443
}
2444+
2445+
@Test
2446+
@Category({ DevFabricTests.class, DevStoreTests.class })
2447+
public void testGetAccountInfo() throws StorageException, URISyntaxException, InvalidKeyException {
2448+
// Test using Shared Key.
2449+
CloudBlob blob = BlobTestHelper.getBlobReference(BlobType.BLOCK_BLOB, this.container, "infoblob");
2450+
AccountInformation accountInformation = blob.downloadAccountInfo();
2451+
assertNotNull(accountInformation.getAccountKind());
2452+
assertNotNull(accountInformation.getSkuName());
2453+
2454+
// Test using SAS.
2455+
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
2456+
cal.setTime(new Date());
2457+
cal.add(Calendar.SECOND, 60);
2458+
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
2459+
policy.setSharedAccessExpiryTime(cal.getTime());
2460+
policy.setPermissionsFromString("r");
2461+
String sas = blob.generateSharedAccessSignature(policy, null);
2462+
CloudBlob sasBlob = BlobTestHelper.getBlobReference(BlobType.BLOCK_BLOB, new StorageCredentialsSharedAccessSignature(sas), blob.getUri());
2463+
accountInformation = sasBlob.downloadAccountInfo();
2464+
assertNotNull(accountInformation.getAccountKind());
2465+
assertNotNull(accountInformation.getSkuName());
2466+
}
24542467
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright Microsoft Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package com.microsoft.azure.storage;
17+
18+
/**
19+
* Holds information related to the storage account.
20+
*/
21+
public final class AccountInformation {
22+
23+
private String skuName;
24+
25+
private String accountKind;
26+
27+
/**
28+
* @return
29+
* The name of the storage SKU, also known as account type.
30+
* Example: Standard_LRS, Standard_GRS, Standard_RAGRS, Premium_LRS, Premium_ZRS
31+
*/
32+
public String getSkuName() {
33+
return this.skuName;
34+
}
35+
36+
/**
37+
38+
* @return
39+
* Describes the flavour of the storage account, also known as account kind.
40+
* Example: Storage, StorageV2, BlobStorage
41+
*/
42+
public String getAccountKind() {
43+
return this.accountKind;
44+
}
45+
46+
public void setSkuName(String skuName) {
47+
this.skuName = skuName;
48+
}
49+
50+
public void setAccountKind(String accountKind) {
51+
this.accountKind = accountKind;
52+
}
53+
}

microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ public static class HeaderConstants {
324324
*/
325325
public static final String ACCEPT_CHARSET = "Accept-Charset";
326326

327+
/**
328+
* The header that represents the kind of storage account.
329+
*/
330+
public static final String ACCOUNT_KIND = PREFIX_FOR_STORAGE_HEADER + "account-kind";
331+
327332
/**
328333
* The Authorization header.
329334
*/
@@ -625,6 +630,11 @@ public static class HeaderConstants {
625630
*/
626631
public static final String SERVER_REQUEST_ENCRYPTED = PREFIX_FOR_STORAGE_HEADER + "request-server-encrypted";
627632

633+
/**
634+
* The header that specifies the sku name for an account.
635+
*/
636+
public static final String SKU_NAME = PREFIX_FOR_STORAGE_HEADER + "sku-name";
637+
628638
/**
629639
* The header that specifies the snapshot ID.
630640
*/

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobResponse.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Calendar;
2222
import java.util.Date;
2323

24+
import com.microsoft.azure.storage.AccountInformation;
2425
import com.microsoft.azure.storage.Constants;
2526
import com.microsoft.azure.storage.StorageException;
2627
import com.microsoft.azure.storage.StorageUri;
@@ -242,6 +243,22 @@ public static BlobContainerAttributes getBlobContainerAttributes(final HttpURLCo
242243
return containerAttributes;
243244
}
244245

246+
/**
247+
* Gets the accountInformation
248+
*
249+
* @param request
250+
* The response from the server.
251+
* @return The AccountInformation.
252+
* @throws StorageException
253+
*/
254+
public static AccountInformation getAccountInformation(final HttpURLConnection request) throws StorageException {
255+
AccountInformation accountInformation = new AccountInformation();
256+
accountInformation.setSkuName(request.getHeaderField(Constants.HeaderConstants.SKU_NAME));
257+
accountInformation.setAccountKind(request.getHeaderField(Constants.HeaderConstants.ACCOUNT_KIND));
258+
259+
return accountInformation;
260+
}
261+
245262
/**
246263
* Gets the copyState
247264
*

0 commit comments

Comments
 (0)