use of com.microsoft.azuretools.authmanage.SubscriptionManager in project azure-tools-for-java by Microsoft.
the class SubscriptionsDialog method refreshSubscriptions.
private void refreshSubscriptions() {
EventUtil.executeWithLog(ACCOUNT, GET_SUBSCRIPTIONS, (operation) -> {
AzureManager manager = AuthMethodManager.getInstance().getAzureManager();
if (manager == null) {
return;
}
final SubscriptionManager subscriptionManager = manager.getSubscriptionManager();
subscriptionManager.cleanSubscriptions();
Azure.az(AzureAccount.class).account().reloadSubscriptions().block();
SelectSubscriptionsAction.loadSubscriptions(subscriptionManager, project);
// System.out.println("refreshSubscriptions: calling getSubscriptionDetails()");
sdl = subscriptionManager.getSubscriptionDetails();
setSubscriptions();
// to notify subscribers
subscriptionManager.setSubscriptionDetails(sdl);
}, (ex) -> {
ex.printStackTrace();
ErrorWindow.show(project, ex.getMessage(), "Refresh Subscriptions Error");
});
}
use of com.microsoft.azuretools.authmanage.SubscriptionManager in project azure-tools-for-java by Microsoft.
the class SelectSubsriptionsCommandHandler method onSelectSubscriptions.
public static void onSelectSubscriptions(Shell parentShell) {
try {
AzureManager manager = AuthMethodManager.getInstance().getAzureManager();
if (manager == null) {
return;
}
SubscriptionManager sm = manager.getSubscriptionManager();
SubscriptionsDialog.go(parentShell, sm);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of com.microsoft.azuretools.authmanage.SubscriptionManager in project azure-tools-for-java by Microsoft.
the class AzureModule method composeName.
private static String composeName() {
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
if (AuthMethodManager.getInstance().isRestoringSignIn()) {
return BASE_MODULE_NAME + " (Signing In...)";
}
// not signed in
if (azureManager == null) {
return BASE_MODULE_NAME + " (Not Signed In)";
}
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
List<SubscriptionDetail> subscriptionDetails = subscriptionManager.getSubscriptionDetails();
List<SubscriptionDetail> selectedSubscriptions = subscriptionDetails.stream().filter(SubscriptionDetail::isSelected).collect(Collectors.toList());
return String.format("%s (%s)", BASE_MODULE_NAME, getAccountDescription(selectedSubscriptions));
} catch (AzureRuntimeException e) {
DefaultLoader.getUIHelper().showInfoNotification(ERROR_GETTING_SUBSCRIPTIONS_TITLE, ErrorEnum.getDisplayMessageByCode(e.getCode()));
} catch (Exception e) {
final String msg = String.format(ERROR_GETTING_SUBSCRIPTIONS_MESSAGE, e.getMessage());
DefaultLoader.getUIHelper().showException(msg, e, ERROR_GETTING_SUBSCRIPTIONS_TITLE, false, true);
}
return BASE_MODULE_NAME;
}
use of com.microsoft.azuretools.authmanage.SubscriptionManager in project azure-tools-for-java by Microsoft.
the class SynapseCosmosSparkPool method getConfigurationInfo.
@Override
public void getConfigurationInfo() throws IOException {
if (!isConfigInfoAvailable()) {
// Extract Subscription ID from ADLA resource ID
// Sample adlaResouceId: /subscriptions/a00b00a0-00a0-0000-b000-a000b0a00000/resourceGroups/testRG/providers/Microsoft.DataLakeAnalytics/accounts/testAccount
Matcher matcher = ADLA_RESOURCE_ID_PATTERN.matcher(getAdlaResourceId());
if (!matcher.matches()) {
String errorMsg = String.format("ADLA resource ID doesn't match with pattern. AdlaResourceId: %s. Pattern: %s", getAdlaResourceId(), ADLA_RESOURCE_ID_PATTERN);
throw new IOException(errorMsg);
}
String subscriptionId = matcher.group("sid");
// Get SubscriptionDetail from subscription ID
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
SubscriptionDetail subscription = subscriptionManager.getSubscriptionIdToSubscriptionDetailsMap().getOrDefault(subscriptionId, null);
if (subscription == null) {
throw new IOException("User has no permission to access subscription " + subscriptionId + ".");
}
// Get ADLA account details through Azure REST API
AzureHttpObservable managementHttp = new AzureManagementHttpObservable(subscription, ApiVersion.VERSION);
String resourceManagerEndpoint = CommonSettings.getAdEnvironment().resourceManagerEndpoint();
URI accountDetailUri = URI.create(resourceManagerEndpoint).resolve(getAdlaResourceId());
AzureSparkServerlessAccount azureSparkServerlessAccount = managementHttp.withUuidUserAgent().get(accountDetailUri.toString(), null, null, DataLakeAnalyticsAccount.class).doOnError(err -> log().warn("Error getting ADLA account details with error: " + err.getMessage())).map(dataLakeAnalyticsAccount -> new AzureSparkServerlessAccount(subscription, URI.create("https://" + dataLakeAnalyticsAccount.endpoint()), dataLakeAnalyticsAccount.name()).setDetailResponse(dataLakeAnalyticsAccount)).subscribeOn(Schedulers.io()).toBlocking().singleOrDefault(null);
// Get default storage account info from ADLA account
String storageRootPath = azureSparkServerlessAccount.getStorageRootPath();
IHDIStorageAccount adlsGen1StorageAccount = storageRootPath == null ? null : new AzureSparkCosmosCluster.StorageAccount(azureSparkServerlessAccount.getDetailResponse().defaultDataLakeStoreAccount(), storageRootPath, azureSparkServerlessAccount.getSubscription().getSubscriptionId());
synchronized (this) {
if (!isConfigInfoAvailable()) {
this.http = managementHttp;
this.storageAccount = adlsGen1StorageAccount;
isConfigInfoAvailable = true;
}
}
}
}
use of com.microsoft.azuretools.authmanage.SubscriptionManager in project azure-tools-for-java by Microsoft.
the class SignInDialog method doCreateServicePrincipal.
private void doCreateServicePrincipal() {
setErrorMessage(null);
AdAuthManager adAuthManager = null;
try {
adAuthManager = AdAuthManager.getInstance();
if (adAuthManager.isSignedIn()) {
adAuthManager.signOut();
}
signInAsync();
if (!adAuthManager.isSignedIn()) {
// canceled by the user
System.out.println(">> Canceled by the user");
return;
}
AccessTokenAzureManager accessTokenAzureManager = new AccessTokenAzureManager();
SubscriptionManager subscriptionManager = accessTokenAzureManager.getSubscriptionManager();
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Getting Subscription List...", IProgressMonitor.UNKNOWN);
try {
subscriptionManager.getSubscriptionDetails();
} catch (Exception ex) {
System.out.println("run@ProgressDialog@doCreateServicePrincipal@SignInDialog: " + ex.getMessage());
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@doCreateServicePrincipal@SignInDialogg", ex));
}
}
};
new ProgressMonitorDialog(this.getShell()).run(true, false, op);
SrvPriSettingsDialog d = SrvPriSettingsDialog.go(this.getShell(), subscriptionManager.getSubscriptionDetails());
List<SubscriptionDetail> subscriptionDetailsUpdated;
String destinationFolder;
if (d != null) {
subscriptionDetailsUpdated = d.getSubscriptionDetails();
destinationFolder = d.getDestinationFolder();
} else {
System.out.println(">> Canceled by the user");
return;
}
Map<String, List<String>> tidSidsMap = new HashMap<>();
for (SubscriptionDetail sd : subscriptionDetailsUpdated) {
if (sd.isSelected()) {
System.out.format(">> %s\n", sd.getSubscriptionName());
String tid = sd.getTenantId();
List<String> sidList;
if (!tidSidsMap.containsKey(tid)) {
sidList = new LinkedList<>();
} else {
sidList = tidSidsMap.get(tid);
}
sidList.add(sd.getSubscriptionId());
tidSidsMap.put(tid, sidList);
}
}
SrvPriCreationStatusDialog d1 = SrvPriCreationStatusDialog.go(this.getShell(), tidSidsMap, destinationFolder);
if (d1 == null) {
System.out.println(">> Canceled by the user");
return;
}
String path = d1.getSelectedAuthFilePath();
if (path == null) {
System.out.println(">> No file was created");
return;
}
textAuthenticationFilePath.setText(path);
fileDialog.setFilterPath(destinationFolder);
} catch (Exception ex) {
ex.printStackTrace();
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "doCreateServicePrincipal@SignInDialog", ex));
} finally {
if (adAuthManager != null) {
adAuthManager.signOut();
}
}
}
Aggregations