use of com.microsoft.azure.toolkit.lib.auth.AzureAccount in project azure-tools-for-java by Microsoft.
the class SignInCommandHandler method loginDeviceCodeSingle.
private static Single<DeviceCodeAccount> loginDeviceCodeSingle() {
final AzureString title = AzureOperationBundle.title("account.sign_in");
final AzureTask<DeviceCodeAccount> deviceCodeTask = new AzureTask<>(null, title, true, () -> {
final AzureAccount az = Azure.az(AzureAccount.class);
return (DeviceCodeAccount) checkCanceled(null, az.loginAsync(AuthType.DEVICE_CODE, true), () -> {
throw Lombok.sneakyThrow(new InterruptedException("user cancel"));
});
});
return AzureTaskManager.getInstance().runInBackgroundAsObservable(deviceCodeTask).toSingle();
}
use of com.microsoft.azure.toolkit.lib.auth.AzureAccount in project azure-tools-for-java by Microsoft.
the class SubscriptionsDialog method doOKAction.
@Override
protected void doOKAction() {
DefaultTableModel model = (DefaultTableModel) table.getModel();
int rc = model.getRowCount();
int unselectedCount = 0;
for (int ri = 0; ri < rc; ++ri) {
boolean selected = (boolean) model.getValueAt(ri, CHECKBOX_COLUMN);
if (!selected) {
unselectedCount++;
}
}
if (rc != 0 && unselectedCount == rc) {
DefaultLoader.getUIHelper().showMessageDialog(contentPane, "Please select at least one subscription", "Subscription dialog info", Messages.getInformationIcon());
return;
}
for (int ri = 0; ri < rc; ++ri) {
boolean selected = (boolean) model.getValueAt(ri, CHECKBOX_COLUMN);
this.sdl.get(ri).setSelected(selected);
}
List<String> selectedIds = this.sdl.stream().filter(SubscriptionDetail::isSelected).map(SubscriptionDetail::getSubscriptionId).collect(Collectors.toList());
IdentityAzureManager.getInstance().selectSubscriptionByIds(selectedIds);
IdentityAzureManager.getInstance().getSubscriptionManager().notifySubscriptionListChanged();
Mono.fromCallable(() -> {
AzureAccount az = Azure.az(AzureAccount.class);
selectedIds.stream().limit(5).forEach(sid -> {
// pr-load regions
az.listRegions(sid);
});
return 1;
}).subscribeOn(Schedulers.boundedElastic()).subscribe();
final Map<String, String> properties = new HashMap<>();
properties.put("subsCount", String.valueOf(rc));
properties.put("selectedSubsCount", String.valueOf(rc - unselectedCount));
EventUtil.logEvent(EventType.info, ACCOUNT, SELECT_SUBSCRIPTIONS, null);
super.doOKAction();
}
use of com.microsoft.azure.toolkit.lib.auth.AzureAccount in project azure-tools-for-java by Microsoft.
the class SubscriptionsDialog method okPressed.
@Override
public void okPressed() {
EventUtil.logEvent(EventType.info, ACCOUNT, SELECT_SUBSCRIPTIONS, null);
TableItem[] tia = table.getItems();
int rc = tia.length;
int chekedCount = 0;
for (TableItem ti : tia) {
if (ti.getChecked()) {
chekedCount++;
}
}
if (chekedCount == 0) {
this.setErrorMessage("Select at least one subscription");
return;
}
for (int i = 0; i < tia.length; ++i) {
this.sdl.get(i).setSelected(tia[i].getChecked());
}
try {
subscriptionManager.setSubscriptionDetails(sdl);
} catch (Exception ex) {
ex.printStackTrace();
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "okPressed@SubscriptionDialog", ex));
}
List<String> selectedIds = this.sdl.stream().filter(SubscriptionDetail::isSelected).map(SubscriptionDetail::getSubscriptionId).collect(Collectors.toList());
IdentityAzureManager.getInstance().selectSubscriptionByIds(selectedIds);
IdentityAzureManager.getInstance().getSubscriptionManager().notifySubscriptionListChanged();
Mono.fromCallable(() -> {
AzureAccount az = Azure.az(AzureAccount.class);
selectedIds.stream().limit(5).forEach(sid -> {
// pr-load regions
az.listRegions(sid);
});
return 1;
}).subscribeOn(Schedulers.boundedElastic()).subscribe();
final Map<String, String> properties = new HashMap<>();
properties.put("subsCount", String.valueOf(rc));
properties.put("selectedSubsCount", String.valueOf(chekedCount));
EventUtil.logEvent(EventType.info, ACCOUNT, SELECT_SUBSCRIPTIONS, null);
super.okPressed();
}
use of com.microsoft.azure.toolkit.lib.auth.AzureAccount in project azure-tools-for-java by Microsoft.
the class AzureSignInAction method loginDeviceCodeSingle.
private static Single<DeviceCodeAccount> loginDeviceCodeSingle() {
final AzureString title = AzureOperationBundle.title("account.sign_in");
final AzureTask<DeviceCodeAccount> deviceCodeTask = new AzureTask<>(null, title, true, () -> {
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
indicator.setIndeterminate(true);
final AzureAccount az = Azure.az(AzureAccount.class);
return (DeviceCodeAccount) checkCanceled(indicator, az.loginAsync(AuthType.DEVICE_CODE, true), () -> {
throw Lombok.sneakyThrow(new InterruptedException("user cancel"));
});
});
return AzureTaskManager.getInstance().runInBackgroundAsObservable(deviceCodeTask).toSingle();
}
use of com.microsoft.azure.toolkit.lib.auth.AzureAccount in project azure-tools-for-java by Microsoft.
the class AzureSignInAction method onAzureSignIn.
public static void onAzureSignIn(Project project) {
JFrame frame = WindowManager.getInstance().getFrame(project);
AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
boolean isSignIn = authMethodManager.isSignedIn();
if (isSignIn) {
boolean res = DefaultLoader.getUIHelper().showYesNoDialog(frame.getRootPane(), getSignOutWarningMessage(authMethodManager), "Azure Sign Out", AzureIconLoader.loadIcon(AzureIconSymbol.Common.AZURE));
if (res) {
EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
authMethodManager.signOut();
});
}
} else {
signInIfNotSignedIn(project).subscribe(isLoggedIn -> {
if (isLoggedIn) {
AzureAccount az = Azure.az(AzureAccount.class);
AzureTaskManager.getInstance().runOnPooledThread(() -> authMethodManager.getAzureManager().getSelectedSubscriptions().stream().limit(5).forEach(s -> {
// pre-load regions;
az.listRegions(s.getId());
}));
}
});
}
}
Aggregations