Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished apidoc #59

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public ResponseEntity<String> newCaptureRelp(@RequestBody CaptureRelp newCapture
@ApiResponse(responseCode = "200", description = "Capture deleted",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = CaptureRelp.class))}),
@ApiResponse(responseCode = "400", description = "Capture does not exist or it is being used",
@ApiResponse(responseCode = "400", description = "Capture does not exist OR Capture is being used",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public ResponseEntity<String> newCaptureGroup(@RequestBody CaptureGroup newCaptu
@ApiResponse(responseCode = "200", description = "Capture group deleted",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = CaptureGroup.class))}),
@ApiResponse(responseCode = "400", description = "Capture group does not exist or it is being used",
@ApiResponse(responseCode = "400", description = "Capture group does not exist OR Capture group is being used",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
package com.teragrep.cfe18.handlers;

import com.teragrep.cfe18.FileCaptureMetaMapper;
import com.teragrep.cfe18.handlers.entities.CaptureGroup;
import com.teragrep.cfe18.handlers.entities.FileCaptureMeta;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.json.JSONObject;
Expand Down Expand Up @@ -130,6 +131,15 @@ public List<FileCaptureMeta> getAllProcessingType() {


@RequestMapping(path = "/meta/rule", method = RequestMethod.PUT, produces = "application/json")
@Operation(summary = "Insert processing type for file based capture")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "New processing type created",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = FileCaptureMeta.class))}),
@ApiResponse(responseCode = "400", description = "Similar processing type already exists with same values but different name OR Null value was inserted",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<String> newFileMeta(@RequestBody FileCaptureMeta newFileCaptureMeta) {
LOGGER.info("About to insert <[{}]>",newFileCaptureMeta);
try {
Expand Down Expand Up @@ -174,6 +184,15 @@ public ResponseEntity<String> newFileMeta(@RequestBody FileCaptureMeta newFileCa

// Delete
@RequestMapping(path = "meta/{name}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Delete processing type")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Processing type deleted",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = FileCaptureMeta.class))}),
@ApiResponse(responseCode = "400", description = "Processing type is being used OR Processing type does not exist",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<String> removeProcessingType(@PathVariable("name") String name) {
LOGGER.info("Deleting processing type <[{}]>",name);
JSONObject jsonErr = new JSONObject();
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/teragrep/cfe18/handlers/FlowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@
package com.teragrep.cfe18.handlers;

import com.teragrep.cfe18.FlowMapper;
import com.teragrep.cfe18.handlers.entities.FileCaptureMeta;
import com.teragrep.cfe18.handlers.entities.Flow;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.json.JSONObject;
import org.mybatis.spring.SqlSessionTemplate;
Expand Down Expand Up @@ -81,11 +87,26 @@ public class FlowController {
// Get ALL endpoint

@RequestMapping(path = "", method = RequestMethod.GET, produces = "application/json")
@Operation(summary = "Fetch all flows", description = "Will return empty list if there are no flows to fetch")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Flows types fetched",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = Flow.class))})
})
public List<Flow> getAllFlow() {
return flowMapper.getAllFlow();
}

@RequestMapping(path = "", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Insert new flow")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "New flow created",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = Flow.class))}),
@ApiResponse(responseCode = "400", description = "Internal SQL Exception, most likely NULL",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<String> newFlow(@RequestBody Flow newFlow) {
LOGGER.info("About to insert <[{}]>",newFlow);
try {
Expand All @@ -105,6 +126,15 @@ public ResponseEntity<String> newFlow(@RequestBody Flow newFlow) {

// Delete
@RequestMapping(path = "/{name}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Delete flow")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Flow deleted",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = Flow.class))}),
@ApiResponse(responseCode = "400", description = "Flow is being used OR Flow does not exist",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<String> removeFlow(@PathVariable("name") String name) {
LOGGER.info("Deleting flow <[{}]>",name);
try {
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/teragrep/cfe18/handlers/HostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@
package com.teragrep.cfe18.handlers;

import com.teragrep.cfe18.HostMapper;
import com.teragrep.cfe18.handlers.entities.FileCaptureMeta;
import com.teragrep.cfe18.handlers.entities.HostFile;
import com.teragrep.cfe18.handlers.entities.HostRelp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.json.JSONObject;
import org.mybatis.spring.SqlSessionTemplate;
Expand Down Expand Up @@ -82,6 +88,15 @@ public class HostController {

// Get host by id
@RequestMapping(path = "/file/{id}", method = RequestMethod.GET, produces = "application/json")
@Operation(summary = "Fetch file based host by ID")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "File based host retrieved",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostFile.class))}),
@ApiResponse(responseCode = "400", description = "ID given does not match any host_id OR ID given directs to a hub based host OR ID given points to different type of host",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<?> getHostFile(@PathVariable("id") int id) {
try {
HostFile hf = hostMapper.getHostFileById(id);
Expand Down Expand Up @@ -116,6 +131,15 @@ public ResponseEntity<?> getHostFile(@PathVariable("id") int id) {

// Get host by id
@RequestMapping(path = "/relp/{id}", method = RequestMethod.GET, produces = "application/json")
@Operation(summary = "Fetch relp based host by ID")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Relp based host retrieved",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostRelp.class))}),
@ApiResponse(responseCode = "400", description = "ID given does not match any host_id OR ID given points to different type of host",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<?> getHostRelp(@PathVariable("id") int id) {
try {
HostRelp hr = hostMapper.getHostRelpById(id);
Expand Down Expand Up @@ -146,13 +170,28 @@ public ResponseEntity<?> getHostRelp(@PathVariable("id") int id) {

// GET ALL hosts
@RequestMapping(path = "", method = RequestMethod.GET, produces = "application/json")
@Operation(summary = "Fetch all hosts", description = "Will return empty list if there are no hosts to fetch")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Hosts fetched",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostFile.class))})
})
public List<HostFile> getAllHost() {
return hostMapper.getAllHost();
}


//Insert new host with cfe type
@RequestMapping(path = "/file", method = RequestMethod.PUT, produces = "application/json")
@Operation(summary = "Insert file based host")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "New file based host created",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostFile.class))}),
@ApiResponse(responseCode = "400", description = "ID,MD5 or fqhost already exists OR Hub does not exist",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<String> newHostFile(@RequestBody HostFile newHostFile) {
LOGGER.info("About to insert <[{}]>",newHostFile);
try {
Expand Down Expand Up @@ -187,6 +226,15 @@ public ResponseEntity<String> newHostFile(@RequestBody HostFile newHostFile) {
}

@RequestMapping(path = "/relp", method = RequestMethod.PUT, produces = "application/json")
@Operation(summary = "Insert relp based host")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "New relp based host created",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostRelp.class))}),
@ApiResponse(responseCode = "400", description = "ID,MD5 or fqhost already exists",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<String> newHostRelp(@RequestBody HostRelp newHostRelp) {
LOGGER.info("About to insert <[{}]>",newHostRelp);
try {
Expand Down Expand Up @@ -219,6 +267,15 @@ public ResponseEntity<String> newHostRelp(@RequestBody HostRelp newHostRelp) {

// Delete
@RequestMapping(path = "/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Delete host")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Host deleted",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostFile.class))}),
@ApiResponse(responseCode = "400", description = "Host is being used OR Host does not exist",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<String> removeHost(@PathVariable("id") int id) {
LOGGER.info("Deleting Host <[{}]>",id);
JSONObject jsonErr = new JSONObject();
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/teragrep/cfe18/handlers/HostGroupController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@
package com.teragrep.cfe18.handlers;

import com.teragrep.cfe18.HostGroupMapper;
import com.teragrep.cfe18.handlers.entities.FileCaptureMeta;
import com.teragrep.cfe18.handlers.entities.HostGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.json.JSONObject;
import org.mybatis.spring.SqlSessionTemplate;
Expand Down Expand Up @@ -81,6 +87,15 @@ public class HostGroupController {

// Get host group details
@RequestMapping(path = "/group/{name}", method = RequestMethod.GET, produces = "application/json")
@Operation(summary = "Fetch host group by name")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Host group retrieved",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostGroup.class))}),
@ApiResponse(responseCode = "400", description = "Host group does not exist with the given host group name",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<?> getResults(@PathVariable("name") String name) {
JSONObject jsonErr = new JSONObject();
jsonErr.put("id", 0);
Expand All @@ -103,13 +118,28 @@ public ResponseEntity<?> getResults(@PathVariable("name") String name) {


@RequestMapping(path = "/group", method = RequestMethod.GET, produces = "application/json")
@Operation(summary = "Fetch all host groups", description = "Will return empty list if there are no host groups to fetch")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Host groups fetched",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostGroup.class))})
})
public List<HostGroup> getAllHostGroup() {
return hostGroupMapper.getAllHostGroup();
}


// Insert host group with host
@RequestMapping(path = "/group", method = RequestMethod.PUT, produces = "application/json")
@Operation(summary = "Insert host group with host")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "New host group created AND/OR host linked to host group",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostGroup.class))}),
@ApiResponse(responseCode = "400", description = "Type mismatch between host group and host OR Host does not exist",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<String> newHostGroup(@RequestBody HostGroup newHostGroup) {
LOGGER.info("About to insert <[{}]>",newHostGroup);
try {
Expand Down Expand Up @@ -145,6 +175,15 @@ public ResponseEntity<String> newHostGroup(@RequestBody HostGroup newHostGroup)

// Delete
@RequestMapping(path = "/group/{name}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Delete host group")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Host group deleted",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = HostGroup.class))}),
@ApiResponse(responseCode = "400", description = "Host group is being used OR Host group does not exist",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal server error, contact admin", content = @Content)
})
public ResponseEntity<String> removeHost(@PathVariable("name") String name) {
LOGGER.info("Deleting Host Group <[{}]>", name);
JSONObject jsonErr = new JSONObject();
Expand Down
Loading