Search in sources :

Example 1 with AzureAccount

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();
}
Also used : DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 2 with AzureAccount

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();
}
Also used : HashMap(java.util.HashMap) DefaultTableModel(javax.swing.table.DefaultTableModel) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount)

Example 3 with AzureAccount

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();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) HashMap(java.util.HashMap) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with AzureAccount

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();
}
Also used : DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 5 with AzureAccount

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());
                }));
            }
        });
    }
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) Azure(com.microsoft.azure.toolkit.lib.Azure) AzureBundle.message(com.microsoft.intellij.ui.messages.AzureBundle.message) DataKeys(com.intellij.openapi.actionSystem.DataKeys) ACCOUNT(com.microsoft.azuretools.telemetry.TelemetryConstants.ACCOUNT) StringUtils(org.apache.commons.lang3.StringUtils) IDeviceLoginUI(com.microsoft.azuretools.adauth.IDeviceLoginUI) DeviceLoginUI(com.microsoft.intellij.ui.DeviceLoginUI) AzureIconSymbol(com.microsoft.tooling.msservices.serviceexplorer.AzureIconSymbol) AzureCloud(com.microsoft.azure.toolkit.lib.auth.AzureCloud) Single(rx.Single) UIHelperImpl(com.microsoft.intellij.helpers.UIHelperImpl) Duration(java.time.Duration) Map(java.util.Map) AzureAnAction(com.microsoft.intellij.AzureAnAction) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) IdentityAzureManager(com.microsoft.azuretools.sdkmanage.IdentityAzureManager) AccountEntity(com.microsoft.azure.toolkit.lib.auth.model.AccountEntity) AZURE_ENVIRONMENT(com.microsoft.azuretools.telemetry.TelemetryConstants.AZURE_ENVIRONMENT) Logger(com.intellij.openapi.diagnostic.Logger) JFrame(javax.swing.JFrame) MsalClientException(com.microsoft.aad.msal4j.MsalClientException) AzureLoginHelper(com.microsoft.intellij.util.AzureLoginHelper) ProgressManager(com.intellij.openapi.progress.ProgressManager) CancellationException(java.util.concurrent.CancellationException) AuthMethod(com.microsoft.azuretools.authmanage.AuthMethod) WindowManager(com.intellij.openapi.wm.WindowManager) ErrorType(com.microsoft.azuretools.telemetrywrapper.ErrorType) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AuthConfiguration(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration) SIGNIN_METHOD(com.microsoft.azuretools.telemetry.TelemetryConstants.SIGNIN_METHOD) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SIGNIN(com.microsoft.azuretools.telemetry.TelemetryConstants.SIGNIN) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Optional(java.util.Optional) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) Lombok(lombok.Lombok) NotNull(org.jetbrains.annotations.NotNull) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) AzureEnvironmentUtils(com.microsoft.azure.toolkit.lib.auth.util.AzureEnvironmentUtils) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) AzureIconLoader(com.microsoft.intellij.helpers.AzureIconLoader) Exceptions(rx.exceptions.Exceptions) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) SignInWindow(com.microsoft.intellij.ui.SignInWindow) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Project(com.intellij.openapi.project.Project) DefaultLoader(com.microsoft.tooling.msservices.components.DefaultLoader) Schedulers(reactor.core.scheduler.Schedulers) ServicePrincipalLoginDialog(com.microsoft.intellij.ui.ServicePrincipalLoginDialog) SIGNOUT(com.microsoft.azuretools.telemetry.TelemetryConstants.SIGNOUT) AuthMethodDetails(com.microsoft.azuretools.authmanage.models.AuthMethodDetails) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) Mono(reactor.core.publisher.Mono) ErrorWindow(com.microsoft.intellij.ui.ErrorWindow) Flux(reactor.core.publisher.Flux) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) SignInOutAction(com.microsoft.intellij.serviceexplorer.azure.SignInOutAction) TelemetryManager(com.microsoft.azuretools.telemetrywrapper.TelemetryManager) AuthType(com.microsoft.azure.toolkit.lib.auth.model.AuthType) JFrame(javax.swing.JFrame) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager)

Aggregations

AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)9 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)5 HashMap (java.util.HashMap)5 DeviceCodeAccount (com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount)4 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)4 AccountEntity (com.microsoft.azure.toolkit.lib.auth.model.AccountEntity)3 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)3 AuthMethodDetails (com.microsoft.azuretools.authmanage.models.AuthMethodDetails)3 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 MsalClientException (com.microsoft.aad.msal4j.MsalClientException)2 Azure (com.microsoft.azure.toolkit.lib.Azure)2 AzureCloud (com.microsoft.azure.toolkit.lib.auth.AzureCloud)2 AuthConfiguration (com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration)2 AuthType (com.microsoft.azure.toolkit.lib.auth.model.AuthType)2 AzureEnvironmentUtils (com.microsoft.azure.toolkit.lib.auth.util.AzureEnvironmentUtils)2 AzureMessager (com.microsoft.azure.toolkit.lib.common.messager.AzureMessager)2 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)2 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 AzureOperationBundle (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle)2