blob: 10a3219caa7f0c77960761ba4a1d9568ad8bc299 [file] [log] [blame]
Joey Armstrongaca03cf2024-04-23 09:29:52 -04001/* -----------------------------------------------------------------------
2 * Copyright 2022-2024 Open Networking Foundation Contributors
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 * -----------------------------------------------------------------------
16 * SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors
17 * SPDX-License-Identifier: Apache-2.0
18 * -----------------------------------------------------------------------
Naveen Sampath04696f72022-06-13 15:19:14 +053019 */
20
21// Package envutils provides the env parsing utility functions
22package envutils
23
24import (
25 "fmt"
26 "os"
27 "strconv"
28)
29
30// common constants
31const (
32 // common environment variables
33
34 KafkaAdapterHost = "KAFKA_ADAPTER_HOST"
35 KafkaAdapterPort = "KAFKA_ADAPTER_PORT"
36 KafkaClusterHost = "KAFKA_CLUSTER_HOST"
37 KafkaClusterPort = "KAFKA_CLUSTER_PORT"
38 KvStoreType = "KV_STORE_TYPE"
39 KvStoreTimeout = "KV_STORE_TIMEOUT"
40 KvStoreHost = "KV_STORE_HOST"
41 KvStorePort = "KV_STORE_PORT"
42 AdapterTopic = "ADAPTER_TOPIC"
43 CoreTopic = "CORE_TOPIC"
44 EventTopic = "EVENT_TOPIC"
45 LogLevel = "LOG_LEVEL"
46 OnuNumber = "ONU_NUMBER"
47 Banner = "BANNER"
48 DisplayVersionOnly = "DISPLAY_VERSION_ONLY"
49 ProbeHost = "PROBE_HOST"
50 ProbePort = "PROBE_PORT"
51 LiveProbeInterval = "LIVE_PROBE_INTERVAL"
52 NotLiveProbeInterval = "NOT_LIVE_PROBE_INTERVAL"
53 VolthaHost = "VOLTHA_HOST"
54 VolthaPort = "VOLTHA_PORT"
55 HostName = "HOST_NAME"
56
57 // openolt adapter environment variables
58
59 HeartbeatCheckInterval = "HEARTBEAT_CHECK_INTERVAL"
60 HeartbeatFailReportInterval = "HEARTBEAT_FAIL_REPORT_INTERVAL"
61 GrpcTimeoutInterval = "GRPC_TIMEOUT_INTERVAL"
62
63 // rwcore environment variables
64
65 RWCoreEndpoint = "RW_CORE_ENDPOINT"
66 GrpcHost = "GRPC_HOST"
67 GrpcPort = "GRPC_PORT"
68 AffinityRouterTopic = "AFFINITY_ROUTER_TOPIC"
69 InCompetingMode = "IN_COMPETING_MODE"
70 KVTxnKeyDelTime = "KV_TXN_KEY_DEL_TIME"
71 KVStoreDataPrefix = "KV_STORE_DATA_PREFIX"
72 LongRunningRequestTimeout = "LONG_RUNNING_REQ_TIMEOUT"
73 DefaultRequestTimeout = "DEFAULT_REQ_TIMEOUT"
74 DefaultCoreTimeout = "DEFAULT_CORE_TIMEOUT"
75 CoreBindingKey = "CORE_BINDING_KEY"
76 CorePairTopic = "CORE_PAIR_TOPIC"
77 MaxConnectionRetries = "MAX_CONNECTION_RETRIES"
78 ConnectionRetryInterval = "CONNECTION_RETRY_INTERVAL"
79
80 // vgc environment variables
81
82 DeviceListRefreshInterval = "DEVICE_LIST_REFRESH_INTERVAL" // in seconds
83 CPUProfile = "CPU_PROFILE"
84 MemProfile = "MEM_PROFILE"
85 VendorID = "VENDOR_ID"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053086 DeviceSyncDuration = "DEVICE_SYNC_DURATION"
Sridhar Ravindra3ec14232024-01-01 19:11:48 +053087 MaxFlowRetryDuration = "MAX_FLOW_RETRY_DURATION"
Naveen Sampath04696f72022-06-13 15:19:14 +053088 // openonu environment variables
89
90 OmciPacketCapture = "SAVE_OMCI_PACKET_CAPTURE"
91)
92
93// ParseStringEnvVariable reads the environment variable and returns env as string
94func ParseStringEnvVariable(envVarName string, defaultVal string) string {
95 envValue := os.Getenv(envVarName)
96 if envValue == "" {
97 fmt.Println("Environment variable " + envVarName + " undefined")
98 return defaultVal
99 }
100 return envValue
101}
102
103// ParseIntEnvVariable reads the environment variable and returns env as int64
104func ParseIntEnvVariable(envVarName string, defaultVal int64) int64 {
105 envValue := os.Getenv(envVarName)
106 if envValue == "" {
107 fmt.Println("Environment variable "+envVarName+" undefined", envVarName)
108 return defaultVal
109 }
110 returnVal, err := strconv.Atoi(envValue)
111 if err != nil {
112 fmt.Println("Unable to convert string to integer environment variable")
113 return defaultVal
114 }
115 return int64(returnVal)
116}
117
118// ParseBoolEnvVariable reads the environment variable and returns env as boolean
119func ParseBoolEnvVariable(envVarName string, defaultVal bool) bool {
120 envValue := os.Getenv(envVarName)
121 if envValue == "" {
122 fmt.Println("Environment variable " + envVarName + " undefined")
123 return defaultVal
124 }
125 if envValue == "true" || envValue == "True" {
126 return true
127 }
128 return false
129}