Skip to content

realmd: rearrange realm permit, deny methods#233

Closed
shridhargadekar wants to merge 1 commit intoSSSD:masterfrom
shridhargadekar:realm_d
Closed

realmd: rearrange realm permit, deny methods#233
shridhargadekar wants to merge 1 commit intoSSSD:masterfrom
shridhargadekar:realm_d

Conversation

@shridhargadekar
Copy link
Contributor

Rearranging realm permit and realm deny methods for flexible test writing.
realm permit works on a whole realm, users, groups
To restrict local log in of a specific user use --withdraw with permit.
realm deny works on either "--all" or entire realm.

@gemini-code-assist
Copy link

Summary of Changes

Hello @shridhargadekar, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the permit and deny methods within the realmd utility to enhance their flexibility. By transitioning from specific parameters like user and withdraw to a more generic args list, the methods now directly construct and execute the underlying realm commands. This modification simplifies the internal logic and provides callers, particularly test suites, with finer-grained control over the command-line arguments, facilitating more diverse and robust testing scenarios.

Highlights

  • Refactored permit method: The permit method in realmd.py was refactored to no longer accept explicit user and withdraw parameters. Instead, it now directly passes all arguments via a generic args list to the realm permit command, offering greater flexibility.
  • Refactored deny method: The deny method in realmd.py was refactored to directly execute the realm deny command with a generic args list. Previously, it internally called the permit method with withdraw=True, which is no longer the case.
  • Improved flexibility for test writing: These changes allow for more flexible test writing by enabling callers to pass any valid realm permit or realm deny arguments directly, rather than being constrained by specific method parameters.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • sssd_test_framework/utils/realmd.py
    • Refactored permit method to accept a generic args list instead of explicit user and withdraw parameters, directly executing realm permit.
    • Refactored deny method to directly execute realm deny with a generic args list, removing its dependency on the permit method.
    • Updated docstrings for permit and deny methods to reflect the new parameter signature and functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the realm permit and realm deny methods to provide more flexibility for test writing. The changes remove specific parameters like user and withdraw, making the methods more generic wrappers around the realm command-line tool. The caller is now expected to pass all arguments through the args parameter. Additionally, the deny method is corrected to use the realm deny command.

The changes are logical and improve the utility's flexibility. I've added one suggestion to refactor the new methods to reduce code duplication by introducing a helper method, which would improve maintainability.

Comment on lines +194 to +220
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])

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)

Rearranging "realm permit" and "realm deny" methods
for flexible test writing.
"realm permit" works on a whole realm, users, groups
To restrict local log in of a specific user use
"--withdraw" with "permit".
"realm deny" works on either "--all" or entire realm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant