2 * Copyright © 2018-2019 AT&T Intellectual Property.
4 * Modifications Copyright © 2020 Bell Canada.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.onap.ccsdk.cds.blueprintsprocessor.ssh
21 import com.fasterxml.jackson.databind.JsonNode
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
25 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder
30 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder
31 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType
33 /** Relationships Types DSL for Message Producer */
34 fun ServiceTemplateBuilder.relationshipTypeConnectsToSshClient() {
35 val relationshipType = BluePrintTypes.relationshipTypeConnectsToSshClient()
36 if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf()
37 this.relationshipTypes!![relationshipType.id!!] = relationshipType
40 fun BluePrintTypes.relationshipTypeConnectsToSshClient(): RelationshipType {
41 return relationshipType(
42 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT,
43 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
44 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
45 description = "Relationship connects to through SSH Client."
48 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
49 BluePrintConstants.DATA_TYPE_MAP,
51 "Connection Config details."
53 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
57 /** Relationships Templates for Ssh */
58 fun TopologyTemplateBuilder.relationshipTemplateSshClient(
61 block: SshRelationshipTemplateBuilder.() -> Unit
63 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
64 val relationshipTemplate = SshRelationshipTemplateBuilder(name, description).apply(block).build()
65 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
68 open class SshRelationshipTemplateBuilder(name: String, description: String) :
69 RelationshipTemplateBuilder(
71 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT, description
74 fun basicAuth(block: BasicAuthSshClientPropertiesAssignmentBuilder.() -> Unit) {
75 property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthSshProperties(block))
79 fun BluePrintTypes.basicAuthSshProperties(block: BasicAuthSshClientPropertiesAssignmentBuilder.() -> Unit): JsonNode {
80 val sshProperties = BasicAuthSshClientPropertiesAssignmentBuilder().apply(block).build()
81 sshProperties[SshClientProperties::type.name] = SshLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive()
82 return sshProperties.asJsonType()
85 open class SshClientPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() {
87 fun connectionTimeOut(connectionTimeOut: Int) = connectionTimeOut(connectionTimeOut.asJsonPrimitive())
89 fun connectionTimeOut(connectionTimeOut: JsonNode) =
90 property(SshClientProperties::connectionTimeOut.name, connectionTimeOut)
92 fun port(port: Int) = port(port.asJsonPrimitive())
94 fun port(port: JsonNode) = property(SshClientProperties::port.name, port)
96 fun host(host: String) = host(host.asJsonPrimitive())
98 fun host(host: JsonNode) = property(SshClientProperties::host.name, host)
100 fun logging(logging: Boolean) = logging(logging.asJsonPrimitive())
102 fun logging(logging: JsonNode) = property(SshClientProperties::logging.name, logging)
105 class BasicAuthSshClientPropertiesAssignmentBuilder : SshClientPropertiesAssignmentBuilder() {
107 fun username(username: String) = username(username.asJsonPrimitive())
109 fun username(username: JsonNode) = property(BasicAuthSshClientProperties::username.name, username)
111 fun password(password: String) = password(password.asJsonPrimitive())
113 fun password(password: JsonNode) = property(BasicAuthSshClientProperties::password.name, password)