diff --git a/docs/custom_datasources_index.rst b/docs/custom_datasources_index.rst index 2dd11b1e3..8a18afb8c 100644 --- a/docs/custom_datasources_index.rst +++ b/docs/custom_datasources_index.rst @@ -211,11 +211,11 @@ insights.specs.datasources.sys_fs_cgroup_memory_tasks_number :show-inheritance: :undoc-members: -insights.specs.datasources.system_user_dirs -------------------------------------------- +insights.specs.datasources.rpm_pkgs +----------------------------------- -.. automodule:: insights.specs.datasources.system_user_dirs - :members: system_user_dirs +.. automodule:: insights.specs.datasources.rpm_pkgs + :members: pkgs_with_writable_dirs :show-inheritance: :undoc-members: diff --git a/docs/shared_parsers_catalog/rpm_pkgs.rst b/docs/shared_parsers_catalog/rpm_pkgs.rst new file mode 100644 index 000000000..09205b93a --- /dev/null +++ b/docs/shared_parsers_catalog/rpm_pkgs.rst @@ -0,0 +1,3 @@ +.. automodule:: insights.parsers.rpm_pkgs + :members: + :show-inheritance: diff --git a/docs/shared_parsers_catalog/system_user_dirs.rst b/docs/shared_parsers_catalog/system_user_dirs.rst deleted file mode 100644 index 7f85bfbce..000000000 --- a/docs/shared_parsers_catalog/system_user_dirs.rst +++ /dev/null @@ -1,3 +0,0 @@ -.. automodule:: insights.parsers.system_user_dirs - :members: - :show-inheritance: diff --git a/insights/parsers/rpm_pkgs.py b/insights/parsers/rpm_pkgs.py new file mode 100644 index 000000000..8d5eb3ddf --- /dev/null +++ b/insights/parsers/rpm_pkgs.py @@ -0,0 +1,31 @@ +""" +RpmPkgs - datasource ``rpm_pkgs`` +================================= + +Parser for CVE-2021-35937, CVE-2021-35938, and CVE-2021-35939. +For more information, see the ``rpm_pkgs`` datasource. +""" + +from insights import Parser, parser +from insights.specs import Specs + + +@parser(Specs.rpm_pkgs) +class RpmPkgs(Parser): + """ + Class for enabling the data from the ``rpm_pkgs`` datasource. + + Sample output of this datasource is:: + + ["httpd-core"] + + Examples: + + >>> type(rpm_pkgs) + + >>> rpm_pkgs.packages + ['httpd-core'] + """ + + def parse_content(self, content): + self.packages = content diff --git a/insights/parsers/system_user_dirs.py b/insights/parsers/system_user_dirs.py deleted file mode 100644 index 62bed1774..000000000 --- a/insights/parsers/system_user_dirs.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -SystemUserDirs - datasource ``system_user_dirs`` -================================================ - -Parser for CVE-2021-35937, CVE-2021-35938, and CVE-2021-35939. -For more information, see the ``system_user_dirs`` datasource. -""" - -from insights import Parser, parser -from insights.specs import Specs - - -@parser(Specs.system_user_dirs) -class SystemUserDirs(Parser): - """ - Class for enabling the data from the ``system_user_dirs`` datasource. - - Sample output of this datasource is:: - - ["httpd-core"] - - Examples: - - >>> type(system_user_dirs) - - >>> system_user_dirs.packages - ['httpd-core'] - """ - - def parse_content(self, content): - self.packages = content diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py index 9d928bd2a..3db842488 100644 --- a/insights/specs/__init__.py +++ b/insights/specs/__init__.py @@ -598,6 +598,7 @@ class Specs(SpecSet): route = RegistryPoint() rpm_V_packages = RegistryPoint() rpm_ostree_status = RegistryPoint() + rpm_pkgs = RegistryPoint() rsyslog_conf = RegistryPoint(filterable=True, multi_output=True) samba = RegistryPoint(filterable=True) samba_logs = RegistryPoint(multi_output=True, filterable=True) @@ -700,7 +701,6 @@ class Specs(SpecSet): sysctl_conf_initramfs = RegistryPoint(multi_output=True) sysctl_d_conf_etc = RegistryPoint(multi_output=True) sysctl_d_conf_usr = RegistryPoint(multi_output=True) - system_user_dirs = RegistryPoint() systemctl_cat_dnsmasq_service = RegistryPoint() systemctl_cat_rpcbind_socket = RegistryPoint() systemctl_cinder_volume = RegistryPoint() diff --git a/insights/specs/datasources/system_user_dirs.py b/insights/specs/datasources/rpm_pkgs.py similarity index 96% rename from insights/specs/datasources/system_user_dirs.py rename to insights/specs/datasources/rpm_pkgs.py index e37a6b16d..f21a45458 100644 --- a/insights/specs/datasources/system_user_dirs.py +++ b/insights/specs/datasources/rpm_pkgs.py @@ -15,7 +15,7 @@ class LocalSpecs(Specs): """ - Local spec used only by the system_user_dirs datasource. + Local spec used only by the rpm_pkgs datasource. """ rpm_args = simple_command( 'rpm -qa --nosignature --qf="[%{=NAME}; %{FILENAMES}; %{FILEMODES:perms}; %{FILEUSERNAME}; %{FILEGROUPNAME}\n]"', @@ -70,7 +70,7 @@ def get_groups(users): @datasource(LocalSpecs.rpm_args, HostContext) -def system_user_dirs(broker): +def pkgs_with_writable_dirs(broker): r""" Custom datasource for CVE-2021-35937, CVE-2021-35938, and CVE-2021-35939. @@ -115,5 +115,5 @@ def system_user_dirs(broker): if packages: return DatasourceProvider( - content=sorted(packages), relative_path="insights_commands/system_user_dirs" + content=sorted(packages), relative_path="insights_commands/rpm_pkgs" ) diff --git a/insights/specs/default.py b/insights/specs/default.py index 18b60afa1..bea5e6908 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -27,7 +27,7 @@ aws, awx_manage, cloud_init, candlepin_broker, corosync as corosync_ds, dir_list, ethernet, httpd, ipcs, kernel_module_list, lpstat, md5chk, package_provides, ps as ps_datasource, sap, satellite_missed_queues, - semanage, ssl_certificate, sys_fs_cgroup_memory_tasks_number, system_user_dirs, user_group, yum_updates, luks_devices) + semanage, ssl_certificate, sys_fs_cgroup_memory_tasks_number, rpm_pkgs, user_group, yum_updates, luks_devices) from insights.specs.datasources.sap import sap_hana_sid, sap_hana_sid_SID_nr from insights.specs.datasources.pcp import pcp_enabled, pmlog_summary_args from insights.specs.datasources.container import running_rhel_containers, containers_inspect @@ -508,6 +508,7 @@ class DefaultSpecs(Specs): ros_config = simple_file("/var/lib/pcp/config/pmlogger/config.ros") rpm_V_packages = simple_command("/bin/rpm -V coreutils procps procps-ng shadow-utils passwd sudo chrony", keep_rc=True, signum=signal.SIGTERM) rpm_ostree_status = simple_command("/usr/bin/rpm-ostree status --json", signum=signal.SIGTERM) + rpm_pkgs = rpm_pkgs.pkgs_with_writable_dirs rsyslog_conf = glob_file(["/etc/rsyslog.conf", "/etc/rsyslog.d/*.conf"]) samba = simple_file("/etc/samba/smb.conf") sap_hana_landscape = foreach_execute(sap_hana_sid_SID_nr, "/bin/su -l %sadm -c 'python /usr/sap/%s/HDB%s/exe/python_support/landscapeHostConfiguration.py'", keep_rc=True) @@ -615,7 +616,6 @@ class DefaultSpecs(Specs): sysctl_conf = simple_file("/etc/sysctl.conf") sysctl_d_conf_etc = glob_file("/etc/sysctl.d/*.conf") sysctl_d_conf_usr = glob_file("/usr/lib/sysctl.d/*.conf") - system_user_dirs = system_user_dirs.system_user_dirs systemctl_cat_rpcbind_socket = simple_command("/bin/systemctl cat rpcbind.socket") systemctl_httpd = simple_command("/bin/systemctl show httpd") systemctl_list_unit_files = simple_command("/bin/systemctl list-unit-files") diff --git a/insights/tests/datasources/test_system_user_dirs.py b/insights/tests/datasources/test_rpm_pkgs.py similarity index 78% rename from insights/tests/datasources/test_system_user_dirs.py rename to insights/tests/datasources/test_rpm_pkgs.py index 2ccef420e..56248831a 100644 --- a/insights/tests/datasources/test_system_user_dirs.py +++ b/insights/tests/datasources/test_rpm_pkgs.py @@ -5,7 +5,7 @@ from insights.core.dr import SkipComponent from insights.core.spec_factory import DatasourceProvider -from insights.specs.datasources.system_user_dirs import LocalSpecs, system_user_dirs +from insights.specs.datasources.rpm_pkgs import LocalSpecs, pkgs_with_writable_dirs RPM_CMD = """ httpd-core; /usr/share/doc/httpd-core; drwxr-xr-x; apache; root @@ -21,7 +21,7 @@ RPM_EMPTY_CMD = "" -RELATIVE_PATH = "insights_commands/system_user_dirs" +RELATIVE_PATH = "insights_commands/rpm_pkgs" def get_users(): @@ -32,14 +32,14 @@ def get_groups(users): return ["apache", "postgres"] -@mock.patch("insights.specs.datasources.system_user_dirs.get_users", get_users) -@mock.patch("insights.specs.datasources.system_user_dirs.get_groups", get_groups) +@mock.patch("insights.specs.datasources.rpm_pkgs.get_users", get_users) +@mock.patch("insights.specs.datasources.rpm_pkgs.get_groups", get_groups) def test_rpm(): rpm_args = Mock() rpm_args.content = RPM_CMD.splitlines() broker = {LocalSpecs.rpm_args: rpm_args} - result = system_user_dirs(broker) + result = pkgs_with_writable_dirs(broker) expected = DatasourceProvider(content=RPM_EXPECTED, relative_path=RELATIVE_PATH) assert result assert isinstance(result, DatasourceProvider) @@ -54,4 +54,4 @@ def test_no_rpm(no_rpm): broker = {LocalSpecs.rpm_args: rpm_args} with pytest.raises(SkipComponent): - system_user_dirs(broker) + pkgs_with_writable_dirs(broker) diff --git a/insights/tests/parsers/test_rpm_pkgs.py b/insights/tests/parsers/test_rpm_pkgs.py new file mode 100644 index 000000000..9a82b7dd8 --- /dev/null +++ b/insights/tests/parsers/test_rpm_pkgs.py @@ -0,0 +1,20 @@ +import doctest + +from insights.parsers import rpm_pkgs +from insights.parsers.rpm_pkgs import RpmPkgs +from insights.tests import context_wrap + +PACKAGES = ["httpd-core"] + + +def test_system_user_dirs(): + test = RpmPkgs(context_wrap(PACKAGES)) + assert test.packages == PACKAGES + + +def test_doc_examples(): + env = { + "rpm_pkgs": RpmPkgs(context_wrap(PACKAGES)) + } + failed, total = doctest.testmod(rpm_pkgs, globs=env) + assert failed == 0 diff --git a/insights/tests/parsers/test_system_user_dirs.py b/insights/tests/parsers/test_system_user_dirs.py deleted file mode 100644 index 254d767be..000000000 --- a/insights/tests/parsers/test_system_user_dirs.py +++ /dev/null @@ -1,20 +0,0 @@ -import doctest - -from insights.parsers import system_user_dirs -from insights.parsers.system_user_dirs import SystemUserDirs -from insights.tests import context_wrap - -PACKAGES = ["httpd-core"] - - -def test_system_user_dirs(): - test = SystemUserDirs(context_wrap(PACKAGES)) - assert test.packages == PACKAGES - - -def test_doc_examples(): - env = { - "system_user_dirs": SystemUserDirs(context_wrap(PACKAGES)) - } - failed, total = doctest.testmod(system_user_dirs, globs=env) - assert failed == 0