From e0a0801689a3de1a13e901aebd58f76811514fc1 Mon Sep 17 00:00:00 2001 From: Vishruti Buddhadev Date: Tue, 26 Nov 2024 00:12:04 +0530 Subject: [PATCH] feature : Allow Debug variable to be set via Environment (#58) * modified code so that debug variable can be set through the environment * modified code to set debug variable through environment --- internal/client.go | 1 + internal/configuration.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/client.go b/internal/client.go index dd126cd..244a6f8 100644 --- a/internal/client.go +++ b/internal/client.go @@ -30,6 +30,7 @@ const ( envBloxOneCSPURL = "BLOXONE_CSP_URL" envBloxOneAPIKey = "BLOXONE_API_KEY" + envIBLogLevel = "IB_LOG_LEVEL" version = "0.1" sdkIdentifier = "golang-sdk" diff --git a/internal/configuration.go b/internal/configuration.go index a775785..e1c31e8 100644 --- a/internal/configuration.go +++ b/internal/configuration.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "os" + "strconv" "strings" ) @@ -79,7 +80,7 @@ func NewConfiguration() *Configuration { CSPURL: lookupEnv(envBloxOneCSPURL, "https://csp.infoblox.com"), APIKey: lookupEnv(envBloxOneAPIKey, ""), DefaultHeader: make(map[string]string), - Debug: false, + Debug: lookupEnvBool(envIBLogLevel, false), UserAgent: fmt.Sprintf("bloxone-%s/%s", sdkIdentifier, version), Servers: ServerConfigurations{}, OperationServers: map[string]ServerConfigurations{}, @@ -210,3 +211,12 @@ func lookupEnv(key, def string) string { } return def } + +func lookupEnvBool(key string, def bool) bool { + if logLvlStr, ok := os.LookupEnv(key); ok { + if logLvl, err := strconv.ParseBool(logLvlStr); err == nil { + return logLvl + } + } + return def +}