2 * Copyright © 2017-2019 AT&T, Bell Canada
3 * Modifications Copyright © 2019 IBM.
4 * Modifications Copyright © 2019 Huawei.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.onap.ccsdk.cds.blueprintsprocessor.rest.service
21 import com.fasterxml.jackson.databind.JsonNode
22 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
23 import org.onap.ccsdk.cds.blueprintsprocessor.rest.*
24 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
25 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
26 import org.springframework.stereotype.Service
28 @Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
29 open class BluePrintRestLibPropertyService(private var bluePrintProperties:
30 BluePrintProperties) {
32 open fun blueprintWebClientService(jsonNode: JsonNode):
33 BlueprintWebClientService {
34 val restClientProperties = restClientProperties(jsonNode)
35 return blueprintWebClientService(restClientProperties)
38 open fun blueprintWebClientService(selector: String): BlueprintWebClientService {
39 val prefix = "blueprintsprocessor.restclient.$selector"
40 val restClientProperties = restClientProperties(prefix)
41 return blueprintWebClientService(restClientProperties)
44 fun restClientProperties(prefix: String): RestClientProperties {
45 val type = bluePrintProperties.propertyBeanType(
46 "$prefix.type", String::class.java)
48 RestLibConstants.TYPE_BASIC_AUTH -> {
49 basicAuthRestClientProperties(prefix)
51 RestLibConstants.TYPE_TOKEN_AUTH -> {
52 tokenRestClientProperties(prefix)
54 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
55 sslBasicAuthRestClientProperties(prefix)
57 RestLibConstants.TYPE_SSL_TOKEN_AUTH -> {
58 sslTokenAuthRestClientProperties(prefix)
60 RestLibConstants.TYPE_SSL_NO_AUTH -> {
61 sslNoAuthRestClientProperties(prefix)
63 RestLibConstants.TYPE_DME2_PROXY -> {
64 dme2ProxyClientProperties(prefix)
66 RestLibConstants.TYPE_POLICY_MANAGER -> {
67 policyManagerRestClientProperties(prefix)
70 throw BluePrintProcessorException("Rest adaptor($type) is" +
76 fun restClientProperties(jsonNode: JsonNode): RestClientProperties {
78 val type = jsonNode.get("type").textValue()
80 RestLibConstants.TYPE_TOKEN_AUTH -> {
81 JacksonUtils.readValue(jsonNode, TokenAuthRestClientProperties::class.java)!!
83 RestLibConstants.TYPE_BASIC_AUTH -> {
84 JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!!
86 RestLibConstants.TYPE_DME2_PROXY -> {
87 JacksonUtils.readValue(jsonNode, DME2RestClientProperties::class.java)!!
89 RestLibConstants.TYPE_POLICY_MANAGER -> {
90 JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!!
92 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
93 JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!!
95 RestLibConstants.TYPE_SSL_TOKEN_AUTH -> {
96 JacksonUtils.readValue(jsonNode, SSLTokenAuthRestClientProperties::class.java)!!
98 RestLibConstants.TYPE_SSL_NO_AUTH -> {
99 JacksonUtils.readValue(jsonNode, SSLRestClientProperties::class.java)!!
102 throw BluePrintProcessorException(
103 "Rest adaptor($type) is not supported")
108 private fun blueprintWebClientService(restClientProperties: RestClientProperties):
109 BlueprintWebClientService {
111 when (restClientProperties) {
112 is SSLRestClientProperties -> {
113 return SSLRestClientService(restClientProperties)
115 is TokenAuthRestClientProperties -> {
116 return TokenAuthRestClientService(restClientProperties)
118 is BasicAuthRestClientProperties -> {
119 return BasicAuthRestClientService(restClientProperties)
121 is DME2RestClientProperties -> {
122 return DME2ProxyRestClientService(restClientProperties)
125 throw BluePrintProcessorException("couldn't get rest service for type:${restClientProperties.type} uri: ${restClientProperties.url}")
130 private fun tokenRestClientProperties(prefix: String):
131 TokenAuthRestClientProperties {
132 return bluePrintProperties.propertyBeanType(
133 prefix, TokenAuthRestClientProperties::class.java)
136 private fun basicAuthRestClientProperties(prefix: String):
137 BasicAuthRestClientProperties {
138 return bluePrintProperties.propertyBeanType(
139 prefix, BasicAuthRestClientProperties::class.java)
142 private fun sslBasicAuthRestClientProperties(prefix: String):
143 SSLRestClientProperties {
145 val sslProps: SSLBasicAuthRestClientProperties =
146 bluePrintProperties.propertyBeanType(
147 prefix, SSLBasicAuthRestClientProperties::class.java)
148 val basicProps: BasicAuthRestClientProperties =
149 bluePrintProperties.propertyBeanType(
150 prefix, BasicAuthRestClientProperties::class.java)
151 sslProps.basicAuth = basicProps
155 private fun sslTokenAuthRestClientProperties(prefix: String):
156 SSLRestClientProperties {
158 val sslProps: SSLTokenAuthRestClientProperties =
159 bluePrintProperties.propertyBeanType(prefix,
160 SSLTokenAuthRestClientProperties::class.java)
161 val basicProps: TokenAuthRestClientProperties =
162 bluePrintProperties.propertyBeanType(prefix,
163 TokenAuthRestClientProperties::class.java)
164 sslProps.tokenAuth = basicProps
168 private fun sslNoAuthRestClientProperties(prefix: String):
169 SSLRestClientProperties {
170 return bluePrintProperties.propertyBeanType(
171 prefix, SSLRestClientProperties::class.java)
174 private fun dme2ProxyClientProperties(prefix: String):
175 DME2RestClientProperties {
176 return bluePrintProperties.propertyBeanType(
177 prefix, DME2RestClientProperties::class.java)
180 private fun policyManagerRestClientProperties(prefix: String):
181 PolicyManagerRestClientProperties {
182 return bluePrintProperties.propertyBeanType(
183 prefix, PolicyManagerRestClientProperties::class.java)