Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions sssd_test_framework/utils/realmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from pytest_mh import MultihostHost, MultihostUtility
from pytest_mh.cli import CLIBuilder, CLIBuilderArgs
from pytest_mh.conn import ProcessResult

__all__ = [
Expand Down Expand Up @@ -191,37 +190,33 @@ def renew(
command = ["realm", "renew", domain, "--verbose", *args]
return self.host.conn.exec(command)

def permit(self, user: str, *, withdraw: bool = False, args: list[str] | None = None) -> ProcessResult:
def permit(self, *, args: list[str] | None = None) -> ProcessResult:
"""
Permit users log in.

:param user: User to permit.
:type user: str
:param withdraw: Withdraw permission, defaults to False
:type withdraw: bool, optional
:param args: Additional arguments, defaults to None
:type args: list[str] | None, optional
:return: Result of called command.
:rtype: ProcessResult
"""
cli_args: CLIBuilderArgs = {"withdraw": (self.cli.option.SWITCH, withdraw)}
if args is None:
args = []

return self.host.conn.exec(["realm", "permit", *self.cli.args(cli_args), *args, user])
return self.host.conn.exec(["realm", "permit", *args])

def deny(self, user: str, *, args: list[str] | None = None) -> ProcessResult:
def deny(self, *, args: list[str] | None = None) -> ProcessResult:
"""
Deny users log in.
Deny local log in.

:param user: User.
:type user: str
:param args: Additional arguments, defaults to None
:type args: list[str] | None, optional
:return: Result of called command.
:rtype: ProcessResult
"""
return self.permit(user, withdraw=True, args=args)
if args is None:
args = []

return self.host.conn.exec(["realm", "deny", *args])
Comment on lines +193 to +219
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To reduce code duplication and improve maintainability, you could extract the common logic for executing a realm subcommand into a private helper method. Both permit and deny methods perform very similar operations.

    def _exec_realm_cmd(self, subcommand: str, args: list[str] | None = None) -> ProcessResult:
        if args is None:
            args = []
        return self.host.conn.exec(["realm", subcommand, *args])

    def permit(self, *, args: list[str] | None = None) -> ProcessResult:
        """
        Permit users log in.

        :param args: Additional arguments, defaults to None
        :type args: list[str] | None, optional
        :return: Result of called command.
        :rtype: ProcessResult
        """
        return self._exec_realm_cmd("permit", args=args)

    def deny(self, *, args: list[str] | None = None) -> ProcessResult:
        """
        Deny local log in.

        :param args: Additional arguments, defaults to None
        :type args: list[str] | None, optional
        :return: Result of called command.
        :rtype: ProcessResult
        """
        return self._exec_realm_cmd("deny", args=args)


def list(self, *, args: list[str] | None = None) -> ProcessResult:
"""
Expand Down
Loading