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.TopologyTemplateBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType
30 /** Relationships Type DSL for Rest */
31 fun BluePrintTypes.relationshipTypeConnectsToRestClient(): RelationshipType {
32 return relationshipType(
33 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT,
34 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
35 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
36 description = "Relationship connects to through"
39 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
40 BluePrintConstants.DATA_TYPE_MAP,
42 "Connection Config details."
44 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
48 /** Relationships Templates DSL for Rest */
49 fun TopologyTemplateBuilder.relationshipTemplateRestClient(
52 block: RestClientRelationshipTemplateBuilder.() -> Unit
54 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
55 val relationshipTemplate = RestClientRelationshipTemplateBuilder(name, description).apply(block).build()
56 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
59 open class RestClientRelationshipTemplateBuilder(name: String, description: String) :
60 RelationshipTemplateBuilder(
62 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT, description
65 fun basicAuth(block: BasicAuthRestClientPropertiesAssignmentBuilder.() -> Unit) {
66 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthRestClientProperties(block))
69 fun tokenAuth(block: TokenAuthRestClientPropertiesAssignmentBuilder.() -> Unit) {
70 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthRestClientProperties(block))
73 fun sslAuth(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit) {
74 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.sslRestClientProperties(block))
78 fun BluePrintTypes.basicAuthRestClientProperties(block: BasicAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode {
79 val assignments = BasicAuthRestClientPropertiesAssignmentBuilder().apply(block).build()
80 assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive()
81 return assignments.asJsonType()
84 fun BluePrintTypes.tokenAuthRestClientProperties(block: TokenAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode {
85 val assignments = TokenAuthRestClientPropertiesAssignmentBuilder().apply(block).build()
86 assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive()
87 return assignments.asJsonType()
90 fun BluePrintTypes.sslRestClientProperties(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode {
91 val assignments = SslAuthRestClientPropertiesAssignmentBuilder().apply(block).build()
92 assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_SSL_NO_AUTH.asJsonPrimitive()
93 return assignments.asJsonType()
96 open class RestClientPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() {
98 open fun url(url: String) {
99 url(url.asJsonPrimitive())
102 open fun url(url: JsonNode) {
103 property(RestClientProperties::url, url)
107 open class BasicAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() {
108 open fun password(password: String) {
109 password(password.asJsonPrimitive())
112 open fun password(password: JsonNode) {
113 property(BasicAuthRestClientProperties::password, password)
116 open fun username(username: String) {
117 username(username.asJsonPrimitive())
120 open fun username(username: JsonNode) {
121 property(BasicAuthRestClientProperties::username, username)
125 open class TokenAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() {
126 open fun token(token: String) {
127 token(token.asJsonPrimitive())
130 open fun token(token: JsonNode) {
131 property(TokenAuthRestClientProperties::token, token)
135 open class SslAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() {
136 open fun keyStoreInstance(keyStoreInstance: String) {
137 keyStoreInstance(keyStoreInstance.asJsonPrimitive())
140 open fun keyStoreInstance(keyStoreInstance: JsonNode) {
141 property(SSLRestClientProperties::keyStoreInstance, keyStoreInstance)
144 open fun sslTrust(sslTrust: String) {
145 sslTrust(sslTrust.asJsonPrimitive())
148 open fun sslTrust(sslTrust: JsonNode) {
149 property(SSLRestClientProperties::sslTrust, sslTrust)
152 open fun sslTrustPassword(sslTrustPassword: String) {
153 sslTrustPassword(sslTrustPassword.asJsonPrimitive())
156 open fun sslTrustPassword(sslTrustPassword: JsonNode) {
157 property(SSLRestClientProperties::sslTrustPassword, sslTrustPassword)
160 open fun sslKey(sslKey: String) {
161 sslKey(sslKey.asJsonPrimitive())
164 open fun sslKey(sslKey: JsonNode) {
165 property(SSLRestClientProperties::sslKey, sslKey)
168 open fun sslKeyPassword(sslKeyPassword: String) {
169 sslKeyPassword(sslKeyPassword.asJsonPrimitive())
172 open fun sslKeyPassword(sslKeyPassword: JsonNode) {
173 property(SSLRestClientProperties::sslKeyPassword, sslKeyPassword)
177 open class SSLBasicAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() {
181 open class SSLTokenAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() {