diff options
author | 2019-11-22 18:06:08 -0500 | |
---|---|---|
committer | 2019-11-26 21:32:38 +0000 | |
commit | 341db21b2ac0a14a1ed2b8bf7930914dda054bfe (patch) | |
tree | 113bba965b06cfe3a8af3a0a527d1a41c9faf0f9 /ms/blueprintsprocessor/modules/commons/rest-lib/src/main | |
parent | d274e5fc552cf9ae25500f504f0434981cf3accf (diff) |
Formatting Code base with ktlint
No Business logic change, just the code format.
Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3
To format run: mvn process-sources -P format
Issue-ID: CCSDK-1947
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/rest-lib/src/main')
11 files changed, 174 insertions, 104 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt index 182d5defa..9e1be36a7 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt @@ -35,19 +35,16 @@ open class BluePrintRestLibConfiguration * Exposed Dependency Service by this Rest Lib Module */ fun BluePrintDependencyService.restLibPropertyService(): BluePrintRestLibPropertyService = - instance(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY) - + instance(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY) fun BluePrintDependencyService.restClientService(selector: String): BlueprintWebClientService { return restLibPropertyService().blueprintWebClientService(selector) } - fun BluePrintDependencyService.restClientService(jsonNode: JsonNode): BlueprintWebClientService { return restLibPropertyService().blueprintWebClientService(jsonNode) } - class RestLibConstants { companion object { const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service" diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt index ea32a1635..4c18f81ab 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt @@ -35,11 +35,13 @@ open class SSLRestClientProperties : RestClientProperties() { // FIXME("Define basic auth userName and password properties") open class SSLBasicAuthRestClientProperties : SSLRestClientProperties() { + var basicAuth: BasicAuthRestClientProperties? = null } // FIXME("Define token properties") open class SSLTokenAuthRestClientProperties : SSLRestClientProperties() { + var tokenAuth: TokenAuthRestClientProperties? = null } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt index a3da44f61..429931377 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt @@ -129,9 +129,9 @@ open class SSLRestClientPropertiesBuilder : RestClientPropertiesBuilder() { } open class SSLBasicAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() { - //TODO() + // TODO() } open class SSLTokenAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() { - //TODO() -}
\ No newline at end of file + // TODO() +} diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/filters/RestServerLoggingWebFilter.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/filters/RestServerLoggingWebFilter.kt index 5aaee24de..5b6691eff 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/filters/RestServerLoggingWebFilter.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/filters/RestServerLoggingWebFilter.kt @@ -24,15 +24,15 @@ import org.springframework.web.server.WebFilterChain import reactor.core.publisher.Mono import reactor.util.context.Context - open class RestServerLoggingWebFilter : WebFilter { override fun filter(serverWebExchange: ServerWebExchange, webFilterChain: WebFilterChain): Mono<Void> { val loggingService = RestLoggerService() loggingService.entering(serverWebExchange.request) val filterChain = webFilterChain.filter(serverWebExchange).subscriberContext( - Context.of(MDCContext, MDCContext())) + Context.of(MDCContext, MDCContext()) + ) loggingService.exiting(serverWebExchange.request, serverWebExchange.response) return filterChain } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt index 9ce3beab6..540b3d9ad 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt @@ -21,37 +21,42 @@ import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties import org.springframework.http.HttpHeaders import org.springframework.http.MediaType import java.nio.charset.Charset -import java.util.* +import java.util.Base64 -class BasicAuthRestClientService(private val restClientProperties: - BasicAuthRestClientProperties) : +class BasicAuthRestClientService( + private val restClientProperties: + BasicAuthRestClientProperties +) : BlueprintWebClientService { override fun defaultHeaders(): Map<String, String> { - val encodedCredentials = setBasicAuth(restClientProperties.username, - restClientProperties.password) + val encodedCredentials = setBasicAuth( + restClientProperties.username, + restClientProperties.password + ) return mapOf( HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.AUTHORIZATION to "Basic $encodedCredentials") + HttpHeaders.AUTHORIZATION to "Basic $encodedCredentials" + ) } override fun host(uri: String): String { return restClientProperties.url + uri } - override fun convertToBasicHeaders(headers: Map<String, String>): - Array<BasicHeader> { + Array<BasicHeader> { val customHeaders: MutableMap<String, String> = headers.toMutableMap() - //inject additionalHeaders + // inject additionalHeaders customHeaders.putAll(verifyAdditionalHeaders(restClientProperties)) if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { val encodedCredentials = setBasicAuth( restClientProperties.username, - restClientProperties.password) + restClientProperties.password + ) customHeaders[HttpHeaders.AUTHORIZATION] = "Basic $encodedCredentials" } @@ -61,7 +66,7 @@ class BasicAuthRestClientService(private val restClientProperties: private fun setBasicAuth(username: String, password: String): String { val credentialsString = "$username:$password" return Base64.getEncoder().encodeToString( - credentialsString.toByteArray(Charset.defaultCharset())) + credentialsString.toByteArray(Charset.defaultCharset()) + ) } - } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt index 84ba7d414..8f528a2ef 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt @@ -20,7 +20,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest.service import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.rest.* +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.PolicyManagerRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLTokenAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.TokenAuthRestClientProperties import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.stereotype.Service @@ -43,7 +50,7 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic open fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService { val service = preInterceptor?.getInstance(jsonNode) - ?: blueprintWebClientService(restClientProperties(jsonNode)) + ?: blueprintWebClientService(restClientProperties(jsonNode)) return postInterceptor?.getInstance(jsonNode, service) ?: service } @@ -58,7 +65,8 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic fun restClientProperties(prefix: String): RestClientProperties { val type = bluePrintPropertiesService.propertyBeanType( - "$prefix.type", String::class.java) + "$prefix.type", String::class.java + ) return when (type) { RestLibConstants.TYPE_BASIC_AUTH -> { basicAuthRestClientProperties(prefix) @@ -80,8 +88,10 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic policyManagerRestClientProperties(prefix) } else -> { - throw BluePrintProcessorException("Rest adaptor($type) is" + - " not supported") + throw BluePrintProcessorException( + "Rest adaptor($type) is" + + " not supported" + ) } } } @@ -111,7 +121,8 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic } else -> { throw BluePrintProcessorException( - "Rest adaptor($type) is not supported") + "Rest adaptor($type) is not supported" + ) } } } @@ -138,24 +149,28 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic private fun tokenRestClientProperties(prefix: String): TokenAuthRestClientProperties { return bluePrintPropertiesService.propertyBeanType( - prefix, TokenAuthRestClientProperties::class.java) + prefix, TokenAuthRestClientProperties::class.java + ) } private fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties { return bluePrintPropertiesService.propertyBeanType( - prefix, BasicAuthRestClientProperties::class.java) + prefix, BasicAuthRestClientProperties::class.java + ) } private fun sslBasicAuthRestClientProperties(prefix: String): SSLRestClientProperties { val sslProps: SSLBasicAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, SSLBasicAuthRestClientProperties::class.java) + bluePrintPropertiesService.propertyBeanType( + prefix, SSLBasicAuthRestClientProperties::class.java + ) val basicProps: BasicAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, BasicAuthRestClientProperties::class.java) + bluePrintPropertiesService.propertyBeanType( + prefix, BasicAuthRestClientProperties::class.java + ) sslProps.basicAuth = basicProps return sslProps } @@ -164,11 +179,15 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic SSLRestClientProperties { val sslProps: SSLTokenAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType(prefix, - SSLTokenAuthRestClientProperties::class.java) + bluePrintPropertiesService.propertyBeanType( + prefix, + SSLTokenAuthRestClientProperties::class.java + ) val basicProps: TokenAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType(prefix, - TokenAuthRestClientProperties::class.java) + bluePrintPropertiesService.propertyBeanType( + prefix, + TokenAuthRestClientProperties::class.java + ) sslProps.tokenAuth = basicProps return sslProps } @@ -176,13 +195,15 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic private fun sslNoAuthRestClientProperties(prefix: String): SSLRestClientProperties { return bluePrintPropertiesService.propertyBeanType( - prefix, SSLRestClientProperties::class.java) + prefix, SSLRestClientProperties::class.java + ) } private fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties { return bluePrintPropertiesService.propertyBeanType( - prefix, PolicyManagerRestClientProperties::class.java) + prefix, PolicyManagerRestClientProperties::class.java + ) } interface PreInterceptor { @@ -197,5 +218,3 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic fun getInstance(selector: String, service: BlueprintWebClientService): BlueprintWebClientService } } - - diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt index 3e31bf9ec..3c8d92c26 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt @@ -23,7 +23,12 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.apache.commons.io.IOUtils import org.apache.http.client.ClientProtocolException -import org.apache.http.client.methods.* +import org.apache.http.client.methods.HttpDelete +import org.apache.http.client.methods.HttpGet +import org.apache.http.client.methods.HttpPatch +import org.apache.http.client.methods.HttpPost +import org.apache.http.client.methods.HttpPut +import org.apache.http.client.methods.HttpUriRequest import org.apache.http.entity.StringEntity import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients @@ -57,8 +62,12 @@ interface BlueprintWebClientService { /** High performance non blocking Retry function, If execution block [block] throws BluePrintRetryException * exception then this will perform wait and retrigger accoring to times [times] with delay [delay] */ - suspend fun <T> retry(times: Int = 1, initialDelay: Long = 0, delay: Long = 1000, - block: suspend (Int) -> T): T { + suspend fun <T> retry( + times: Int = 1, + initialDelay: Long = 0, + delay: Long = 1000, + block: suspend (Int) -> T + ): T { val exceptionBlock = { e: Exception -> if (e !is BluePrintRetryException) { throw e @@ -71,8 +80,12 @@ interface BlueprintWebClientService { return this.exchangeResource(methodType, path, request, defaultHeaders()) } - fun exchangeResource(methodType: String, path: String, request: String, - headers: Map<String, String>): WebClientResponse<String> { + fun exchangeResource( + methodType: String, + path: String, + request: String, + headers: Map<String, String> + ): WebClientResponse<String> { /** * TODO: Basic headers in the implementations of this client do not get added * in blocking version, whereas in NB version defaultHeaders get added. @@ -86,11 +99,12 @@ interface BlueprintWebClientService { HttpMethod.PUT -> put(path, request, convertedHeaders, String::class.java) HttpMethod.PATCH -> patch(path, request, convertedHeaders, String::class.java) else -> throw BluePrintProcessorException( - "Unsupported methodType($methodType) attempted on path($path)") + "Unsupported methodType($methodType) attempted on path($path)" + ) } } - //TODO: convert to multi-map + // TODO: convert to multi-map fun convertToBasicHeaders(headers: Map<String, String>): Array<BasicHeader> { return headers.map { BasicHeader(it.key, it.value) }.toTypedArray() } @@ -145,8 +159,10 @@ interface BlueprintWebClientService { @Throws(IOException::class, ClientProtocolException::class) private fun <T> performCallAndExtractTypedWebClientResponse( - httpUriRequest: HttpUriRequest, responseType: Class<T>): - WebClientResponse<T> { + httpUriRequest: HttpUriRequest, + responseType: Class<T> + ): + WebClientResponse<T> { val httpResponse = httpClient().execute(httpUriRequest) val statusCode = httpResponse.statusLine.statusCode httpResponse.entity.content.use { @@ -164,7 +180,7 @@ interface BlueprintWebClientService { } suspend fun <T> getNB(path: String, additionalHeaders: Array<BasicHeader>?, responseType: Class<T>): - WebClientResponse<T> = withContext(Dispatchers.IO) { + WebClientResponse<T> = withContext(Dispatchers.IO) { get(path, additionalHeaders!!, responseType) } @@ -176,8 +192,12 @@ interface BlueprintWebClientService { return postNB(path, request, additionalHeaders, String::class.java) } - suspend fun <T> postNB(path: String, request: Any, additionalHeaders: Array<BasicHeader>?, - responseType: Class<T>): WebClientResponse<T> = withContext(Dispatchers.IO) { + suspend fun <T> postNB( + path: String, + request: Any, + additionalHeaders: Array<BasicHeader>?, + responseType: Class<T> + ): WebClientResponse<T> = withContext(Dispatchers.IO) { post(path, request, additionalHeaders!!, responseType) } @@ -185,14 +205,20 @@ interface BlueprintWebClientService { return putNB(path, request, null, String::class.java) } - suspend fun putNB(path: String, request: Any, - additionalHeaders: Array<BasicHeader>?): WebClientResponse<String> { + suspend fun putNB( + path: String, + request: Any, + additionalHeaders: Array<BasicHeader>? + ): WebClientResponse<String> { return putNB(path, request, additionalHeaders, String::class.java) } - suspend fun <T> putNB(path: String, request: Any, - additionalHeaders: Array<BasicHeader>?, - responseType: Class<T>): WebClientResponse<T> = withContext(Dispatchers.IO) { + suspend fun <T> putNB( + path: String, + request: Any, + additionalHeaders: Array<BasicHeader>?, + responseType: Class<T> + ): WebClientResponse<T> = withContext(Dispatchers.IO) { put(path, request, additionalHeaders!!, responseType) } @@ -201,36 +227,42 @@ interface BlueprintWebClientService { } suspend fun <T> deleteNB(path: String, additionalHeaders: Array<BasicHeader>?): - WebClientResponse<String> { + WebClientResponse<String> { return deleteNB(path, additionalHeaders, String::class.java) } suspend fun <T> deleteNB(path: String, additionalHeaders: Array<BasicHeader>?, responseType: Class<T>): - WebClientResponse<T> = withContext(Dispatchers.IO) { + WebClientResponse<T> = withContext(Dispatchers.IO) { delete(path, additionalHeaders!!, responseType) } suspend fun <T> patchNB(path: String, request: Any, additionalHeaders: Array<BasicHeader>?, responseType: Class<T>): - WebClientResponse<T> = withContext(Dispatchers.IO) { + WebClientResponse<T> = withContext(Dispatchers.IO) { patch(path, request, additionalHeaders!!, responseType) } suspend fun exchangeNB(methodType: String, path: String, request: Any): WebClientResponse<String> { - return exchangeNB(methodType, path, request, hashMapOf(), - String::class.java) + return exchangeNB( + methodType, path, request, hashMapOf(), + String::class.java + ) } suspend fun exchangeNB(methodType: String, path: String, request: Any, additionalHeaders: Map<String, String>?): - WebClientResponse<String> { + WebClientResponse<String> { return exchangeNB(methodType, path, request, additionalHeaders, String::class.java) } - suspend fun <T> exchangeNB(methodType: String, path: String, request: Any, - additionalHeaders: Map<String, String>?, - responseType: Class<T>): WebClientResponse<T> { + suspend fun <T> exchangeNB( + methodType: String, + path: String, + request: Any, + additionalHeaders: Map<String, String>?, + responseType: Class<T> + ): WebClientResponse<T> { - //TODO: possible inconsistency - //NOTE: this basic headers function is different from non-blocking + // TODO: possible inconsistency + // NOTE: this basic headers function is different from non-blocking val convertedHeaders: Array<BasicHeader> = basicHeaders(additionalHeaders!!) return when (HttpMethod.resolve(methodType)) { HttpMethod.GET -> getNB(path, convertedHeaders, responseType) @@ -259,7 +291,7 @@ interface BlueprintWebClientService { } private fun basicHeaders(headers: Map<String, String>?): - Array<BasicHeader> { + Array<BasicHeader> { val basicHeaders = mutableListOf<BasicHeader>() defaultHeaders().forEach { (name, value) -> basicHeaders.add(BasicHeader(name, value)) @@ -278,18 +310,18 @@ interface BlueprintWebClientService { .build() } - //TODO maybe there could be cases where we care about return headers? + // TODO maybe there could be cases where we care about return headers? data class WebClientResponse<T>(val status: Int, val body: T) fun verifyAdditionalHeaders(restClientProperties: RestClientProperties): Map<String, String> { val customHeaders: MutableMap<String, String> = mutableMapOf() - //Extract additionalHeaders from the requestProperties and - //throw an error if HttpHeaders.AUTHORIZATION key (headers are case-insensitive) + // Extract additionalHeaders from the requestProperties and + // throw an error if HttpHeaders.AUTHORIZATION key (headers are case-insensitive) restClientProperties.additionalHeaders?.let { if (it.keys.map { k -> k.toLowerCase().trim() }.contains(HttpHeaders.AUTHORIZATION.toLowerCase())) { val errMsg = "Error in definition of endpoint ${restClientProperties.url}." + - " User-supplied \"additionalHeaders\" cannot contain AUTHORIZATION header with" + - " auth-type \"${RestLibConstants.TYPE_BASIC_AUTH}\"" + " User-supplied \"additionalHeaders\" cannot contain AUTHORIZATION header with" + + " auth-type \"${RestLibConstants.TYPE_BASIC_AUTH}\"" WebClientUtils.log.error(errMsg) throw BluePrintProcessorException(errMsg) } else { diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt index 969de836c..dbb98f849 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt @@ -16,7 +16,13 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest.service -import kotlinx.coroutines.* +import kotlinx.coroutines.AbstractCoroutine +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.CoroutineStart +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.InternalCoroutinesApi +import kotlinx.coroutines.handleCoroutineException +import kotlinx.coroutines.newCoroutineContext import kotlinx.coroutines.reactor.ReactorContext import kotlinx.coroutines.reactor.asCoroutineContext import org.apache.http.message.BasicHeader @@ -37,7 +43,7 @@ import java.net.InetAddress import java.time.ZoneOffset import java.time.ZonedDateTime import java.time.format.DateTimeFormatter -import java.util.* +import java.util.UUID import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -89,17 +95,19 @@ class RestLoggerService { } } - /** Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context. */ @UseExperimental(InternalCoroutinesApi::class) -fun <T> monoMdc(context: CoroutineContext = EmptyCoroutineContext, - block: suspend CoroutineScope.() -> T?): Mono<T> = Mono.create { sink -> +fun <T> monoMdc( + context: CoroutineContext = EmptyCoroutineContext, + block: suspend CoroutineScope.() -> T? +): Mono<T> = Mono.create { sink -> val reactorContext = (context[ReactorContext]?.context?.putAll(sink.currentContext()) - ?: sink.currentContext()).asCoroutineContext() + ?: sink.currentContext()).asCoroutineContext() /** Populate MDC context only if present in Reactor Context */ - val newContext = if (!reactorContext.context.isEmpty - && reactorContext.context.hasKey(MDCContext)) { + val newContext = if (!reactorContext.context.isEmpty && + reactorContext.context.hasKey(MDCContext) + ) { val mdcContext = reactorContext.context.get<MDCContext>(MDCContext) GlobalScope.newCoroutineContext(context + reactorContext + mdcContext) } else GlobalScope.newCoroutineContext(context + reactorContext) @@ -111,9 +119,10 @@ fun <T> monoMdc(context: CoroutineContext = EmptyCoroutineContext, @InternalCoroutinesApi class MonoMDCCoroutine<in T>( - parentContext: CoroutineContext, - private val sink: MonoSink<T> + parentContext: CoroutineContext, + private val sink: MonoSink<T> ) : AbstractCoroutine<T>(parentContext, true), Disposable { + private var disposed = false override fun onCompleted(value: T) { diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt index 0ef1757e2..86e3ced06 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest.service +import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.conn.ssl.SSLConnectionSocketFactory import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients @@ -32,7 +33,6 @@ import java.io.File import java.io.FileInputStream import java.security.KeyStore import java.security.cert.X509Certificate -import org.apache.http.conn.ssl.NoopHostnameVerifier class SSLRestClientService(private val restClientProperties: SSLRestClientProperties) : BlueprintWebClientService { @@ -44,8 +44,8 @@ class SSLRestClientService(private val restClientProperties: SSLRestClientProper } private fun getAuthService(): BlueprintWebClientService? { - //type,url and additional headers don't get carried over to TokenAuthRestClientProperties from SSLTokenAuthRestClientProperties - //set them in auth obj to be consistent. TODO: refactor + // type,url and additional headers don't get carried over to TokenAuthRestClientProperties from SSLTokenAuthRestClientProperties + // set them in auth obj to be consistent. TODO: refactor return when (restClientProperties) { is SSLBasicAuthRestClientProperties -> { val basicAuthProps = restClientProperties.basicAuth!! @@ -62,7 +62,7 @@ class SSLRestClientService(private val restClientProperties: SSLRestClientProper TokenAuthRestClientService(token) } else -> { - //Returns null for No auth + // Returns null for No auth null } } @@ -74,7 +74,8 @@ class SSLRestClientService(private val restClientProperties: SSLRestClientProper } return mapOf( HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE) + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE + ) } override fun host(uri: String): String { @@ -104,7 +105,7 @@ class SSLRestClientService(private val restClientProperties: SSLRestClientProper } sslContext.loadTrustMaterial(File(sslTrust), sslTrustPwd.toCharArray(), acceptingTrustStrategy) - var csf : SSLConnectionSocketFactory + var csf: SSLConnectionSocketFactory if (sslTrustIgnoreHostname) { csf = SSLConnectionSocketFactory(sslContext.build(), NoopHostnameVerifier()) } else { @@ -123,14 +124,16 @@ class SSLRestClientService(private val restClientProperties: SSLRestClientProper override fun convertToBasicHeaders(headers: Map<String, String>): Array<BasicHeader> { val mergedDefaultAndSuppliedHeaders = defaultHeaders().plus(headers) - //During the initialization, getAuthService() sets the auth variable. - //If it's not null, then we have an authentication mechanism. - //If null - indicates no-auth used + // During the initialization, getAuthService() sets the auth variable. + // If it's not null, then we have an authentication mechanism. + // If null - indicates no-auth used if (auth != null) { return auth!!.convertToBasicHeaders(mergedDefaultAndSuppliedHeaders) } - //inject additionalHeaders - return super.convertToBasicHeaders(mergedDefaultAndSuppliedHeaders - .plus(verifyAdditionalHeaders(restClientProperties))) + // inject additionalHeaders + return super.convertToBasicHeaders( + mergedDefaultAndSuppliedHeaders + .plus(verifyAdditionalHeaders(restClientProperties)) + ) } } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt index 73b534143..57702f8ac 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt @@ -21,21 +21,24 @@ import org.onap.ccsdk.cds.blueprintsprocessor.rest.TokenAuthRestClientProperties import org.springframework.http.HttpHeaders import org.springframework.http.MediaType -class TokenAuthRestClientService(private val restClientProperties: - TokenAuthRestClientProperties) : +class TokenAuthRestClientService( + private val restClientProperties: + TokenAuthRestClientProperties +) : BlueprintWebClientService { override fun defaultHeaders(): Map<String, String> { return mapOf( HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.AUTHORIZATION to restClientProperties.token!!) + HttpHeaders.AUTHORIZATION to restClientProperties.token!! + ) } override fun convertToBasicHeaders(headers: Map<String, String>): - Array<BasicHeader> { + Array<BasicHeader> { val customHeaders: MutableMap<String, String> = headers.toMutableMap() - //inject additionalHeaders + // inject additionalHeaders customHeaders.putAll(verifyAdditionalHeaders(restClientProperties)) if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { customHeaders[HttpHeaders.AUTHORIZATION] = restClientProperties.token!! diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/utils/WebClientUtils.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/utils/WebClientUtils.kt index 42006569f..ff4d54730 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/utils/WebClientUtils.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/utils/WebClientUtils.kt @@ -32,4 +32,4 @@ class WebClientUtils { fun logResponse(): HttpResponseInterceptor = HttpResponseInterceptor { response, _ -> log.info("Response status(${response.statusLine.statusCode} - ${response.statusLine.reasonPhrase})") } } -}
\ No newline at end of file +} |