2 * Copyright © 2019 IBM.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.rest
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
21 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
22 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
23 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
25 fun BluePrintTypes.dslBasicAuthRestClientProperties(block: BasicAuthRestClientPropertiesBuilder.() -> Unit): JsonNode {
26 val assignments = BasicAuthRestClientPropertiesBuilder().apply(block).build()
27 assignments[RestLibConstants.PROPERTY_TYPE] = RestLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive()
28 return assignments.asJsonType()
31 fun BluePrintTypes.dslTokenAuthRestClientProperties(block: TokenAuthRestClientPropertiesBuilder.() -> Unit): JsonNode {
32 val assignments = TokenAuthRestClientPropertiesBuilder().apply(block).build()
33 assignments[RestLibConstants.PROPERTY_TYPE] = RestLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive()
34 return assignments.asJsonType()
37 fun BluePrintTypes.dslSSLRestClientProperties(block: SSLRestClientPropertiesBuilder.() -> Unit): JsonNode {
38 val assignments = SSLRestClientPropertiesBuilder().apply(block).build()
39 assignments[RestLibConstants.PROPERTY_TYPE] = RestLibConstants.TYPE_SSL_NO_AUTH.asJsonPrimitive()
40 return assignments.asJsonType()
43 open class RestClientPropertiesBuilder : PropertiesAssignmentBuilder() {
44 fun type(type: String) {
45 type(type.asJsonPrimitive())
48 fun type(type: JsonNode) {
49 property(RestLibConstants.PROPERTY_TYPE, type)
52 open fun url(url: String) {
53 url(url.asJsonPrimitive())
56 open fun url(url: JsonNode) {
61 open class BasicAuthRestClientPropertiesBuilder : RestClientPropertiesBuilder() {
62 open fun password(password: String) {
63 password(password.asJsonPrimitive())
66 open fun password(password: JsonNode) {
67 property("password", password)
70 open fun username(username: String) {
71 username(username.asJsonPrimitive())
74 open fun username(username: JsonNode) {
75 property("username", username)
79 open class TokenAuthRestClientPropertiesBuilder : RestClientPropertiesBuilder() {
80 open fun token(token: String) {
81 token(token.asJsonPrimitive())
84 open fun token(token: JsonNode) {
85 property("token", token)
89 open class SSLRestClientPropertiesBuilder : RestClientPropertiesBuilder() {
90 open fun keyStoreInstance(keyStoreInstance: String) {
91 keyStoreInstance(keyStoreInstance.asJsonPrimitive())
94 open fun keyStoreInstance(keyStoreInstance: JsonNode) {
95 property("keyStoreInstance", keyStoreInstance)
98 open fun sslTrust(sslTrust: String) {
99 sslTrust(sslTrust.asJsonPrimitive())
102 open fun sslTrust(sslTrust: JsonNode) {
103 property("sslTrust", sslTrust)
106 open fun sslTrustPassword(sslTrustPassword: String) {
107 sslTrustPassword(sslTrustPassword.asJsonPrimitive())
110 open fun sslTrustPassword(sslTrustPassword: JsonNode) {
111 property("sslTrustPassword", sslTrustPassword)
114 open fun sslKey(sslKey: String) {
115 sslKey(sslKey.asJsonPrimitive())
118 open fun sslKey(sslKey: JsonNode) {
119 property("sslKey", sslKey)
122 open fun sslKeyPassword(sslKeyPassword: String) {
123 sslKeyPassword(sslKeyPassword.asJsonPrimitive())
126 open fun sslKeyPassword(sslKeyPassword: JsonNode) {
127 property("sslKeyPassword", sslKeyPassword)
131 open class SSLBasicAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() {
135 open class SSLTokenAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() {