use of org.graylog2.rest.models.system.inputs.responses.InputSummary in project graylog2-server by Graylog2.
the class InputsResource method get.
@GET
@Timed
@ApiOperation(value = "Get information of a single input on this node")
@Path("/{inputId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input.") })
public InputSummary get(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
checkPermission(RestPermissions.INPUTS_READ, inputId);
final Input input = inputService.find(inputId);
return getInputSummary(input);
}
use of org.graylog2.rest.models.system.inputs.responses.InputSummary in project graylog2-server by Graylog2.
the class InputsResourceMaskingPasswordsTest method testRetrievalOfInputWithPasswordFieldIfUserIsNotAllowedToEditInput.
@Test
public void testRetrievalOfInputWithPasswordFieldIfUserIsNotAllowedToEditInput() throws NotFoundException {
final String inputId = "myinput";
final String inputType = "dummyinput";
final Input input = getInput(inputId, inputType);
when(inputService.find(inputId)).thenReturn(input);
final ConfigurationField fooInput = mock(ConfigurationField.class);
when(fooInput.getName()).thenReturn("foo");
final TextField passwordInput = getPasswordField("password");
final ConfigurationRequest configurationRequest = ConfigurationRequest.createWithFields(fooInput, passwordInput);
final InputDescription inputDescription = getInputDescription(configurationRequest);
this.availableInputs.put(inputType, inputDescription);
when(currentSubject.isPermitted(RestPermissions.INPUTS_READ + ":" + inputId)).thenReturn(true);
when(currentSubject.isPermitted(RestPermissions.INPUTS_EDIT + ":" + inputId)).thenReturn(false);
final Map<String, Object> configuration = ImmutableMap.of("foo", 42, "password", "verysecret");
when(input.getConfiguration()).thenReturn(configuration);
final InputSummary summary = this.inputsResource.get(inputId);
assertThat(summary.attributes()).hasSize(2);
assertThat(summary.attributes()).containsEntry("password", "<password set>");
assertThat(summary.attributes()).containsEntry("foo", 42);
}
use of org.graylog2.rest.models.system.inputs.responses.InputSummary in project graylog2-server by Graylog2.
the class InputsResource method getInputSummary.
private InputSummary getInputSummary(Input input) {
final InputDescription inputDescription = this.availableInputs.get(input.getType());
final String name = inputDescription != null ? inputDescription.getName() : "Unknown Input (" + input.getType() + ")";
return InputSummary.create(input.getTitle(), input.isGlobal(), name, input.getContentPack(), input.getId(), input.getCreatedAt(), input.getType(), input.getCreatorUserId(), input.getConfiguration(), input.getStaticFields(), input.getNodeId());
}
use of org.graylog2.rest.models.system.inputs.responses.InputSummary in project graylog2-server by Graylog2.
the class InputsResourceMaskingPasswordsTest method testRetrievalOfInputWithPasswordFieldIfUserIsAllowedToEditInput.
@Test
public void testRetrievalOfInputWithPasswordFieldIfUserIsAllowedToEditInput() throws NotFoundException {
final String inputId = "myinput";
final String inputType = "dummyinput";
final Input input = getInput(inputId, inputType);
when(inputService.find(inputId)).thenReturn(input);
final ConfigurationField fooInput = mock(ConfigurationField.class);
when(fooInput.getName()).thenReturn("foo");
final TextField passwordInput = getPasswordField("password");
final ConfigurationRequest configurationRequest = ConfigurationRequest.createWithFields(fooInput, passwordInput);
final InputDescription inputDescription = getInputDescription(configurationRequest);
this.availableInputs.put(inputType, inputDescription);
when(currentSubject.isPermitted(RestPermissions.INPUTS_READ + ":" + inputId)).thenReturn(true);
when(currentSubject.isPermitted(RestPermissions.INPUTS_EDIT + ":" + inputId)).thenReturn(true);
final Map<String, Object> configuration = ImmutableMap.of("foo", 42, "password", "verysecret");
when(input.getConfiguration()).thenReturn(configuration);
final InputSummary summary = this.inputsResource.get(inputId);
assertThat(summary.attributes()).hasSize(2);
assertThat(summary.attributes()).containsEntry("password", "verysecret");
assertThat(summary.attributes()).containsEntry("foo", 42);
}
use of org.graylog2.rest.models.system.inputs.responses.InputSummary in project graylog2-server by Graylog2.
the class AbstractInputsResource method getInputSummary.
/**
* @return A {@link InputSummary} JSON value object for the input entity.
*/
protected InputSummary getInputSummary(Input input) {
final InputDescription inputDescription = this.availableInputs.get(input.getType());
final String name = inputDescription != null ? inputDescription.getName() : "Unknown Input (" + input.getType() + ")";
final ConfigurationRequest configurationRequest = inputDescription != null ? inputDescription.getConfigurationRequest() : null;
final Map<String, Object> configuration = isPermitted(RestPermissions.INPUTS_EDIT, input.getId()) ? input.getConfiguration() : maskPasswordsInConfiguration(input.getConfiguration(), configurationRequest);
return InputSummary.create(input.getTitle(), input.isGlobal(), name, input.getContentPack(), input.getId(), input.getCreatedAt(), input.getType(), input.getCreatorUserId(), configuration, input.getStaticFields(), input.getNodeId());
}
Aggregations