use of net.ripe.rpki.validator3.api.ApiResponse in project rpki-validator-3 by RIPE-NCC.
the class BgpPreviewController method list.
@GetMapping(path = "/")
public ResponseEntity<ApiResponse<Stream<BgpPreview>>> list(@RequestParam(name = "startFrom", defaultValue = "0") int startFrom, @RequestParam(name = "pageSize", defaultValue = "20") int pageSize, @RequestParam(name = "search", defaultValue = "", required = false) String searchString, @RequestParam(name = "sortBy", defaultValue = "prefix") String sortBy, @RequestParam(name = "sortDirection", defaultValue = "asc") String sortDirection) {
final SearchTerm searchTerm = StringUtils.isNotBlank(searchString) ? new SearchTerm(searchString) : null;
final Sorting sorting = Sorting.parse(sortBy, sortDirection);
final Paging paging = Paging.of(startFrom, pageSize);
BgpPreviewService.BgpPreviewResult bgpPreviewResult = bgpPreviewService.find(searchTerm, sorting, paging);
return ResponseEntity.ok(ApiResponse.<Stream<BgpPreview>>builder().data(bgpPreviewResult.getData().map(entry -> BgpPreview.of(entry.getOrigin().toString(), entry.getPrefix().toString(), entry.getValidity().name()))).metadata(Metadata.of(bgpPreviewResult.getTotalCount())).build());
}
use of net.ripe.rpki.validator3.api.ApiResponse in project rpki-validator-3 by RIPE-NCC.
the class RoaPrefixAssertionsController method add.
@PostMapping(consumes = { Api.API_MIME_TYPE, "application/json" })
public ResponseEntity<ApiResponse<RoaPrefixAssertionResource>> add(@RequestBody @Valid ApiCommand<AddRoaPrefixAssertion> command) {
final long id = roaPrefixAssertionsService.execute(command.getData());
final RoaPrefixAssertion ignoreFilter = roaPrefixAssertions.get(id);
final Link selfRel = linkTo(methodOn(RoaPrefixAssertionsController.class).get(id)).withSelfRel();
return ResponseEntity.created(URI.create(selfRel.getHref())).body(ApiResponse.data(toResource(ignoreFilter)));
}
use of net.ripe.rpki.validator3.api.ApiResponse in project rpki-validator-3 by RIPE-NCC.
the class RoaPrefixAssertionsController method list.
@GetMapping
public ResponseEntity<ApiResponse<Stream<RoaPrefixAssertionResource>>> list(@RequestParam(name = "startFrom", defaultValue = "0") int startFrom, @RequestParam(name = "pageSize", defaultValue = "20") int pageSize, @RequestParam(name = "search", defaultValue = "", required = false) String searchString, @RequestParam(name = "sortBy", defaultValue = "prefix") String sortBy, @RequestParam(name = "sortDirection", defaultValue = "asc") String sortDirection) {
final SearchTerm searchTerm = StringUtils.isNotBlank(searchString) ? new SearchTerm(searchString) : null;
final Sorting sorting = Sorting.parse(sortBy, sortDirection);
final Paging paging = Paging.of(startFrom, pageSize);
final List<RoaPrefixAssertion> matching = roaPrefixAssertions.find(searchTerm, sorting, paging).collect(Collectors.toList());
int totalSize = (int) roaPrefixAssertions.count(searchTerm);
final Links links = Paging.links(startFrom, pageSize, totalSize, (sf, ps) -> methodOn(RoaPrefixAssertionsController.class).list(sf, ps, searchString, sortBy, sortDirection));
return ResponseEntity.ok(ApiResponse.<Stream<RoaPrefixAssertionResource>>builder().links(links).metadata(Metadata.of(totalSize)).data(matching.stream().map(this::toResource)).build());
}
use of net.ripe.rpki.validator3.api.ApiResponse in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorControllerTest method should_fail_on_invalid_request.
@Test
public void should_fail_on_invalid_request() throws Exception {
ResultActions result = mvc.perform(post("/api/trust-anchors").accept(Api.API_MIME_TYPE).contentType(Api.API_MIME_TYPE).content(objectMapper.writeValueAsString(ApiCommand.of(AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(TEST_CA_NAME).locations(Arrays.asList("invalid-location")).subjectPublicKeyInfo("public key info too short").build()))));
result.andExpect(status().isBadRequest()).andExpect(content().contentType(Api.API_MIME_TYPE));
ApiResponse<TrustAnchorResource> response = addTrustAnchorResponse(result);
assertThat(response.getErrors()).isNotEmpty();
}
use of net.ripe.rpki.validator3.api.ApiResponse in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorControllerTest method should_add_trust_anchor.
@Test
public void should_add_trust_anchor() throws Exception {
ResultActions result = mvc.perform(post("/api/trust-anchors").accept(Api.API_MIME_TYPE).contentType(Api.API_MIME_TYPE).content(objectMapper.writeValueAsString(ApiCommand.of(AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(TEST_CA_NAME).locations(Arrays.asList("rsync://example.com/rpki")).subjectPublicKeyInfo("jdfakljkldf;adsfjkdsfkl;nasdjfnsldajfklsd;ajfk;ljdsakjfkla;sdhfkjdshfkljadsl;kjfdklfjdaksl;jdfkl;jafkldjsfkl;adjsfkl;adjsf;lkjkl;dj;adskjfdljadjbkfbkjblafkjdfbasfjlka").build()))));
result.andExpect(status().isCreated()).andExpect(content().contentType(Api.API_MIME_TYPE));
ApiResponse<TrustAnchorResource> response = addTrustAnchorResponse(result);
assertThat(response.getData()).isNotNull();
TrustAnchorResource resource = response.getData();
Link selfRel = resource.getLinks().getLink("self");
mvc.perform(get(selfRel.getHref()).accept(Api.API_MIME_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(Api.API_MIME_TYPE)).andExpect(jsonPath("$.data.name").value(TEST_CA_NAME));
}
Aggregations