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() {
115 open fun password(password: String) {
116 password(password.asJsonPrimitive())
119 open fun password(password: JsonNode) {
120 property(BasicAuthRestClientProperties::password, password)
123 open fun username(username: String) {
124 username(username.asJsonPrimitive())
127 open fun username(username: JsonNode) {
128 property(BasicAuthRestClientProperties::username, username)
132 open class TokenAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() {
133 open fun token(token: String) {
134 token(token.asJsonPrimitive())
137 open fun token(token: JsonNode) {
138 property(TokenAuthRestClientProperties::token, token)
142 open class SslAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() {
143 open fun keyStoreInstance(keyStoreInstance: String) {
144 keyStoreInstance(keyStoreInstance.asJsonPrimitive())
147 open fun keyStoreInstance(keyStoreInstance: JsonNode) {
148 property(SSLRestClientProperties::keyStoreInstance, keyStoreInstance)
151 open fun sslTrust(sslTrust: String) {
152 sslTrust(sslTrust.asJsonPrimitive())
155 open fun sslTrust(sslTrust: JsonNode) {
156 property(SSLRestClientProperties::sslTrust, sslTrust)
159 open fun sslTrustPassword(sslTrustPassword: String) {
160 sslTrustPassword(sslTrustPassword.asJsonPrimitive())
163 open fun sslTrustPassword(sslTrustPassword: JsonNode) {
164 property(SSLRestClientProperties::sslTrustPassword, sslTrustPassword)
167 open fun sslKey(sslKey: String) {
168 sslKey(sslKey.asJsonPrimitive())
171 open fun sslKey(sslKey: JsonNode) {
172 property(SSLRestClientProperties::sslKey, sslKey)
175 open fun sslKeyPassword(sslKeyPassword: String) {
176 sslKeyPassword(sslKeyPassword.asJsonPrimitive())
179 open fun sslKeyPassword(sslKeyPassword: JsonNode) {
180 property(SSLRestClientProperties::sslKeyPassword, sslKeyPassword)
184 open class SSLBasicAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() {
188 open class SSLTokenAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() {