Skip to content
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

add username filter when query users and credentials #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public PageOfUsers queryUsers(long offset, long limit, String filter) {
String tenantId = kvMap.get(OSIS_TENANT_ID);
String cdTenantId = kvMap.get(OSIS_CD_TENANT_ID);
String userId = kvMap.get(OSIS_USER_ID);
String username = kvMap.get(OSIS_USERNAME);
String cdUserId = kvMap.get(OSIS_CD_USER_ID);
String canonicalUserId = kvMap.get(OSIS_CANONICAL_USER_ID);
String displayName = kvMap.get(OSIS_DISPLAY_NAME);
Expand All @@ -147,7 +148,7 @@ public PageOfUsers queryUsers(long offset, long limit, String filter) {

List<OsisUser> osisUsers = uids.stream().map(tenantUid -> rgwAdmin.getUserInfo(tenantUid))
.filter(Optional::isPresent).map(u -> ModelConverter.toOsisUser(u.get())).collect(Collectors.toList());
osisUsers = filterOsisUsers(osisUsers, displayName, cdTenantId, cdUserId, activeStr, null);
osisUsers = filterOsisUsers(osisUsers, displayName, cdTenantId, cdUserId, username, activeStr, null);

return paginate(offset, limit, new PageOfUsers(), osisUsers);
}
Expand Down Expand Up @@ -185,6 +186,7 @@ public PageOfS3Credentials queryS3Credentials(long offset, long limit, String fi
String tenantId = kvMap.get(OSIS_TENANT_ID);
String cdTenantId = kvMap.get(OSIS_CD_TENANT_ID);
String userId = kvMap.get(OSIS_USER_ID);
String username = kvMap.get(OSIS_USERNAME);
String cdUserId = kvMap.get(OSIS_CD_USER_ID);
String activeStr = kvMap.get(OSIS_ACTIVE);
String accessKey = kvMap.get(OSIS_ACCESS_KEY);
Expand All @@ -200,20 +202,22 @@ public PageOfS3Credentials queryS3Credentials(long offset, long limit, String fi
List<OsisUser> osisUsers = uids.stream().map(tenantUid -> rgwAdmin.getUserInfo(tenantUid))
.filter(Optional::isPresent)
.map(u -> ModelConverter.toOsisUser(u.get())).collect(Collectors.toList());
osisUsers = filterOsisUsers(osisUsers, null, cdTenantId, cdUserId, activeStr, accessKey);
osisUsers = filterOsisUsers(osisUsers, null, cdTenantId, cdUserId, username, activeStr, accessKey);

List<OsisS3Credential> s3Credentials = osisUsers.stream().flatMap(osisUser ->
osisUser.getOsisS3Credentials().stream().filter(c -> StringUtils.isBlank(accessKey) || c.getAccessKey().equals(accessKey))).collect(Collectors.toList());
return paginate(offset, limit, new PageOfS3Credentials(), s3Credentials);
}

private List<OsisUser> filterOsisUsers(List<OsisUser> osisUsers, String displayName, String cdTenantId, String cdUserId, String activeStr, String accessKey) {
private List<OsisUser> filterOsisUsers(List<OsisUser> osisUsers, String displayName, String cdTenantId, String cdUserId, String username, String activeStr, String accessKey) {
osisUsers = osisUsers.stream().filter(osisUser ->
(StringUtils.isBlank(accessKey) || osisUser.getOsisS3Credentials().stream().anyMatch(c -> c.getAccessKey().equals(accessKey)))
&& (StringUtils.isBlank(displayName) || displayName.equals(osisUser.getUsername()))
&& (StringUtils.isBlank(activeStr) || osisUser.getActive() == Boolean.parseBoolean(activeStr))
&& (StringUtils.isBlank(cdTenantId) || cdTenantId.equals(osisUser.getCdTenantId()))
&& (StringUtils.isBlank(cdUserId) || cdUserId.equals(osisUser.getCdUserId())))
&& (StringUtils.isBlank(cdUserId) || cdUserId.equals(osisUser.getCdUserId()))
&& (StringUtils.isBlank(username) || username.equals(osisUser.getUsername()))
)
.collect(Collectors.toList());
return osisUsers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private CephConstants() {
public static final String OSIS_TENANT_ID = "tenant_id";
public static final String OSIS_CD_TENANT_ID = "cd_tenant_id";
public static final String OSIS_USER_ID = "user_id";
public static final String OSIS_USERNAME = "username";
public static final String OSIS_CD_USER_ID = "cd_user_id";
public static final String OSIS_CANONICAL_USER_ID = "canonical_user_id";
public static final String OSIS_DISPLAY_NAME = "display_name";
Expand Down