Search in sources :

Example 21 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class SubscriptionsDialog method setSubscriptionDetails.

private void setSubscriptionDetails() {
    try {
        sdl = subscriptionManager.getSubscriptionDetails();
        for (SubscriptionDetail sd : sdl) {
            TableItem item = new TableItem(table, SWT.NULL);
            item.setText(new String[] { sd.getSubscriptionName(), sd.getSubscriptionId() });
            item.setChecked(sd.isSelected());
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "setSubscriptionDetails@SubscriptionDialog", ex));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TableItem(org.eclipse.swt.widgets.TableItem) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) IOException(java.io.IOException)

Example 22 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class SubscriptionsDialog method setSubscriptions.

private void setSubscriptions() {
    DefaultTableModel model = (DefaultTableModel) table.getModel();
    for (SubscriptionDetail sd : sdl) {
        model.addRow(new Object[] { sd.isSelected(), sd.getSubscriptionName(), sd.getSubscriptionId() });
    }
    model.fireTableDataChanged();
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail)

Example 23 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method fillAppServiceDetails.

private void fillAppServiceDetails() {
    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    int selectedRow = table.getSelectedRow();
    if (selectedRow >= 0) {
        String appServiceName = (String) tableModel.getValueAt(selectedRow, 0);
        WebAppDetails wad = webAppWebAppDetailsMap.get(appServiceName);
        SubscriptionDetail sd = wad.subscriptionDetail;
        AppServicePlan asp = wad.appServicePlan;
        StringBuilder sb = new StringBuilder();
        sb.append("<div style=\"margin: 7px 7px 7px 7px;\">");
        sb.append(String.format("App Service Name:&nbsp;<b>%s</b><br/>", appServiceName));
        sb.append(String.format("Subscription Name:&nbsp;<b>%s</b>;&nbsp;ID:&nbsp;<b>%s</b><br/>", sd.getSubscriptionName(), sd.getSubscriptionId()));
        String aspName = asp == null ? "N/A" : asp.name();
        String aspPricingTier = asp == null ? "N/A" : asp.pricingTier().toString();
        sb.append(String.format("App Service Plan Name:&nbsp;<b>%s</b>;&nbsp;Pricing Tier:&nbsp;<b>%s</b><br/>", aspName, aspPricingTier));
        String link = buildSiteLink(wad.webApp, null);
        sb.append(String.format("Link:&nbsp;<a href=\"%s\">%s</a>", link, link));
        sb.append("</div>");
        editorPaneAppServiceDetails.setText(sb.toString());
    }
//        listWebAppDetails.setModel(listModel);
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) DefaultTableModel(javax.swing.table.DefaultTableModel) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan)

Example 24 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail 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();
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) HashMap(java.util.HashMap) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) AccessTokenAzureManager(com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager) AdAuthManager(com.microsoft.azuretools.authmanage.AdAuthManager) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AuthCanceledException(com.microsoft.azuretools.adauth.AuthCanceledException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) LinkedList(java.util.LinkedList) List(java.util.List)

Example 25 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class SignInWindow method doCreateServicePrincipal.

private void doCreateServicePrincipal() {
    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();
        ProgressManager.getInstance().run(new Task.Modal(project, "Load Subscriptions Progress", true) {

            @Override
            public void run(ProgressIndicator progressIndicator) {
                progressIndicator.setText("Loading subscriptions...");
                try {
                    progressIndicator.setIndeterminate(true);
                    subscriptionManager.getSubscriptionDetails();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    //LOGGER.error("doCreateServicePrincipal::Task.Modal", ex);
                    ApplicationManager.getApplication().invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            ErrorWindow.show(project, ex.getMessage(), "Load Subscription Error");
                        }
                    });
                }
            }
        });
        SrvPriSettingsDialog d = SrvPriSettingsDialog.go(subscriptionManager.getSubscriptionDetails(), project);
        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(tidSidsMap, destinationFolder, project);
        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;
        }
        authFileTextField.setText(path);
        fileChooser.setCurrentDirectory(new File(destinationFolder));
    } catch (Exception ex) {
        ex.printStackTrace();
        //LOGGER.error("doCreateServicePrincipal", ex);
        ErrorWindow.show(project, ex.getMessage(), "Get Subscription Error");
    } finally {
        if (adAuthManager != null) {
            try {
                System.out.println(">> Signing out...");
                adAuthManager.signOut();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Task(com.intellij.openapi.progress.Task) HashMap(java.util.HashMap) AccessTokenAzureManager(com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager) AdAuthManager(com.microsoft.azuretools.authmanage.AdAuthManager) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) IOException(java.io.IOException) AuthCanceledException(com.microsoft.azuretools.adauth.AuthCanceledException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) LinkedList(java.util.LinkedList) List(java.util.List) File(java.io.File)

Aggregations

SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)52 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)17 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)13 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)13 IOException (java.io.IOException)9 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)7 Location (com.microsoft.azure.management.resources.Location)7 List (java.util.List)7 WebApp (com.microsoft.azure.management.appservice.WebApp)5 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Azure (com.microsoft.azure.management.Azure)4 Subscription (com.microsoft.azure.management.resources.Subscription)4 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)4 HashMap (java.util.HashMap)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 Label (org.eclipse.swt.widgets.Label)4 AccessTokenAzureManager (com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3