I am trying to list the storage accounts of a given subscription and with that I am trying to pull all the blob end points of the subscription.
The way it is done is as follows.
a. create a cache with subscriptionId vs Azure.Authenticated object. This is basically for reuse, for the subsequent sdk api calls in the business process
b. if the subscriptionid is not present in the above cache, then create Azure.Authenticated object as follows, and put it in the cache
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
subscription.getClientId(),
subscription.getTenantId(),
subscription.getKey(),
subscription.getEnvironmentType().getEnvironment());
Azure.Authenticated = Azure.configure()
.withLogLevel(LogLevel.NONE)
.authenticate(credentials);
c. Get the Azure object, using the subscription id
azure = authenticatedClient.withSubscription(subscription.getSubscriptionId());
d. Use the storageAccounts list API to paginate and list all the storage accounts of a given subscription.
try {
PagedList<StorageAccount> strgAccList = azure.storageAccounts().list();
boolean hasNextPage = null != strgAccList.currentPage();
int pageCount = 0;
if (hasNextPage) {
while (hasNextPage) {
++pageCount;
Page<StorageAccount> resourcePage = strgAccList.currentPage();
Iterator<StorageAccount> it = resourcePage.items().iterator();
while (it.hasNext()) {
StorageAccount storageAccount = it.next();
storageAccounts.put(storageAccount.name(), storageAccount);
}
hasNextPage = strgAccList.hasNextPage();
if (hasNextPage) {
strgAccList.loadNextPage();
}
}
}
} catch (Exception e) {
//log exception here
}
Since this azure object is cached, it is possible that this object(I assume there is a token wrapped inside it) might expire in this iteration or and will eventually result in exception scenario. My question is
a. what is the TTL of this object?
b. should I create a new azure object, incase if of TTL expires?
c. Or will the sdk api will take care of renewing the token with new one?
Documentation doesn't help(I don't see it either), and I searched in the azure java sdk github project. The samples in there was also not of any help. Please enlighten me with all the wisdom. Thanks!