Skip to content

Commit

Permalink
Merge pull request #55 from OpsMx/OP-7390-v3.10
Browse files Browse the repository at this point in the history
OP-7390: bug fix for file upload status return from service
  • Loading branch information
sriharshakancharla authored Oct 8, 2021
2 parents ed4314d + 3ebe9fa commit c59eebd
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.util.stream.Collectors

import com.netflix.spinnaker.gate.config.ServiceConfiguration
import com.netflix.spinnaker.gate.services.internal.OpsmxOesService
import com.netflix.spinnaker.gate.exceptions.OesRequestException
import com.netflix.spinnaker.security.AuthenticatedRequest

import groovy.util.logging.Slf4j
Expand Down Expand Up @@ -298,16 +299,23 @@ class OpsmxOesController {
else
headersMap.putAt(key,"")
}
AuthenticatedRequest.propagate {
def obj = AuthenticatedRequest.propagate {
def request = new Request.Builder()
.url(serviceConfiguration.getServiceEndpoint("opsmx").url +"/oes/accountsConfig/spinnaker/addOrUpdateCloudProviderAccount")
.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 String
return response
}.call() as okhttp3.Response

if (!obj.isSuccessful()) {
def error = obj.body().string();
throw new OesRequestException(error)
} else{
return obj.body()?.string() ?: "Unknown reason: " + obj.code() as Object
}
}

Object addOrUpdateSpinnaker(MultipartFile files, String data) {
Expand All @@ -332,25 +340,32 @@ class OpsmxOesController {
}

private Object createOrUpdateSpinnaker(MultipartFile files, String data, String version) {
Map<String, Optional<String>> 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/version/spinnakerX509".replace("version", version))
.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
}
Map<String, Optional<String>> authenticationHeaders = AuthenticatedRequest.getAuthenticationHeaders();
Map headersMap = new HashMap()
authenticationHeaders.each { key, val ->
if(val.isPresent())
headersMap.putAt(key,val.get())
else
headersMap.putAt(key,"")
}
def obj = AuthenticatedRequest.propagate {
def request = new Request.Builder()
.url(serviceConfiguration.getServiceEndpoint("opsmx").url +"/oes/accountsConfig/version/spinnakerX509".replace("version", version))
.headers(Headers.of(headersMap))
.post(uploadFileOkHttp(data,files))
.build()
def response = okHttpClient.newCall(request).execute()
return response
}.call() as okhttp3.Response

if (!obj.isSuccessful()) {
def error = obj.body().string();
log.error("Failed to setup the Spinnaker : {}", error)
throw new OesRequestException(error)
} else{
return obj.body()?.string() ?: "Unknown reason: " + obj.code() as Object
}
}

private String addOrUpdateCloudProverAccount(MultipartFile files, String data) {
Map<String, Optional<String>> authenticationHeaders = AuthenticatedRequest.getAuthenticationHeaders();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021 Netflix, 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.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
public class OesRequestException extends RuntimeException {

public OesRequestException(String message) {
super(message);
}
}

0 comments on commit c59eebd

Please sign in to comment.