From 681672de19822e372f57a00418c86bcf569b1a68 Mon Sep 17 00:00:00 2001 From: Pranav-b-7 Date: Mon, 8 Mar 2021 16:23:58 +0530 Subject: [PATCH] register canary v3 endpoint bypassed --- .../spinnaker/gate/config/AuthConfig.groovy | 2 ++ .../OpsmxAutopilotController.groovy | 32 +++---------------- .../internal/OpsmxAutopilotService.groovy | 7 ++-- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy index 565568c290..79d489655c 100644 --- a/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy +++ b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy @@ -100,6 +100,7 @@ class AuthConfig { .antMatchers(HttpMethod.GET,'/autopilot/api/v1/autopilot/canaries/{id}').permitAll() .antMatchers(HttpMethod.POST,'/autopilot/api/v1/registerCanary').permitAll() .antMatchers(HttpMethod.POST,'/autopilot/api/v2/registerCanary').permitAll() + .antMatchers(HttpMethod.POST,'/autopilot/api/v3/registerCanary').permitAll() .antMatchers(HttpMethod.GET,'/autopilot/canaries/{id}').permitAll() .antMatchers(HttpMethod.POST,'/visibilityservice/v1/approvalGates/{id}/trigger').permitAll() .antMatchers(HttpMethod.POST,'/visibilityservice/v2/approvalGates/{id}/trigger').permitAll() @@ -147,6 +148,7 @@ class AuthConfig { .antMatchers(HttpMethod.POST,'/autopilot/registerCanary').permitAll() .antMatchers(HttpMethod.POST,'/autopilot/api/v1/registerCanary').permitAll() .antMatchers(HttpMethod.POST,'/autopilot/api/v2/registerCanary').permitAll() + .antMatchers(HttpMethod.POST,'/autopilot/api/v3/registerCanary').permitAll() .antMatchers(HttpMethod.GET,'/autopilot/canaries/{id}').permitAll() .antMatchers(HttpMethod.GET,'/autopilot/api/v2/autopilot/canaries/{id}').permitAll() .antMatchers(HttpMethod.GET,'/autopilot/api/v1/autopilot/canaries/{id}').permitAll() diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxAutopilotController.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxAutopilotController.groovy index d540ec9db2..4322fa5b5f 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxAutopilotController.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxAutopilotController.groovy @@ -93,10 +93,10 @@ class OpsmxAutopilotController { } @ApiOperation(value = "Endpoint for autopilot rest services") - @RequestMapping(value = "/api/v1/registerCanary", method = RequestMethod.POST) - @ResponseBody Object triggerV1RegisterCanary(@RequestBody(required = false) Object data) throws Exception { + @RequestMapping(value = "/api/{version}/registerCanary", method = RequestMethod.POST) + Object triggerRegisterCanary(@PathVariable("version") String version, @RequestBody(required = false) Object data) throws Exception { - Response response = opsmxAutopilotService.triggerV1RegisterCanary(data) + Response response = opsmxAutopilotService.triggerRegisterCanary(version, data) InputStream inputStream = null try { @@ -104,30 +104,8 @@ class OpsmxAutopilotController { headers.add("Location", response.getHeaders().stream().filter({ header -> header.getName().trim().equalsIgnoreCase("Location") }).collect(Collectors.toList()).get(0).value) inputStream = response.getBody().in() String responseBody = new String(IOUtils.toByteArray(inputStream)) - RegisterCanaryResponseModel registerCanaryResponseModel = gson.fromJson(responseBody, RegisterCanaryResponseModel.class) - return new ResponseEntity(registerCanaryResponseModel, headers, HttpStatus.valueOf(response.getStatus())) - - } finally{ - if (inputStream!=null){ - inputStream.close() - } - } - } - - @ApiOperation(value = "Endpoint for autopilot rest services") - @RequestMapping(value = "/api/v2/registerCanary", method = RequestMethod.POST) - @ResponseBody Object triggerV2RegisterCanary(@RequestBody(required = false) Object data) throws Exception { - - Response response = opsmxAutopilotService.triggerV2RegisterCanary(data) - InputStream inputStream = null - - try { - HttpHeaders headers = new HttpHeaders() - headers.add("Location", response.getHeaders().stream().filter({ header -> header.getName().trim().equalsIgnoreCase("Location") }).collect(Collectors.toList()).get(0).value) - inputStream = response.getBody().in() - String responseBody = new String(IOUtils.toByteArray(inputStream)) - RegisterCanaryResponseModel registerCanaryResponseModel = gson.fromJson(responseBody, RegisterCanaryResponseModel.class) - return new ResponseEntity(registerCanaryResponseModel, headers, HttpStatus.valueOf(response.getStatus())) + //RegisterCanaryResponseModel registerCanaryResponseModel = gson.fromJson(responseBody, RegisterCanaryResponseModel.class) + return new ResponseEntity(responseBody, headers, HttpStatus.valueOf(response.getStatus())) } finally{ if (inputStream!=null){ diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/internal/OpsmxAutopilotService.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/internal/OpsmxAutopilotService.groovy index 9c9ab92b19..ef4648f135 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/internal/OpsmxAutopilotService.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/internal/OpsmxAutopilotService.groovy @@ -24,11 +24,8 @@ interface OpsmxAutopilotService { @GET("/autopilot/canaries/debugLogsData") Response downloadDebugData(@Query("id") Integer canaryId) - @POST("/autopilot/api/v1/registerCanary") - Response triggerV1RegisterCanary(@Body Object data) - - @POST("/autopilot/api/v2/registerCanary") - Response triggerV2RegisterCanary(@Body Object data) + @POST("/autopilot/api/{version}/registerCanary") + Response triggerRegisterCanary(@Path('version') String version, @Body Object data) @GET("/autopilot/{type}/{source}") Object getAutoResponse(@Path('type') String type,