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.BasicAuthRestClientProperties
24 import org.onap.ccsdk.cds.blueprintsprocessor.rest.DME2RestClientProperties
25 import org.onap.ccsdk.cds.blueprintsprocessor.rest.PolicyManagerRestClientProperties
26 import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties
27 import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants
28 import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties
29 import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLRestClientProperties
30 import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLTokenAuthRestClientProperties
31 import org.onap.ccsdk.cds.blueprintsprocessor.rest.TokenAuthRestClientProperties
32 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
33 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
34 import org.springframework.stereotype.Service
36 @Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
37 open class BluePrintRestLibPropertyService(private var bluePrintProperties:
38 BluePrintProperties) {
40 open fun blueprintWebClientService(jsonNode: JsonNode):
41 BlueprintWebClientService {
42 val restClientProperties = restClientProperties(jsonNode)
43 return blueprintWebClientService(restClientProperties)
46 open fun blueprintWebClientService(selector: String): BlueprintWebClientService {
47 val prefix = "blueprintsprocessor.restclient.$selector"
48 val restClientProperties = restClientProperties(prefix)
49 return blueprintWebClientService(restClientProperties)
52 fun restClientProperties(prefix: String): RestClientProperties {
53 val type = bluePrintProperties.propertyBeanType(
54 "$prefix.type", String::class.java)
56 RestLibConstants.TYPE_BASIC_AUTH -> {
57 basicAuthRestClientProperties(prefix)
59 RestLibConstants.TYPE_TOKEN_AUTH -> {
60 tokenRestClientProperties(prefix)
62 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
63 sslBasicAuthRestClientProperties(prefix)
65 RestLibConstants.TYPE_SSL_TOKEN_AUTH -> {
66 sslTokenAuthRestClientProperties(prefix)
68 RestLibConstants.TYPE_SSL_NO_AUTH -> {
69 sslNoAuthRestClientProperties(prefix)
71 RestLibConstants.TYPE_DME2_PROXY -> {
72 dme2ProxyClientProperties(prefix)
74 RestLibConstants.TYPE_POLICY_MANAGER -> {
75 policyManagerRestClientProperties(prefix)
78 throw BluePrintProcessorException("Rest adaptor($type) is" +
84 fun restClientProperties(jsonNode: JsonNode): RestClientProperties {
86 val type = jsonNode.get("type").textValue()
88 RestLibConstants.TYPE_TOKEN_AUTH -> {
89 JacksonUtils.readValue(jsonNode, TokenAuthRestClientProperties::class.java)!!
91 RestLibConstants.TYPE_BASIC_AUTH -> {
92 JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!!
94 RestLibConstants.TYPE_DME2_PROXY -> {
95 JacksonUtils.readValue(jsonNode, DME2RestClientProperties::class.java)!!
97 RestLibConstants.TYPE_POLICY_MANAGER -> {
98 JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!!
100 RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
101 JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!!
103 RestLibConstants.TYPE_SSL_TOKEN_AUTH -> {
104 JacksonUtils.readValue(jsonNode, SSLTokenAuthRestClientProperties::class.java)!!
106 RestLibConstants.TYPE_SSL_NO_AUTH -> {
107 JacksonUtils.readValue(jsonNode, SSLRestClientProperties::class.java)!!
110 throw BluePrintProcessorException(
111 "Rest adaptor($type) is not supported")
116 private fun blueprintWebClientService(restClientProperties: RestClientProperties):
117 BlueprintWebClientService {
119 when (restClientProperties) {
120 is SSLRestClientProperties -> {
121 return SSLRestClientService(restClientProperties)
123 is TokenAuthRestClientProperties -> {
124 return TokenAuthRestClientService(restClientProperties)
126 is BasicAuthRestClientProperties -> {
127 return BasicAuthRestClientService(restClientProperties)
129 is DME2RestClientProperties -> {
130 return DME2ProxyRestClientService(restClientProperties)
133 throw BluePrintProcessorException("couldn't get rest service for type:${restClientProperties.type} uri: ${restClientProperties.url}")
138 private fun tokenRestClientProperties(prefix: String):
139 TokenAuthRestClientProperties {
140 return bluePrintProperties.propertyBeanType(
141 prefix, TokenAuthRestClientProperties::class.java)
144 private fun basicAuthRestClientProperties(prefix: String):
145 BasicAuthRestClientProperties {
146 return bluePrintProperties.propertyBeanType(
147 prefix, BasicAuthRestClientProperties::class.java)
150 private fun sslBasicAuthRestClientProperties(prefix: String):
151 SSLRestClientProperties {
153 val sslProps: SSLBasicAuthRestClientProperties =
154 bluePrintProperties.propertyBeanType(
155 prefix, SSLBasicAuthRestClientProperties::class.java)
156 val basicProps: BasicAuthRestClientProperties =
157 bluePrintProperties.propertyBeanType(
158 prefix, BasicAuthRestClientProperties::class.java)
159 sslProps.basicAuth = basicProps
163 private fun sslTokenAuthRestClientProperties(prefix: String):
164 SSLRestClientProperties {
166 val sslProps: SSLTokenAuthRestClientProperties =
167 bluePrintProperties.propertyBeanType(prefix,
168 SSLTokenAuthRestClientProperties::class.java)
169 val basicProps: TokenAuthRestClientProperties =
170 bluePrintProperties.propertyBeanType(prefix,
171 TokenAuthRestClientProperties::class.java)
172 sslProps.tokenAuth = basicProps
176 private fun sslNoAuthRestClientProperties(prefix: String):
177 SSLRestClientProperties {
178 return bluePrintProperties.propertyBeanType(
179 prefix, SSLRestClientProperties::class.java)
182 private fun dme2ProxyClientProperties(prefix: String):
183 DME2RestClientProperties {
184 return bluePrintProperties.propertyBeanType(
185 prefix, DME2RestClientProperties::class.java)
188 private fun policyManagerRestClientProperties(prefix: String):
189 PolicyManagerRestClientProperties {
190 return bluePrintProperties.propertyBeanType(
191 prefix, PolicyManagerRestClientProperties::class.java)