/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.elasticsearch.plugin.discovery.azure;

import org.elasticsearch.cloud.azure.AzureDiscoveryModule;
import org.elasticsearch.cloud.azure.management.AzureComputeService;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.discovery.DiscoveryModule;
import org.elasticsearch.discovery.azure.AzureDiscovery;
import org.elasticsearch.discovery.azure.AzureUnicastHostsProvider;
import org.elasticsearch.plugins.Plugin;

import java.util.Collection;
import java.util.Collections;

import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.KEYSTORE_PASSWORD_SETTING;
import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.KEYSTORE_PATH_SETTING;
import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.KEYSTORE_TYPE_SETTING;
import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.SUBSCRIPTION_ID_SETTING;

/**
 *
 */
public class AzureDiscoveryPlugin extends Plugin {

    private final Settings settings;
    protected final ESLogger logger = Loggers.getLogger(AzureDiscoveryPlugin.class);

    public AzureDiscoveryPlugin(Settings settings) {
        this.settings = settings;
        logger.trace("starting azure discovery plugin...");
    }

    @Override
    public String name() {
        return "discovery-azure";
    }

    @Override
    public String description() {
        return "Azure Discovery Plugin";
    }

    @Override
    public Collection<Module> nodeModules() {
        return Collections.singletonList((Module) new AzureDiscoveryModule(settings));
    }

    public void onModule(DiscoveryModule discoveryModule) {
        if (AzureDiscoveryModule.isDiscoveryReady(settings, logger)) {
            discoveryModule.addDiscoveryType("azure", AzureDiscovery.class);
            discoveryModule.addUnicastHostProvider(AzureUnicastHostsProvider.class);
        }
    }

    public void onModule(SettingsModule settingsModule) {
        settingsModule.registerSetting(AzureComputeService.Discovery.REFRESH_SETTING);
        settingsModule.registerSetting(AzureComputeService.Management.KEYSTORE_PASSWORD_SETTING);
        settingsModule.registerSetting(AzureComputeService.Management.KEYSTORE_PATH_SETTING);
        settingsModule.registerSetting(AzureComputeService.Management.KEYSTORE_TYPE_SETTING);
        settingsModule.registerSetting(AzureComputeService.Management.SUBSCRIPTION_ID_SETTING);
        settingsModule.registerSetting(AzureComputeService.Management.SERVICE_NAME_SETTING);
        settingsModule.registerSetting(AzureComputeService.Discovery.HOST_TYPE_SETTING);
        // Cloud management API settings we need to hide
        settingsModule.registerSettingsFilter(KEYSTORE_PATH_SETTING.getKey());
        settingsModule.registerSettingsFilter(KEYSTORE_PASSWORD_SETTING.getKey());
        settingsModule.registerSettingsFilter(KEYSTORE_TYPE_SETTING.getKey());
        settingsModule.registerSettingsFilter(SUBSCRIPTION_ID_SETTING.getKey());
    }
}

@@ -1499,462 +1499,8 @@
 s;%0A%0A
-import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.KEYSTORE_PASSWORD_SETTING;%0Aimport static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.KEYSTORE_PATH_SETTING;%0Aimport static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.KEYSTORE_TYPE_SETTING;%0Aimport static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.SUBSCRIPTION_ID_SETTING;%0A%0A/**%0A *%0A */%0A
 publ
@@ -3270,32 +3270,63 @@
 rSettingsFilter(
+AzureComputeService.Management.
 KEYSTORE_PATH_SE
@@ -3380,32 +3380,63 @@
 rSettingsFilter(
+AzureComputeService.Management.
 KEYSTORE_PASSWOR
@@ -3502,16 +3502,47 @@
 sFilter(
+AzureComputeService.Management.
 KEYSTORE
@@ -3612,16 +3612,47 @@
 sFilter(
+AzureComputeService.Management.
 SUBSCRIP

fix imports