summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2022-08-18 21:50:31 +0200
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2022-08-24 14:48:20 +0000
commit9ab2a91f585864bf18fef788adeaf61f4f450b39 (patch)
tree295613f89d73e18a888e8ffd5c68be65911a7b59 /ms/blueprintsprocessor/functions
parente1db2469a8e42d591bd905e588975be0f2a8861e (diff)
Refactor rest clients and support timeouts
- Refactored rest clients to remove redundant code - Timeouts added to the configuration of rest clients Issue-ID: CCSDK-3716 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> Change-Id: I706b8efd8447570455b8b65bd5b1a22da474f62b
Diffstat (limited to 'ms/blueprintsprocessor/functions')
-rw-r--r--ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sAbstractRestClientService.kt52
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockBlueprintWebClientService.kt11
2 files changed, 12 insertions, 51 deletions
diff --git a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sAbstractRestClientService.kt b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sAbstractRestClientService.kt
index 14f14f61b..b9c45e423 100644
--- a/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sAbstractRestClientService.kt
+++ b/ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/K8sAbstractRestClientService.kt
@@ -19,23 +19,20 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s
-import org.apache.http.message.BasicHeader
import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
-import org.springframework.http.HttpHeaders.ACCEPT
-import org.springframework.http.HttpHeaders.AUTHORIZATION
-import org.springframework.http.HttpHeaders.CONTENT_TYPE
-import org.springframework.http.MediaType.APPLICATION_JSON_VALUE
-import java.nio.charset.Charset
-import java.util.Base64
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService
abstract class K8sAbstractRestClientService(
private val k8sConfiguration: K8sConnectionPluginConfiguration
-) : BlueprintWebClientService {
+) : BasicAuthRestClientService(BasicAuthRestClientProperties()) {
protected val baseUrl: String = k8sConfiguration.getProperties().url
private var restClientProperties: BasicAuthRestClientProperties? = null
+ override fun getRestClientProperties(): BasicAuthRestClientProperties {
+ return getBasicAuthRestClientProperties()
+ }
+
private fun getBasicAuthRestClientProperties(): BasicAuthRestClientProperties {
return if (restClientProperties != null)
restClientProperties!!
@@ -55,45 +52,8 @@ abstract class K8sAbstractRestClientService(
mapOfHeaders["Accept"] = "application/json"
mapOfHeaders["Content-Type"] = "application/json"
mapOfHeaders["cache-control"] = " no-cache"
- mapOfHeaders["Accept"] = "application/json"
return mapOfHeaders
}
- private fun setBasicAuth(username: String, password: String): String {
- val credentialsString = "$username:$password"
- return Base64.getEncoder().encodeToString(credentialsString.toByteArray(Charset.defaultCharset()))
- }
-
- override fun defaultHeaders(): Map<String, String> {
- val encodedCredentials = setBasicAuth(
- getBasicAuthRestClientProperties().username,
- getBasicAuthRestClientProperties().password
- )
- return mapOf(
- CONTENT_TYPE to APPLICATION_JSON_VALUE,
- ACCEPT to APPLICATION_JSON_VALUE,
- AUTHORIZATION to "Basic $encodedCredentials"
- )
- }
-
- override fun host(uri: String): String {
- return getBasicAuthRestClientProperties().url + uri
- }
-
- override fun convertToBasicHeaders(headers: Map<String, String>): Array<BasicHeader> {
- val customHeaders: MutableMap<String, String> = headers.toMutableMap()
- // inject additionalHeaders
- customHeaders.putAll(verifyAdditionalHeaders(getBasicAuthRestClientProperties()))
-
- if (!headers.containsKey(AUTHORIZATION)) {
- val encodedCredentials = setBasicAuth(
- getBasicAuthRestClientProperties().username,
- getBasicAuthRestClientProperties().password
- )
- customHeaders[AUTHORIZATION] = "Basic $encodedCredentials"
- }
- return super.convertToBasicHeaders(customHeaders)
- }
-
abstract fun apiUrl(): String
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockBlueprintWebClientService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockBlueprintWebClientService.kt
index 86a9ed056..ba273e179 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockBlueprintWebClientService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockBlueprintWebClientService.kt
@@ -21,6 +21,7 @@ import org.mockserver.model.Header
import org.mockserver.model.HttpRequest.request
import org.mockserver.model.HttpResponse.response
import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BaseBlueprintWebClientService
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
@@ -28,7 +29,7 @@ import java.nio.charset.Charset
import java.util.Base64
class MockBlueprintWebClientService(private var restClientProperties: RestClientProperties) :
- BlueprintWebClientService {
+ BaseBlueprintWebClientService<RestClientProperties>() {
private var mockServer: ClientAndServer
private var port: String = if (restClientProperties.url.split(":")[2].isEmpty()) "8080"
@@ -52,6 +53,10 @@ class MockBlueprintWebClientService(private var restClientProperties: RestClient
)
}
+ override fun getRestClientProperties(): RestClientProperties {
+ return restClientProperties
+ }
+
override fun defaultHeaders(): Map<String, String> {
val encodedCredentials = this.setBasicAuth("admin", "aaiTest")
return mapOf(
@@ -61,10 +66,6 @@ class MockBlueprintWebClientService(private var restClientProperties: RestClient
)
}
- override fun host(uri: String): String {
- return restClientProperties.url + uri
- }
-
fun tearDown() {
mockServer.close()
}