private synchronized void loadAccessTokens() throws IOException {
try {
AzureCliSubscription.Wrapper wrapper = MAPPER.readValue(azureProfile, AzureCliSubscription.Wrapper.class);
List<AzureCliToken> tokens = MAPPER.readValue(accessTokens, new TypeReference<List<AzureCliToken>>() { });
while (wrapper == null || tokens == null || tokens.isEmpty() || wrapper.subscriptions == null || wrapper.subscriptions.isEmpty()) {
System.err.println("Please login in Azure CLI and press any key to continue after you've successfully logged in.");
System.in.read();
wrapper = MAPPER.readValue(azureProfile, AzureCliSubscription.Wrapper.class);
tokens = MAPPER.readValue(accessTokens, new TypeReference<List<AzureCliToken>>() { });
}
for (AzureCliSubscription subscription : wrapper.subscriptions) {
for (AzureCliToken token : tokens) {
if (subscription.isServicePrincipal() == token.isServicePrincipal()
&& subscription.userName().equalsIgnoreCase(token.user())
&& subscription.tenant().equalsIgnoreCase(token.tenant())) {
subscriptions.put(subscription.id(), subscription.withToken(token));
if (subscription.isDefault()) {
withDefaultSubscriptionId(subscription.id());
}
}
}
}
} catch (IOException e) {
System.err.println(String.format("Cannot read files %s and %s. Are you logged in Azure CLI?", azureProfile.getAbsolutePath(), accessTokens.getAbsolutePath()));
throw e;
}
}