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.BluePrintConstants
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
23 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType
25 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
26 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType
31 /** Relationships Type DSL for Rest */
32 fun ServiceTemplateBuilder.relationshipTypeConnectsToRestClient() {
33 val relationshipType = BluePrintTypes.relationshipTypeConnectsToRestClient()
34 if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf()
35 this.relationshipTypes!![relationshipType.id!!] = relationshipType
38 fun BluePrintTypes.relationshipTypeConnectsToRestClient(): RelationshipType {
39 return relationshipType(
40 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT,
41 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
42 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
43 description = "Relationship connects to through"
46 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
47 BluePrintConstants.DATA_TYPE_MAP,
49 "Connection Config details."
51 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
55 /** Relationships Templates DSL for Rest */
56 fun TopologyTemplateBuilder.relationshipTemplateRestClient(
59 block: RestClientRelationshipTemplateBuilder.() -> Unit
61 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
62 val relationshipTemplate = RestClientRelationshipTemplateBuilder(name, description).apply(block).build()
63 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
66 open class RestClientRelationshipTemplateBuilder(name: String, description: String) :
67 RelationshipTemplateBuilder(
69 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT, description
72 fun basicAuth(block: BasicAuthRestClientPropertiesAssignmentBuilder.() -> Unit) {
73 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthRestClientProperties(block))
76 fun tokenAuth(block: TokenAuthRestClientPropertiesAssignmentBuilder.() -> Unit) {
77 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthRestClientProperties(block))
80 fun sslAuth(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit) {
81 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.sslRestClientProperties(block))
85 fun BluePrintTypes.basicAuthRestClientProperties(block: BasicAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode {
86 val assignments = BasicAuthRestClientPropertiesAssignmentBuilder().apply(block).build()
87 assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive()
88 return assignments.asJsonType()
91 fun BluePrintTypes.tokenAuthRestClientProperties(block: TokenAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode {
92 val assignments = TokenAuthRestClientPropertiesAssignmentBuilder().apply(block).build()
93 assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive()
94 return assignments.asJsonType()
97 fun BluePrintTypes.sslRestClientProperties(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode {
98 val assignments = SslAuthRestClientPropertiesAssignmentBuilder().apply(block).build()
99 assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_SSL_NO_AUTH.asJsonPrimitive()
100 return assignments.asJsonType()
103 open class RestClientPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() {
105 open fun url(url: String) {
106 url(url.asJsonPrimitive())
109 open fun url(url: JsonNode) {
110 property(RestClientProperties::url, url)
114 open class BasicAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() {
116 open fun password(password: String) {
117 password(password.asJsonPrimitive())
120 open fun password(password: JsonNode) {
121 property(BasicAuthRestClientProperties::password, password)
124 open fun username(username: String) {
125 username(username.asJsonPrimitive())
128 open fun username(username: JsonNode) {
129 property(BasicAuthRestClientProperties::username, username)
133 open class TokenAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() {
135 open fun token(token: String) {
136 token(token.asJsonPrimitive())
139 open fun token(token: JsonNode) {
140 property(TokenAuthRestClientProperties::token, token)
144 open class SslAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() {
146 open fun keyStoreInstance(keyStoreInstance: String) {
147 keyStoreInstance(keyStoreInstance.asJsonPrimitive())
150 open fun keyStoreInstance(keyStoreInstance: JsonNode) {
151 property(SSLRestClientProperties::keyStoreInstance, keyStoreInstance)
154 open fun sslTrust(sslTrust: String) {
155 sslTrust(sslTrust.asJsonPrimitive())
158 open fun sslTrust(sslTrust: JsonNode) {
159 property(SSLRestClientProperties::sslTrust, sslTrust)
162 open fun sslTrustPassword(sslTrustPassword: String) {
163 sslTrustPassword(sslTrustPassword.asJsonPrimitive())
166 open fun sslTrustPassword(sslTrustPassword: JsonNode) {
167 property(SSLRestClientProperties::sslTrustPassword, sslTrustPassword)
170 open fun sslKey(sslKey: String) {
171 sslKey(sslKey.asJsonPrimitive())
174 open fun sslKey(sslKey: JsonNode) {
175 property(SSLRestClientProperties::sslKey, sslKey)
178 open fun sslKeyPassword(sslKeyPassword: String) {
179 sslKeyPassword(sslKeyPassword.asJsonPrimitive())
182 open fun sslKeyPassword(sslKeyPassword: JsonNode) {
183 property(SSLRestClientProperties::sslKeyPassword, sslKeyPassword)
187 open class SSLBasicAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() {
191 open class SSLTokenAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() {