# Licensed 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.

from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils

from sahara import conductor as cond
from sahara import context
from sahara import exceptions as exc
from sahara.i18n import _
from sahara.plugins import provisioning as base
from sahara.plugins import utils as pl_utils
from sahara.service.castellan import utils as key_manager
from sahara.utils import cluster as cl_utils
from sahara.utils import cluster_progress_ops as cpo
from sahara.utils import files


conductor = cond.API
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
POLICY_FILES_DIR = '/tmp/UnlimitedPolicy'


class KDCInstallationFailed(exc.SaharaException):
    code = 'KDC_INSTALL_FAILED'
    message_template = _('KDC installation failed by reason: {reason}')

    def __init__(self, reason):
        message = self.message_template.format(reason=reason)
        super(KDCInstallationFailed, self).__init__(message)


def _config(**kwargs):
    return base.Config(
        applicable_target='Kerberos', priority=1,
        is_optional=True, scope='cluster', **kwargs)


enable_kerberos = _config(
    name='Enable Kerberos Security', config_type='bool',
    default_value=False)
use_existing_kdc = _config(
    name='Existing KDC', config_type='bool',
    default_value=False)