use of org.graylog.plugins.sidecar.rest.models.ConfigurationVariable in project graylog2-server by Graylog2.
the class ConfigurationServiceTest method testTemplateRenderWithConfigurationVariables.
@Test
public void testTemplateRenderWithConfigurationVariables() throws Exception {
final String TEMPLATE = "foo bar\n myVariable: ${user.myVariable}\n";
final String TEMPLATE_RENDERED = "foo bar\n myVariable: content of myVariable\n";
configuration = buildTestConfig(TEMPLATE);
this.configurationService.save(configuration);
ConfigurationVariable myVariable = ConfigurationVariable.create("myVariable", "desc", "content of myVariable");
this.configurationVariableService.save(myVariable);
Configuration result = this.configurationService.renderConfigurationForCollector(sidecar, configuration);
assertEquals(TEMPLATE_RENDERED, result.template());
}
use of org.graylog.plugins.sidecar.rest.models.ConfigurationVariable in project graylog2-server by Graylog2.
the class ConfigurationVariableResource method getConfigurationVariablesConfigurations.
@GET
@Path("/{id}/configurations")
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_READ)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Show configurations using this variable")
public List<Configuration> getConfigurationVariablesConfigurations(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
final ConfigurationVariable configurationVariable = findVariableOrFail(id);
final List<Configuration> configurations = this.configurationService.findByConfigurationVariable(configurationVariable);
return configurations;
}
use of org.graylog.plugins.sidecar.rest.models.ConfigurationVariable in project graylog2-server by Graylog2.
the class ConfigurationVariableResource method updateConfigurationVariable.
@PUT
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_UPDATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a configuration variable")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_VARIABLE_UPDATE)
public Response updateConfigurationVariable(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "JSON body", required = true) @Valid @NotNull ConfigurationVariable request) {
final ConfigurationVariable previousConfigurationVariable = findVariableOrFail(id);
ValidationResult validationResult = validateConfigurationVariableHelper(request);
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
if (!previousConfigurationVariable.name().equals(request.name())) {
configurationService.replaceVariableNames(previousConfigurationVariable.fullName(), request.fullName());
}
final ConfigurationVariable updatedConfigurationVariable = persistConfigurationVariable(id, request);
etagService.invalidateAll();
return Response.ok().entity(updatedConfigurationVariable).build();
}
use of org.graylog.plugins.sidecar.rest.models.ConfigurationVariable in project graylog2-server by Graylog2.
the class ConfigurationVariableResource method deleteConfigurationVariable.
@DELETE
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_UPDATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete a configuration variable")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_VARIABLE_DELETE)
public Response deleteConfigurationVariable(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
final ConfigurationVariable configurationVariable = findVariableOrFail(id);
final List<Configuration> configurations = this.configurationService.findByConfigurationVariable(configurationVariable);
if (!configurations.isEmpty()) {
final ValidationResult validationResult = new ValidationResult();
validationResult.addError("name", "Variable is still used in the following configurations: " + configurations.stream().map(c -> c.name()).collect(Collectors.joining(", ")));
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
int deleted = configurationVariableService.delete(id);
if (deleted == 0) {
return Response.notModified().build();
}
etagService.invalidateAll();
return Response.accepted().build();
}
use of org.graylog.plugins.sidecar.rest.models.ConfigurationVariable in project graylog2-server by Graylog2.
the class ConfigurationVariableResource method createConfigurationVariable.
@POST
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_CREATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create new configuration variable")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_VARIABLE_CREATE)
public Response createConfigurationVariable(@ApiParam(name = "JSON body", required = true) @Valid @NotNull ConfigurationVariable request) {
ValidationResult validationResult = validateConfigurationVariableHelper(request);
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
final ConfigurationVariable configurationVariable = persistConfigurationVariable(null, request);
return Response.ok().entity(configurationVariable).build();
}
Aggregations