use of com.microsoft.azuretools.telemetry.TelemetryConstants.ACCOUNT 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());
}));
}
});
}
}
use of com.microsoft.azuretools.telemetry.TelemetryConstants.ACCOUNT in project azure-tools-for-java by Microsoft.
the class AzureSignInAction method signInIfNotSignedInInternal.
private static Mono<Boolean> signInIfNotSignedInInternal(Project project) {
final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
final IDeviceLoginUI deviceLoginUI = new DeviceLoginUI();
return Mono.create(sink -> AzureTaskManager.getInstance().runLater(() -> {
final AuthConfiguration auth;
try {
auth = showSignInWindowAndGetAuthConfiguration(project);
} catch (InterruptedException e) {
sink.error(e);
return;
}
Single<AuthMethodDetails> single;
if (auth.getType() != AuthType.DEVICE_CODE) {
single = loginNonDeviceCodeSingle(auth);
} else {
single = loginDeviceCodeSingle().map(account -> {
AzureTaskManager.getInstance().runLater(() -> deviceLoginUI.promptDeviceCode(account.getDeviceCode()));
CompletableFuture<AuthMethodDetails> future = account.continueLogin().map(ac -> fromAccountEntity(ac.getEntity())).doFinally(signal -> deviceLoginUI.closePrompt()).toFuture();
deviceLoginUI.setFuture(future);
try {
return future.get();
} catch (Throwable ex) {
if (!(ex instanceof CancellationException)) {
ex.printStackTrace();
ErrorWindow.show(project, ex.getMessage(), SIGN_IN_ERROR);
}
return new AuthMethodDetails();
}
});
}
single.subscribeOn(rx.schedulers.Schedulers.io()).subscribe(authMethodDetails -> {
if (authMethodManager.isSignedIn()) {
authMethodManager.setAuthMethodDetails(authMethodDetails);
}
sink.success(authMethodManager.isSignedIn());
}, sink::error);
}));
}
Aggregations