use of org.graylog2.contentpacks.model.ContentPack in project graylog2-server by Graylog2.
the class ContentPackResource method deleteContentPackInstallationById.
@DELETE
@Path("{contentPackId}/installations/{installationId}")
@Timed
@ApiOperation(value = "Uninstall a content pack installation")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Error loading content packs") })
@AuditEvent(type = AuditEventTypes.CONTENT_PACK_UNINSTALL)
@JsonView(ContentPackView.HttpView.class)
public Response deleteContentPackInstallationById(@ApiParam(name = "contentPackId", value = "Content pack ID", required = true) @PathParam("contentPackId") ModelId contentPackId, @ApiParam(name = "installationId", value = "Installation ID", required = true) @PathParam("installationId") String installationId) {
checkPermission(RestPermissions.CONTENT_PACK_UNINSTALL, contentPackId.toString());
final ContentPackInstallation installation = contentPackInstallationPersistenceService.findById(new ObjectId(installationId)).orElseThrow(() -> new NotFoundException("Couldn't find installation " + installationId));
final ContentPack contentPack = contentPackPersistenceService.findByIdAndRevision(installation.contentPackId(), installation.contentPackRevision()).orElseThrow(() -> new NotFoundException("Couldn't find content pack " + installation.contentPackId() + " rev " + installation.contentPackRevision()));
final ContentPackUninstallation removedInstallation = contentPackService.uninstallContentPack(contentPack, installation);
return Response.ok(ImmutableMap.of("content_pack", contentPack, "uninstalled", removedInstallation)).build();
}
use of org.graylog2.contentpacks.model.ContentPack in project graylog2-server by Graylog2.
the class ContentPackResource method createContentPack.
@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Upload a content pack")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Missing or invalid content pack"), @ApiResponse(code = 500, message = "Error while saving content pack") })
@AuditEvent(type = AuditEventTypes.CONTENT_PACK_CREATE)
@JsonView(ContentPackView.HttpView.class)
public Response createContentPack(@ApiParam(name = "Request body", value = "Content pack", required = true) @NotNull @Valid final ContentPack contentPack) {
checkPermission(RestPermissions.CONTENT_PACK_CREATE);
final ContentPack pack = contentPackPersistenceService.filterMissingResourcesAndInsert(contentPack).orElseThrow(() -> new BadRequestException("Content pack " + contentPack.id() + " with this revision " + contentPack.revision() + " already found!"));
final URI packUri = getUriBuilderToSelf().path(ContentPackResource.class).path("{contentPackId}").build(pack.id());
return Response.created(packUri).build();
}
use of org.graylog2.contentpacks.model.ContentPack in project graylog2-server by Graylog2.
the class ContentPackResource method getContentPackRevisions.
@GET
@Path("{contentPackId}/{revision}")
@Timed
@ApiOperation(value = "Get a revision of a content pack")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Error loading content packs") })
@JsonView(ContentPackView.HttpView.class)
public ContentPackResponse getContentPackRevisions(@ApiParam(name = "contentPackId", value = "Content pack ID", required = true) @PathParam("contentPackId") ModelId id, @ApiParam(name = "revision", value = "Content pack revision", required = true) @PathParam("revision") int revision) {
checkPermission(RestPermissions.CONTENT_PACK_READ);
ContentPack contentPack = contentPackPersistenceService.findByIdAndRevision(id, revision).orElseThrow(() -> new NotFoundException("Content pack " + id + " with revision " + revision + " not found!"));
Set<ConstraintCheckResult> constraints = contentPackService.checkConstraints(contentPack);
return ContentPackResponse.create(contentPack, constraints);
}
use of org.graylog2.contentpacks.model.ContentPack in project graylog2-server by Graylog2.
the class V20191219090834_AddSourcesPageTest method upgradeFailsBecauseSourcePageContentPackExists.
@Test
public void upgradeFailsBecauseSourcePageContentPackExists() throws IOException {
final URL contentPackURL = V20191219090834_AddSourcesPage.class.getResource("V20191219090834_AddSourcesPage_Content_Pack.json");
final ContentPack contentPack = ContentPackV1.builder().id(ModelId.of("04fcf179-49e0-4e8f-9c02-0ff13062efbe")).summary("summary").revision(1).name("Sources Page").description("description").vendor("").url(URI.create("http://graylog.com")).entities(ImmutableSet.of()).build();
final ContentPackInstallation contentPackInstallation = ContentPackInstallation.builder().contentPackId(contentPack.id()).contentPackRevision(1).parameters(ImmutableMap.of()).entities(ImmutableSet.of()).comment("Comment").createdAt(Instant.now()).createdBy("admin").build();
when(configService.get(V20191219090834_AddSourcesPage.MigrationCompleted.class)).thenReturn(null);
when(objectMapper.readValue(contentPackURL, ContentPack.class)).thenReturn(contentPack);
when(contentPackPersistenceService.insert(contentPack)).thenReturn(Optional.empty());
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> migration.upgrade()).withMessage("Could not install Source Page Content Pack.");
verify(configService).write(V20191219090834_AddSourcesPage.MigrationCompleted.create("04fcf179-49e0-4e8f-9c02-0ff13062efbe"));
verifyZeroInteractions(contentPackService);
}
use of org.graylog2.contentpacks.model.ContentPack in project graylog2-server by Graylog2.
the class ContentPackPersistenceServiceTest method insertDuplicate.
@Test
public void insertDuplicate() {
final ContentPackV1 contentPack = ContentPackV1.builder().id(ModelId.of("id")).revision(1).name("name").description("description").summary("summary").vendor("vendor").url(URI.create("https://www.graylog.org/")).entities(ImmutableSet.of()).build();
contentPackPersistenceService.insert(contentPack);
final Optional<ContentPack> savedContentPack2 = contentPackPersistenceService.insert(contentPack);
assertThat(savedContentPack2).isEmpty();
}
Aggregations