<commit_before>#
# Copyright (c) 2010 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

from gopher.agent.config import Config
from logging import getLogger

log = getLogger(__name__)


class Identity:
    """
    Agent identity
    @ivar plugin: The identity plugin
    @type plugin: An identity function
    """
    plugins = []
        
    def getuuid(self):
        """
        Get the agent UUID.
        @return: The UUID.
        @rtype: str
        """
        for plugin in self.plugins:
            try:
                return plugin.getuuid()
            except:
                log.error('plugin (%s) failed', plugin, exc_info=True)
        cfg = Config()
        return cfg.main.uuid


def identity(cls):
    """
    Identity decorator
    @param cls: A class that provides identity
    @type cls: plugin class
    """
    plugin = cls()
    Identity.plugins.append(plugin)
    return cls<commit_msg>add getcert() to Identity.<commit_after>#
# Copyright (c) 2010 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

from gopher.agent.config import Config
from logging import getLogger

log = getLogger(__name__)


class Identity:
    """
    Agent identity
    @ivar plugin: The identity plugin
    @type plugin: An identity function
    """
    plugins = []
        
    def getuuid(self):
        """
        Get the agent UUID.
        @return: The UUID.
        @rtype: str
        """
        for plugin in self.plugins:
            try:
                return plugin.getuuid()
            except:
                log.error('plugin (%s) failed', plugin, exc_info=True)
        cfg = Config()
        return cfg.main.uuid
    
    def getcert(self):
        """
        Get the x509 certificate & private key location.
        @return: tuple (key-path, crt-path)
        @rtype: tuple
        """
        for plugin in self.plugins:
            try:
                return plugin.getcert()
            except:
                log.error('plugin (%s) failed', plugin, exc_info=True)
        cfg = Config()
        keypath = None
        crtpath = cfg.messaging.clientcert
        return (keypath, crtpath)


def identity(cls):
    """
    Identity decorator
    @param cls: A class that provides identity
    @type cls: plugin class
    """
    plugin = cls()
    Identity.plugins.append(plugin)
    return cls
{'fraction_non_alphanumeric': 0.0869437076333628, 'fraction_numerical': 0.006778661951075744, 'mean_word_length': 2.3438423645320197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7293020', 'n_tokens_mistral': 949, 'n_tokens_neox': 917, 'n_words': 361}