-
Notifications
You must be signed in to change notification settings - Fork 76
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
Reduce logs in webapp container (depends on blackduck-common release, do not merge) #1390
base: master
Are you sure you want to change the base?
Conversation
UserGroupService userGroupService = blackDuckServicesFactory.createUserGroupService(); | ||
List<RoleAssignmentView> roles = userGroupService.getServerRolesForUser(userView); | ||
boolean isAdmin = checkIsAdmin(roles); | ||
version = blackDuckRegistrationService.getBlackDuckServerData(isAdmin).getVersion(); |
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.
As discussed on a call, the greater intention of passing in isAdmin
here is not clear.
To someone working with this code in the future it may look like the only thing this code cares about here is the version.
That could lead a developer down a path of refactoring, not realizing the importance of the side effect, and all of a sudden we will start making extra calls in other places again.
I think Ideally we would:
- Determine user roles once
- Fetch BlackDuckServerData based on it once
- Pass around this data to wherever its needed, including phone home
This is more work but I believe is more reliable and would minimize the number of API calls needed,.
version = blackDuckRegistrationService.getBlackDuckServerData().getVersion(); | ||
UserView userView = userService.findCurrentUser(); | ||
UserGroupService userGroupService = blackDuckServicesFactory.createUserGroupService(); | ||
List<RoleAssignmentView> roles = userGroupService.getServerRolesForUser(userView); |
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.
One thing to be careful about here is pagination.
I'm not sure what the maximum number of roles is, but it may be greater than the default page size.
JIRA Ticket
IDETECT-4209
Description
This update aims to reduce excessive logs in hub webapp container when a non-sysadmin user tries to access registration key calling the endpoint
/api/registration
during detect startup and phone-homing.Detect can determine the current user’s roles during startup by communicating with
blackduck-common
. By checking if the user has sysadmin privileges, we can pass this status toBlackDuckRegistrationService#getBlackDuckServerData(isAdmin)
, reducing unnecessary calls.Solution Approach
getBlackDuckServerData()
to accept anisAdmin
flag and pass it fromdetermineConnectivity()
.getRegistrationId()
ifisAdmin
isfalse
to avoid redundant requests.This fix depends on the release of
blackduck-common
library containing the following code updates.blackducksoftware/blackduck-common#453