use of com.microsoft.azuretools.authmanage.SubscriptionManager 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");
}
}
use of com.microsoft.azuretools.authmanage.SubscriptionManager 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);
}
}
use of com.microsoft.azuretools.authmanage.SubscriptionManager in project azure-tools-for-java by Microsoft.
the class VMArmModule method refreshItems.
@Override
protected void refreshItems() throws AzureCmdException {
List<Pair<String, String>> failedSubscriptions = new ArrayList<>();
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
Set<String> sidList = subscriptionManager.getSelectedSubscriptionDetails().stream().filter(subscriptionDetail -> Objects.nonNull(subscriptionDetail) && subscriptionDetail.isSelected()).map(subscriptionDetail -> subscriptionDetail.getSubscriptionId()).collect(Collectors.toSet());
for (String sid : sidList) {
try {
Azure azure = azureManager.getAzure(sid);
List<VirtualMachine> virtualMachines = azure.virtualMachines().list();
for (VirtualMachine vm : virtualMachines) {
addChildNode(new VMNode(this, sid, vm));
}
} catch (Exception ex) {
failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage()));
continue;
}
}
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Virtual Machines\n\n" + ex.getMessage(), ex);
}
if (!failedSubscriptions.isEmpty()) {
StringBuilder errorMessage = new StringBuilder("An error occurred when trying to load Storage Accounts for the subscriptions:\n\n");
for (Pair error : failedSubscriptions) {
errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n");
}
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Storage Accounts\n\n" + errorMessage.toString(), null);
}
}
use of com.microsoft.azuretools.authmanage.SubscriptionManager in project azure-tools-for-java by Microsoft.
the class SelectSubscriptionsAction method selectSubscriptions.
public static Single<List<SubscriptionDetail>> selectSubscriptions(Project project) {
final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
final AzureManager manager = authMethodManager.getAzureManager();
if (manager == null) {
return Single.fromCallable(() -> null);
}
final SubscriptionManager subscriptionManager = manager.getSubscriptionManager();
return loadSubscriptions(subscriptionManager, project).switchMap((subs) -> selectSubscriptions(project, subs)).toSingle().doOnSuccess((subs) -> Optional.ofNullable(subs).ifPresent(subscriptionManager::setSubscriptionDetails));
}
Aggregations