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.ServiceTemplateBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType
31 /** Relationships Types DSL for GRPC Server Producer */
32 fun ServiceTemplateBuilder.relationshipTypeConnectsToGrpcServer() {
33 val relationshipType = BluePrintTypes.relationshipTypeConnectsToGrpcServer()
34 if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf()
35 this.relationshipTypes!![relationshipType.id!!] = relationshipType
38 fun BluePrintTypes.relationshipTypeConnectsToGrpcServer(): RelationshipType {
39 return relationshipType(
40 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER,
41 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
42 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
43 description = "Relationship connects to through GRPC Server."
46 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
47 BluePrintConstants.DATA_TYPE_MAP,
49 "Connection Config details."
51 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
55 fun ServiceTemplateBuilder.relationshipTypeConnectsToGrpcClient() {
56 val relationshipType = BluePrintTypes.relationshipTypeConnectsToGrpcClient()
57 if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf()
58 this.relationshipTypes!![relationshipType.id!!] = relationshipType
61 fun BluePrintTypes.relationshipTypeConnectsToGrpcClient(): RelationshipType {
62 return relationshipType(
63 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT,
64 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
65 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
66 description = "Relationship connects to through GRPC Client."
69 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
70 BluePrintConstants.DATA_TYPE_MAP,
72 "Connection Config details."
74 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
78 /** Relationships Templates for GRPC Server */
79 fun TopologyTemplateBuilder.relationshipTemplateGrpcServer(
82 block: GrpcServerRelationshipTemplateBuilder.() -> Unit
84 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
85 val relationshipTemplate = GrpcServerRelationshipTemplateBuilder(name, description).apply(block).build()
86 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
89 class GrpcServerRelationshipTemplateBuilder(name: String, description: String) :
90 RelationshipTemplateBuilder(
92 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER, description
95 fun tokenAuth(block: GrpcServerTokenAuthPropertiesAssignmentBuilder.() -> Unit) {
96 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthGrpcServerProperties(block))
99 fun tlsAuth(block: GrpcServerTLSAuthPropertiesAssignmentBuilder.() -> Unit) {
100 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tlsAuthGrpcServerProperties(block))
104 fun BluePrintTypes.tokenAuthGrpcServerProperties(block: GrpcServerTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
105 val assignments = GrpcServerTokenAuthPropertiesAssignmentBuilder().apply(block).build()
106 assignments[GrpcServerProperties::type.name] = GRPCLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive()
107 return assignments.asJsonNode()
110 fun BluePrintTypes.tlsAuthGrpcServerProperties(block: GrpcServerTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
111 val assignments = GrpcServerTLSAuthPropertiesAssignmentBuilder().apply(block).build()
112 assignments[GrpcServerProperties::type.name] = GRPCLibConstants.TYPE_TLS_AUTH.asJsonPrimitive()
113 return assignments.asJsonNode()
116 open class GrpcServerPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() {
118 fun port(port: Int) = port(port.asJsonPrimitive())
120 fun port(port: JsonNode) =
121 property(GrpcServerProperties::port, port)
124 open class GrpcServerTokenAuthPropertiesAssignmentBuilder : GrpcServerPropertiesAssignmentBuilder() {
126 fun token(selector: String) = token(selector.asJsonPrimitive())
128 fun token(selector: JsonNode) = property(TokenAuthGrpcServerProperties::token, selector)
131 open class GrpcServerTLSAuthPropertiesAssignmentBuilder : GrpcServerPropertiesAssignmentBuilder() {
133 fun certChain(certChain: String) = certChain(certChain.asJsonPrimitive())
135 fun certChain(certChain: JsonNode) = property(TLSAuthGrpcServerProperties::certChain, certChain)
137 fun privateKey(privateKey: String) = privateKey(privateKey.asJsonPrimitive())
139 fun privateKey(privateKey: JsonNode) = property(TLSAuthGrpcServerProperties::privateKey, privateKey)
141 fun trustCertCollection(trustCertCollection: String) = trustCertCollection(trustCertCollection.asJsonPrimitive())
143 fun trustCertCollection(trustCertCollection: JsonNode) =
144 property(TLSAuthGrpcServerProperties::trustCertCollection, trustCertCollection)
147 /** Relationships Templates for GRPC Client */
148 fun TopologyTemplateBuilder.relationshipTemplateGrpcClient(
151 block: GrpcClientRelationshipTemplateBuilder.() -> Unit
153 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
154 val relationshipTemplate = GrpcClientRelationshipTemplateBuilder(name, description).apply(block).build()
155 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
158 class GrpcClientRelationshipTemplateBuilder(name: String, description: String) :
159 RelationshipTemplateBuilder(
161 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT, description
164 fun basicAuth(block: GrpcClientBasicAuthPropertiesAssignmentBuilder.() -> Unit) {
165 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthGrpcClientProperties(block))
168 fun tokenAuth(block: GrpcClientTokenAuthPropertiesAssignmentBuilder.() -> Unit) {
169 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthGrpcClientProperties(block))
172 fun tlsAuth(block: GrpcClientTLSAuthPropertiesAssignmentBuilder.() -> Unit) {
173 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tlsAuthGrpcClientProperties(block))
177 fun BluePrintTypes.basicAuthGrpcClientProperties(block: GrpcClientBasicAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
178 val assignments = GrpcClientBasicAuthPropertiesAssignmentBuilder().apply(block).build()
179 assignments[GrpcClientProperties::type.name] = GRPCLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive()
180 return assignments.asJsonNode()
183 fun BluePrintTypes.tokenAuthGrpcClientProperties(block: GrpcClientTokenAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
184 val assignments = GrpcClientTokenAuthPropertiesAssignmentBuilder().apply(block).build()
185 assignments[GrpcClientProperties::type.name] = GRPCLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive()
186 return assignments.asJsonNode()
189 fun BluePrintTypes.tlsAuthGrpcClientProperties(block: GrpcClientTLSAuthPropertiesAssignmentBuilder.() -> Unit): JsonNode {
190 val assignments = GrpcClientTLSAuthPropertiesAssignmentBuilder().apply(block).build()
191 assignments[GrpcClientProperties::type.name] = GRPCLibConstants.TYPE_TLS_AUTH.asJsonPrimitive()
192 return assignments.asJsonNode()
195 open class GrpcClientPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() {
197 fun host(host: String) = host(host.asJsonPrimitive())
199 fun host(host: JsonNode) =
200 property(GrpcClientProperties::host, host)
202 fun port(port: Int) = port(port.asJsonPrimitive())
204 fun port(port: JsonNode) =
205 property(GrpcClientProperties::port, port)
208 open class GrpcClientBasicAuthPropertiesAssignmentBuilder : GrpcClientPropertiesAssignmentBuilder() {
210 fun username(username: String) = username(username.asJsonPrimitive())
212 fun username(username: JsonNode) = property(BasicAuthGrpcClientProperties::username, username)
214 fun password(password: String) = password(password.asJsonPrimitive())
216 fun password(password: JsonNode) = property(BasicAuthGrpcClientProperties::password, password)
219 open class GrpcClientTokenAuthPropertiesAssignmentBuilder : GrpcClientPropertiesAssignmentBuilder() {
221 fun token(selector: String) = token(selector.asJsonPrimitive())
223 fun token(selector: JsonNode) = property(TokenAuthGrpcClientProperties::token, selector)
226 open class GrpcClientTLSAuthPropertiesAssignmentBuilder : GrpcClientPropertiesAssignmentBuilder() {
228 fun trustCertCollection(trustCertCollection: String) = trustCertCollection(trustCertCollection.asJsonPrimitive())
230 fun trustCertCollection(trustCertCollection: JsonNode) =
231 property(TLSAuthGrpcClientProperties::trustCertCollection, trustCertCollection)
233 fun clientCertChain(clientCertChain: String) = clientCertChain(clientCertChain.asJsonPrimitive())
235 fun clientCertChain(clientCertChain: JsonNode) =
236 property(TLSAuthGrpcClientProperties::clientCertChain, clientCertChain)
238 fun clientPrivateKey(clientPrivateKey: String) = clientPrivateKey(clientPrivateKey.asJsonPrimitive())
240 fun clientPrivateKey(clientPrivateKey: JsonNode) =
241 property(TLSAuthGrpcClientProperties::clientPrivateKey, clientPrivateKey)