Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / ssh-lib / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / ssh / SshPropertiesDSL.kt
1 /*
2  * Copyright © 2018-2019 AT&T Intellectual Property.
3  *
4  * Modifications Copyright © 2020 Bell Canada.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 package org.onap.ccsdk.cds.blueprintsprocessor.ssh
20
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
32
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
38 }
39
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."
46     ) {
47         property(
48             BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
49             BluePrintConstants.DATA_TYPE_MAP,
50             true,
51             "Connection Config details."
52         )
53         validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
54     }
55 }
56
57 /** Relationships Templates for Ssh */
58 fun TopologyTemplateBuilder.relationshipTemplateSshClient(
59     name: String,
60     description: String,
61     block: SshRelationshipTemplateBuilder.() -> Unit
62 ) {
63     if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
64     val relationshipTemplate = SshRelationshipTemplateBuilder(name, description).apply(block).build()
65     relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
66 }
67
68 open class SshRelationshipTemplateBuilder(name: String, description: String) :
69     RelationshipTemplateBuilder(
70         name,
71         BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT, description
72     ) {
73
74     fun basicAuth(block: BasicAuthSshClientPropertiesAssignmentBuilder.() -> Unit) {
75         property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthSshProperties(block))
76     }
77 }
78
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()
83 }
84
85 open class SshClientPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() {
86
87     fun connectionTimeOut(connectionTimeOut: Int) = connectionTimeOut(connectionTimeOut.asJsonPrimitive())
88
89     fun connectionTimeOut(connectionTimeOut: JsonNode) =
90         property(SshClientProperties::connectionTimeOut.name, connectionTimeOut)
91
92     fun port(port: Int) = port(port.asJsonPrimitive())
93
94     fun port(port: JsonNode) = property(SshClientProperties::port.name, port)
95
96     fun host(host: String) = host(host.asJsonPrimitive())
97
98     fun host(host: JsonNode) = property(SshClientProperties::host.name, host)
99
100     fun logging(logging: Boolean) = logging(logging.asJsonPrimitive())
101
102     fun logging(logging: JsonNode) = property(SshClientProperties::logging.name, logging)
103 }
104
105 class BasicAuthSshClientPropertiesAssignmentBuilder : SshClientPropertiesAssignmentBuilder() {
106
107     fun username(username: String) = username(username.asJsonPrimitive())
108
109     fun username(username: JsonNode) = property(BasicAuthSshClientProperties::username.name, username)
110
111     fun password(password: String) = password(password.asJsonPrimitive())
112
113     fun password(password: JsonNode) = property(BasicAuthSshClientProperties::password.name, password)
114 }