-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,7 @@ | |
import com.blackduck.integration.blackduck.service.dataservice.BlackDuckRegistrationService; | ||
import com.blackduck.integration.blackduck.service.dataservice.UserGroupService; | ||
import com.blackduck.integration.blackduck.service.dataservice.UserService; | ||
import com.blackduck.integration.configuration.property.Properties; | ||
import com.blackduck.integration.configuration.property.types.enums.EnumProperty; | ||
import com.blackduck.integration.detect.configuration.DetectProperties; | ||
import com.blackduck.integration.detect.configuration.DetectUserFriendlyException; | ||
import com.blackduck.integration.detect.configuration.enumeration.BlackduckScanMode; | ||
import com.blackduck.integration.detect.configuration.enumeration.ExitCodeType; | ||
import com.blackduck.integration.exception.IntegrationException; | ||
import com.blackduck.integration.log.SilentIntLogger; | ||
|
@@ -29,7 +25,7 @@ | |
|
||
public class BlackDuckConnectivityChecker { | ||
private static final LinkMultipleResponses<UserGroupView> USERGROUPS = new LinkMultipleResponses<>("usergroups", UserGroupView.class); | ||
|
||
private static final String SYS_ADMIN_ROLE = "System Administrator"; | ||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
public BlackDuckConnectivityResult determineConnectivity(BlackDuckServerConfig blackDuckServerConfig) | ||
|
@@ -51,15 +47,15 @@ public BlackDuckConnectivityResult determineConnectivity(BlackDuckServerConfig b | |
|
||
String version = ""; | ||
try { | ||
version = blackDuckRegistrationService.getBlackDuckServerData().getVersion(); | ||
UserView userView = userService.findCurrentUser(); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. As discussed on a call, the greater intention of passing in I think Ideally we would:
This is more work but I believe is more reliable and would minimize the number of API calls needed,. |
||
logger.info(String.format("Successfully connected to Black Duck (version %s)!", version)); | ||
|
||
if (logger.isDebugEnabled()) { | ||
UserView userView = userService.findCurrentUser(); | ||
logger.debug("Connected as: " + userView.getUserName()); | ||
|
||
UserGroupService userGroupService = blackDuckServicesFactory.createUserGroupService(); | ||
List<RoleAssignmentView> roles = userGroupService.getServerRolesForUser(userView); | ||
logger.debug("Server Roles: " + roles.stream().map(RoleAssignmentView::getName).distinct().collect(Collectors.joining(", "))); | ||
|
||
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient(); | ||
|
@@ -75,4 +71,8 @@ public BlackDuckConnectivityResult determineConnectivity(BlackDuckServerConfig b | |
} | ||
return BlackDuckConnectivityResult.success(blackDuckServicesFactory, blackDuckServerConfig, version); | ||
} | ||
} | ||
|
||
private boolean checkIsAdmin(List<RoleAssignmentView> roles) { | ||
return roles.stream().anyMatch(role -> SYS_ADMIN_ROLE.equals(role.getName())); | ||
} | ||
} |
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.