adcli: Add provider object support to reduce verbosity#249
adcli: Add provider object support to reduce verbosity#249shridhargadekar wants to merge 1 commit into
Conversation
This commit enhances adcli utility methods to accept GenericADProvider
objects in addition to domain strings, significantly reducing boilerplate
in test code.
Changes:
- Import GenericADProvider type for type hinting
- Modify join(), show_computer(), and delete_computer() to accept
GenericADProvider | str as first parameter
- Add convenience parameters to join() for common options:
--host-keytab, --computer-name, --domain-ou, --verbose, --show-details
- Automatically extract domain, adminuser, and adminpw from provider
- Support credential overrides via optional login_user and password params
- Maintain backward compatibility with domain string mode
Before (verbose):
client.adcli.join(
domain=provider.host.domain,
login_user=provider.host.adminuser,
password=provider.host.adminpw,
args=["--verbose", f"--host-keytab={path}"],
krb=False,
)
After (concise):
client.adcli.join(provider, host_keytab=path, verbose=True)
Signed-off-by: shridhargadekar <shridhar.always@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request updates the adcli utility to support GenericADProvider objects in the join, delete_computer, and show_computer methods, while also adding several convenience parameters for common adcli options. Review feedback highlights that changing the domain keyword-only parameter to a positional provider parameter is a breaking change for existing callers. Additionally, it is recommended to refactor the duplicated provider resolution logic into a helper method and use the domain property directly from the provider object to improve maintainability and type safety.
|
|
||
| def join( | ||
| self, | ||
| provider: GenericADProvider | str, |
There was a problem hiding this comment.
The change from a keyword-only domain parameter to a positional provider parameter is a breaking change for any existing callers that use domain="...". To maintain backward compatibility as stated in the PR description, consider keeping domain as an optional keyword argument or using a default value for provider and checking both.
|
|
||
| def delete_computer( | ||
| self, | ||
| provider: GenericADProvider | str, |
|
|
||
| def show_computer( | ||
| self, | ||
| provider: GenericADProvider | str, |
| if isinstance(provider, str): | ||
| # Domain string mode (backward compatibility) | ||
| domain = provider | ||
| if not login_user or not password: | ||
| raise ValueError( | ||
| "When using domain string mode, both 'login_user' and 'password' are required. " | ||
| "Consider passing a GenericADProvider object instead." | ||
| ) | ||
| else: | ||
| # Provider object mode | ||
| domain = provider.host.domain # type: ignore[attr-defined] | ||
| login_user = login_user or provider.host.adminuser # type: ignore[attr-defined] | ||
| password = password or provider.host.adminpw # type: ignore[attr-defined] | ||
|
|
There was a problem hiding this comment.
This logic for resolving the domain and credentials from either a provider object or a string is duplicated in join(), delete_computer(), and show_computer(). It should be refactored into a private helper method (e.g., _resolve_provider_data) to improve maintainability. Additionally, GenericADProvider defines a domain property, so you should use provider.domain instead of provider.host.domain to adhere to the interface and avoid unnecessary type: ignore comments.
| if isinstance(provider, str): | |
| # Domain string mode (backward compatibility) | |
| domain = provider | |
| if not login_user or not password: | |
| raise ValueError( | |
| "When using domain string mode, both 'login_user' and 'password' are required. " | |
| "Consider passing a GenericADProvider object instead." | |
| ) | |
| else: | |
| # Provider object mode | |
| domain = provider.host.domain # type: ignore[attr-defined] | |
| login_user = login_user or provider.host.adminuser # type: ignore[attr-defined] | |
| password = password or provider.host.adminpw # type: ignore[attr-defined] | |
| if isinstance(provider, str): | |
| # Domain string mode (backward compatibility) | |
| domain = provider | |
| if not login_user or not password: | |
| raise ValueError( | |
| "When using domain string mode, both 'login_user' and 'password' are required. " | |
| "Consider passing a GenericADProvider object instead." | |
| ) | |
| else: | |
| # Provider object mode | |
| domain = provider.domain | |
| login_user = login_user or provider.host.adminuser # type: ignore[attr-defined] | |
| password = password or provider.host.adminpw # type: ignore[attr-defined] |
This commit enhances adcli utility methods to accept GenericADProvider objects in addition to domain strings, significantly reducing boilerplate in test code.
Changes:
Before (verbose):
client.adcli.join( domain=provider.host.domain, login_user=provider.host.adminuser, password=provider.host.adminpw, args=["--verbose", f"--host-keytab={path}"], krb=False, )
After (concise):
client.adcli.join(provider, host_keytab=path, verbose=True)