1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/orchestrator/helpers.go
Googlom ac5cf17317
refactor(orchestrator): Use singleton in orchestrator package and rename methods (#4639)
* rename interface, types and methods.
some type changes and refactor

* update dependent methods and variables

* fix unit tests

* a bit more refactor and fix

* concurrent safe singleton

* return old Options struct

* refactor creating config provider and fix nil pointer derefernce

* fix unit test and linter errors

* introduce resetting config provider (for unit tests)

* fix annoying error message when config provider is not configured

---------

Co-authored-by: Gulom Alimov <gulomjon.alimov@sap.com>
Co-authored-by: Muhammadali Nazarov <muhammadalinazarov@gmail.com>
2024-01-09 16:01:15 +05:00

41 lines
953 B
Go

package orchestrator
import (
"github.com/SAP/jenkins-library/pkg/log"
"os"
)
// envVarsAreSet verifies if any envvar from the list has nona non-empty, non-false value
func envVarsAreSet(envVars []string) bool {
for _, v := range envVars {
if envVarIsTrue(v) {
return true
}
}
return false
}
// envVarIsTrue verifies if the variable is set and has a non-empty, non-false value.
func envVarIsTrue(key string) bool {
val, exists := os.LookupEnv(key)
if !exists {
return false
}
if len(val) == 0 || val == "no" || val == "false" || val == "off" || val == "0" {
return false
}
return true
}
// Wrapper function to read env variable and set default value
func getEnv(key, fallback string) string {
if value, found := os.LookupEnv(key); found {
log.Entry().Debugf("For: %s, found: %s", key, value)
return value
}
log.Entry().Debugf("Could not read env variable %v using fallback value %v", key, fallback)
return fallback
}