Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
n1v0lg committed Oct 1, 2024
1 parent fbcad41 commit 8459cac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ private void assertRoleMappingsSaveOK(CountDownLatch savedClusterState, AtomicLo
// cluster-state role mappings are retrievable by the role mapping action since they are treated as reserved role mappings and need
// to be surfaced via API for BWC
assertGetResponseHasMappings("everyone_kibana", "everyone_fleet");
// assert filtering by name works
assertGetResponseHasMappings("everyone_kibana");
assertGetResponseHasMappings("everyone_fleet");

// role mappings (with the same names) cannot be modified via API calls since they are reserved
expectThrows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,26 +324,17 @@ public void onFailure(Exception e) {
}

public void getRoleMappings(Set<String> names, ActionListener<List<ExpressionRoleMapping>> listener) {
innerGetRoleMappings(
names,
listener.delegateFailureAndWrap((l, mappings) -> l.onResponse(reservedRoleMappings.mergeWithReserved(mappings)))
);
}

/**
* Retrieves one or more mappings from the index.
* If <code>names</code> is <code>null</code> or {@link Set#isEmpty empty}, then this retrieves all mappings.
* Otherwise it retrieves the specified mappings by name.
*/
private void innerGetRoleMappings(Set<String> names, ActionListener<List<ExpressionRoleMapping>> listener) {
// TODO clean up the redundancy
if (enabled == false) {
listener.onResponse(List.of());
listener.onResponse(reservedRoleMappings.mergeWithReserved(List.of()));
} else if (names == null || names.isEmpty()) {
getMappings(listener);
getMappings(listener.safeMap(reservedRoleMappings::mergeWithReserved));
} else {
// TODO make sure order in which we are filtering is as expected... i.e., name filter happens _after_ mergeWithReserved is
// called... listeners upon listeners...
getMappings(listener.safeMap(mappings -> mappings.stream().filter(m -> names.contains(m.getName())).toList()));
getMappings(
listener.safeMap(
mappings -> reservedRoleMappings.mergeWithReserved(mappings).stream().filter(m -> names.contains(m.getName())).toList()
)
);
}
}

Expand Down

0 comments on commit 8459cac

Please sign in to comment.