-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix OpenLDAP custom queries to use search_scope parameter #21385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix OpenLDAP custom queries to use search_scope parameter #21385
Conversation
- Add support for search_scope parameter in custom queries - Default to 'subtree' when search_scope is not specified - Update existing tests to include search_scope parameter - Add comprehensive test for search_scope functionality Fixes DataDog#20685
LDAP3 library requires constants (ldap3.BASE, ldap3.LEVEL, ldap3.SUBTREE) instead of string values for search_scope parameter.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
AAraKKe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR @puretension ! I just left a couple of small requests, once they are handled I am happy to go ahead with the merge.
My Feedback Legend
Here's a quick guide to the prefixes I use in my comments:
praise: no action needed, just celebrate!
question: I need clarification or I'm seeking to understand your approach.
suggestion: I'm proposing an improvement. This is optional but recommended.
nit: A minor, non-blocking issue (e.g., style, typo). Feel free to ignore.
request: A change I believe is necessary before this can be merged.
The only blocking comments are request, any other type of comment can be applied at discretion of the developer.
| self.log.error("`search_filter` field is required for custom query #%s", name) | ||
| continue | ||
| attrs = query.get("attributes") | ||
| search_scope_str = query.get("search_scope", "subtree") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request: thanks for defining the default in our side! Since the documentation clearly states the default it is good that we are not allowing this default to be chosen by the library implementation.
Can you please keep this default as an ldap3 constant as a class constant instead of hidden here? Something like DEFAULT_SEARCH_SCOPE = ldqp3.SUBREE would be great.
- Add SEARCH_SCOPE_MAPPING class constant for efficient lookups - Change invalid scope handling from warning+fallback to error+skip - Add comprehensive parameterized tests for all valid values - Add tests for default behavior and invalid value handling Signed-off-by: puretension <[email protected]>
|
Hi @AAraKKe, Thank you for the detailed feedback! I've addressed all your requests in the latest commit. I added the DEFAULT_SEARCH_SCOPE class constant using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the follow up @puretension !! I just have a question and a very small request on the updated tests. Would you mind clarifying why the constant is not used? The intention of defining it is to use it there but I am not seeing why the lower method would be an issue.
Once clarified I am happy to merge it.
Thanks!!
My Feedback Legend
Here's a quick guide to the prefixes I use in my comments:
praise: no action needed, just celebrate!
note: just a comment/information, no need to take any action.
question: I need clarification or I'm seeking to understand your approach.
nit: A minor, non-blocking issue (e.g., style, typo). Feel free to ignore.
suggestion: I'm proposing an improvement. This is optional but recommended.
request: A change I believe is necessary before this can be merged.
The only blocking comments are request, any other type of comment can be applied at discretion of the developer.
- Replace hardcoded 'subtree' with DEFAULT_SEARCH_SCOPE in main code - Replace ldap3.SUBTREE with DEFAULT_SEARCH_SCOPE in all tests - Ensures centralized management of default search scope value Signed-off-by: puretension <[email protected]>
|
The following files, which will be shipped with the agent, were modified in this PR and You can ignore this if you are sure the changes in this PR do not require QA. Otherwise, consider removing the label. List of modified files that will be shipped with the agent |
|
@AAraKKe Thanks for catching that! You're absolutely right! I missed using the constant even though it was already defined. I've updated both the main code and tests to use As you mentioned, |
AAraKKe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @puretension! I left a small nit, will leave to you to decide if you want to change it but it is approved. Will check later and merge if nothing else has changed.
Review from AAraKKe is dismissed. Related teams and files:
- agent-integrations
- openldap/tests/test_unit.py
|
@puretension I was about to merge and noticed that there is a linting error, can you fix it? I cannot update the branch through the |
Signed-off-by: puretension <[email protected]>
f4aa331 to
f1f785c
Compare
Organize imports in test files to comply with ruff linting rules: - tests/conftest.py: Sort imports alphabetically - tests/test_check.py: Sort imports alphabetically - tests/test_unit.py: Sort imports alphabetically Signed-off-by: puretension <[email protected]>
f1f785c to
f1139b2
Compare
|
Can you please make sure to update your branch with the latest in master to make sure you have the latest version to run the tests? It seems that you fix the issue and force push after I have updated it from the PR which downgrades it again.
Thanks! |
Signed-off-by: puretension <[email protected]>
4a70bc0 to
f1db660
Compare
Signed-off-by: puretension <[email protected]>
|
Hi @AAraKKe, Thank you for your patience! I've completed all the requested steps. I really appreciate you teaching me about the ddev test --fmt command. I wasn't familiar with it before. |
AAraKKe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @puretension ! All good from my side 🚀
* Fix OpenLDAP custom queries to use search_scope parameter - Add support for search_scope parameter in custom queries - Default to 'subtree' when search_scope is not specified - Update existing tests to include search_scope parameter - Add comprehensive test for search_scope functionality Fixes #20685 * Add changelog entry for search_scope parameter fix * Simplify search_scope test to avoid CI issues * Fix code formatting for linting compliance * Fix search_scope to use ldap3 constants instead of strings LDAP3 library requires constants (ldap3.BASE, ldap3.LEVEL, ldap3.SUBTREE) instead of string values for search_scope parameter. * Fix trailing whitespace for linting compliance * Address reviewer feedback: use mapping dict and improve error handling - Add SEARCH_SCOPE_MAPPING class constant for efficient lookups - Change invalid scope handling from warning+fallback to error+skip - Add comprehensive parameterized tests for all valid values - Add tests for default behavior and invalid value handling Signed-off-by: puretension <[email protected]> * Use DEFAULT_SEARCH_SCOPE constant instead of hardcoded values - Replace hardcoded 'subtree' with DEFAULT_SEARCH_SCOPE in main code - Replace ldap3.SUBTREE with DEFAULT_SEARCH_SCOPE in all tests - Ensures centralized management of default search scope value Signed-off-by: puretension <[email protected]> * Fix code formatting for linting compliance Signed-off-by: puretension <[email protected]> * Fix import sorting in OpenLDAP test files Organize imports in test files to comply with ruff linting rules: - tests/conftest.py: Sort imports alphabetically - tests/test_check.py: Sort imports alphabetically - tests/test_unit.py: Sort imports alphabetically Signed-off-by: puretension <[email protected]> * Fix import formatting for linting compliance Signed-off-by: puretension <[email protected]> * Run ddev test --fmt openldap to fix linting issues Signed-off-by: puretension <[email protected]> --------- Signed-off-by: puretension <[email protected]> Co-authored-by: Juanpe Araque <[email protected]>
What does this PR do?
Fixes the OpenLDAP integration to properly use the
search_scopeparameter in custom queries. The parameter was documented in the configuration but was being ignored during LDAP search operations.Motivation
Users reported in #20685 that the
search_scopeparameter in OpenLDAP custom queries was not working as expected. The parameter is documented inconf.yaml.examplebut the actual search implementation was not using this parameter, making it impossible to control LDAP search scope (base, level, or subtree).Review checklist (to be filled by reviewers)
qa/skip-qalabel if the PR doesn't need to be tested during QA.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged