use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.
the class AzureSDKManager method getLocationsForInsights.
public static List<String> getLocationsForInsights(String subscriptionId) throws IOException {
final HttpGet request = new HttpGet(INSIGHTS_REGION_LIST_URL);
final AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
if (azureManager == null) {
return Collections.emptyList();
}
Subscription subscription = com.microsoft.azure.toolkit.lib.Azure.az(AzureAccount.class).account().getSubscription(subscriptionId);
final String accessToken = azureManager.getAccessToken(subscription.getTenantId());
request.setHeader("Authorization", String.format("Bearer %s", accessToken));
final CloseableHttpResponse response = HttpClients.createDefault().execute(request);
final InputStream responseStream = response.getEntity().getContent();
try (final InputStreamReader isr = new InputStreamReader(responseStream)) {
final Gson gson = new Gson();
final JsonObject jsonContent = (gson).fromJson(isr, JsonObject.class);
final JsonArray jsonResourceTypes = jsonContent.getAsJsonArray("resourceTypes");
for (int i = 0; i < jsonResourceTypes.size(); ++i) {
Object obj = jsonResourceTypes.get(i);
if (obj instanceof JsonObject) {
JsonObject jsonResourceType = (JsonObject) obj;
String resourceType = jsonResourceType.get("resourceType").getAsString();
if (resourceType.equalsIgnoreCase("components")) {
JsonArray jsonLocations = jsonResourceType.getAsJsonArray("locations");
return gson.fromJson(jsonLocations, new ArrayList().getClass());
}
}
}
} catch (IOException | JsonParseException e) {
Log.error(e);
}
return Collections.emptyList();
}
use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.
the class CreateArmStorageAccountForm method fillRegions.
private void fillRegions() {
Subscription subs = (Subscription) subscriptionComboBox.getData(subscriptionComboBox.getText());
final List<Region> locations = Azure.az(AzureAccount.class).listRegions(subs.getId());
AzureTaskManager.getInstance().runLater(() -> {
for (Region location : locations) {
regionComboBox.add(location.getLabel());
regionComboBox.setData(location.getLabel(), location);
}
if (locations.size() > 0) {
regionComboBox.select(0);
}
});
}
use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.
the class CreateArmStorageAccountForm method loadRegionsAndGroups.
public void loadRegionsAndGroups() {
subscriptionComboBox.getData(subscriptionComboBox.getText()).toString();
Subscription subs = (Subscription) subscriptionComboBox.getData(subscriptionComboBox.getText());
if (subs != null) {
AzureTaskManager.getInstance().runInBackground("Loading Available Locations...", () -> {
try {
// warm cache
Azure.az(AzureAccount.class).listRegions(subs.getId());
AzureTaskManager.getInstance().runLater(new Runnable() {
@Override
public void run() {
fillRegions();
fillGroups();
}
});
} catch (Exception ex) {
PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), Messages.err, "Error loading locations", ex);
}
});
} else {
fillRegions();
fillGroups();
}
}
use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.
the class CreateArmStorageAccountForm method fillGroups.
public void fillGroups() {
final Subscription subs = (Subscription) subscriptionComboBox.getData(subscriptionComboBox.getText());
List<ResourceGroup> resourceGroups = Azure.az(AzureGroup.class).list(subs.getId(), true);
List<String> sortedGroups = resourceGroups.stream().map(ResourceGroup::getName).sorted().collect(Collectors.toList());
AzureTaskManager.getInstance().runLater(new Runnable() {
@Override
public void run() {
final Vector<Object> vector = new Vector<Object>();
vector.addAll(sortedGroups);
resourceGroupViewer.setInput(vector);
if (sortedGroups.size() > 0) {
resourceGrpCombo.select(0);
}
}
});
}
use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.
the class AppInsightsMngmtPanel method refreshDataForDialog.
public static void refreshDataForDialog() {
try {
Project project = PluginUtil.getSelectedProject();
if (AuthMethodManager.getInstance().isSignedIn()) {
List<Subscription> subList = AuthMethodManager.getInstance().getAzureManager().getSelectedSubscriptions();
// authenticated using AD. Proceed for updating application insights registry.
updateApplicationInsightsResourceRegistry(subList, project);
} else {
// Neither clear subscription list nor show sign in dialog as user may just want to add key manually.
keeepManuallyAddedList(project);
}
} catch (Exception ex) {
AzurePlugin.log(ex.getMessage());
}
}
Aggregations