Skip to content

Commit

Permalink
OP-21637: Added POST endpoint for audit client service's system audit (
Browse files Browse the repository at this point in the history
…#480)

Co-authored-by: Utkarsh Shukla <[email protected]>
  • Loading branch information
utkarsh-opsmx and Utkarsh Shukla authored Sep 2, 2024
1 parent 7fe0286 commit dddc335
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.http.HttpHeaders
import retrofit.client.Response
import org.apache.commons.io.IOUtils
Expand Down Expand Up @@ -187,6 +188,41 @@ class OpsmxAuditClientServiceController {
return ResponseEntity.status(response.getStatus()).build()
}

@Operation(summary = "Endpoint for platform rest services")
@RequestMapping(value = "/{version}/{type}/{source}", method = RequestMethod.POST)
Object postAuditClientResponse1(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@RequestBody(required = false) Object data) {

return opsmxAuditClientService.postAuditClientResponse1(version, type, source, data)
}

@Operation(summary = "Endpoint for platform rest services")
@RequestMapping(value = "/{version}/{type}/{source}/download", method = RequestMethod.POST)
Object downloadCSVFileSystemAudit(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@RequestBody(required = false) Object data) {
Response response = opsmxAuditClientService.downloadCSVFile2(version, type, source, data)
log.info("response for the system audit endpoint:" + response.getHeaders())
if (response.getBody()!= null) {
InputStream inputStream = response.getBody().in()
try {
byte[] csvFile = IOUtils.toByteArray(inputStream)
HttpHeaders headers = new HttpHeaders()
headers.setContentType(MediaType.parseMediaType("text/csv"));
headers.add("Content-Disposition", response.getHeaders().stream().filter({ header -> header.getName().trim().equalsIgnoreCase("Content-Disposition") }).collect(Collectors.toList()).get(0).value)
return ResponseEntity.ok().headers(headers).body(csvFile)
} finally {
if (inputStream != null) {
inputStream.close()
}
}
}
return ResponseEntity.status(response.getStatus()).build()
}

@Operation(summary = "Endpoint for Delivery Insights controller to download csv file")
@RequestMapping(value = "/{version}/{type}/{source}/download", produces = "text/csv", method = RequestMethod.GET)
Object downloadCSVFileAuditService(@PathVariable("version") String version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package com.opsmx.spinnaker.gate.services
import org.springframework.web.bind.annotation.RequestParam
import retrofit.client.Response
import retrofit.http.GET
import retrofit.http.POST
import retrofit.http.Path
import retrofit.http.Body
import retrofit.http.Query

interface OpsmxAuditClientService {
Expand Down Expand Up @@ -137,4 +139,16 @@ interface OpsmxAuditClientService {
@Query('search') String search,
@Query("noOfDays") String noOfDays,
@Query('limit') Integer limit)

@POST("/auditclientservice/{version}/{type}/{source}")
Object postAuditClientResponse1(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Body Object data)

@POST("/auditclientservice/{version}/{type}/{source}/download")
Response downloadCSVFile2(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Body Object data)
}

0 comments on commit dddc335

Please sign in to comment.