realmd: rearrange realm permit, deny methods#233
realmd: rearrange realm permit, deny methods#233shridhargadekar wants to merge 1 commit intoSSSD:masterfrom
Conversation
Summary of ChangesHello @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 Highlights
🧠 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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]) |
There was a problem hiding this comment.
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
662b3a9 to
a7965a9
Compare
Rearranging
realm permitandrealm denymethods for flexible test writing.realm permitworks on a whole realm, users, groupsTo restrict local log in of a specific user use
--withdrawwithpermit.realm denyworks on either "--all" or entire realm.