use of org.graylog.plugins.views.search.export.MessagesRequest in project graylog2-server by Graylog2.
the class MessagesResourceTest method appliesDefaultStreamsToRequestIfOmitted.
@Test
void appliesDefaultStreamsToRequestIfOmitted() {
MessagesRequest request = validRequest();
final SearchUser searchUser = TestSearchUser.builder().allowStream("stream-1").allowStream("stream-2").build();
ArgumentCaptor<MessagesRequest> captor = ArgumentCaptor.forClass(MessagesRequest.class);
when(commandFactory.buildFromRequest(captor.capture())).thenReturn(ExportMessagesCommand.withDefaults());
sut.retrieve(request, searchUser);
MessagesRequest value = captor.getValue();
assertThat(value.streams()).containsExactly("stream-1", "stream-2");
}
use of org.graylog.plugins.views.search.export.MessagesRequest in project graylog2-server by Graylog2.
the class MessagesResourceTest method checksStreamPermissionsForPlainRequest.
@Test
void checksStreamPermissionsForPlainRequest() {
final SearchUser searchUser = TestSearchUser.builder().denyStream("stream-1").build();
MessagesRequest request = validRequest().toBuilder().streams(ImmutableSet.of("stream-1")).build();
PermissionException exception = new PermissionException("The wurst is yet to come");
doThrow(exception).when(executionGuard).checkUserIsPermittedToSeeStreams(eq(ImmutableSet.of("stream-1")), any());
assertThatExceptionOfType(PermissionException.class).isThrownBy(() -> sut.retrieve(request, searchUser)).withMessageContaining(exception.getMessage());
}
use of org.graylog.plugins.views.search.export.MessagesRequest in project graylog2-server by Graylog2.
the class MessagesResource method retrieve.
@ApiOperation(value = "Export messages as CSV", notes = "Use this endpoint, if you want to configure export parameters freely instead of relying on an existing Search")
@POST
@Produces(MoreMediaTypes.TEXT_CSV)
@NoAuditEvent("Has custom audit events")
public ChunkedOutput<SimpleMessageChunk> retrieve(@ApiParam @Valid MessagesRequest rawrequest, @Context SearchUser searchUser) {
final MessagesRequest request = fillInIfNecessary(rawrequest, searchUser);
final ValidationRequest.Builder validationReq = ValidationRequest.builder();
Optional.ofNullable(rawrequest.queryString()).ifPresent(validationReq::query);
Optional.ofNullable(rawrequest.timeRange()).ifPresent(validationReq::timerange);
Optional.ofNullable(rawrequest.streams()).ifPresent(validationReq::streams);
final ValidationResponse validationResponse = queryValidationService.validate(validationReq.build());
if (validationResponse.status().equals(ValidationStatus.ERROR)) {
validationResponse.explanations().stream().findFirst().map(ValidationMessage::errorMessage).ifPresent(message -> {
throw new BadRequestException("Request validation failed: " + message);
});
}
executionGuard.checkUserIsPermittedToSeeStreams(request.streams(), searchUser::canReadStream);
ExportMessagesCommand command = commandFactory.buildFromRequest(request);
return asyncRunner.apply(chunkConsumer -> exporter().export(command, chunkConsumer));
}
Aggregations