diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/rest-lib/src/main')
5 files changed, 84 insertions, 12 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt index 6e9e4b554..526f208c6 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt @@ -51,6 +51,8 @@ class RestLibConstants { const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service" const val PROPERTY_REST_CLIENT_PREFIX = "blueprintsprocessor.restclient." const val PROPERTY_TYPE = "type" + const val TYPE_NO_DEF_HEADERS = "no-def-headers" + const val TYPE_SSL_NO_DEF_HEADERS = "ssl-no-def-headers" const val TYPE_TOKEN_AUTH = "token-auth" const val TYPE_BASIC_AUTH = "basic-auth" const val TYPE_SSL_BASIC_AUTH = "ssl-basic-auth" diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt index b0282c40f..a12680e07 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt @@ -22,6 +22,7 @@ open class RestClientProperties { lateinit var type: String lateinit var url: String + lateinit var values: Map<String, Any> var connectTimeout: Int = 0 var socketTimeout: Int = 0 var connectionRequestTimeout: Int = 0 diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt index ac6cac2b7..d412d0dbc 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt @@ -75,7 +75,16 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic val type = bluePrintPropertiesService.propertyBeanType( "$prefix.type", String::class.java ) - return when (type) { + val allValues = bluePrintPropertiesService.propertyBeanType( + prefix, HashMap<String, Any>()::class.java + ) + val properties = when (type) { + RestLibConstants.TYPE_NO_DEF_HEADERS -> { + noDefHeadersRestClientProperties(prefix, false) + } + RestLibConstants.TYPE_SSL_NO_DEF_HEADERS -> { + noDefHeadersRestClientProperties(prefix, true) + } RestLibConstants.TYPE_BASIC_AUTH -> { basicAuthRestClientProperties(prefix) } @@ -102,12 +111,18 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic ) } } + properties.values = allValues + return properties } fun restClientProperties(jsonNode: JsonNode): RestClientProperties { val type = jsonNode.get("type").textValue() - return when (type) { + val allValues = JacksonUtils.readValue(jsonNode, HashMap<String, Any>()::class.java)!! + val properties = when (type) { + RestLibConstants.TYPE_NO_DEF_HEADERS -> { + JacksonUtils.readValue(jsonNode, RestClientProperties::class.java)!! + } RestLibConstants.TYPE_TOKEN_AUTH -> { JacksonUtils.readValue(jsonNode, TokenAuthRestClientProperties::class.java)!! } @@ -115,6 +130,9 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!! } + RestLibConstants.TYPE_SSL_NO_DEF_HEADERS -> { + JacksonUtils.readValue(jsonNode, SSLRestClientProperties::class.java)!! + } RestLibConstants.TYPE_POLICY_MANAGER -> { JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!! } @@ -133,27 +151,41 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic ) } } + properties.values = allValues + return properties } private fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService { - - when (restClientProperties) { + return when (restClientProperties) { is SSLRestClientProperties -> { - return SSLRestClientService(restClientProperties) + SSLRestClientService(restClientProperties) } is TokenAuthRestClientProperties -> { - return TokenAuthRestClientService(restClientProperties) + TokenAuthRestClientService(restClientProperties) } is BasicAuthRestClientProperties -> { - return BasicAuthRestClientService(restClientProperties) + BasicAuthRestClientService(restClientProperties) } else -> { - throw BluePrintProcessorException("couldn't get rest service for type:${restClientProperties.type} uri: ${restClientProperties.url}") + NoHeadersBlueprintWebClientService(restClientProperties) } } } + private fun noDefHeadersRestClientProperties(prefix: String, ssl: Boolean): + RestClientProperties { + return if (ssl) { + bluePrintPropertiesService.propertyBeanType( + prefix, SSLRestClientProperties::class.java + ) + } else { + bluePrintPropertiesService.propertyBeanType( + prefix, RestClientProperties::class.java + ) + } + } + private fun tokenRestClientProperties(prefix: String): TokenAuthRestClientProperties { return bluePrintPropertiesService.propertyBeanType( diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/NoHeadersBlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/NoHeadersBlueprintWebClientService.kt new file mode 100644 index 000000000..761b0137e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/NoHeadersBlueprintWebClientService.kt @@ -0,0 +1,33 @@ +/* + * Copyright © 2022 Deutsche Telekom AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties + +open class NoHeadersBlueprintWebClientService( + private val restClientProperties: RestClientProperties +) : + BaseBlueprintWebClientService<RestClientProperties>() { + + override fun getRestClientProperties(): RestClientProperties { + return restClientProperties + } + + override fun defaultHeaders(): Map<String, String> { + return mapOf() + } +} diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt index 602609b6a..8c8c70ff6 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/SSLRestClientService.kt @@ -25,6 +25,7 @@ import org.apache.http.message.BasicHeader import org.apache.http.ssl.SSLContextBuilder import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLRestClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLTokenAuthRestClientProperties @@ -80,10 +81,13 @@ open class SSLRestClientService(private val restClientProperties: SSLRestClientP if (auth != null) { return auth!!.defaultHeaders() } - return mapOf( - HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE - ) + return if (restClientProperties.type == RestLibConstants.TYPE_SSL_NO_DEF_HEADERS) + mapOf() + else + mapOf( + HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE + ) } override fun httpClient(): CloseableHttpClient { |