Property based GRPC server service. 41/98541/1
authorBrinda Santh <bs2796@att.com>
Tue, 19 Nov 2019 00:06:58 +0000 (19:06 -0500)
committerBrinda Santh <bs2796@att.com>
Tue, 19 Nov 2019 00:06:58 +0000 (19:06 -0500)
Issue-ID: CCSDK-1747
Signed-off-by: Brinda Santh <bs2796@att.com>
Change-Id: I948d4fac974a0d6d0c855ad4e24766a9ce6b7a6a

ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/BasicAuthServerInterceptor.kt
ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt
ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt
ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt

index f821462..a0a4ae2 100644 (file)
@@ -49,7 +49,7 @@ class BasicAuthServerInterceptor(private val authenticationManager: Authenticati
             log.info("Basic Authentication Authorization header found for user: {}", username)
 
             val authRequest = UsernamePasswordAuthenticationToken(username, tokens[1])
-            val authResult = authenticationManager!!.authenticate(authRequest).block()
+            val authResult = authenticationManager.authenticate(authRequest).block()
 
             log.info("Authentication success: {}", authResult)
 
index 0ec049a..c37c626 100644 (file)
@@ -45,6 +45,8 @@ fun BluePrintDependencyService.grpcClientService(jsonNode: JsonNode): BluePrintG
 class GRPCLibConstants {
     companion object {
         const val SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY = "blueprint-grpc-lib-property-service"
+        const val PROPERTY_GRPC_CLIENT_PREFIX = "blueprintsprocessor.grpcclient."
+        const val PROPERTY_GRPC_SERVER_PREFIX = "blueprintsprocessor.grpcserver."
         const val TYPE_TOKEN_AUTH = "token-auth"
         const val TYPE_BASIC_AUTH = "basic-auth"
         const val TYPE_TLS_AUTH = "tls-auth"
index fbc9ddd..02d5cc6 100644 (file)
@@ -28,6 +28,18 @@ import org.springframework.stereotype.Service
 @Service(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY)
 open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesService: BluePrintPropertiesService) {
 
+    fun blueprintGrpcServerService(jsonNode: JsonNode): BluePrintGrpcServerService {
+        val grpcServerProperties = grpcServerProperties(jsonNode)
+        return blueprintGrpcServerService(grpcServerProperties)
+    }
+
+    fun blueprintGrpcServerService(selector: String): BluePrintGrpcServerService {
+        val prefix = "${GRPCLibConstants.PROPERTY_GRPC_SERVER_PREFIX}$selector"
+        val grpcServerProperties = grpcServerProperties(prefix)
+        return blueprintGrpcServerService(grpcServerProperties)
+    }
+
+
     /** GRPC Server Lib Property Service */
     fun grpcServerProperties(jsonNode: JsonNode): GrpcServerProperties {
         return when (val type = jsonNode.get("type").textValue()) {
@@ -67,6 +79,19 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic
         return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthGrpcServerProperties::class.java)
     }
 
+    private fun blueprintGrpcServerService(grpcServerProperties: GrpcServerProperties)
+            : BluePrintGrpcServerService {
+        when (grpcServerProperties) {
+            is TLSAuthGrpcServerProperties -> {
+                return TLSAuthGrpcServerService(grpcServerProperties)
+            }
+            else -> {
+                throw BluePrintProcessorException("couldn't get grpc client service for properties $grpcServerProperties")
+            }
+        }
+    }
+
+
     /** GRPC Client Lib Property Service */
 
     fun blueprintGrpcClientService(jsonNode: JsonNode): BluePrintGrpcClientService {
@@ -75,7 +100,7 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic
     }
 
     fun blueprintGrpcClientService(selector: String): BluePrintGrpcClientService {
-        val prefix = "blueprintsprocessor.grpcclient.$selector"
+        val prefix = "${GRPCLibConstants.PROPERTY_GRPC_CLIENT_PREFIX}$selector"
         val restClientProperties = grpcClientProperties(prefix)
         return blueprintGrpcClientService(restClientProperties)
     }
index e4bfd5d..13432c0 100644 (file)
@@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service
 
 import com.fasterxml.jackson.databind.JsonNode
 import com.fasterxml.jackson.databind.ObjectMapper
+import org.junit.Assert
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService
@@ -190,5 +191,9 @@ class BluePrintGrpcLibPropertyServiceTest {
         val jsonProperties = bluePrintGrpcLibPropertyService
                 .grpcServerProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcServerProperties
         assertNotNull(jsonProperties, "failed to create property bean from json")
+
+        val grpcServerService = bluePrintGrpcLibPropertyService.blueprintGrpcServerService("tls-sample")
+        assertNotNull(grpcServerService, "failed to get grpc server service")
+        Assert.assertEquals(TLSAuthGrpcServerService::class.java, grpcServerService.javaClass)
     }
 }
\ No newline at end of file