2 * Copyright © 2017-2019 AT&T, Bell Canada
3 * Modifications Copyright © 2019 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.apps.blueprintsprocessor.rest.service
20 import com.fasterxml.jackson.databind.JsonNode
21 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
22 import org.onap.ccsdk.apps.blueprintsprocessor.rest.BasicAuthRestClientProperties
23 import org.onap.ccsdk.apps.blueprintsprocessor.rest.DME2RestClientProperties
24 import org.onap.ccsdk.apps.blueprintsprocessor.rest.PolicyManagerRestClientProperties
25 import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestClientProperties
26 import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestLibConstants
27 import org.onap.ccsdk.apps.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties
28 import org.onap.ccsdk.apps.blueprintsprocessor.rest.TokenAuthRestClientProperties
29 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
30 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
31 import org.springframework.stereotype.Service
33 @Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
34 open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
36 fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService {
37 val restClientProperties = restClientProperties(jsonNode)
38 return blueprintWebClientService(restClientProperties)
41 fun blueprintWebClientService(selector: String): BlueprintWebClientService {
42 val prefix = "blueprintsprocessor.restclient.$selector"
43 val restClientProperties = restClientProperties(prefix)
44 return blueprintWebClientService(restClientProperties)
47 fun restClientProperties(prefix: String): RestClientProperties {
48 val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
50 RestLibConstants.TYPE_BASIC_AUTH -> {
51 basicAuthRestClientProperties(prefix)
53 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
54 sslBasicAuthRestClientProperties(prefix)
56 RestLibConstants.TYPE_DME2_PROXY -> {
57 dme2ProxyClientProperties(prefix)
59 RestLibConstants.TYPE_POLICY_MANAGER -> {
60 policyManagerRestClientProperties(prefix)
63 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
68 private fun restClientProperties(jsonNode: JsonNode): RestClientProperties {
69 val type = jsonNode.get("type").textValue()
71 RestLibConstants.TYPE_TOKEN_AUTH -> {
72 JacksonUtils.readValue(jsonNode, TokenAuthRestClientProperties::class.java)!!
74 RestLibConstants.TYPE_BASIC_AUTH -> {
75 JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!!
77 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
78 JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!!
80 RestLibConstants.TYPE_DME2_PROXY -> {
81 JacksonUtils.readValue(jsonNode, DME2RestClientProperties::class.java)!!
83 RestLibConstants.TYPE_POLICY_MANAGER -> {
84 JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!!
87 throw BluePrintProcessorException("Rest adaptor($type) is not supported")
92 private fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService {
93 when (restClientProperties) {
94 is TokenAuthRestClientProperties -> {
95 return TokenAuthRestClientService(restClientProperties)
97 is BasicAuthRestClientProperties -> {
98 return BasicAuthRestClientService(restClientProperties)
100 is SSLBasicAuthRestClientProperties -> {
101 return SSLBasicAuthRestClientService(restClientProperties)
103 is DME2RestClientProperties -> {
104 return DME2ProxyRestClientService(restClientProperties)
107 throw BluePrintProcessorException("couldn't get rest service for")
112 private fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties {
113 return bluePrintProperties.propertyBeanType(prefix, BasicAuthRestClientProperties::class.java)
116 private fun sslBasicAuthRestClientProperties(prefix: String): SSLBasicAuthRestClientProperties {
117 return bluePrintProperties.propertyBeanType(prefix, SSLBasicAuthRestClientProperties::class.java)
120 private fun dme2ProxyClientProperties(prefix: String): DME2RestClientProperties {
121 return bluePrintProperties.propertyBeanType(prefix, DME2RestClientProperties::class.java)
124 private fun policyManagerRestClientProperties(prefix: String): PolicyManagerRestClientProperties {
125 return bluePrintProperties.propertyBeanType(prefix, PolicyManagerRestClientProperties::class.java)