Formatting Code base with ktlint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / rest-lib / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / rest / RestClientPropertiesDSL.kt
1 /*
2  *  Copyright © 2019 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.rest
18
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
24
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()
29 }
30
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()
35 }
36
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()
41 }
42
43 open class RestClientPropertiesBuilder : PropertiesAssignmentBuilder() {
44     fun type(type: String) {
45         type(type.asJsonPrimitive())
46     }
47
48     fun type(type: JsonNode) {
49         property(RestLibConstants.PROPERTY_TYPE, type)
50     }
51
52     open fun url(url: String) {
53         url(url.asJsonPrimitive())
54     }
55
56     open fun url(url: JsonNode) {
57         property("url", url)
58     }
59 }
60
61 open class BasicAuthRestClientPropertiesBuilder : RestClientPropertiesBuilder() {
62     open fun password(password: String) {
63         password(password.asJsonPrimitive())
64     }
65
66     open fun password(password: JsonNode) {
67         property("password", password)
68     }
69
70     open fun username(username: String) {
71         username(username.asJsonPrimitive())
72     }
73
74     open fun username(username: JsonNode) {
75         property("username", username)
76     }
77 }
78
79 open class TokenAuthRestClientPropertiesBuilder : RestClientPropertiesBuilder() {
80     open fun token(token: String) {
81         token(token.asJsonPrimitive())
82     }
83
84     open fun token(token: JsonNode) {
85         property("token", token)
86     }
87 }
88
89 open class SSLRestClientPropertiesBuilder : RestClientPropertiesBuilder() {
90     open fun keyStoreInstance(keyStoreInstance: String) {
91         keyStoreInstance(keyStoreInstance.asJsonPrimitive())
92     }
93
94     open fun keyStoreInstance(keyStoreInstance: JsonNode) {
95         property("keyStoreInstance", keyStoreInstance)
96     }
97
98     open fun sslTrust(sslTrust: String) {
99         sslTrust(sslTrust.asJsonPrimitive())
100     }
101
102     open fun sslTrust(sslTrust: JsonNode) {
103         property("sslTrust", sslTrust)
104     }
105
106     open fun sslTrustPassword(sslTrustPassword: String) {
107         sslTrustPassword(sslTrustPassword.asJsonPrimitive())
108     }
109
110     open fun sslTrustPassword(sslTrustPassword: JsonNode) {
111         property("sslTrustPassword", sslTrustPassword)
112     }
113
114     open fun sslKey(sslKey: String) {
115         sslKey(sslKey.asJsonPrimitive())
116     }
117
118     open fun sslKey(sslKey: JsonNode) {
119         property("sslKey", sslKey)
120     }
121
122     open fun sslKeyPassword(sslKeyPassword: String) {
123         sslKeyPassword(sslKeyPassword.asJsonPrimitive())
124     }
125
126     open fun sslKeyPassword(sslKeyPassword: JsonNode) {
127         property("sslKeyPassword", sslKeyPassword)
128     }
129 }
130
131 open class SSLBasicAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() {
132     // TODO()
133 }
134
135 open class SSLTokenAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() {
136     // TODO()
137 }