import os

from exception import ConfigException

from log import logger_cli

from other import utils

pkg_dir = os.path.dirname(__file__)
pkg_dir = os.path.join(pkg_dir, os.pardir, os.pardir)
pkg_dir = os.path.normpath(pkg_dir)
pkg_dir = os.path.abspath(pkg_dir)

_default_work_folder = os.path.normpath(pkg_dir)


class CheckerConfiguration(object):
    def load_nodes_list():
        return utils.get_nodes_list(
            os.environ.get('CFG_ALL_NODES', None),
            os.environ.get('SALT_NODE_LIST_FILE', None)
        )

    def _init_values(self):
        """Load values from environment variables or put default ones
        """

        self.name = "CheckerConfig"
        self.working_folder = os.environ.get(
            'CFG_TESTS_WORK_DIR',
            _default_work_folder
        )
        self.date_format = "%Y-%m-%d %H:%M:%S.%f%z"
        self.default_tz = "UTC"

        self.pkg_versions_map = 'versions_map.csv'

        self.ssh_uses_sudo = False
        self.ssh_key = os.environ.get('SSH_KEY', None)
        self.ssh_user = os.environ.get('SSH_USER', None)
        self.ssh_host = os.environ.get('SSH_HOST', None)

        self.salt_host = os.environ.get('SALT_URL', None)
        self.salt_port = os.environ.get('SALT_PORT', '6969')
        self.salt_user = os.environ.get('SALT_USER', 'salt')
        self.salt_timeout = os.environ.get('SALT_TIMEOUT', 30)
        self.salt_file_root = os.environ.get('SALT_FILE_ROOT', None)
        self.salt_scripts_folder = os.environ.get(
            'SALT_SCRIPTS_FOLDER',
            'cfg_checker_scripts'
        )

        self.skip_nodes = utils.node_string_to_list(os.environ.get(
            'CFG_SKIP_NODES',
            None
        ))

    def _init_env(self, env_name=None):
        """Inits the environment vars from the env file
        Uses simple validation for the values and names

        Keyword Arguments:
            env_name {str} -- environment name to search configuration
                files in etc/<env_name>.env (default: {None})

        Raises:
            ConfigException -- on IO error when loading env file
            ConfigException -- on env file failed validation
        """
        # load env file as init os.environment with its values
        if env_name is None:
            _env_name = 'local'
        else:
            _env_name = env_name
        _config_path = os.path.join(pkg_dir, 'etc', _env_name + '.env')
        if os.path.isfile(_config_path):
            with open(_config_path) as _f:
                _list = _f.read().splitlines()
            logger_cli.info(
                "# Loading env vars from '{}'".format(
                    _config_path
                )
            )
        else:
            raise ConfigException(
                "# Failed to load enviroment vars from '{}'".format(
                    _config_path
                )
            )
        for index in range(len(_list)):
            _line = _list[index]
            # skip comments
            if _line.strip().startswith('#'):
                continue
            # validate
            _errors = []
            if _line.find('=') < 0 or _line.count('=') > 1:
                _errors.append("Line {}: {}".format(index, _line))
            else:
                # save values
                _t = _line.split('=')
                _key, _value = _t[0], _t[1]
                os.environ[_key] = _value
        # if there was errors, report them
        if _errors:
            raise ConfigException(
                "# Environment file failed validation in lines: {}".format(
                    "\n".join(_errors)
                )
            )
        else:
            logger_cli.debug(
                "-> ...loaded total of '{}' vars".format(
                    len(_list)
                )
            )
            self.salt_env = _env_name

    def __init__(self):
        """Base configuration class. Only values that are common for all scripts
        """
        _env = os.getenv('SALT_ENV', None)
        self._init_env(_env)
        self._init_values()


config = CheckerConfiguration()
