Search in sources :

Example 1 with AzureConfiguration

use of com.microsoft.azure.toolkit.lib.AzureConfiguration 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;
}
Also used : AzureEnvironment(com.azure.core.management.AzureEnvironment) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration)

Example 2 with AzureConfiguration

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

the class AzureConfigInitializer method saveAzConfig.

public static void saveAzConfig() {
    final AzureConfiguration config = Azure.az().config();
    IIdeStore ideStore = AzureStoreManager.getInstance().getIdeStore();
    AzureStoreManager.getInstance().getMachineStore().setProperty(TELEMETRY, TELEMETRY_INSTALLATION_ID, config.getMachineId());
    ideStore.setProperty(TELEMETRY, TELEMETRY_ALLOW_TELEMETRY, Boolean.toString(config.getTelemetryEnabled()));
    ideStore.setProperty(ACCOUNT, AZURE_ENVIRONMENT_KEY, config.getCloud());
    ideStore.setProperty(FUNCTION, FUNCTION_CORE_TOOLS_PATH, config.getFunctionCoreToolsPath());
    ideStore.setProperty(DATABASE, PASSWORD_SAVE_TYPE, config.getDatabasePasswordSaveType());
// don't save pluginVersion, it is saved in AzurePlugin class
}
Also used : AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration)

Example 3 with AzureConfiguration

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

the class AzureConfigInitializer method initialize.

public static void initialize(String defaultMachineId, String pluginName, String pluginVersion) {
    String machineId = AzureStoreManager.getInstance().getMachineStore().getProperty(TELEMETRY, TELEMETRY_INSTALLATION_ID);
    if (StringUtils.isBlank(machineId) || !InstallationIdUtils.isValidHashMac(machineId)) {
        machineId = defaultMachineId;
    }
    final AzureConfiguration config = Azure.az().config();
    config.setMachineId(machineId);
    final IIdeStore ideStore = AzureStoreManager.getInstance().getIdeStore();
    final String allowTelemetry = ideStore.getProperty(TELEMETRY, TELEMETRY_ALLOW_TELEMETRY, "true");
    config.setTelemetryEnabled(Boolean.parseBoolean(allowTelemetry));
    final String azureCloud = ideStore.getProperty(ACCOUNT, AZURE_ENVIRONMENT_KEY, "Azure");
    config.setCloud(azureCloud);
    final String funcPath = ideStore.getProperty(FUNCTION, FUNCTION_CORE_TOOLS_PATH, "");
    if (StringUtils.isNotBlank(funcPath) && Files.exists(Paths.get(funcPath))) {
        config.setFunctionCoreToolsPath(funcPath);
    }
    final String passwordSaveType = ideStore.getProperty(DATABASE, PASSWORD_SAVE_TYPE, "");
    if (StringUtils.isNotBlank(passwordSaveType)) {
        config.setDatabasePasswordSaveType(passwordSaveType);
    }
    ideStore.getProperty(TELEMETRY, TELEMETRY_PLUGIN_VERSION, "");
    final String userAgent = String.format("%s, v%s, machineid:%s", pluginName, pluginVersion, config.getTelemetryEnabled() ? config.getMachineId() : StringUtils.EMPTY);
    config.setUserAgent(userAgent);
    config.setProduct(pluginName);
    config.setLogLevel("NONE");
    config.setVersion(pluginVersion);
    saveAzConfig();
}
Also used : AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration)

Example 4 with AzureConfiguration

use of com.microsoft.azure.toolkit.lib.AzureConfiguration 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;
}
Also used : AzureEnvironment(com.azure.core.management.AzureEnvironment) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration) AzureCloud(com.microsoft.azure.toolkit.lib.auth.AzureCloud) AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager)

Aggregations

AzureConfiguration (com.microsoft.azure.toolkit.lib.AzureConfiguration)4 AzureEnvironment (com.azure.core.management.AzureEnvironment)2 AzureCloud (com.microsoft.azure.toolkit.lib.auth.AzureCloud)1 AuthMethodManager (com.microsoft.azuretools.authmanage.AuthMethodManager)1