2 * Copyright © 2018-2019 AT&T Intellectual Property.
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.grpc
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.asJsonNode
23 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
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 Types DSL for GRPC Server Producer */
31 fun BluePrintTypes.relationshipTypeConnectsToGrpcServer(): RelationshipType {
32 return relationshipType(
33 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER,
34 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
35 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
36 description = "Relationship connects to through GRPC Server."
39 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
40 BluePrintConstants.DATA_TYPE_MAP,
42 "Connection Config details."
44 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
48 fun BluePrintTypes.relationshipTypeConnectsToGrpcClient(): RelationshipType {
49 return relationshipType(
50 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT,
51 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
52 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
53 description = "Relationship connects to through GRPC Client."
56 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
57 BluePrintConstants.DATA_TYPE_MAP,
59 "Connection Config details."
61 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
65 /** Relationships Templates for GRPC Server */
66 fun TopologyTemplateBuilder.relationshipTemplateGrpcServer(
69 block: GrpcServerRelationshipTemplateBuilder.() -> Unit
71 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
72 val relationshipTemplate = GrpcServerRelationshipTemplateBuilder(name, description).apply(block).build()
73 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
76 class GrpcServerRelationshipTemplateBuilder(name: String, description: String) :
77 RelationshipTemplateBuilder(
79 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER, description
82 fun tokenAuth(block: GrpcServerTokenAuthPropertiesAssignmentBuilder.() -> Unit) {
83 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthGrpcServerProperties(block))
86 fun tlsAuth(block: GrpcServerTLSAuthPropertiesAssignmentBuilder.() -> Unit) {
87 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tlsAuthGrpcServerProperties(block))
91 fun BluePrintTypes.tokenAuthGrpcServerProperties(block: GrpcServerTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
92 val assignments = GrpcServerTokenAuthPropertiesAssignmentBuilder().apply(block).build()
93 assignments[GrpcServerProperties::type.name] = GRPCLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive()
94 return assignments.asJsonNode()
97 fun BluePrintTypes.tlsAuthGrpcServerProperties(block: GrpcServerTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
98 val assignments = GrpcServerTLSAuthPropertiesAssignmentBuilder().apply(block).build()
99 assignments[GrpcServerProperties::type.name] = GRPCLibConstants.TYPE_TLS_AUTH.asJsonPrimitive()
100 return assignments.asJsonNode()
103 open class GrpcServerPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() {
105 fun port(port: Int) = port(port.asJsonPrimitive())
107 fun port(port: JsonNode) =
108 property(GrpcServerProperties::port, port)
111 open class GrpcServerTokenAuthPropertiesAssignmentBuilder : GrpcServerPropertiesAssignmentBuilder() {
113 fun token(selector: String) = token(selector.asJsonPrimitive())
115 fun token(selector: JsonNode) = property(TokenAuthGrpcServerProperties::token, selector)
118 open class GrpcServerTLSAuthPropertiesAssignmentBuilder : GrpcServerPropertiesAssignmentBuilder() {
120 fun certChain(certChain: String) = certChain(certChain.asJsonPrimitive())
122 fun certChain(certChain: JsonNode) = property(TLSAuthGrpcServerProperties::certChain, certChain)
124 fun privateKey(privateKey: String) = privateKey(privateKey.asJsonPrimitive())
126 fun privateKey(privateKey: JsonNode) = property(TLSAuthGrpcServerProperties::privateKey, privateKey)
128 fun trustCertCollection(trustCertCollection: String) = trustCertCollection(trustCertCollection.asJsonPrimitive())
130 fun trustCertCollection(trustCertCollection: JsonNode) =
131 property(TLSAuthGrpcServerProperties::trustCertCollection, trustCertCollection)
134 /** Relationships Templates for GRPC Client */
135 fun TopologyTemplateBuilder.relationshipTemplateGrpcClient(
138 block: GrpcClientRelationshipTemplateBuilder.() -> Unit
140 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
141 val relationshipTemplate = GrpcClientRelationshipTemplateBuilder(name, description).apply(block).build()
142 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
145 class GrpcClientRelationshipTemplateBuilder(name: String, description: String) :
146 RelationshipTemplateBuilder(
148 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT, description
151 fun basicAuth(block: GrpcClientBasicAuthPropertiesAssignmentBuilder.() -> Unit) {
152 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthGrpcClientProperties(block))
155 fun tokenAuth(block: GrpcClientTokenAuthPropertiesAssignmentBuilder.() -> Unit) {
156 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthGrpcClientProperties(block))
159 fun tlsAuth(block: GrpcClientTLSAuthPropertiesAssignmentBuilder.() -> Unit) {
160 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tlsAuthGrpcClientProperties(block))
164 fun BluePrintTypes.basicAuthGrpcClientProperties(block: GrpcClientBasicAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
165 val assignments = GrpcClientBasicAuthPropertiesAssignmentBuilder().apply(block).build()
166 assignments[GrpcClientProperties::type.name] = GRPCLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive()
167 return assignments.asJsonNode()
170 fun BluePrintTypes.tokenAuthGrpcClientProperties(block: GrpcClientTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
171 val assignments = GrpcClientTokenAuthPropertiesAssignmentBuilder().apply(block).build()
172 assignments[GrpcClientProperties::type.name] = GRPCLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive()
173 return assignments.asJsonNode()
176 fun BluePrintTypes.tlsAuthGrpcClientProperties(block: GrpcClientTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
177 val assignments = GrpcClientTLSAuthPropertiesAssignmentBuilder().apply(block).build()
178 assignments[GrpcClientProperties::type.name] = GRPCLibConstants.TYPE_TLS_AUTH.asJsonPrimitive()
179 return assignments.asJsonNode()
182 open class GrpcClientPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() {
184 fun host(host: String) = host(host.asJsonPrimitive())
186 fun host(host: JsonNode) =
187 property(GrpcClientProperties::host, host)
189 fun port(port: Int) = port(port.asJsonPrimitive())
191 fun port(port: JsonNode) =
192 property(GrpcClientProperties::port, port)
195 open class GrpcClientBasicAuthPropertiesAssignmentBuilder : GrpcClientPropertiesAssignmentBuilder() {
197 fun username(username: String) = username(username.asJsonPrimitive())
199 fun username(username: JsonNode) = property(BasicAuthGrpcClientProperties::username, username)
201 fun password(password: String) = password(password.asJsonPrimitive())
203 fun password(password: JsonNode) = property(BasicAuthGrpcClientProperties::password, password)
206 open class GrpcClientTokenAuthPropertiesAssignmentBuilder : GrpcClientPropertiesAssignmentBuilder() {
208 fun token(selector: String) = token(selector.asJsonPrimitive())
210 fun token(selector: JsonNode) = property(TokenAuthGrpcClientProperties::token, selector)
213 open class GrpcClientTLSAuthPropertiesAssignmentBuilder : GrpcClientPropertiesAssignmentBuilder() {
215 fun trustCertCollection(trustCertCollection: String) = trustCertCollection(trustCertCollection.asJsonPrimitive())
217 fun trustCertCollection(trustCertCollection: JsonNode) =
218 property(TLSAuthGrpcClientProperties::trustCertCollection, trustCertCollection)
220 fun clientCertChain(clientCertChain: String) = clientCertChain(clientCertChain.asJsonPrimitive())
222 fun clientCertChain(clientCertChain: JsonNode) =
223 property(TLSAuthGrpcClientProperties::clientCertChain, clientCertChain)
225 fun clientPrivateKey(clientPrivateKey: String) = clientPrivateKey(clientPrivateKey.asJsonPrimitive())
227 fun clientPrivateKey(clientPrivateKey: JsonNode) =
228 property(TLSAuthGrpcClientProperties::clientPrivateKey, clientPrivateKey)