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/grpc-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/grpc-lib/src/main')
12 files changed, 129 insertions, 87 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt index 55cf0941d..97b462a3c 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcExtensions.kt @@ -24,4 +24,4 @@ fun Metadata.getStringKey(key: String): String? { fun Metadata.putStringKeyValue(key: String, value: String) { this.put(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER), value) -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt index c37c6263a..a3823c6ac 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt @@ -32,7 +32,7 @@ open class BluePrintGrpcLibConfiguration * Exposed Dependency Service by this GRPC Lib Module */ fun BluePrintDependencyService.grpcLibPropertyService(): BluePrintGrpcLibPropertyService = - instance(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY) + instance(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY) fun BluePrintDependencyService.grpcClientService(selector: String): BluePrintGrpcClientService { return grpcLibPropertyService().blueprintGrpcClientService(selector) @@ -51,4 +51,4 @@ class GRPCLibConstants { const val TYPE_BASIC_AUTH = "basic-auth" const val TYPE_TLS_AUTH = "tls-auth" } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt index 47d16fbc7..f94d918a2 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibData.kt @@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc /** GRPC Server Properties */ open class GrpcServerProperties { + lateinit var type: String var port: Int = -1 } @@ -36,6 +37,7 @@ open class TLSAuthGrpcServerProperties : GrpcServerProperties() { /** GRPC Client Properties */ open class GrpcClientProperties { + lateinit var type: String lateinit var host: String var port: Int = -1 @@ -55,4 +57,4 @@ open class TLSAuthGrpcClientProperties : GrpcClientProperties() { open class BasicAuthGrpcClientProperties : GrpcClientProperties() { lateinit var username: String lateinit var password: String -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcClientLoggingInterceptor.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcClientLoggingInterceptor.kt index f3b14b59f..99ac74070 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcClientLoggingInterceptor.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcClientLoggingInterceptor.kt @@ -16,18 +16,27 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor -import io.grpc.* +import io.grpc.CallOptions +import io.grpc.Channel +import io.grpc.ClientCall +import io.grpc.ClientInterceptor +import io.grpc.ForwardingClientCall +import io.grpc.ForwardingClientCallListener +import io.grpc.Metadata +import io.grpc.MethodDescriptor import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.GrpcLoggerService import org.onap.ccsdk.cds.controllerblueprints.core.logger - class GrpcClientLoggingInterceptor : ClientInterceptor { val log = logger(GrpcClientLoggingInterceptor::class) val loggingService = GrpcLoggerService() - override fun <ReqT, RespT> interceptCall(method: MethodDescriptor<ReqT, RespT>, - callOptions: CallOptions, channel: Channel): ClientCall<ReqT, RespT> { + override fun <ReqT, RespT> interceptCall( + method: MethodDescriptor<ReqT, RespT>, + callOptions: CallOptions, + channel: Channel + ): ClientCall<ReqT, RespT> { return object : ForwardingClientCall .SimpleForwardingClientCall<ReqT, RespT>(channel.newCall(method, callOptions)) { @@ -42,6 +51,5 @@ class GrpcClientLoggingInterceptor : ClientInterceptor { super.start(listener, headers) } } - } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt index e21d5d3ce..ec0761af4 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/interceptor/GrpcServerLoggingInterceptor.kt @@ -16,7 +16,12 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor -import io.grpc.* +import io.grpc.ForwardingServerCall +import io.grpc.ForwardingServerCallListener +import io.grpc.Metadata +import io.grpc.ServerCall +import io.grpc.ServerCallHandler +import io.grpc.ServerInterceptor import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.GrpcLoggerService import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.logger @@ -30,9 +35,12 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { val log = logger(GrpcServerLoggingInterceptor::class) val loggingService = GrpcLoggerService() - override fun <ReqT : Any, RespT : Any> interceptCall(call: ServerCall<ReqT, RespT>, - requestHeaders: Metadata, next: ServerCallHandler<ReqT, RespT>) - : ServerCall.Listener<ReqT> { + override fun <ReqT : Any, RespT : Any> interceptCall( + call: ServerCall<ReqT, RespT>, + requestHeaders: Metadata, + next: ServerCallHandler<ReqT, RespT> + ): + ServerCall.Listener<ReqT> { val forwardingServerCall = object : ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) { override fun sendHeaders(responseHeaders: Metadata) { @@ -41,9 +49,10 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { } } - return object - : ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>( - next.startCall(forwardingServerCall, requestHeaders)) { + return object : + ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>( + next.startCall(forwardingServerCall, requestHeaders) + ) { override fun onMessage(message: ReqT) { /** Get the requestId, SubRequestId and Originator Id and set in MDS context @@ -52,22 +61,22 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { when (message) { is ExecutionServiceInput -> { val commonHeader = message.commonHeader - ?: throw BluePrintProcessorException("missing common header in request") + ?: throw BluePrintProcessorException("missing common header in request") loggingService.grpcRequesting(call, commonHeader, next) } is BluePrintUploadInput -> { val commonHeader = message.commonHeader - ?: throw BluePrintProcessorException("missing common header in request") + ?: throw BluePrintProcessorException("missing common header in request") loggingService.grpcRequesting(call, commonHeader, next) } is BluePrintDownloadInput -> { val commonHeader = message.commonHeader - ?: throw BluePrintProcessorException("missing common header in request") + ?: throw BluePrintProcessorException("missing common header in request") loggingService.grpcRequesting(call, commonHeader, next) } is BluePrintRemoveInput -> { val commonHeader = message.commonHeader - ?: throw BluePrintProcessorException("missing common header in request") + ?: throw BluePrintProcessorException("missing common header in request") loggingService.grpcRequesting(call, commonHeader, next) } else -> { @@ -86,7 +95,6 @@ class GrpcServerLoggingInterceptor : ServerInterceptor { MDC.clear() super.onCancel() } - } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt index a175d8b3a..e3fd14c1e 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BasicAuthGrpcClientService.kt @@ -22,19 +22,16 @@ import io.grpc.internal.PickFirstLoadBalancerProvider import io.grpc.netty.NettyChannelBuilder import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties - -open class BasicAuthGrpcClientService(private val basicAuthGrpcClientProperties: BasicAuthGrpcClientProperties) - : BluePrintGrpcClientService { +open class BasicAuthGrpcClientService(private val basicAuthGrpcClientProperties: BasicAuthGrpcClientProperties) : + BluePrintGrpcClientService { override suspend fun channel(): ManagedChannel { val managedChannel = NettyChannelBuilder - .forAddress(basicAuthGrpcClientProperties.host, basicAuthGrpcClientProperties.port) - .nameResolverFactory(DnsNameResolverProvider()) - .loadBalancerFactory(PickFirstLoadBalancerProvider()) - // .intercept(BasicAuthClientInterceptor(basicAuthGrpcClientProperties)).usePlaintext() - .build() + .forAddress(basicAuthGrpcClientProperties.host, basicAuthGrpcClientProperties.port) + .nameResolverFactory(DnsNameResolverProvider()) + .loadBalancerFactory(PickFirstLoadBalancerProvider()) + // .intercept(BasicAuthClientInterceptor(basicAuthGrpcClientProperties)).usePlaintext() + .build() return managedChannel } - - } diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt index 02d5cc695..8a3c5a6a7 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt @@ -19,7 +19,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.grpc.* +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GrpcServerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcServerProperties import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.returnNullIfMissing import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils @@ -39,7 +46,6 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic return blueprintGrpcServerService(grpcServerProperties) } - /** GRPC Server Lib Property Service */ fun grpcServerProperties(jsonNode: JsonNode): GrpcServerProperties { return when (val type = jsonNode.get("type").textValue()) { @@ -57,7 +63,8 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic fun grpcServerProperties(prefix: String): GrpcServerProperties { val type = bluePrintPropertiesService.propertyBeanType( - "$prefix.type", String::class.java) + "$prefix.type", String::class.java + ) return when (type) { GRPCLibConstants.TYPE_TOKEN_AUTH -> { tokenAuthGrpcServerProperties(prefix) @@ -79,8 +86,8 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthGrpcServerProperties::class.java) } - private fun blueprintGrpcServerService(grpcServerProperties: GrpcServerProperties) - : BluePrintGrpcServerService { + private fun blueprintGrpcServerService(grpcServerProperties: GrpcServerProperties): + BluePrintGrpcServerService { when (grpcServerProperties) { is TLSAuthGrpcServerProperties -> { return TLSAuthGrpcServerService(grpcServerProperties) @@ -91,7 +98,6 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic } } - /** GRPC Client Lib Property Service */ fun blueprintGrpcClientService(jsonNode: JsonNode): BluePrintGrpcClientService { @@ -105,10 +111,9 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic return blueprintGrpcClientService(restClientProperties) } - fun grpcClientProperties(jsonNode: JsonNode): GrpcClientProperties { val type = jsonNode.get("type").returnNullIfMissing()?.textValue() - ?: BluePrintProcessorException("missing type property") + ?: BluePrintProcessorException("missing type property") return when (type) { GRPCLibConstants.TYPE_TOKEN_AUTH -> { JacksonUtils.readValue(jsonNode, TokenAuthGrpcClientProperties::class.java)!! @@ -127,7 +132,8 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic fun grpcClientProperties(prefix: String): GrpcClientProperties { val type = bluePrintPropertiesService.propertyBeanType( - "$prefix.type", String::class.java) + "$prefix.type", String::class.java + ) return when (type) { GRPCLibConstants.TYPE_TOKEN_AUTH -> { tokenAuthGrpcClientProperties(prefix) @@ -140,7 +146,6 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic } else -> { throw BluePrintProcessorException("Grpc type($type) not supported") - } } } @@ -174,4 +179,4 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic private fun basicAuthGrpcClientProperties(prefix: String): BasicAuthGrpcClientProperties { return bluePrintPropertiesService.propertyBeanType(prefix, BasicAuthGrpcClientProperties::class.java) } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt index 0d9291615..e71525f0a 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcService.kt @@ -26,4 +26,4 @@ interface BluePrintGrpcServerService { interface BluePrintGrpcClientService { suspend fun channel(): ManagedChannel -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt index 6d2ba43cc..510a21581 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/GrpcLoggerService.kt @@ -36,35 +36,45 @@ import java.net.InetSocketAddress import java.time.ZoneOffset import java.time.ZonedDateTime import java.time.format.DateTimeFormatter -import java.util.* +import java.util.UUID class GrpcLoggerService { private val log = logger(GrpcLoggerService::class) /** Used when server receives request */ - fun <ReqT : Any, RespT : Any> grpcRequesting(call: ServerCall<ReqT, RespT>, - headers: Metadata, next: ServerCallHandler<ReqT, RespT>) { + fun <ReqT : Any, RespT : Any> grpcRequesting( + call: ServerCall<ReqT, RespT>, + headers: Metadata, + next: ServerCallHandler<ReqT, RespT> + ) { val requestID = headers.getStringKey(ONAP_REQUEST_ID).defaultToUUID() val invocationID = headers.getStringKey(ONAP_INVOCATION_ID).defaultToUUID() val partnerName = headers.getStringKey(ONAP_PARTNER_NAME) ?: "UNKNOWN" grpcRequesting(requestID, invocationID, partnerName, call) } - fun <ReqT : Any, RespT : Any> grpcRequesting(call: ServerCall<ReqT, RespT>, - headers: CommonHeader, next: ServerCallHandler<ReqT, RespT>) { + fun <ReqT : Any, RespT : Any> grpcRequesting( + call: ServerCall<ReqT, RespT>, + headers: CommonHeader, + next: ServerCallHandler<ReqT, RespT> + ) { val requestID = headers.requestId.defaultToUUID() val invocationID = headers.subRequestId.defaultToUUID() val partnerName = headers.originatorId ?: "UNKNOWN" grpcRequesting(requestID, invocationID, partnerName, call) } - fun <ReqT : Any, RespT : Any> grpcRequesting(requestID: String, invocationID: String, partnerName: String, - call: ServerCall<ReqT, RespT>) { + fun <ReqT : Any, RespT : Any> grpcRequesting( + requestID: String, + invocationID: String, + partnerName: String, + call: ServerCall<ReqT, RespT> + ) { val localhost = InetAddress.getLocalHost() val clientSocketAddress = call.attributes.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR) as? InetSocketAddress - ?: throw BluePrintProcessorException("failed to get client address") + ?: throw BluePrintProcessorException("failed to get client address") val serviceName = call.methodDescriptor.fullMethodName MDC.put("InvokeTimestamp", ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)) @@ -77,7 +87,6 @@ class GrpcLoggerService { log.trace("MDC Properties : ${MDC.getCopyOfContextMap()}") } - /** Used before invoking any GRPC outbound request, Inbound Invocation ID is used as request Id * for outbound Request, If invocation Id is missing then default Request Id will be generated. */ @@ -98,4 +107,4 @@ class GrpcLoggerService { log.warn("couldn't set grpc response headers", e) } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt index a70cbbce0..68ca3c16b 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcClientService.kt @@ -26,17 +26,17 @@ import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor.GrpcClientLoggingInterceptor import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile -class TLSAuthGrpcClientService(private val tlsAuthGrpcClientProperties: TLSAuthGrpcClientProperties) - : BluePrintGrpcClientService { +class TLSAuthGrpcClientService(private val tlsAuthGrpcClientProperties: TLSAuthGrpcClientProperties) : + BluePrintGrpcClientService { override suspend fun channel(): ManagedChannel { return NettyChannelBuilder - .forAddress(tlsAuthGrpcClientProperties.host, tlsAuthGrpcClientProperties.port) - .nameResolverFactory(DnsNameResolverProvider()) - .loadBalancerFactory(PickFirstLoadBalancerProvider()) - .intercept(GrpcClientLoggingInterceptor()) - .sslContext(sslContext()) - .build() + .forAddress(tlsAuthGrpcClientProperties.host, tlsAuthGrpcClientProperties.port) + .nameResolverFactory(DnsNameResolverProvider()) + .loadBalancerFactory(PickFirstLoadBalancerProvider()) + .intercept(GrpcClientLoggingInterceptor()) + .sslContext(sslContext()) + .build() } fun sslContext(): SslContext { @@ -44,11 +44,14 @@ class TLSAuthGrpcClientService(private val tlsAuthGrpcClientProperties: TLSAuthG if (tlsAuthGrpcClientProperties.trustCertCollection != null) { builder.trustManager(normalizedFile(tlsAuthGrpcClientProperties.trustCertCollection!!)) } - if (tlsAuthGrpcClientProperties.clientCertChain != null - && tlsAuthGrpcClientProperties.clientPrivateKey != null) { - builder.keyManager(normalizedFile(tlsAuthGrpcClientProperties.clientCertChain!!), - normalizedFile(tlsAuthGrpcClientProperties.clientPrivateKey!!)) + if (tlsAuthGrpcClientProperties.clientCertChain != null && + tlsAuthGrpcClientProperties.clientPrivateKey != null + ) { + builder.keyManager( + normalizedFile(tlsAuthGrpcClientProperties.clientCertChain!!), + normalizedFile(tlsAuthGrpcClientProperties.clientPrivateKey!!) + ) } return builder.build() } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt index fc73d43f9..915ea1730 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TLSAuthGrpcServerService.kt @@ -24,20 +24,21 @@ import io.netty.handler.ssl.SslContextBuilder import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile - -class TLSAuthGrpcServerService(private val tlsAuthGrpcServerProperties: TLSAuthGrpcServerProperties) - : BluePrintGrpcServerService { +class TLSAuthGrpcServerService(private val tlsAuthGrpcServerProperties: TLSAuthGrpcServerProperties) : + BluePrintGrpcServerService { override fun serverBuilder(): NettyServerBuilder { return NettyServerBuilder - .forPort(tlsAuthGrpcServerProperties.port) - .sslContext(sslContext()) + .forPort(tlsAuthGrpcServerProperties.port) + .sslContext(sslContext()) } fun sslContext(): SslContext { val sslClientContextBuilder = SslContextBuilder - .forServer(normalizedFile(tlsAuthGrpcServerProperties.certChain), - normalizedFile(tlsAuthGrpcServerProperties.privateKey)) + .forServer( + normalizedFile(tlsAuthGrpcServerProperties.certChain), + normalizedFile(tlsAuthGrpcServerProperties.privateKey) + ) tlsAuthGrpcServerProperties.trustCertCollection?.let { trustCertFile -> sslClientContextBuilder.trustManager(normalizedFile(trustCertFile)) @@ -45,5 +46,4 @@ class TLSAuthGrpcServerService(private val tlsAuthGrpcServerProperties: TLSAuthG } return GrpcSslContexts.configure(sslClientContextBuilder).build() } - -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt index 601dc0e33..371353db2 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/TokenAuthGrpcClientService.kt @@ -16,31 +16,41 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service -import io.grpc.* +import io.grpc.CallOptions +import io.grpc.Channel +import io.grpc.ClientCall +import io.grpc.ClientInterceptor +import io.grpc.ForwardingClientCall +import io.grpc.ManagedChannel +import io.grpc.Metadata +import io.grpc.MethodDescriptor import io.grpc.internal.DnsNameResolverProvider import io.grpc.internal.PickFirstLoadBalancerProvider import io.grpc.netty.NettyChannelBuilder import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.grpc.interceptor.GrpcClientLoggingInterceptor -class TokenAuthGrpcClientService(private val tokenAuthGrpcClientProperties: TokenAuthGrpcClientProperties) - : BluePrintGrpcClientService { +class TokenAuthGrpcClientService(private val tokenAuthGrpcClientProperties: TokenAuthGrpcClientProperties) : + BluePrintGrpcClientService { override suspend fun channel(): ManagedChannel { val managedChannel = NettyChannelBuilder - .forAddress(tokenAuthGrpcClientProperties.host, tokenAuthGrpcClientProperties.port) - .nameResolverFactory(DnsNameResolverProvider()) - .loadBalancerFactory(PickFirstLoadBalancerProvider()) - .intercept(GrpcClientLoggingInterceptor()) - .intercept(TokenAuthClientInterceptor(tokenAuthGrpcClientProperties)).usePlaintext().build() + .forAddress(tokenAuthGrpcClientProperties.host, tokenAuthGrpcClientProperties.port) + .nameResolverFactory(DnsNameResolverProvider()) + .loadBalancerFactory(PickFirstLoadBalancerProvider()) + .intercept(GrpcClientLoggingInterceptor()) + .intercept(TokenAuthClientInterceptor(tokenAuthGrpcClientProperties)).usePlaintext().build() return managedChannel } } class TokenAuthClientInterceptor(private val tokenAuthGrpcClientProperties: TokenAuthGrpcClientProperties) : ClientInterceptor { - override fun <ReqT, RespT> interceptCall(method: MethodDescriptor<ReqT, RespT>, - callOptions: CallOptions, channel: Channel): ClientCall<ReqT, RespT> { + override fun <ReqT, RespT> interceptCall( + method: MethodDescriptor<ReqT, RespT>, + callOptions: CallOptions, + channel: Channel + ): ClientCall<ReqT, RespT> { val authHeader = Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER) |