8954fd22f6167b952012f9d75b28317eae882c12
[dcaegen2/collectors/hv-ves.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * dcaegen2-collectors-veshv
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.simulators.xnf.config
21
22 import org.apache.commons.cli.CommandLine
23 import org.apache.commons.cli.DefaultParser
24 import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
25 import org.onap.dcae.collectors.veshv.utils.commandline.ArgBasedConfiguration
26 import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.*
27
28
29 /**
30  * @author Jakub Dudycz <jakub.dudycz@nokia.com>
31  * @since June 2018
32  */
33 internal class ArgConfigurationProvider : ArgBasedConfiguration<SimulatorConfiguration>(DefaultParser()) {
34     override val cmdLineOptionsList = listOf(
35             VES_HV_PORT,
36             VES_HV_HOST,
37             LISTEN_PORT,
38             SSL_DISABLE,
39             PRIVATE_KEY_FILE,
40             CERT_FILE,
41             TRUST_CERT_FILE
42     )
43
44     override fun getConfiguration(cmdLine: CommandLine): SimulatorConfiguration {
45         val vesHost = cmdLine.stringValue(VES_HV_HOST, DefaultValues.VES_HV_HOST)
46         val vesPort = cmdLine.intValue(VES_HV_PORT, DefaultValues.VES_HV_PORT)
47         val listenPort = cmdLine.intValue(LISTEN_PORT, DefaultValues.LISTEN_PORT)
48
49         return SimulatorConfiguration(
50                 listenPort,
51                 vesHost,
52                 vesPort,
53                 parseSecurityConfig(cmdLine))
54     }
55
56     private fun parseSecurityConfig(cmdLine: CommandLine): SecurityConfiguration {
57         val sslDisable = cmdLine.hasOption(SSL_DISABLE)
58         val pkFile = cmdLine.stringValue(PRIVATE_KEY_FILE, DefaultValues.PRIVATE_KEY_FILE)
59         val certFile = cmdLine.stringValue(CERT_FILE, DefaultValues.CERT_FILE)
60         val trustCertFile = cmdLine.stringValue(TRUST_CERT_FILE, DefaultValues.TRUST_CERT_FILE)
61
62         return SecurityConfiguration(
63                 sslDisable = sslDisable,
64                 privateKey = stringPathToPath(pkFile),
65                 cert = stringPathToPath(certFile),
66                 trustedCert = stringPathToPath(trustCertFile))
67     }
68
69     internal object DefaultValues {
70         const val PRIVATE_KEY_FILE = "/etc/ves-hv/client.key"
71         const val CERT_FILE = "/etc/ves-hv/client.crt"
72         const val TRUST_CERT_FILE = "/etc/ves-hv/trust.crt"
73         const val VES_HV_PORT = 6061
74         const val VES_HV_HOST = "veshvcollector"
75         const val LISTEN_PORT = 6062
76     }
77 }