From 0aada8b17e2a52ba5c812f21fe6c89c1e9221830 Mon Sep 17 00:00:00 2001 From: Sudhakar Guvvalapall Date: Mon, 28 Jun 2021 19:29:56 +0530 Subject: [PATCH] OP-6857:Spinnaker Setup X509 Implementation for V1 version (#16) --- .../controllers/OpsmxOesController.groovy | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxOesController.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxOesController.groovy index 9e06028b2c..c1d7ee3b47 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxOesController.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxOesController.groovy @@ -278,7 +278,13 @@ class OpsmxOesController { String filename = files ? files.getOriginalFilename() : '' return addOrUpdateSpinnakerCloudProverAccount(files, postData.get("postData")) } - + + @ApiOperation(value = "Add or Update V1 Spinnaker x509") + @RequestMapping(value = "/accountsConfig/v1/spinnakerX509", method = RequestMethod.POST) + Object addOrUpdateSpinnakerSetupV1(@RequestParam MultipartFile files, @RequestParam Map postData) { + return addOrUpdateSpinnakerV1(files, postData.get("postData")) + } + private String addOrUpdateSpinnakerCloudProverAccount(MultipartFile files, String data) { Map> authenticationHeaders = AuthenticatedRequest.getAuthenticationHeaders(); Map headersMap = new HashMap() @@ -321,6 +327,27 @@ class OpsmxOesController { }.call() as Object } + private Object addOrUpdateSpinnakerV1(MultipartFile files, String data) { + Map> authenticationHeaders = AuthenticatedRequest.getAuthenticationHeaders(); + Map headersMap = new HashMap() + authenticationHeaders.each { key, val -> + if(val.isPresent()) + headersMap.putAt(key,val.get()) + else + headersMap.putAt(key,"") + } + AuthenticatedRequest.propagate { + def request = new Request.Builder() + .url(serviceConfiguration.getServiceEndpoint("opsmx").url +"/oes/accountsConfig/v1/spinnakerX509") + .headers(Headers.of(headersMap)) + .post(uploadFileOkHttp(data,files)) + .build() + + def response = okHttpClient.newCall(request).execute() + return response.body()?.string() ?: "Unknown reason: " + response.code() + }.call() as Object + } + private String addOrUpdateCloudProverAccount(MultipartFile files, String data) { Map> authenticationHeaders = AuthenticatedRequest.getAuthenticationHeaders(); Map headersMap = new HashMap()