Add selective attribute retrieval support#97
Conversation
…bute retrieval details
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #97 +/- ##
===========================================
+ Coverage 96.66% 100.00% +3.33%
===========================================
Files 2 2
Lines 30 30
Branches 10 10
===========================================
+ Hits 29 30 +1
+ Misses 1 0 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR enhances the LDAP client library with selective attribute retrieval capabilities across getEntry(), search(), and searchWithType() methods. This feature is particularly beneficial for Active Directory scenarios where directory entries contain numerous attributes and retrieving only required ones improves performance and reduces network overhead.
Changes:
- Added optional
attributesparameter togetEntry()andsearch()methods for explicit selective attribute retrieval - Enhanced
searchWithType()to automatically extract attribute names from the target record type for type-safe selective retrieval - Updated specification, changelog, and comprehensive test coverage
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| native/src/main/java/io/ballerina/lib/ldap/Utils.java | Added getAttributesFromEntriesType() method to extract attribute names from record type for automatic selective retrieval |
| native/src/main/java/io/ballerina/lib/ldap/Client.java | Updated getEntry(), search(), and searchWithType() to support selective attribute retrieval with proper null handling |
| ballerina/client.bal | Updated method signatures with optional attributes parameters and enhanced documentation |
| docs/spec/spec.md | Added comprehensive documentation for selective attribute retrieval feature across all affected methods |
| changelog.md | Added detailed changelog entries documenting the new feature |
| ballerina/tests/test.bal | Added 8 comprehensive test cases covering selective and all-attribute retrieval scenarios |
| ballerina/Ballerina.toml | Version bump to 1.3.1 |
| ballerina/Dependencies.toml | Updated crypto dependency version and package version |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…e introspection and update documentation
55b7724 to
e60cadb
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Nuvindu Nirmana <63797478+Nuvindu@users.noreply.github.com>
Description
This PR adds support for selective attribute retrieval in the LDAP client's
getEntry,search, andsearchWithTypemethods, addressing the need to retrieve specific attributes from LDAP directory entries rather than always fetching all attributes. This improvement is particularly beneficial for Active Directory use cases where directory entries may contain numerous attributes and retrieving only the required ones improves performance and reduces network overhead.Fixes ballerina-platform/ballerina-library#8563
Changes Made:
getEntry()method: Added optionalattributesparameter to allow specifying which attributes to retrieve. When not provided, attributes are automatically extracted from the target record type definition. Supports both explicit attribute specification and type-based introspection.search()method: Added optionalattributesparameter to enable selective attribute retrieval in search operations. When not provided or set to nil/empty array, all user attributes are retrieved.searchWithType()method: Added optionalattributesparameter to allow explicit attribute specification. When not provided, the method automatically extracts attribute names from the target record type definition, providing type-safe selective attribute retrieval. Explicit attributes take precedence over type-inferred attributes when both are applicable.Implementation Details:
attributesparameter takes precedence when provided (overrides type introspection)Utils.getAttributesFromEntryType()helper method for attribute extraction from record typesClient.javato handle attribute arrays and call appropriate LDAP SDK methodsAll parameters are optional and default to
nil/(), ensuring full backward compatibility with existing code.One line release note:
Type of change
How Has This Been Tested?
The following test cases have been added to verify the changes:
getEntry()method tests (7 tests):testGetEntryWithSelectiveAttributes- Validates retrieving specific attributes ["sn", "cn"] usinggetEntry()with attributes parametertestGetEntryWithAllAttributes- Validates default behavior (all attributes) when no attributes parameter is providedtestGetEntryWithSingleAttribute- Tests retrieving a single attribute ["sn"] onlytestGetEntryWithInvalidAttribute- Tests graceful handling of invalid/non-existent attribute namestestGetEntryWithTypeIntrospection- Validates automatic attribute extraction from UserConfig type when attributes not providedtestGetEntryWithRecordHavingRestField- Validates that Entry type with rest field retrieves all attributestestGetEntryExplicitAttributesOverrideType- Validates explicit ["cn"] overrides type-inferred attributes from UserConfigsearch()method tests (3 tests):testSearchWithSelectiveAttributes- Tests selective attribute retrieval ["sn", "cn"] insearch()methodtestSearchWithAllAttributes- Tests default behavior (all attributes) insearch()methodtestSearchWithEmptyAttributesArray- Tests empty array [] behaves like nil (retrieves all attributes)searchWithType()method tests (3 tests):testSearchWithTypeAutoAttributeExtraction- Validates automatic attribute extraction from UserConfig typetestSearchWithTypeValidateAllFields- Validates that all record type fields are correctly populatedtestSearchWithTypeExplicitAttributes- Validates explicit ["sn", "cn"] parameter overrides type-inferred attributesTest Configuration:
Checklist:
Security checks