PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /lib/python3.6/site-packages/sssd/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //lib/python3.6/site-packages/sssd/source_files.py

import glob
import logging

from sssd.source_reader import Reader

logger = logging.getLogger()


class Files(Reader):
    """
    A class used to represent a Log Files Reader

    Args:
        path -- the path where SSSD logs are to
           be read (default /var/log/sssd/)
    """

    def __init__(self, path):
        super().__init__()
        self.log_files = []
        self.path = self.resolve_path(path)
        self.domains = self.get_domain_logfiles()

    def __iter__(self):
        """
        Yields:
            str: The next line in the log file
        """
        for files in self.log_files:
            try:
                with open(files) as file:
                    for line in file:
                        yield line
            except FileNotFoundError as err:
                logger.warning("Could not find domain log file, skipping")
                logger.warning(err)
                continue

    def resolve_path(self, path):
        if path.endswith("/"):
            return path
        else:
            return path + "/"

    def get_domain_logfiles(self, child=False):
        """ Retrieve list of SSSD log files, exclude rotated (.gz) files """
        domain_files = []
        exclude_list = ["ifp", "nss", "pam", "sudo", "autofs",
                        "ssh", "pac", "kcm", ".gz"]
        if child:
            file_list = glob.glob(self.path + "*.log")
        else:
            file_list = glob.glob(self.path + "sssd_*")
        for file in file_list:
            if not any(s in file for s in exclude_list):
                domain_files.append(file)

        return domain_files

    def set_component(self, component, child):
        """
        Switch the reader to interact with a certain SSSD component
        NSS, PAM, BE
        """
        self.log_files = []
        if component == self.Component.NSS:
            self.log_files.append(self.path + "sssd_nss.log")
        elif component == self.Component.PAM:
            self.log_files.append(self.path + "sssd_pam.log")
        elif component == self.Component.BE:
            domains = self.get_domain_logfiles(child)
            if not domains:
                raise IOError
            # error: No domains found?
            for dom in domains:
                self.log_files.append(dom)