aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/CommandLineOption.kt
blob: 9d875571daa855fe6da33e715c44c5b08edc2373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * ============LICENSE_START=======================================================
 * dcaegen2-collectors-veshv
 * ================================================================================
 * Copyright (C) 2018-2019 NOKIA
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */
package org.onap.dcae.collectors.veshv.commandline

import org.apache.commons.cli.Option


enum class CommandLineOption(val option: Option, val required: Boolean = false) {
    CONFIGURATION_FILE(required = true,
            option = option {
                shortOpt = "c"
                longOpt = "configuration-file"
                desc = "Json file containing HV-VES configuration"
                hasArgument = true
            }),
    LISTEN_PORT(required = true,
            option = option {
                shortOpt = "p"
                longOpt = "listen-port"
                desc = "Listen port"
                hasArgument = true
            }),
    VES_HV_PORT(required = true,
            option = option {
                shortOpt = "v"
                longOpt = "ves-port"
                desc = "VesHvCollector port"
                hasArgument = true
            }),
    VES_HV_HOST(required = true,
            option = option {
                shortOpt = "h"
                longOpt = "ves-host"
                desc = "VesHvCollector host"
                hasArgument = true
            }),
    KAFKA_SERVERS(required = true,
            option = option {
                shortOpt = "s"
                longOpt = "kafka-bootstrap-servers"
                desc = "Comma-separated Kafka bootstrap servers in <host>:<port> format"
                hasArgument = true
            }),
    KAFKA_TOPICS(required = true,
            option = option {
                shortOpt = "f"
                longOpt = "kafka-topics"
                desc = "Comma-separated Kafka topics"
                hasArgument = true
            }),
    HEALTH_CHECK_API_PORT(option {
        shortOpt = "H"
        longOpt = "health-check-api-port"
        desc = "Health check rest api listen port"
        hasArgument = true
    }),
    SSL_DISABLE(option {
        shortOpt = "l"
        longOpt = "ssl-disable"
        desc = "Disable SSL encryption"
    }),
    KEY_STORE_FILE(option {
        shortOpt = "k"
        longOpt = "key-store"
        desc = "Key store in PKCS12 format"
        hasArgument = true
    }),
    KEY_STORE_PASSWORD_FILE(option {
        shortOpt = "kp"
        longOpt = "key-store-password-file"
        desc = "File with key store password"
        hasArgument = true
    }),
    TRUST_STORE_FILE(option {
        shortOpt = "t"
        longOpt = "trust-store"
        desc = "File with trusted certificate bundle in PKCS12 format"
        hasArgument = true
    }),
    TRUST_STORE_PASSWORD_FILE(option {
        shortOpt = "tp"
        longOpt = "trust-store-password-file"
        desc = "File with trust store password"
        hasArgument = true
    }),
    MAXIMUM_PAYLOAD_SIZE_BYTES(option {
        shortOpt = "m"
        longOpt = "max-payload-size"
        desc = "Maximum supported payload size in bytes"
        hasArgument = true
    }),
    DISABLE_PROCESSING(option {
        shortOpt = "d"
        longOpt = "disable-processing"
        desc = "Message queue consumer option. Indicates whether messages should be fully processed"
    });

    fun environmentVariableName(prefix: String = ""): String =
            option.longOpt.toUpperCase().replace('-', '_').let { mainPart ->
                if (prefix.isNotBlank()) {
                    "${prefix}_${mainPart}"
                } else {
                    mainPart
                }
            }
}


private class OptionDSL {
    lateinit var shortOpt: String
    lateinit var longOpt: String
    lateinit var desc: String
    var hasArgument: Boolean = false
}

private fun option(conf: OptionDSL.() -> Unit): Option {
    val dsl = OptionDSL().apply(conf)
    return Option.builder(dsl.shortOpt)
            .longOpt(dsl.longOpt)
            .hasArg(dsl.hasArgument)
            .desc(dsl.desc)
            .build()
}