-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dan Lavu
committed
Aug 10, 2023
1 parent
97a3994
commit 3713bac
Showing
1 changed file
with
122 additions
and
0 deletions.
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,122 @@ | ||
""""PAM Tools.""" | ||
|
||
from __future__ import annotations | ||
|
||
import textwrap | ||
|
||
from pytest_mh import MultihostHost, MultihostUtility | ||
from pytest_mh.utils.fs import LinuxFileSystem | ||
|
||
__all__ = [ | ||
"PAMUtils", | ||
"PAMAccess", | ||
"PAMFaillock", | ||
] | ||
|
||
|
||
class PAMUtils(MultihostUtility[MultihostHost]): | ||
""" | ||
Management of PAM modules | ||
""" | ||
|
||
def __init__(self, host: MultihostHost) -> None: | ||
""" | ||
:param host: Remote host instance. | ||
:type host: MultihostHost | ||
""" | ||
super().__init__(host) | ||
|
||
def access(self) -> PAMAccess: | ||
""" | ||
:return: PAM Access object. | ||
:rtype: PAMAccess | ||
""" | ||
return PAMAccess(self) | ||
|
||
def faillock(self) -> PAMFaillock: | ||
""" | ||
:return: PAM Faillock object. | ||
:rtype: PAMFaillock | ||
""" | ||
return PAMFaillock(self) | ||
|
||
|
||
class PAMAccess: | ||
""" | ||
Management of PAM Access on the client host. | ||
.. code-block:: python | ||
:caption: Example usage | ||
@pytest.mark.topology(KnownTopologyGroup.AnyProvider) | ||
def test_example(client: Client, | ||
""" | ||
def __init__(self, | ||
util: PAMUtils, | ||
fs: LinuxFileSystem, | ||
file: str | None = "/etc/security/access.conf" | ||
) -> None: | ||
""" | ||
:rtype: object | ||
:param util: PAMUtils object. | ||
:type util: PAMUtils | ||
:param file: File name of access file. | ||
:type file: str, optional | ||
""" | ||
self.util: PAMUtils = util | ||
self.fs: LinuxFileSystem = fs | ||
self.file: str = file | ||
|
||
fs.backup(self.file) | ||
|
||
def add(self, | ||
*, | ||
permission: str | None = "+", | ||
name: str, | ||
origin: str | None = "ALL" | ||
) -> PAMAccess: | ||
""" | ||
:param name: Name of the user or group | ||
:type name: str | None, required | ||
:param permission: Permission flag, defaults to None | ||
:type permission: str | None, optional | ||
:param origin: Origination of access, defaults to None | ||
:type origin: str | None, optional | ||
:return: Self. | ||
:rtype: PAMAccess | ||
""" | ||
content = f"{permission}:{name}:{origin}" | ||
|
||
self.util.logger.info(f"{content} written to {self.file} on {self.util.host.hostname}") | ||
self.fs.write(self.file, content, dedent=True) | ||
|
||
return self | ||
|
||
def delete(self): | ||
""" | ||
:return: | ||
""" | ||
def get(self): | ||
""" | ||
:return: | ||
""" | ||
|
||
|
||
class PAMFaillock: | ||
""" | ||
Management of PAM Faillock on the client host. | ||
.. code-block:: python | ||
:caption: Example usage | ||
@pytest.mark.topology(KnownTopologyGroup.AnyProvider) | ||
def test_example(client: Client, | ||
""" | ||
def __init__(self, util: PAMUtils) -> None: | ||
""" | ||
:param util: PAMUtils object. | ||
:type util: PAMUtils | ||
""" | ||
self.util: PAMUtils = util |