Search in sources :

Example 41 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsNewDialog method populateResourceGroupValues.

private void populateResourceGroupValues(String subId, String valtoSet) {
    try {
        com.microsoft.azuretools.sdkmanage.AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        Azure azure = azureManager.getAzure(subId);
        List<com.microsoft.azure.management.resources.ResourceGroup> groups = azure.resourceGroups().list();
        List<String> groupStringList = groups.stream().map(com.microsoft.azure.management.resources.ResourceGroup::name).collect(Collectors.toList());
        if (groupStringList.size() > 0) {
            String[] groupArray = groupStringList.toArray(new String[groupStringList.size()]);
            resourceGrpCombo.removeAll();
            resourceGrpCombo.setItems(groupArray);
            if (valtoSet.isEmpty() || !groupStringList.contains(valtoSet)) {
                resourceGrpCombo.setText(groupArray[0]);
            } else {
                resourceGrpCombo.setText(valtoSet);
            }
        }
    } catch (Exception ex) {
        Activator.getDefault().log(Messages.getValuesErrMsg, ex);
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager)

Example 42 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class AzureSDKManager method getApplicationInsightsResources.

public static List<Resource> getApplicationInsightsResources(@NotNull SubscriptionDetail subscription) throws Exception {
    AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    if (azureManager == null) {
        // not signed in
        return null;
    }
    String tenantId = subscription.getTenantId();
    return getApplicationManagementClient(tenantId, azureManager.getAccessToken(tenantId)).getResources(subscription.getSubscriptionId());
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager)

Example 43 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class CreateNewDockerHostAction method actionPerformed.

@Override
public void actionPerformed(NodeActionEvent event) {
    try {
        if (!SignInCommandHandler.doSignIn(PluginUtil.getParentShell()))
            return;
        IProject project;
        Shell shell = PluginUtil.getParentShell();
        try {
            project = AzureDockerUIResources.getCurrentSelectedProject();
        } catch (Exception Ignored) {
            project = null;
        }
        if (project == null) {
            project = (IProject) dockerHostModule.getProject();
        }
        AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureAuthManager == null) {
            return;
        }
        AzureDockerHostsManager dockerManager = AzureDockerHostsManager.getAzureDockerHostsManager(azureAuthManager);
        if (!dockerManager.isInitialized()) {
            AzureDockerUIResources.updateAzureResourcesWithProgressDialog(shell, project);
            if (AzureDockerUIResources.CANCELED) {
                return;
            }
            dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(null);
        }
        if (dockerManager.getSubscriptionsMap().isEmpty()) {
            PluginUtil.displayErrorDialog(shell, "Create Docker Host", "Must select an Azure subscription first");
            return;
        }
        AzureNewDockerWizard newDockerWizard = new AzureNewDockerWizard(project, dockerManager);
        WizardDialog createNewDockerHostDialog = new AzureWizardDialog(shell, newDockerWizard);
        if (createNewDockerHostDialog.open() == Window.OK) {
            newDockerWizard.createHost();
        }
    } catch (Exception ex1) {
        log.log(Level.SEVERE, "actionPerformed", ex1);
        ex1.printStackTrace();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) AzureNewDockerWizard(com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerWizard) AzureDockerHostsManager(com.microsoft.azure.docker.AzureDockerHostsManager) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IProject(org.eclipse.core.resources.IProject)

Example 44 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class SelectSubscriptionsAction method onShowSubscriptions.

public static void onShowSubscriptions(Project project) {
    JFrame frame = WindowManager.getInstance().getFrame(project);
    try {
        //Project project = ProjectManager.getInstance().getDefaultProject();();
        AzureManager manager = AuthMethodManager.getInstance().getAzureManager();
        if (manager == null) {
            return;
        }
        final SubscriptionManager subscriptionManager = manager.getSubscriptionManager();
        updateSubscriptionWithProgressDialog(subscriptionManager, project);
        List<SubscriptionDetail> sdl = subscriptionManager.getSubscriptionDetails();
        for (SubscriptionDetail sd : sdl) {
            System.out.println(sd.getSubscriptionName());
        }
        //System.out.println("onShowSubscriptions: calling getSubscriptionDetails()");
        SubscriptionsDialog d = SubscriptionsDialog.go(subscriptionManager.getSubscriptionDetails(), project);
        List<SubscriptionDetail> subscriptionDetailsUpdated;
        if (d != null) {
            subscriptionDetailsUpdated = d.getSubscriptionDetails();
            subscriptionManager.setSubscriptionDetails(subscriptionDetailsUpdated);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        //LOGGER.error("onShowSubscriptions", ex);
        ErrorWindow.show(project, ex.getMessage(), "Select Subscriptions Action Error");
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) SubscriptionsDialog(com.microsoft.azuretools.ijidea.ui.SubscriptionsDialog) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager)

Example 45 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class Program method main.

@SuppressWarnings("unused")
public static void main(String[] args) {
    LogManager.getLogManager().reset();
    try {
        try {
            if (CommonSettings.getUiFactory() == null)
                CommonSettings.setUiFactory(new UIFactory());
            String wd = "AuthManageWorkingDir";
            Path dirPath = Paths.get(System.getProperty("user.home"), wd);
            if (!Files.exists(dirPath)) {
                Files.createDirectory(dirPath);
            }
            CommonSettings.settingsBaseDir = dirPath.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("--- Service Principals section ---");
        // create with sp
        //final File credFile = new File(System.getProperty("user.home") + "/ServicePrincipals/srv-pri.azureauth-778");
        String path = "C:\\Users\\shch\\_ServicePrincipalsTest\\sp5\\sp-9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef_20161202161437.azureauth";
        final File credFile = new File("C:\\Users\\shch\\_ServicePrincipalsTest\\sp5\\sp-9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef_20161202161437.azureauth");
        AuthMethodDetails amd = new AuthMethodDetails();
        amd.setAuthMethod(AuthMethod.SP);
        amd.setCredFilePath(path);
        AuthMethodManager amm = AuthMethodManager.getInstance();
        amm.setAuthMethodDetails(amd);
        AzureManager am = amm.getAzureManager();
        SubscriptionManager subscriptionManager = am.getSubscriptionManager();
        List<SubscriptionDetail> sdl = subscriptionManager.getSubscriptionDetails();
        //AzureManager spManager = new ServicePrincipalAzureManager(credFile);
        //printResourceGroups(spManager);
        //printSubscriptions(spManager);
        // create with token
        //AzureManager atManager = new AccessTokenAzureManager(Constants.tenant);
        //AzureManager atManager = new AccessTokenAzureManager();
        //SubscriptionManager.getInstance().showSubscriptionDialog();
        //            AdAuthManager adAuthManager = AdAuthManager.getInstance();
        System.out.println("=== Access token section ---");
        //            AuthenticationResult res = AdAuthManager.getInstance().signIn();
        //            UserInfo ui = res.getUserInfo();
        // Setup working dir
        String wd = "AuthManageWorkingDir";
        Path dirPath = Paths.get(System.getProperty("user.home"), wd);
        if (!Files.exists(dirPath)) {
            Files.createDirectory(dirPath);
        }
        CommonSettings.settingsBaseDir = dirPath.toString();
        // Setup uiFactory
        if (CommonSettings.getUiFactory() == null)
            CommonSettings.setUiFactory(new UIFactory());
    //testReporter(dirPath.toString());
    //graphApiAction();
    //createSp();
    //            AzureManager am = AuthMethodManager.getInstance().getAzureManager(AuthMethod.AD);
    //            if (am == null) {
    //                return;
    //            }
    //
    //            System.out.println("-- Subscription list ---");
    //            printSubscriptions(am);
    //           sidList = AdAuthManager.getInstance().getAccountSidList();
    //            for (String sid : AdAuthManager.getInstance().getAccountSidList()) {
    //                System.out.println("  - " + sid);
    //            }
    //printResourceGroups(am);
    //printTenants(atManager);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        System.exit(1);
    }
}
Also used : Path(java.nio.file.Path) AuthMethodDetails(com.microsoft.azuretools.authmanage.models.AuthMethodDetails) IUIFactory(com.microsoft.azuretools.authmanage.interact.IUIFactory) AccessTokenAzureManager(com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) IOException(java.io.IOException) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) File(java.io.File) IOException(java.io.IOException) AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager)

Aggregations

AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)48 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)17 Azure (com.microsoft.azure.management.Azure)15 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)15 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)12 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)8 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)8 DockerHost (com.microsoft.azure.docker.model.DockerHost)6 Location (com.microsoft.azure.management.resources.Location)4 AzureDockerImageInstance (com.microsoft.azure.docker.model.AzureDockerImageInstance)3 EditableDockerHost (com.microsoft.azure.docker.model.EditableDockerHost)3 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)3 Subscription (com.microsoft.azure.management.resources.Subscription)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)3 KeyVaultClient (com.microsoft.azure.keyvault.KeyVaultClient)2 Network (com.microsoft.azure.management.network.Network)2 Kind (com.microsoft.azure.management.storage.Kind)2