Skip to content

Commit 94423d4

Browse files
authored
Rename and document field in index resolution (#136694)
1 parent 8172161 commit 94423d4

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

server/src/main/java/org/elasticsearch/action/ResolvedIndexExpression.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* {
3333
* "original": "my-index-*",
3434
* "localExpressions": {
35-
* "expressions": ["my-index-000001", "my-index-000002"],
35+
* "indices": ["my-index-000001", "my-index-000002"],
3636
* "localIndexResolutionResult": "SUCCESS"
3737
* },
3838
* "remoteExpressions": ["remote1:my-index-*", "remote2:my-index-*"]
@@ -42,7 +42,8 @@
4242
* @param original the original index expression, as provided by the user
4343
* @param localExpressions the local expressions that replace the original along with their resolution result
4444
* and failure info
45-
* @param remoteExpressions the remote expressions that replace the original
45+
* @param remoteExpressions the remote expressions that replace the original one (in the case of CPS/flat index resolution).
46+
* Only set on the local ResolvedIndexExpression, empty otherwise.
4647
*/
4748
public record ResolvedIndexExpression(String original, LocalExpressions localExpressions, Set<String> remoteExpressions)
4849
implements
@@ -64,7 +65,7 @@ public void writeTo(StreamOutput out) throws IOException {
6465
* Failures can be due to concrete resources not being visible (either missing or not visible due to indices options)
6566
* or unauthorized concrete resources.
6667
* A wildcard expression resolving to nothing is still considered a successful resolution.
67-
* The NONE result indicates that no local resolution was attempted, because the expression is known to be remote-only.
68+
* The NONE result indicates that no local resolution was attempted because the expression is known to be remote-only.
6869
*/
6970
public enum LocalIndexResolutionResult {
7071
NONE,
@@ -75,9 +76,11 @@ public enum LocalIndexResolutionResult {
7576

7677
/**
7778
* Represents local (non-remote) resolution results, including expanded indices, and a {@link LocalIndexResolutionResult}.
79+
*
80+
* @param indices represents the resolved concrete indices backing the expression
7881
*/
7982
public record LocalExpressions(
80-
Set<String> expressions,
83+
Set<String> indices,
8184
LocalIndexResolutionResult localIndexResolutionResult,
8285
@Nullable ElasticsearchException exception
8386
) implements Writeable {
@@ -99,7 +102,7 @@ public LocalExpressions(StreamInput in) throws IOException {
99102

100103
@Override
101104
public void writeTo(StreamOutput out) throws IOException {
102-
out.writeStringCollection(expressions);
105+
out.writeStringCollection(indices);
103106
out.writeEnum(localIndexResolutionResult);
104107
ElasticsearchException.writeException(exception, out);
105108
}

server/src/main/java/org/elasticsearch/action/ResolvedIndexExpressions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public ResolvedIndexExpressions(StreamInput in) throws IOException {
3333
}
3434

3535
public List<String> getLocalIndicesList() {
36-
return expressions.stream().flatMap(e -> e.localExpressions().expressions().stream()).toList();
36+
return expressions.stream().flatMap(e -> e.localExpressions().indices().stream()).toList();
3737
}
3838

3939
public List<String> getRemoteIndicesList() {
@@ -86,7 +86,7 @@ public void excludeFromLocalExpressions(Set<String> expressionsToExclude) {
8686
Objects.requireNonNull(expressionsToExclude);
8787
if (expressionsToExclude.isEmpty() == false) {
8888
for (ResolvedIndexExpression prior : expressions) {
89-
final Set<String> localExpressions = prior.localExpressions().expressions();
89+
final Set<String> localExpressions = prior.localExpressions().indices();
9090
if (localExpressions.isEmpty()) {
9191
continue;
9292
}

server/src/main/java/org/elasticsearch/search/crossproject/CrossProjectIndexResolutionValidator.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@ public static ElasticsearchException validate(
9898
ResolvedIndexExpression.LocalExpressions localExpressions = localResolvedIndices.localExpressions();
9999
ResolvedIndexExpression.LocalIndexResolutionResult result = localExpressions.localIndexResolutionResult();
100100
if (isQualifiedExpression) {
101-
ElasticsearchException e = checkResolutionFailure(
102-
localExpressions.expressions(),
103-
result,
104-
originalExpression,
105-
indicesOptions
106-
);
101+
ElasticsearchException e = checkResolutionFailure(localExpressions.indices(), result, originalExpression, indicesOptions);
107102
if (e != null) {
108103
return e;
109104
}
@@ -123,7 +118,7 @@ public static ElasticsearchException validate(
123118
}
124119
} else {
125120
ElasticsearchException localException = checkResolutionFailure(
126-
localExpressions.expressions(),
121+
localExpressions.indices(),
127122
result,
128123
originalExpression,
129124
indicesOptions
@@ -196,7 +191,7 @@ private static ElasticsearchException checkSingleRemoteExpression(
196191
}
197192

198193
return checkResolutionFailure(
199-
matchingExpression.expressions(),
194+
matchingExpression.indices(),
200195
matchingExpression.localIndexResolutionResult(),
201196
remoteExpression,
202197
indicesOptions

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ public void testXPackSecurityUserHasAccessToSecurityIndex() {
20002000
assertEquals(1, resolved.expressions().size());
20012001
var expression = resolved.expressions().getFirst();
20022002
assertEquals("_all", expression.original());
2003-
assertThat(expression.localExpressions().expressions(), hasItem(SECURITY_MAIN_ALIAS));
2003+
assertThat(expression.localExpressions().indices(), hasItem(SECURITY_MAIN_ALIAS));
20042004
}
20052005
{
20062006
IndicesAliasesRequest aliasesRequest = new IndicesAliasesRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT);
@@ -2025,7 +2025,7 @@ public void testXPackUserDoesNotHaveAccessToSecurityIndex() {
20252025
assertEquals(1, resolved.expressions().size());
20262026
var expression = resolved.expressions().getFirst();
20272027
assertEquals("_all", expression.original());
2028-
assertThat(expression.localExpressions().expressions(), not(hasItem(SECURITY_MAIN_ALIAS)));
2028+
assertThat(expression.localExpressions().indices(), not(hasItem(SECURITY_MAIN_ALIAS)));
20292029
}
20302030

20312031
public void testNonXPackUserAccessingSecurityIndex() {
@@ -2051,7 +2051,7 @@ public void testNonXPackUserAccessingSecurityIndex() {
20512051
assertEquals(1, resolved.expressions().size());
20522052
var expression = resolved.expressions().getFirst();
20532053
assertEquals("_all", expression.original());
2054-
assertThat(expression.localExpressions().expressions(), not(hasItem(SECURITY_MAIN_ALIAS)));
2054+
assertThat(expression.localExpressions().indices(), not(hasItem(SECURITY_MAIN_ALIAS)));
20552055
}
20562056

20572057
{

0 commit comments

Comments
 (0)