Skip to content

refactor(ldap.controls): unify control encoding and decoding APIs + automatically register response control subclasses - #681

Open
spaceone wants to merge 7 commits into
refactor/code-cleanupfrom
refactor/controls-api
Open

spaceone wants to merge 7 commits into
refactor/code-cleanupfrom
refactor/controls-api

Conversation

@spaceone

Copy link
Copy Markdown
Contributor
refactor(ldap.controls): unify control encoding and decoding APIs

Standardize LDAP control implementations around the shorter `encode()`
and `decode()` methods, simplify control initialization, and improve
consistency across request and response control handling.

- Introduce `encode()` and `decode()` methods in the base control
  classes, retaining the legacy `encodeControlValue()` and
  `decodeControlValue()` methods as fallback implementations.
- Migrate concrete request and response controls to override the new
  methods instead of their legacy counterparts.
- Update `RequestControlTuples()` and `DecodeControlTuples()` to use
  the unified encoding and decoding interfaces.
- Preserve class-level control OIDs in `RequestControl` when no
  explicit control type is supplied.
- Initialize control subclasses through `super().__init__()` to
  consistently populate control types and criticality flags.
- Define class-level control OIDs for ManageDSAIT, Relax Rules,
  and Proxy Authorization controls.
- Allow callers to configure criticality for ManageDSAIT and
  Relax Rules controls instead of silently forcing it to false.
- Accept arbitrary sequences instead of requiring lists in
  control tuple conversion helpers.
- Simplify response control registration lookups, instantiation,
  and handling of unknown or malformed controls.
- Use an explicit `None` check for the response control registry
  to preserve intentionally empty registries.
- Rename internal variables and parameters for consistency and
  readability.
- Rename the legacy `LDAPControl` constructor argument from
  `encodedControlValue` to `value` and store it accordingly.

Concrete controls now implement `encode()` and
`decode()` instead of `encodeControlValue()` and
`decodeControlValue()`. Applications calling the legacy methods
directly should migrate to the new API. Backwards compatibility will be
removed in 4.0.

The `LDAPControl` constructor also replaces `encodedControlValue`
with `value`, and the control tuple helper functions rename their
parameters, affecting callers that use keyword arguments.

And:

refactor(ldap.controls): automatically register response control subclasses

Introduce automatic registration of LDAP response controls through
`ResponseControl.__init_subclass__()`, eliminating the need for explicit
registration statements in individual control modules.

Previously, each response control implementation had to manually add
itself to the global `KNOWN_RESPONSE_CONTROLS` registry. This duplicated
registration logic across modules.

Centralize this behavior in the `ResponseControl` base class so that
subclasses are automatically registered when they are defined.

- Add `ResponseControl.__init_subclass__()` to automatically register
  subclasses with a defined `controlType` in `KNOWN_RESPONSE_CONTROLS`.
- Skip registration for subclasses without a control type, allowing
  abstract and intermediate control classes to remain unregistered.
- Use `dict.setdefault()` to preserve existing registrations and avoid
  overwriting previously registered implementations for the same OID.
- Remove redundant manual registration statements from response control
  implementations across all builtin control modules.

This simplifies the implementation of new response controls, reduces
boilerplate, and keeps registration behavior consistent throughout
the control hierarchy.

Third-party response control implementations also benefit from automatic
registration when subclassing `ResponseControl` and defining a valid
`controlType`, without requiring explicit registry modifications.

* use PEP8 conform names
* use enumerate
* rename 1 letter variables to something more meaningful
* re-indent useless else block

Issue: #657
Issue: #657
@spaceone
spaceone force-pushed the refactor/controls-api branch from 687c75d to 5ac36fa Compare October 19, 2026 20:56
…lasses

Introduce automatic registration of LDAP response controls through
`ResponseControl.__init_subclass__()`, eliminating the need for explicit
registration statements in individual control modules.

Previously, each response control implementation had to manually add
itself to the global `KNOWN_RESPONSE_CONTROLS` registry. This duplicated
registration logic across modules.

Centralize this behavior in the `ResponseControl` base class so that
subclasses are automatically registered when they are defined.

- Add `ResponseControl.__init_subclass__()` to automatically register
  subclasses with a defined `controlType` in `KNOWN_RESPONSE_CONTROLS`.
- Skip registration for subclasses without a control type, allowing
  abstract and intermediate control classes to remain unregistered.
- Use `dict.setdefault()` to preserve existing registrations and avoid
  overwriting previously registered implementations for the same OID.
- Remove redundant manual registration statements from response control
  implementations across all builtin control modules.

This simplifies the implementation of new response controls, reduces
boilerplate, and keeps registration behavior consistent throughout
the control hierarchy.

Third-party response control implementations also benefit from automatic
registration when subclassing `ResponseControl` and defining a valid
`controlType`, without requiring explicit registry modifications.
@spaceone
spaceone force-pushed the refactor/controls-api branch 2 times, most recently from a690334 to 74778bf Compare October 19, 2026 21:21
Standardize LDAP control implementations around the shorter `encode()`
and `decode()` methods, simplify control initialization, and improve
consistency across request and response control handling.

- Introduce `encode()` and `decode()` methods in the base control
  classes, retaining the legacy `encodeControlValue()` and
  `decodeControlValue()` methods as fallback implementations.
- Migrate concrete request and response controls to override the new
  methods instead of their legacy counterparts.
- Update `RequestControlTuples()` and `DecodeControlTuples()` to use
  the unified encoding and decoding interfaces.
- Preserve class-level control OIDs in `RequestControl` when no
  explicit control type is supplied.
- Initialize control subclasses through `super().__init__()` to
  consistently populate control types and criticality flags.
- Define class-level control OIDs for ManageDSAIT, Relax Rules,
  and Proxy Authorization controls.
- Allow callers to configure criticality for ManageDSAIT and
  Relax Rules controls instead of silently forcing it to false.
- Accept arbitrary sequences instead of requiring lists in
  control tuple conversion helpers.
- Simplify response control registration lookups, instantiation,
  and handling of unknown or malformed controls.
- Use an explicit `None` check for the response control registry
  to preserve intentionally empty registries.
- Rename internal variables and parameters for consistency and
  readability.
- Rename the legacy `LDAPControl` constructor argument from
  `encodedControlValue` to `value` and store it accordingly.

Concrete controls now implement `encode()` and
`decode()` instead of `encodeControlValue()` and
`decodeControlValue()`. Applications calling the legacy methods
directly should migrate to the new API. Backwards compatibility will be
removed in 4.0.

The `LDAPControl` constructor also replaces `encodedControlValue`
with `value`, and the control tuple helper functions rename their
parameters, affecting callers that use keyword arguments.
@spaceone
spaceone force-pushed the refactor/controls-api branch from 74778bf to d4a0dea Compare October 19, 2026 21:41
@spaceone
spaceone force-pushed the refactor/code-cleanup branch 7 times, most recently from 7778b21 to 23b2128 Compare October 25, 2026 08:15
@spaceone spaceone added this to the 3.5.0 milestone Oct 25, 2026
@spaceone
spaceone force-pushed the refactor/code-cleanup branch from 23b2128 to 2985b30 Compare October 25, 2026 21:21
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