blob: ba70d5e091591d02fcb13f45ebf878779a5b5fcf [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"
Sridhar Ravindra3ec14232024-01-01 19:11:48 +053084 MaxFlowRetryDuration = "MAX_FLOW_RETRY_DURATION"
Naveen Sampath04696f72022-06-13 15:19:14 +053085 // openonu environment variables
86
87 OmciPacketCapture = "SAVE_OMCI_PACKET_CAPTURE"
88)
89
90// ParseStringEnvVariable reads the environment variable and returns env as string
91func ParseStringEnvVariable(envVarName string, defaultVal string) string {
92 envValue := os.Getenv(envVarName)
93 if envValue == "" {
94 fmt.Println("Environment variable " + envVarName + " undefined")
95 return defaultVal
96 }
97 return envValue
98}
99
100// ParseIntEnvVariable reads the environment variable and returns env as int64
101func ParseIntEnvVariable(envVarName string, defaultVal int64) int64 {
102 envValue := os.Getenv(envVarName)
103 if envValue == "" {
104 fmt.Println("Environment variable "+envVarName+" undefined", envVarName)
105 return defaultVal
106 }
107 returnVal, err := strconv.Atoi(envValue)
108 if err != nil {
109 fmt.Println("Unable to convert string to integer environment variable")
110 return defaultVal
111 }
112 return int64(returnVal)
113}
114
115// ParseBoolEnvVariable reads the environment variable and returns env as boolean
116func ParseBoolEnvVariable(envVarName string, defaultVal bool) bool {
117 envValue := os.Getenv(envVarName)
118 if envValue == "" {
119 fmt.Println("Environment variable " + envVarName + " undefined")
120 return defaultVal
121 }
122 if envValue == "true" || envValue == "True" {
123 return true
124 }
125 return false
126}