Search in sources :

Example 1 with InputSummary

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);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with InputSummary

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);
}
Also used : InputSummary(org.graylog2.rest.models.system.inputs.responses.InputSummary) Input(org.graylog2.inputs.Input) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) TextField(org.graylog2.plugin.configuration.fields.TextField) InputDescription(org.graylog2.shared.inputs.InputDescription) Test(org.junit.Test)

Example 3 with InputSummary

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());
}
Also used : InputDescription(org.graylog2.shared.inputs.InputDescription)

Example 4 with InputSummary

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);
}
Also used : InputSummary(org.graylog2.rest.models.system.inputs.responses.InputSummary) Input(org.graylog2.inputs.Input) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) TextField(org.graylog2.plugin.configuration.fields.TextField) InputDescription(org.graylog2.shared.inputs.InputDescription) Test(org.junit.Test)

Example 5 with InputSummary

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());
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) InputDescription(org.graylog2.shared.inputs.InputDescription)

Aggregations

InputDescription (org.graylog2.shared.inputs.InputDescription)4 Input (org.graylog2.inputs.Input)3 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)3 ConfigurationField (org.graylog2.plugin.configuration.fields.ConfigurationField)2 TextField (org.graylog2.plugin.configuration.fields.TextField)2 InputSummary (org.graylog2.rest.models.system.inputs.responses.InputSummary)2 Test (org.junit.Test)2 Timed (com.codahale.metrics.annotation.Timed)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 MessageInput (org.graylog2.plugin.inputs.MessageInput)1