forked from spinnaker/gate
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-20548 : Added new controller for SSD service (#376)
- Loading branch information
1 parent
d8ceed7
commit bb58186
Showing
4 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxSsdController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
* Copyright 2023 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.gate.controllers | ||
|
||
import com.netflix.spinnaker.gate.services.internal.OpsmxSsdService | ||
import groovy.util.logging.Slf4j | ||
import io.swagger.annotations.ApiOperation | ||
import org.apache.commons.io.IOUtils | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.MediaType | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.PathVariable | ||
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 retrofit.client.Response | ||
|
||
import java.util.stream.Collectors | ||
|
||
@RequestMapping("/ssdservice") | ||
@RestController | ||
@Slf4j | ||
@ConditionalOnExpression('${services.ssdservice.enabled:false}') | ||
class OpsmxSsdController { | ||
|
||
@Autowired | ||
OpsmxSsdService opsMxSsdService | ||
|
||
@ApiOperation(value = "Endpoint for ssd services") | ||
@RequestMapping(value = "/{version}/{type}", method = RequestMethod.GET) | ||
Object getSsdResponse(@PathVariable("version") String version, | ||
@PathVariable("type") String type, | ||
@RequestParam(value = "appId", required = false) Integer appId, | ||
@RequestParam(value = "image", required = false) String image, | ||
@RequestParam(value = "appName", required = false) String appName) { | ||
return opsMxSsdService.getSddResponse1(version, type, appId, image, appName) | ||
} | ||
|
||
@ApiOperation(value = "Endpoint for ssd services") | ||
@RequestMapping(value = "/{version}/{type}/{source}", method = RequestMethod.GET) | ||
Object getSsdResponse1(@PathVariable("version") String version, | ||
@PathVariable("type") String type, | ||
@PathVariable("source") String source, | ||
@RequestParam(value = "appId", required = false) Integer appId, | ||
@RequestParam(value = "image", required = false) String image, | ||
@RequestParam(value = "appName", required = false) String appName) { | ||
return opsMxSsdService.getSddResponse2(version, type, source, appId, image, appName) | ||
} | ||
|
||
@ApiOperation(value = "Endpoint for ssd services") | ||
@RequestMapping(value = "/{version}/{type}/{source}/{source1}", method = RequestMethod.GET) | ||
Object getSsdResponse2(@PathVariable("version") String version, | ||
@PathVariable("type") String type, | ||
@PathVariable("source") String source, | ||
@PathVariable("source1") String source1, | ||
@RequestParam(value = "appId", required = false) Integer appId, | ||
@RequestParam(value = "image", required = false) String image, | ||
@RequestParam(value = "appName", required = false) String appName) { | ||
return opsMxSsdService.getSddResponse3(version, type, source, source1, appId, image, appName) | ||
} | ||
|
||
@ApiOperation(value = "Endpoint for ssd services") | ||
@RequestMapping(value = "/{version}/{type}/{source}/{source1}/{source2}", method = RequestMethod.GET) | ||
Object getSsdResponse3(@PathVariable("version") String version, | ||
@PathVariable("type") String type, | ||
@PathVariable("source") String source, | ||
@PathVariable("source1") String source1, | ||
@PathVariable("source2") String source2, | ||
@RequestParam(value = "appId", required = false) Integer appId, | ||
@RequestParam(value = "image", required = false) String image, | ||
@RequestParam(value = "appName", required = false) String appName) { | ||
return opsMxSsdService.getSddResponse4(version, type, source, source1, source2, appId, image, appName) | ||
} | ||
|
||
@ApiOperation(value = "Endpoint for ssd services") | ||
@RequestMapping(value = "/{version}/{type}/{source}/{source1}/{source2}/{source3}", method = RequestMethod.GET) | ||
Object getSsdResponse4(@PathVariable("version") String version, | ||
@PathVariable("type") String type, | ||
@PathVariable("source") String source, | ||
@PathVariable("source1") String source1, | ||
@PathVariable("source2") String source2, | ||
@PathVariable("source3") String source3, | ||
@RequestParam(value = "appId", required = false) Integer appId, | ||
@RequestParam(value = "image", required = false) String image, | ||
@RequestParam(value = "appName", required = false) String appName) { | ||
return opsMxSsdService.getSddResponse5(version, type, source, source1, source2, source3, appId, image, appName) | ||
} | ||
|
||
@ApiOperation(value = "Endpoint for ssd services") | ||
@RequestMapping(value = "/{version}/{type}/{source}/{source1}/{source2}/{source3}/{source4}", method = RequestMethod.GET) | ||
Object getSsdResponse5(@PathVariable("version") String version, | ||
@PathVariable("type") String type, | ||
@PathVariable("source") String source, | ||
@PathVariable("source1") String source1, | ||
@PathVariable("source2") String source2, | ||
@PathVariable("source3") String source3, | ||
@PathVariable("source4") String source4, | ||
@RequestParam(value = "appId", required = false) Integer appId, | ||
@RequestParam(value = "image", required = false) String image, | ||
@RequestParam(value = "appName", required = false) String appName) { | ||
return opsMxSsdService.getSddResponse6(version, type, source, source1, source2, source3, source4, appId, image, appName) | ||
} | ||
|
||
@ApiOperation(value = "Endpoint for ssd services") | ||
@RequestMapping(value = "/{version}/{type}/{source}/{source1}/{source2}/{source3}/{source4}/{source5}", method = RequestMethod.GET) | ||
Object getSsdResponse6(@PathVariable("version") String version, | ||
@PathVariable("type") String type, | ||
@PathVariable("source") String source, | ||
@PathVariable("source1") String source1, | ||
@PathVariable("source2") String source2, | ||
@PathVariable("source3") String source3, | ||
@PathVariable("source4") String source4, | ||
@PathVariable("source5") String source5, | ||
@RequestParam(value = "appId", required = false) Integer appId, | ||
@RequestParam(value = "image", required = false) String image, | ||
@RequestParam(value = "appName", required = false) String appName) { | ||
return opsMxSsdService.getSddResponse7(version, type, source, source1, source2, source3, source4, source5, appId, image, appName) | ||
} | ||
|
||
@ApiOperation(value = "Endpoint to download csv file") | ||
@RequestMapping(value = "/{version}/{type}/{source}/download", produces = "text/csv", method = RequestMethod.GET) | ||
Object downloadCSVFileAuditService(@PathVariable("version") String version, | ||
@PathVariable("type") String type, | ||
@PathVariable("source") String source, | ||
@RequestParam(value = "appId", required = false) Integer appId, | ||
@RequestParam(value = "image", required = false) String image, | ||
@RequestParam(value = "appName", required = false) String appName) { | ||
Response response = opsMxSsdService.downloadCSVFile(version, type, source, appId, image, appName) | ||
log.info("response for the download csv 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() | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/internal/OpsmxSsdService.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2023 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.gate.services.internal | ||
|
||
import retrofit.client.Response | ||
import retrofit.http.GET | ||
import retrofit.http.Path | ||
import retrofit.http.Query | ||
|
||
interface OpsmxSsdService { | ||
|
||
@GET("/ssdservice/{version}/{type}") | ||
Object getSddResponse1(@Path('version') String version, | ||
@Path('type') String type, | ||
@Query("appId") Integer appId, | ||
@Query("image") String image, | ||
@Query("appName") String appName) | ||
|
||
@GET("/ssdservice/{version}/{type}/{source}") | ||
Object getSddResponse2(@Path('version') String version, | ||
@Path('type') String type, | ||
@Path('source') String source, | ||
@Query("appId") Integer appId, | ||
@Query("image") String image, | ||
@Query("appName") String appName) | ||
|
||
@GET("/ssdservice/{version}/{type}/{source}/{source1}") | ||
Object getSddResponse3(@Path('version') String version, | ||
@Path('type') String type, | ||
@Path('source') String source, | ||
@Path('source1') String source1, | ||
@Query("appId") Integer appId, | ||
@Query("image") String image, | ||
@Query("appName") String appName) | ||
|
||
@GET("/ssdservice/{version}/{type}/{source}/{source1}/{source2}") | ||
Object getSddResponse4(@Path('version') String version, | ||
@Path('type') String type, | ||
@Path('source') String source, | ||
@Path('source1') String source1, | ||
@Path('source2') String source2, | ||
@Query("appId") Integer appId, | ||
@Query("image") String image, | ||
@Query("appName") String appName) | ||
|
||
@GET("/ssdservice/{version}/{type}/{source}/{source1}/{source2}/{source3}") | ||
Object getSddResponse5(@Path('version') String version, | ||
@Path('type') String type, | ||
@Path('source') String source, | ||
@Path('source1') String source1, | ||
@Path('source2') String source2, | ||
@Path('source3') String source3, | ||
@Query("appId") Integer appId, | ||
@Query("image") String image, | ||
@Query("appName") String appName) | ||
|
||
@GET("/ssdservice/{version}/{type}/{source}/{source1}/{source2}/{source3}/{source4}") | ||
Object getSddResponse6(@Path('version') String version, | ||
@Path('type') String type, | ||
@Path('source') String source, | ||
@Path('source1') String source1, | ||
@Path('source2') String source2, | ||
@Path('source3') String source3, | ||
@Path('source4') String source4, | ||
@Query("appId") Integer appId, | ||
@Query("image") String image, | ||
@Query("appName") String appName) | ||
|
||
@GET("/ssdservice/{version}/{type}/{source}/{source1}/{source2}/{source3}/{source4}/{source5}") | ||
Object getSddResponse7(@Path('version') String version, | ||
@Path('type') String type, | ||
@Path('source') String source, | ||
@Path('source1') String source1, | ||
@Path('source2') String source2, | ||
@Path('source3') String source3, | ||
@Path('source4') String source4, | ||
@Path('source5') String source5, | ||
@Query("appId") Integer appId, | ||
@Query("image") String image, | ||
@Query("appName") String appName) | ||
|
||
@GET("/ssdservice/{version}/{type}/{source}/download") | ||
Response downloadCSVFile(@Path('version') String version, | ||
@Path('type') String type, | ||
@Path('source') String source, | ||
@Query("appId") Integer appId, | ||
@Query("image") String image, | ||
@Query("appName") String appName) | ||
|
||
} |