blob: 392e9b8f2ba98272310c616075639d0b8592cd81 [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
Tinoj Josephaf37ce82022-12-28 11:59:43 +05302
3
Naveen Sampath04696f72022-06-13 15:19:14 +05304* Copyright 2022-present Open Networking Foundation
5* Licensed under the Apache License, Version 2.0 (the "License");
6* you may not use this file except in compliance with the License.
7* You may obtain a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16 */
17
18// Package envutils provides the env parsing utility functions
19package envutils
20
21import (
22 "fmt"
23 "os"
24 "strconv"
25)
26
27// common constants
28const (
29 // common environment variables
30
31 KafkaAdapterHost = "KAFKA_ADAPTER_HOST"
32 KafkaAdapterPort = "KAFKA_ADAPTER_PORT"
33 KafkaClusterHost = "KAFKA_CLUSTER_HOST"
34 KafkaClusterPort = "KAFKA_CLUSTER_PORT"
35 KvStoreType = "KV_STORE_TYPE"
36 KvStoreTimeout = "KV_STORE_TIMEOUT"
37 KvStoreHost = "KV_STORE_HOST"
38 KvStorePort = "KV_STORE_PORT"
39 AdapterTopic = "ADAPTER_TOPIC"
40 CoreTopic = "CORE_TOPIC"
41 EventTopic = "EVENT_TOPIC"
42 LogLevel = "LOG_LEVEL"
43 OnuNumber = "ONU_NUMBER"
44 Banner = "BANNER"
45 DisplayVersionOnly = "DISPLAY_VERSION_ONLY"
46 ProbeHost = "PROBE_HOST"
47 ProbePort = "PROBE_PORT"
48 LiveProbeInterval = "LIVE_PROBE_INTERVAL"
49 NotLiveProbeInterval = "NOT_LIVE_PROBE_INTERVAL"
50 VolthaHost = "VOLTHA_HOST"
51 VolthaPort = "VOLTHA_PORT"
52 HostName = "HOST_NAME"
53
54 // openolt adapter environment variables
55
56 HeartbeatCheckInterval = "HEARTBEAT_CHECK_INTERVAL"
57 HeartbeatFailReportInterval = "HEARTBEAT_FAIL_REPORT_INTERVAL"
58 GrpcTimeoutInterval = "GRPC_TIMEOUT_INTERVAL"
59
60 // rwcore environment variables
61
62 RWCoreEndpoint = "RW_CORE_ENDPOINT"
63 GrpcHost = "GRPC_HOST"
64 GrpcPort = "GRPC_PORT"
65 AffinityRouterTopic = "AFFINITY_ROUTER_TOPIC"
66 InCompetingMode = "IN_COMPETING_MODE"
67 KVTxnKeyDelTime = "KV_TXN_KEY_DEL_TIME"
68 KVStoreDataPrefix = "KV_STORE_DATA_PREFIX"
69 LongRunningRequestTimeout = "LONG_RUNNING_REQ_TIMEOUT"
70 DefaultRequestTimeout = "DEFAULT_REQ_TIMEOUT"
71 DefaultCoreTimeout = "DEFAULT_CORE_TIMEOUT"
72 CoreBindingKey = "CORE_BINDING_KEY"
73 CorePairTopic = "CORE_PAIR_TOPIC"
74 MaxConnectionRetries = "MAX_CONNECTION_RETRIES"
75 ConnectionRetryInterval = "CONNECTION_RETRY_INTERVAL"
76
77 // vgc environment variables
78
79 DeviceListRefreshInterval = "DEVICE_LIST_REFRESH_INTERVAL" // in seconds
80 CPUProfile = "CPU_PROFILE"
81 MemProfile = "MEM_PROFILE"
82 VendorID = "VENDOR_ID"
Tinoj Josephaf37ce82022-12-28 11:59:43 +053083 DeviceSyncDuration = "DEVICE_SYNC_DURATION"
Naveen Sampath04696f72022-06-13 15:19:14 +053084 // openonu environment variables
85
86 OmciPacketCapture = "SAVE_OMCI_PACKET_CAPTURE"
87)
88
89// ParseStringEnvVariable reads the environment variable and returns env as string
90func ParseStringEnvVariable(envVarName string, defaultVal string) string {
91 envValue := os.Getenv(envVarName)
92 if envValue == "" {
93 fmt.Println("Environment variable " + envVarName + " undefined")
94 return defaultVal
95 }
96 return envValue
97}
98
99// ParseIntEnvVariable reads the environment variable and returns env as int64
100func ParseIntEnvVariable(envVarName string, defaultVal int64) int64 {
101 envValue := os.Getenv(envVarName)
102 if envValue == "" {
103 fmt.Println("Environment variable "+envVarName+" undefined", envVarName)
104 return defaultVal
105 }
106 returnVal, err := strconv.Atoi(envValue)
107 if err != nil {
108 fmt.Println("Unable to convert string to integer environment variable")
109 return defaultVal
110 }
111 return int64(returnVal)
112}
113
114// ParseBoolEnvVariable reads the environment variable and returns env as boolean
115func ParseBoolEnvVariable(envVarName string, defaultVal bool) bool {
116 envValue := os.Getenv(envVarName)
117 if envValue == "" {
118 fmt.Println("Environment variable " + envVarName + " undefined")
119 return defaultVal
120 }
121 if envValue == "true" || envValue == "True" {
122 return true
123 }
124 return false
125}