Skip to content

Commit

Permalink
Revert "Fix data-stream name resolution for wild-cards (#1716)" (#1719)
Browse files Browse the repository at this point in the history
This reverts commit 2a05ce4.
  • Loading branch information
peternied authored Mar 30, 2022
1 parent 2a05ce4 commit efc2741
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ private void resolveIndexPatterns(final String name, final IndicesOptions indice

final Collection<String> matchingAliases;
Collection<String> matchingAllIndices;
Collection<String> matchingDataStreams = null;

if (isLocalAll(original)) {
if (isTraceEnabled) {
Expand Down Expand Up @@ -260,11 +259,8 @@ private void resolveIndexPatterns(final String name, final IndicesOptions indice
final boolean isDebugEnabled = log.isDebugEnabled();
try {
matchingAllIndices = Arrays.asList(resolver.concreteIndexNames(state, indicesOptions, localRequestedPatterns.toArray(new String[0])));
matchingDataStreams = resolver.dataStreamNames(state, indicesOptions, localRequestedPatterns.toArray(new String[0]));

if (isDebugEnabled) {
log.debug("Resolved pattern {} to indices: {} and data-streams: {}",
localRequestedPatterns, matchingAllIndices, matchingDataStreams);
log.debug("Resolved pattern {} to {}", localRequestedPatterns, matchingAllIndices);
}
} catch (IndexNotFoundException e1) {
if (isDebugEnabled) {
Expand All @@ -275,16 +271,13 @@ private void resolveIndexPatterns(final String name, final IndicesOptions indice
}
}

if (matchingDataStreams == null || matchingDataStreams.size() == 0) {
matchingDataStreams = Arrays.asList(NOOP);
}

if (isTraceEnabled) {
log.trace("Resolved patterns {} for {} ({}) to [aliases {}, allIndices {}, dataStreams {}, originalRequested{}, remote indices {}]",
original, name, this.name, matchingAliases, matchingAllIndices, matchingDataStreams, Arrays.toString(original), remoteIndices);
log.trace("Resolved patterns {} for {} ({}) to [aliases {}, allIndices {}, originalRequested{}, remote indices {}]",
original, name, this.name, matchingAliases, matchingAllIndices, Arrays.toString(original), remoteIndices);
}

resolveTo(matchingAliases, matchingAllIndices, matchingDataStreams, original, remoteIndices);
resolveTo(matchingAliases, matchingAllIndices, original, remoteIndices);

}

private void resolveToLocalAll() {
Expand All @@ -293,11 +286,9 @@ private void resolveToLocalAll() {
originalRequested.add(Resolved.ANY);
}

private void resolveTo(Iterable<String> matchingAliases, Iterable<String> matchingAllIndices,
Iterable<String> matchingDataStreams, String[] original, Iterable<String> remoteIndices) {
private void resolveTo(Iterable<String> matchingAliases, Iterable<String> matchingAllIndices, String[] original, Iterable<String> remoteIndices) {
aliases.addAll(matchingAliases);
allIndices.addAll(matchingAllIndices);
allIndices.addAll(matchingDataStreams);
originalRequested.add(original);
this.remoteIndices.addAll(remoteIndices);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public void createSampleDataStreams(RestHelper rh) throws Exception{
rh.executePutRequest("/_index_template/my-data-stream-template", getIndexTemplateBody(), encodeBasicHeader("ds1", "nagilum"));

rh.executePutRequest("/_data_stream/my-data-stream11", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
rh.executePutRequest("/_data_stream/my-data-stream21", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
rh.executePutRequest("/_data_stream/my-data-stream22", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
rh.executePutRequest("/_data_stream/my-data-stream23", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
rh.executePutRequest("/_data_stream/my-data-stream33", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
}

Expand Down Expand Up @@ -91,27 +89,6 @@ public void testGetDataStream() throws Exception {

response = rh.executeGetRequest("/_data_stream/my-data-stream33", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream2*", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}

@Test
Expand All @@ -126,39 +103,18 @@ public void testDeleteDataStream() throws Exception {
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream11", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream11", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream22", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream33", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream2*", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds2", "nagilum"));
response = rh.executeDeleteRequest("/_data_stream/my-data-stream22", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds3", "nagilum"));
response = rh.executeDeleteRequest("/_data_stream/my-data-stream33", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}

Expand Down Expand Up @@ -187,26 +143,5 @@ public void testDataStreamStats() throws Exception {

response = rh.executeGetRequest("/_data_stream/my-data-stream33/_stats", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*/_stats", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream21,my-data-stream22/_stats", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*/_stats", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream2*/_stats", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream21,my-data-stream22/_stats", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*/_stats", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*/_stats", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}
}
2 changes: 1 addition & 1 deletion src/test/resources/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ data_stream_1:
allowed_actions:
- "indices:admin/data_stream/get"
- "indices:admin/data_stream/create"
- "indices:admin/data_stream/delete"

data_stream_2:
reserved: true
Expand All @@ -1104,7 +1105,6 @@ data_stream_2:
- "indices:admin/data_stream/get"
- "indices:admin/data_stream/create"
- "indices:monitor/data_stream/stats"
- "indices:admin/data_stream/delete"

data_stream_3:
reserved: true
Expand Down

0 comments on commit efc2741

Please sign in to comment.