-
Notifications
You must be signed in to change notification settings - Fork 15
Fixes user to group syncing #160
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
base: main
Are you sure you want to change the base?
Conversation
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.
Hello @edwardofclt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request addresses issue #73 and focuses on fixing the synchronization of users and groups. The primary goal is to ensure that group memberships are correctly reflected by synchronizing users and groups with user-to-group assignments. The changes involve modifications to the GroupAdapter.java and ScimClient.java files, with a heavy emphasis on logging and error handling to improve debugging and resilience. The author used Github Copilot to implement the changes.
Highlights
- Group Member Synchronization: The pull request enhances the synchronization of group members by querying user mappings based on external IDs and adding them to the group. It includes error handling for cases where user mappings are not found.
- Logging Improvements: Extensive logging has been added throughout the
GroupAdapterto provide better visibility into the group synchronization process, including the number of members collected, processed, and added to SCIM groups. - User Mapping Management: The pull request introduces a mechanism to ensure user mappings exist, creating them if necessary, to avoid issues with missing user associations during group synchronization.
- Patch Request Enhancements: The creation of PATCH requests for groups has been updated to include comprehensive logging and error handling, ensuring that group members are correctly updated or removed.
- SCIM Client Improvements: The SCIM client has been updated to use the correct endpoint path for importing resources and includes improved error logging during the import process.
Changelog
Click here to see the changelog
- src/main/java/sh/libre/scim/core/GroupAdapter.java
- Added logging to track the number of members collected for a group (lines 56-57).
- Added logging to track incoming members for a group and handle potential exceptions during user mapping lookup (lines 68-86).
- Added logging to track the processing of SCIM group members (lines 88-89).
- Implemented logic to ensure user mappings exist, creating them if needed, before adding members to a group (lines 104-110 and 274-327).
- Added logging to track the addition of members to PATCH requests (lines 112-125 and 205-223).
- Improved error handling and logging for PATCH request creation (lines 198-271).
- Added logging during group creation and user addition (lines 166-181).
- src/main/java/sh/libre/scim/core/ScimClient.java
- Updated the import process to use the correct SCIM endpoint path (lines 259-260).
- Added error logging during the import process (line 316).
- src/main/java/sh/libre/scim/core/UserAdapter.java
- Minor formatting changes (lines 17, 166, 253).
- No significant logic changes.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A sync of users,
A group takes its members in,
All now in their place.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request introduces changes to synchronize users and groups with user-to-group assignments using Github Copilot. The changes include modifications to the GroupAdapter and ScimClient classes. Overall, the changes seem to address the intended functionality, but there are some areas that could be improved for better error handling, logging, and code clarity.
Summary of Findings
- Exception Handling in
GroupAdapter.apply(Group group): TheGroupAdapter.apply(Group group)method includes a try-catch block for handling exceptions during user mapping. However, the catch block forNoResultExceptiononly logs an error message without providing additional context or attempting to resolve the issue. It might be beneficial to add more robust error handling or retry logic. - Logging verbosity and consistency: The code includes a lot of logging statements, which is great for debugging. However, the level of detail and formatting varies across different methods. Consider standardizing the logging format and using appropriate log levels (e.g.,
info,warn,error) based on the severity of the event. - User Mapping Logic in
GroupAdapter.toPatchBuilder: TheGroupAdapter.toPatchBuildermethod includes logic to ensure user mappings exist. If a mapping is not found, it attempts to create one. However, if the user is not found in Keycloak, the method returnsnullwithout providing a clear indication of failure. Consider throwing an exception or returning a more informative error message to indicate that the user mapping could not be created.
Merge Readiness
The pull request introduces significant changes to the user and group synchronization process. While the changes appear to address the intended functionality, there are several areas that require further attention before merging. Specifically, the exception handling, logging verbosity, and user mapping logic should be reviewed and improved. I am unable to directly approve this pull request, and recommend that it not be merged until the high severity issues are addressed, and that others review and approve this code before merging.
| if (externalId == null) { | ||
| LOGGER.error(String.format("Could not get or create mapping for user %s, skipping", memberId)); | ||
| continue; |
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.
| if (externalId == null) { | ||
| LOGGER.error( | ||
| String.format("Could not get or create mapping for user %s, skipping", member)); | ||
| continue; |
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.
| } catch (NoResultException e) { | ||
| LOGGER.error(String.format("No user mapping found for externalId: %s", | ||
| groupMember.getValue().get())); |
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.
| LOGGER.info(String.format("Adding member with externalId %s to group %s", externalId, displayName)); | ||
| var groupMember = new Member(); | ||
| groupMember.setValue(externalId); | ||
| groupMember.setType("User"); |
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.
What are the relevant tickets?
#73
Description (What does it do?)
Using Github Copilot (I don't know Java to save my life), I got the groups and users synced with the user to group assignments.
Screenshots (if appropriate):
How can this be tested?
Install the provider and check if the groups, users, and group assignments are created.