Search in sources :

Example 1 with Azure

use of com.microsoft.azure.toolkit.lib.Azure 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)

Example 2 with Azure

use of com.microsoft.azure.toolkit.lib.Azure in project azure-tools-for-java by Microsoft.

the class CreateDeploymentForm method doOKAction.

@Override
protected void doOKAction() {
    deploymentName = deploymentNameTextField.getText();
    final AzureString title = AzureOperationBundle.title("arm|deployment.deploy", deploymentName);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        EventUtil.executeWithLog(TelemetryConstants.ARM, TelemetryConstants.CREATE_DEPLOYMENT, (operation -> {
            Subscription subs = (Subscription) subscriptionCb.getSelectedItem();
            com.microsoft.azure.management.Azure azure = AuthMethodManager.getInstance().getAzureClient(subs.getId());
            WithTemplate template;
            if (createNewRgButton.isSelected()) {
                rgName = rgNameTextFiled.getText();
                final Region region = (Region) regionCb.getSelectedItem();
                template = azure.deployments().define(deploymentName).withNewResourceGroup(rgNameTextFiled.getText(), com.microsoft.azure.management.resources.fluentcore.arm.Region.fromName(region.getName()));
            } else {
                ResourceGroup rg = (ResourceGroup) rgNameCb.getSelectedItem();
                List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance().getDeploymentByRgName(subs.getId(), rg.getName());
                boolean isExist = deployments.parallelStream().anyMatch(deployment -> deployment.getResource().name().equals(deploymentName));
                if (isExist) {
                    throw new RuntimeException(DUPLICATED_DEPLOYMENT_NAME);
                }
                rgName = rg.getName();
                template = azure.deployments().define(deploymentName).withExistingResourceGroup(rg.getName());
            }
            String fileText = templateTextField.getText();
            String content = IOUtils.toString(new FileReader(fileText));
            String parametersPath = parametersTextField.getText();
            String parameters = StringUtils.isEmpty(parametersPath) ? "{}" : IOUtils.toString(new FileReader(parametersPath));
            parameters = DeploymentUtils.parseParameters(parameters);
            template.withTemplate(content).withParameters(parameters).withMode(DeploymentMode.INCREMENTAL).create();
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
            updateUI();
        }), (ex) -> {
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_FAIL + ", " + ex.getMessage(), MessageType.ERROR);
            updateUI();
        });
    }));
    close(DialogWrapper.OK_EXIT_CODE, true);
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) Azure(com.microsoft.azure.toolkit.lib.Azure) NOTIFY_CREATE_DEPLOYMENT_FAIL(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_FAIL) MessageType(com.intellij.openapi.ui.MessageType) SimpleListCellRenderer(com.intellij.ui.SimpleListCellRenderer) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) StringUtils(org.apache.commons.lang3.StringUtils) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) NOTIFY_CREATE_DEPLOYMENT_SUCCESS(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_SUCCESS) StatusBar(com.intellij.openapi.wm.StatusBar) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) ResourceManagementNode(com.microsoft.tooling.msservices.serviceexplorer.azure.arm.ResourceManagementNode) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) JComboBox(javax.swing.JComboBox) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) WindowManager(com.intellij.openapi.wm.WindowManager) JRadioButton(javax.swing.JRadioButton) RegionComboBox(com.microsoft.azure.toolkit.intellij.common.component.RegionComboBox) IOUtils(org.apache.commons.io.IOUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureMvpModel(com.microsoft.azuretools.core.mvp.model.AzureMvpModel) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) JPanel(javax.swing.JPanel) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) JTextField(javax.swing.JTextField) AzureUIRefreshCore(com.microsoft.azuretools.utils.AzureUIRefreshCore) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Region(com.microsoft.azure.toolkit.lib.common.model.Region) DeploymentMode(com.microsoft.azure.management.resources.DeploymentMode) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) JComponent(javax.swing.JComponent) Deployment(com.microsoft.azure.management.resources.Deployment) ButtonGroup(javax.swing.ButtonGroup) UIUtils(com.microsoft.intellij.ui.util.UIUtils) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) JList(javax.swing.JList) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) EventType(com.microsoft.azuretools.telemetrywrapper.EventType) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) JLabel(javax.swing.JLabel) FileReader(java.io.FileReader) SubscriptionComboBox(com.microsoft.azure.toolkit.intellij.common.component.SubscriptionComboBox) BROWSE_TEMPLATE_SAMPLES(com.microsoft.azuretools.telemetry.TelemetryConstants.BROWSE_TEMPLATE_SAMPLES) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) Region(com.microsoft.azure.toolkit.lib.common.model.Region) FileReader(java.io.FileReader) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

Example 3 with Azure

use of com.microsoft.azure.toolkit.lib.Azure in project azure-tools-for-java by Microsoft.

the class SignInCommandHandler method onAzureSignIn.

private void onAzureSignIn(Shell shell) {
    final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
    boolean isSignIn = authMethodManager.isSignedIn();
    if (isSignIn) {
        boolean res = showYesNoDialog(shell, "Azure Sign Out", SignOutCommandHandler.getSignOutWarningMessage(authMethodManager));
        if (res) {
            EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
                authMethodManager.signOut();
            });
        }
    } else {
        signInIfNotSignedIn(shell).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) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) StringUtils(org.apache.commons.lang3.StringUtils) IDeviceLoginUI(com.microsoft.azuretools.adauth.IDeviceLoginUI) AzureCloud(com.microsoft.azure.toolkit.lib.auth.AzureCloud) Single(rx.Single) PluginUtil(com.microsoft.azuretools.core.utils.PluginUtil) Duration(java.time.Duration) Map(java.util.Map) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) IdentityAzureManager(com.microsoft.azuretools.sdkmanage.IdentityAzureManager) AccountEntity(com.microsoft.azure.toolkit.lib.auth.model.AccountEntity) MsalClientException(com.microsoft.aad.msal4j.MsalClientException) CancellationException(java.util.concurrent.CancellationException) AuthMethod(com.microsoft.azuretools.authmanage.AuthMethod) ErrorType(com.microsoft.azuretools.telemetrywrapper.ErrorType) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AuthConfiguration(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration) AzureTaskContext(com.microsoft.azure.toolkit.lib.common.task.AzureTaskContext) Window(org.eclipse.jface.window.Window) List(java.util.List) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) DeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount) SWT(org.eclipse.swt.SWT) DeviceLoginWindow(com.microsoft.azuretools.core.ui.DeviceLoginWindow) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) Lombok(lombok.Lombok) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) SignInDialog(com.microsoft.azuretools.core.ui.SignInDialog) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) AzureAbstractHandler(com.microsoft.azuretools.core.utils.AzureAbstractHandler) AzureEnvironmentUtils(com.microsoft.azure.toolkit.lib.auth.util.AzureEnvironmentUtils) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Exceptions(rx.exceptions.Exceptions) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) 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) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) ServicePrincipalLoginDialog(com.microsoft.azuretools.core.ui.ServicePrincipalLoginDialog) ErrorWindow(com.microsoft.azuretools.core.ui.ErrorWindow) Schedulers(reactor.core.scheduler.Schedulers) AuthMethodDetails(com.microsoft.azuretools.authmanage.models.AuthMethodDetails) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) Shell(org.eclipse.swt.widgets.Shell) Mono(reactor.core.publisher.Mono) ExecutionException(org.eclipse.core.commands.ExecutionException) Flux(reactor.core.publisher.Flux) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) TelemetryManager(com.microsoft.azuretools.telemetrywrapper.TelemetryManager) MessageBox(org.eclipse.swt.widgets.MessageBox) AuthType(com.microsoft.azure.toolkit.lib.auth.model.AuthType) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager)

Example 4 with Azure

use of com.microsoft.azure.toolkit.lib.Azure in project azure-tools-for-java by Microsoft.

the class AzurePlugin method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    // read legacy settings from old data.xml
    final String installationId = "wangmi-azure-intellij-plugin-base";
    final String pluginVersion = "0.0.1-SNAPSHOT";
    // check non-empty for valid data.xml
    if (StringUtils.isNoneBlank(installationId, pluginVersion)) {
        final IntellijStore.AzureConfigurationData config = IntellijStore.getInstance().getState();
        IntellijStore.getInstance().loadState(config);
    }
    final IntellijStore.AzureConfigurationData config = IntellijStore.getInstance().getState();
    String installationID = InstallationIdUtils.getHashMac();
    if (StringUtils.isBlank(installationID)) {
        installationID = StringUtils.firstNonBlank(InstallationIdUtils.getHashMac(), InstallationIdUtils.hash(PermanentInstallationID.get()));
    }
    final String userAgent = String.format(USER_AGENT, PLUGIN_VERSION, installationID);
    Azure.az().config().setLogLevel("NONE");
    Azure.az().config().setUserAgent(userAgent);
    final AnAction action = ActionManager.getInstance().getAction(WhatsNewAction.ID);
    final DataContext context = dataId -> CommonDataKeys.PROJECT.getName().equals(dataId) ? project : null;
    AzureTaskManager.getInstance().runLater(() -> ActionUtil.invokeAction(action, context, "AzurePluginStartupActivity", null, null));
}
Also used : Azure(com.microsoft.azure.toolkit.lib.Azure) WhatsNewAction(com.microsoft.azure.toolkit.intellij.common.action.WhatsNewAction) DataContext(com.intellij.openapi.actionSystem.DataContext) PermanentInstallationID(com.intellij.openapi.application.PermanentInstallationID) ActionUtil(com.intellij.openapi.actionSystem.ex.ActionUtil) StartupActivity(com.intellij.openapi.startup.StartupActivity) PluginManagerCore(com.intellij.ide.plugins.PluginManagerCore) PlatformUtils(com.intellij.util.PlatformUtils) AnAction(com.intellij.openapi.actionSystem.AnAction) StringUtils(org.apache.commons.lang3.StringUtils) SystemInfo(com.intellij.openapi.util.SystemInfo) IntellijStore(com.microsoft.azure.toolkit.intellij.common.settings.IntellijStore) ActionManager(com.intellij.openapi.actionSystem.ActionManager) InstallationIdUtils(com.microsoft.azure.toolkit.lib.common.utils.InstallationIdUtils) Objects(java.util.Objects) PluginStateListener(com.intellij.ide.plugins.PluginStateListener) EventListenerList(javax.swing.event.EventListenerList) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) PluginId(com.intellij.openapi.extensions.PluginId) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) DataContext(com.intellij.openapi.actionSystem.DataContext) IntellijStore(com.microsoft.azure.toolkit.intellij.common.settings.IntellijStore) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

Azure (com.microsoft.azure.toolkit.lib.Azure)4 AzureTaskManager (com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager)4 StringUtils (org.apache.commons.lang3.StringUtils)4 Project (com.intellij.openapi.project.Project)3 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)3 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)3 AzureOperationBundle (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle)3 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)3 AuthMethodManager (com.microsoft.azuretools.authmanage.AuthMethodManager)3 Logger (com.intellij.openapi.diagnostic.Logger)2 WindowManager (com.intellij.openapi.wm.WindowManager)2 MsalClientException (com.microsoft.aad.msal4j.MsalClientException)2 AzureCloud (com.microsoft.azure.toolkit.lib.auth.AzureCloud)2 DeviceCodeAccount (com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount)2 AccountEntity (com.microsoft.azure.toolkit.lib.auth.model.AccountEntity)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 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)2 TelemetryConstants (com.microsoft.azuretools.telemetry.TelemetryConstants)2