use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.
the class AzurePanel method init.
@Override
public void init() {
if (AzurePlugin.IS_ANDROID_STUDIO) {
return;
}
Messages.configureMessagePaneUi(allowTelemetryComment, message("settings.root.telemetry.notice"));
allowTelemetryComment.setForeground(UIUtil.getContextHelpForeground());
final ComboBoxModel<AzureEnvironment> model = new DefaultComboBoxModel<>(Azure.az(AzureCloud.class).list().toArray(new AzureEnvironment[0]));
azureEnvironmentComboBox.setModel(model);
azureEnvironmentComboBox.setRenderer(new SimpleListCellRenderer<>() {
@Override
public void customize(@NotNull JList list, AzureEnvironment value, int index, boolean selected, boolean hasFocus) {
setText(azureEnvironmentDisplayString(value));
}
});
azureEnvDesc.setForeground(UIUtil.getContextHelpForeground());
azureEnvDesc.setMaximumSize(new Dimension());
azureEnvironmentComboBox.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
displayDescriptionForAzureEnv();
}
});
displayDescriptionForAzureEnv();
setData(Azure.az().config());
}
use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.
the class AzurePanel method getData.
public AzureConfiguration getData() {
final AzureConfiguration data = new AzureConfiguration();
data.setCloud(AzureEnvironmentUtils.azureEnvironmentToString((AzureEnvironment) azureEnvironmentComboBox.getSelectedItem()));
if (savePasswordComboBox.getValue() != null) {
data.setDatabasePasswordSaveType(savePasswordComboBox.getValue().name());
}
data.setTelemetryEnabled(allowTelemetryCheckBox.isSelected());
data.setFunctionCoreToolsPath(funcCoreToolsPath.getItem());
return data;
}
use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.
the class AzurePanel method doOKAction.
@Override
public boolean doOKAction() {
final AzureConfiguration data = getData();
// set partial config to global config
final AzureConfiguration config = Azure.az().config();
config.setCloud(data.getCloud());
config.setTelemetryEnabled(data.getTelemetryEnabled());
config.setDatabasePasswordSaveType(data.getDatabasePasswordSaveType());
config.setFunctionCoreToolsPath(data.getFunctionCoreToolsPath());
final String userAgent = String.format(AzurePlugin.USER_AGENT, AzurePlugin.PLUGIN_VERSION, config.getTelemetryEnabled() ? config.getMachineId() : StringUtils.EMPTY);
config.setUserAgent(userAgent);
CommonSettings.setUserAgent(config.getUserAgent());
// we need to get rid of AuthMethodManager, using az.azure_account
if (AuthMethodManager.getInstance().isSignedIn()) {
final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
final String azureEnv = authMethodManager.getAuthMethodDetails().getAzureEnv();
final AzureEnvironment currentEnv = AzureEnvironmentUtils.stringToAzureEnvironment(azureEnv);
if (!Objects.equals(currentEnv, azureEnvironmentComboBox.getSelectedItem())) {
EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
authMethodManager.signOut();
});
}
}
if (StringUtils.isNotBlank(config.getCloud())) {
Azure.az(AzureCloud.class).setByName(config.getCloud());
}
AzureConfigInitializer.saveAzConfig();
return true;
}
use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.
the class AzurePanel method displayDescriptionForAzureEnv.
private void displayDescriptionForAzureEnv() {
if (AuthMethodManager.getInstance().isSignedIn()) {
final String azureEnv = AuthMethodManager.getInstance().getAuthMethodDetails().getAzureEnv();
final AzureEnvironment currentEnv = AzureEnvironmentUtils.stringToAzureEnvironment(azureEnv);
final String currentEnvStr = azureEnvironmentToString(currentEnv);
if (Objects.equals(currentEnv, azureEnvironmentComboBox.getSelectedItem())) {
setTextToLabel(azureEnvDesc, "You are currently signed in with environment: " + currentEnvStr);
azureEnvDesc.setIcon(AllIcons.General.Information);
} else {
setTextToLabel(azureEnvDesc, String.format("You are currently signed in with environment: %s, your change will sign out your account.", currentEnvStr));
azureEnvDesc.setIcon(AllIcons.General.Warning);
}
} else {
setTextToLabel(azureEnvDesc, "You are currently not signed, the environment will be applied when you sign in next time.");
azureEnvDesc.setIcon(AllIcons.General.Warning);
}
}
use of com.azure.core.management.AzureEnvironment in project azure-tools-for-java by Microsoft.
the class FunctionAppService method createApplicationInsights.
@Nullable
private ApplicationInsightsEntity createApplicationInsights(final FunctionAppConfig config) {
try {
AzureMessager.getMessager().info(APPLICATION_INSIGHTS_CREATE_START);
final AzureEnvironment environment = Azure.az(AzureAccount.class).account().getEnvironment();
final ApplicationInsightsEntity resource = Azure.az(ApplicationInsights.class).create(config.getSubscription().getId(), config.getResourceGroup().getName(), config.getRegion(), config.getMonitorConfig().getApplicationInsightsConfig().getName());
AzureMessager.getMessager().info(String.format(APPLICATION_INSIGHTS_CREATED, resource.getName(), IdentityAzureManager.getInstance().getPortalUrl(), resource.getId()));
return resource;
} catch (final Exception e) {
AzureMessager.getMessager().warning(String.format(APPLICATION_INSIGHTS_CREATE_FAILED, e.getMessage()));
return null;
}
}
Aggregations