Skip to content

adcli: Add provider object support to reduce verbosity#249

Draft
shridhargadekar wants to merge 1 commit into
SSSD:masterfrom
shridhargadekar:adcli-provider-support
Draft

adcli: Add provider object support to reduce verbosity#249
shridhargadekar wants to merge 1 commit into
SSSD:masterfrom
shridhargadekar:adcli-provider-support

Conversation

@shridhargadekar
Copy link
Copy Markdown
Contributor

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)

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>
Copy link
Copy Markdown

@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 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,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Similar to join(), changing domain from a keyword-only argument to a positional provider argument breaks backward compatibility for callers using the domain keyword.


def show_computer(
self,
provider: GenericADProvider | str,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Similar to join(), changing domain from a keyword-only argument to a positional provider argument breaks backward compatibility for callers using the domain keyword.

Comment on lines +254 to +267
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]

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

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.

Suggested change
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]

@shridhargadekar shridhargadekar marked this pull request as draft May 22, 2026 15:20
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