diff --git a/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/controllers/OpsmxAuditClientServiceController.groovy b/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/controllers/OpsmxAuditClientServiceController.groovy index 02e9da936c..284570f70f 100644 --- a/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/controllers/OpsmxAuditClientServiceController.groovy +++ b/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/controllers/OpsmxAuditClientServiceController.groovy @@ -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 @@ -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, diff --git a/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/services/OpsmxAuditClientService.groovy b/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/services/OpsmxAuditClientService.groovy index b085c6cf08..b6fd4af4fd 100644 --- a/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/services/OpsmxAuditClientService.groovy +++ b/gate-web/src/main/groovy/com/opsmx/spinnaker/gate/services/OpsmxAuditClientService.groovy @@ -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 { @@ -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) }