Skip to content

Commit

Permalink
feature : Allow Debug variable to be set via Environment (#58)
Browse files Browse the repository at this point in the history
* modified code so that debug variable can  be set through the environment

* modified code to set debug variable through environment
  • Loading branch information
VishrutiBuddhadev authored Nov 25, 2024
1 parent 67934e3 commit e0a0801
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (

envBloxOneCSPURL = "BLOXONE_CSP_URL"
envBloxOneAPIKey = "BLOXONE_API_KEY"
envIBLogLevel = "IB_LOG_LEVEL"

version = "0.1"
sdkIdentifier = "golang-sdk"
Expand Down
12 changes: 11 additions & 1 deletion internal/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"os"
"strconv"
"strings"
)

Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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
}

0 comments on commit e0a0801

Please sign in to comment.