-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: New parser for systemd_perms #3339
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e7879e7
feat: New parser for systemd_perms
4319340
fix: fix ETC_SYSTEMD in test_systemd_perms.py
60844fe
fix: Fix file name and class name
068d332
fix: add doc entry
e399c27
fix: update insights_archive
6c12a3e
fix: fix docs-test error
d972be2
fix: fix length of '-'
a9a1d13
fix: Updating test_etc_systemd() in test_ls_systemd.py
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
""" | ||
Systemd File Permissions parsers | ||
================================ | ||
|
||
Parsers included in this module are: | ||
|
||
SystemdPerms - command ``/bin/ls -lanRL /etc/systemd`` | ||
-------------------------------------------------------------- | ||
|
||
UsrLibSystemdPerms - command ``/bin/ls -lanRL /usr/lib/systemd`` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same comment as above |
||
--------------------------------------------------------------- | ||
|
||
|
||
""" | ||
from insights.core import CommandParser, FileListing | ||
from insights.core.plugins import parser | ||
from insights.specs import Specs | ||
|
||
|
||
@parser(Specs.ls_etc_systemd) | ||
class LsEtcSystemdPermsParser(CommandParser, FileListing): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How above removing the part of |
||
""" | ||
Class for parsing ``ls -lanRL /etc/systemd`` command. | ||
|
||
The ``ls -lanRL /etc/systemd`` command provides information for the listing of the ``/etc/systemd`` directory. | ||
|
||
See the ``FileListing`` class for a more complete description of the available features of the class. | ||
|
||
Sample output of ``ls -lanRL /etc/systemd`` command is:: | ||
|
||
/etc/systemd: | ||
total 48 | ||
drwxr-xr-x 10 501 20 320 Feb 23 2021 . | ||
drwxr-xr-x 129 501 20 4128 Nov 7 15:01 .. | ||
-rw-r--r-- 1 501 20 720 Jan 16 2021 bootchart.conf | ||
-rw-r--r-- 1 501 20 615 Jan 16 2021 coredump.conf | ||
drwxr-xr-x 2 501 20 64 Jan 16 2021 user | ||
-rw-r--r-- 1 501 20 1127 Jan 16 2021 user.conf | ||
|
||
/etc/systemd/user: | ||
total 0 | ||
drwxr-xr-x 2 501 20 64 Jan 16 2021 . | ||
drwxr-xr-x 10 501 20 320 Feb 23 2021 .. | ||
|
||
Examples: | ||
|
||
>>> type(etc_systemd) | ||
<class 'insights.parsers.ls_systemd.LsEtcSystemdPermsParser'> | ||
>>> '/etc/systemd' in etc_systemd | ||
True | ||
>>> '/etc/systemd/system' in etc_systemd | ||
False | ||
>>> etc_systemd.files_of('/etc/systemd') | ||
['bootchart.conf', 'coredump.conf', 'user.conf'] | ||
>>> etc_systemd.dirs_of('/etc/systemd') | ||
['.', '..', 'user'] | ||
>>> etc_systemd.dir_contains('/etc/systemd', 'coredump.conf') | ||
True | ||
>>> etc_systemd_dicts = etc_systemd.listing_of('/etc/systemd') | ||
>>> etc_systemd_dicts['coredump.conf']['perms'] | ||
'rw-r--r--' | ||
>>> etc_systemd_dicts['user']['perms'] | ||
'rwxr-xr-x' | ||
""" | ||
pass | ||
|
||
|
||
@parser(Specs.ls_usr_lib_systemd) | ||
class LsUsrLibSystemdPermsParser(CommandParser, FileListing): | ||
xiangce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Class for parsing ``ls -lanRL /usr/lib/systemd`` command. | ||
|
||
The ``ls -lanRL /usr/lib/systemd`` command provides information for the listing of the ``/usr/lib/systemd`` directory. | ||
|
||
See the ``FileListing`` class for a more complete description of the available features of the class. | ||
|
||
Sample output of ``ls -lanRL /usr/lib/systemd`` command is:: | ||
|
||
/usr/lib/systemd: | ||
total 0 | ||
drwxr-xr-x 4 501 20 128 Feb 23 2021 . | ||
dr-xr-xr-x 8 501 20 256 Oct 13 01:34 .. | ||
drwxr-xr-x 404 501 20 12928 Oct 13 02:50 system | ||
drwxr-xr-x 15 501 20 480 Feb 23 2021 user | ||
|
||
/usr/lib/systemd/user: | ||
total 104 | ||
drwxr-xr-x 15 501 20 480 Feb 23 2021 . | ||
drwxr-xr-x 4 501 20 128 Feb 23 2021 .. | ||
-rw-r--r-- 1 501 20 457 Jan 16 2021 basic.target | ||
-rw-r--r-- 1 501 20 379 Jan 16 2021 bluetooth.target | ||
-rw-r--r-- 1 501 20 414 Jan 16 2021 default.target | ||
-rw-r--r-- 1 501 20 499 Jan 16 2021 exit.target | ||
-rw-r--r-- 1 501 20 147 May 31 2018 glib-pacrunner.service | ||
-rw-r--r-- 1 501 20 354 Jan 16 2021 paths.target | ||
-rw-r--r-- 1 501 20 377 Jan 16 2021 printer.target | ||
-rw-r--r-- 1 501 20 402 Jan 16 2021 shutdown.target | ||
-rw-r--r-- 1 501 20 380 Jan 16 2021 smartcard.target | ||
-rw-r--r-- 1 501 20 356 Jan 16 2021 sockets.target | ||
-rw-r--r-- 1 501 20 380 Jan 16 2021 sound.target | ||
-rw-r--r-- 1 501 20 501 Jan 16 2021 systemd-exit.service | ||
-rw-r--r-- 1 501 20 405 Jan 16 2021 timers.target | ||
|
||
Examples: | ||
|
||
>>> type(usr_lib_systemd) | ||
<class 'insights.parsers.ls_systemd.LsUsrLibSystemdPermsParser'> | ||
>>> '/usr/lib/systemd' in usr_lib_systemd | ||
True | ||
>>> '/usr/lib/systemd/system' in usr_lib_systemd | ||
False | ||
>>> usr_lib_systemd.files_of('/usr/lib/systemd/user') | ||
['basic.target', 'bluetooth.target', 'default.target', 'exit.target', 'glib-pacrunner.service', 'paths.target', 'printer.target', 'shutdown.target', 'smartcard.target', 'sockets.target', 'sound.target', 'systemd-exit.service', 'timers.target'] | ||
>>> usr_lib_systemd.dirs_of('/usr/lib/systemd') | ||
['.', '..', 'system', 'user'] | ||
>>> usr_lib_systemd.dir_contains('/usr/lib/systemd/user', 'basic.target') | ||
True | ||
>>> usr_lib_systemd_dicts = usr_lib_systemd.listing_of('/usr/lib/systemd/user') | ||
>>> usr_lib_systemd_dicts['basic.target']['perms'] | ||
'rw-r--r--' | ||
|
||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
from insights.parsers.ls_systemd import LsEtcSystemdPermsParser, LsUsrLibSystemdPermsParser | ||
from insights.parsers import ls_systemd | ||
from insights.tests import context_wrap | ||
import doctest | ||
|
||
ETC_SYSTEMD = """ | ||
/etc/systemd: | ||
total 48 | ||
drwxr-xr-x 10 501 20 320 Feb 23 2021 . | ||
drwxr-xr-x 129 501 20 4128 Nov 7 15:01 .. | ||
-rw-r--r-- 1 501 20 720 Jan 16 2021 bootchart.conf | ||
-rw-r--r-- 1 501 20 615 Jan 16 2021 coredump.conf | ||
-rw-r--r-- 1 501 20 983 Jan 16 2021 journald.conf | ||
-rw-r--r-- 1 501 20 957 Jan 16 2021 logind.conf | ||
drwxr-xr-x 39 501 20 1248 Oct 14 04:49 system | ||
-rw-r--r-- 1 501 20 1552 Jan 16 2021 system.conf | ||
drwxr-xr-x 2 501 20 64 Jan 16 2021 user | ||
-rw-r--r-- 1 501 20 1127 Jan 16 2021 user.conf | ||
|
||
/etc/systemd/system: | ||
total 104 | ||
drwxr-xr-x 39 501 20 1248 Oct 14 04:49 . | ||
drwxr-xr-x 10 501 20 320 Feb 23 2021 .. | ||
drwxr-xr-x 5 501 20 160 Jun 19 2018 basic.target.wants | ||
-rw-r--r-- 1 501 20 657 Apr 16 2021 dbus-org.fedoraproject.FirewallD1.service | ||
-rw-r--r-- 1 501 20 1445 Sep 30 2020 dbus-org.freedesktop.NetworkManager.service | ||
-rw-r--r-- 1 501 20 353 Sep 30 2020 dbus-org.freedesktop.nm-dispatcher.service | ||
-rw-r--r-- 1 501 20 492 Jan 16 2021 default.target | ||
-rw-r--r-- 1 501 20 149 Oct 13 02:51 postgresql.service | ||
-r--r--r-- 1 501 20 946 Oct 13 03:02 pulpcore-api.service | ||
-r--r--r-- 1 501 20 157 Oct 13 03:02 pulpcore-api.socket | ||
-r--r--r-- 1 501 20 832 Oct 14 04:49 pulpcore-content.service | ||
-r--r--r-- 1 501 20 162 Oct 13 03:02 pulpcore-content.socket | ||
-r--r--r-- 1 501 20 813 Oct 13 03:02 pulpcore-resource-manager.service | ||
-r--r--r-- 1 501 20 861 Oct 13 03:02 [email protected] | ||
-rw-r--r-- 1 501 20 164 May 13 2020 [email protected] | ||
-rw-r--r-- 1 501 20 602 Jan 16 2020 rh-mongodb34-mongod.service | ||
|
||
/etc/systemd/system/basic.target.wants: | ||
total 24 | ||
drwxr-xr-x 5 501 20 160 Jun 19 2018 . | ||
drwxr-xr-x 39 501 20 1248 Oct 14 04:49 .. | ||
-rw-r--r-- 1 501 20 657 Apr 16 2021 firewalld.service | ||
-rw-r--r-- 1 501 20 284 Jul 28 2021 microcode.service | ||
-rw-r--r-- 1 501 20 217 May 22 2020 rhel-dmesg.service | ||
|
||
/etc/systemd/user: | ||
total 0 | ||
drwxr-xr-x 2 501 20 64 Jan 16 2021 . | ||
drwxr-xr-x 10 501 20 320 Feb 23 2021 .. | ||
""" | ||
|
||
ETC_SYSTEMD_EXAMPLE = """ | ||
/etc/systemd: | ||
total 48 | ||
drwxr-xr-x 10 501 20 320 Feb 23 2021 . | ||
drwxr-xr-x 129 501 20 4128 Nov 7 15:01 .. | ||
-rw-r--r-- 1 501 20 720 Jan 16 2021 bootchart.conf | ||
-rw-r--r-- 1 501 20 615 Jan 16 2021 coredump.conf | ||
drwxr-xr-x 2 501 20 64 Jan 16 2021 user | ||
-rw-r--r-- 1 501 20 1127 Jan 16 2021 user.conf | ||
|
||
/etc/systemd/user: | ||
total 0 | ||
drwxr-xr-x 2 501 20 64 Jan 16 2021 . | ||
drwxr-xr-x 10 501 20 320 Feb 23 2021 .. | ||
""" | ||
|
||
USR_LIB_SYSTEMD = """ | ||
/usr/lib/systemd: | ||
total 0 | ||
drwxr-xr-x 4 501 20 128 Feb 23 2021 . | ||
dr-xr-xr-x 8 501 20 256 Oct 13 01:34 .. | ||
drwxr-xr-x 404 501 20 12928 Oct 13 02:50 system | ||
drwxr-xr-x 15 501 20 480 Feb 23 2021 user | ||
|
||
/usr/lib/systemd/user: | ||
total 104 | ||
drwxr-xr-x 15 501 20 480 Feb 23 2021 . | ||
drwxr-xr-x 4 501 20 128 Feb 23 2021 .. | ||
-rw-r--r-- 1 501 20 457 Jan 16 2021 basic.target | ||
-rw-r--r-- 1 501 20 379 Jan 16 2021 bluetooth.target | ||
-rw-r--r-- 1 501 20 414 Jan 16 2021 default.target | ||
-rw-r--r-- 1 501 20 499 Jan 16 2021 exit.target | ||
-rw-r--r-- 1 501 20 147 May 31 2018 glib-pacrunner.service | ||
-rw-r--r-- 1 501 20 354 Jan 16 2021 paths.target | ||
-rw-r--r-- 1 501 20 377 Jan 16 2021 printer.target | ||
-rw-r--r-- 1 501 20 402 Jan 16 2021 shutdown.target | ||
-rw-r--r-- 1 501 20 380 Jan 16 2021 smartcard.target | ||
-rw-r--r-- 1 501 20 356 Jan 16 2021 sockets.target | ||
-rw-r--r-- 1 501 20 380 Jan 16 2021 sound.target | ||
-rw-r--r-- 1 501 20 501 Jan 16 2021 systemd-exit.service | ||
-rw-r--r-- 1 501 20 405 Jan 16 2021 timers.target | ||
""" | ||
|
||
|
||
def test_etc_systemd(): | ||
etc_systemd_perm = LsEtcSystemdPermsParser(context_wrap(ETC_SYSTEMD)) | ||
assert '/etc/systemd' in etc_systemd_perm | ||
assert '/etc/systemd/system' in etc_systemd_perm | ||
assert '/etc/systemd/system/basic.target.wants' in etc_systemd_perm | ||
assert '/etc/systemd/user' in etc_systemd_perm | ||
assert etc_systemd_perm.dirs_of('/etc/systemd') == ['.', '..', 'system', 'user'] | ||
|
||
basic_target_wants = etc_systemd_perm.files_of('/etc/systemd/system/basic.target.wants') | ||
assert 'firewalld.service' in basic_target_wants | ||
assert 'microcode.service' in basic_target_wants | ||
assert 'rhel-dmesg.service' in basic_target_wants | ||
assert len(basic_target_wants) == 3 | ||
|
||
assert etc_systemd_perm.listing_of('/etc/systemd')['user.conf'] == {'type': '-', 'perms': 'rw-r--r--', 'links': 1, 'owner': '501', 'group': '20', 'size': 1127, 'date': 'Jan 16 2021', 'name': 'user.conf', 'raw_entry': '-rw-r--r-- 1 501 20 1127 Jan 16 2021 user.conf', 'dir': '/etc/systemd'} | ||
|
||
|
||
def test_usr_lib_systemd(): | ||
usr_lib_systemd_perm = LsUsrLibSystemdPermsParser(context_wrap(USR_LIB_SYSTEMD)) | ||
assert '/usr/lib/systemd' in usr_lib_systemd_perm | ||
assert '/usr/lib/systemd/user' in usr_lib_systemd_perm | ||
assert usr_lib_systemd_perm.dirs_of('/usr/lib/systemd') == ['.', '..', 'system', 'user'] | ||
|
||
usr_lib_systemd_use = usr_lib_systemd_perm.files_of('/usr/lib/systemd/user') | ||
assert 'basic.target' in usr_lib_systemd_use | ||
assert 'bluetooth.target' in usr_lib_systemd_use | ||
assert len(usr_lib_systemd_use) == 13 | ||
|
||
assert usr_lib_systemd_perm.listing_of('/usr/lib/systemd/user')['timers.target'] == {'type': '-', 'perms': 'rw-r--r--', 'links': 1, 'owner': '501', 'group': '20', 'size': 405, 'date': 'Jan 16 2021', 'name': 'timers.target', 'raw_entry': '-rw-r--r-- 1 501 20 405 Jan 16 2021 timers.target', 'dir': '/usr/lib/systemd/user'} | ||
|
||
|
||
def test_systemd_examples(): | ||
env = { | ||
'etc_systemd': LsEtcSystemdPermsParser(context_wrap(ETC_SYSTEMD_EXAMPLE)), | ||
'usr_lib_systemd': LsUsrLibSystemdPermsParser(context_wrap(USR_LIB_SYSTEMD)) | ||
} | ||
failed, total = doctest.testmod(ls_systemd, globs=env) | ||
assert failed == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be modified too.