Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelandis committed Aug 26, 2024
1 parent 992e4a5 commit 069e575
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ boolean basicSecurityMode = Boolean.valueOf(providers.systemProperty('basicSecur
def fulfillingCluster = testClusters.register('fulfilling-cluster') {
testDistribution = providers.systemProperty('run.distribution').orElse('default').get()


version = '8.14.0'
setting 'xpack.security.enabled', 'true'
setting 'xpack.watcher.enabled', 'false'
setting 'xpack.ml.enabled', 'false'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1417,32 +1417,14 @@ private static BytesReference convertRoleDescriptorsMapToBytes(Map<String, Objec
}

static BytesReference maybeRemoveRemoteClusterFromRoleDescriptors(BytesReference roleDescriptorsBytes) {
if (roleDescriptorsBytes == null || roleDescriptorsBytes.length() == 0) {
return roleDescriptorsBytes;
}

final Map<String, Object> roleDescriptorsMap = convertRoleDescriptorsBytesToMap(roleDescriptorsBytes);
final AtomicBoolean removedAtLeastOne = new AtomicBoolean(false);
roleDescriptorsMap.forEach((key, value) -> {
if (value instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> roleDescriptor = (Map<String, Object>) value;
boolean removed = roleDescriptor.remove(RoleDescriptor.Fields.REMOTE_CLUSTER.getPreferredName()) != null;
if (removed) {
removedAtLeastOne.set(true);
}
}
});

if (removedAtLeastOne.get()) {
return convertRoleDescriptorsMapToBytes(roleDescriptorsMap);
} else {
// No need to serialize if we did not remove anything.
return roleDescriptorsBytes;
}
return maybeRemoveTopLevelFromRoleDescriptors(roleDescriptorsBytes, RoleDescriptor.Fields.REMOTE_CLUSTER.getPreferredName());
}

static BytesReference maybeRemoveRemoteIndicesFromRoleDescriptors(BytesReference roleDescriptorsBytes) {
return maybeRemoveTopLevelFromRoleDescriptors(roleDescriptorsBytes, RoleDescriptor.Fields.REMOTE_INDICES.getPreferredName());
}

static BytesReference maybeRemoveTopLevelFromRoleDescriptors(BytesReference roleDescriptorsBytes, String topLevelField) {
if (roleDescriptorsBytes == null || roleDescriptorsBytes.length() == 0) {
return roleDescriptorsBytes;
}
Expand All @@ -1453,7 +1435,7 @@ static BytesReference maybeRemoveRemoteIndicesFromRoleDescriptors(BytesReference
if (value instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> roleDescriptor = (Map<String, Object>) value;
boolean removed = roleDescriptor.remove(RoleDescriptor.Fields.REMOTE_INDICES.getPreferredName()) != null;
boolean removed = roleDescriptor.remove(topLevelField) != null;
if (removed) {
removedAtLeastOne.set(true);
}
Expand Down

0 comments on commit 069e575

Please sign in to comment.