# SPDX-License-Identifier: LGPL-2.1-or-later

# Copyright (c) 2019 Red Hat, Inc.
# Copyright (c) 2019 Tomáš Mráz <tmraz@fedoraproject.org>

import os.path

from .configgenerator import ConfigGenerator

class AuthGenerator(ConfigGenerator):
    CONFIG_NAME = 'auth'
    SCOPES = {'auth'}
    
    RELOAD_CMD = '/usr/share/crypto-policies-scripts/auth_apply.sh 2>/dev/null || :\n'

    @classmethod
    def generate_config(cls, policy):
        p = policy.enabled
        sep = '\n'
        s = ''
        authopt_data = p['authopt']
        if len(authopt_data) > 0:
            auth_profile = authopt_data.pop(0)
            opt_list = []
            for item in authopt_data:
                if item not in opt_list:
                    if item.startswith('with'):
                        opt_list.append(item)
            s = cls.append(s, auth_profile, sep)
            for item in opt_list:
                s = cls.append(s, item, sep)
        return s

    @classmethod
    def test_config(cls, config):  # pylint: disable=unused-argument
        return True
