mirror of
https://github.com/minio/minio.git
synced 2025-11-10 05:59:43 -05:00
Extend further validation of config values (#8469)
- This PR allows config KVS to be validated properly without being affected by ENV overrides, rejects invalid values during set operation - Expands unit tests and refactors the error handling for notification targets, returns error instead of ignoring targets for invalid KVS - Does all the prep-work for implementing safe-mode style operation for MinIO server, introduces a new global variable to toggle safe mode based operations NOTE: this PR itself doesn't provide safe mode operations
This commit is contained in:
committed by
kannappanr
parent
599aae5ba6
commit
9e7a3e6adc
35
pkg/env/env.go
vendored
35
pkg/env/env.go
vendored
@@ -3,26 +3,47 @@ package env
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
privateMutex sync.RWMutex
|
||||
envOff bool
|
||||
)
|
||||
|
||||
// SetEnvOff - turns off env lookup
|
||||
func SetEnvOff() {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
|
||||
envOff = true
|
||||
}
|
||||
|
||||
// SetEnvOn - turns on env lookup
|
||||
func SetEnvOn() {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
|
||||
envOff = false
|
||||
}
|
||||
|
||||
// Get retrieves the value of the environment variable named
|
||||
// by the key. If the variable is present in the environment the
|
||||
// value (which may be empty) is returned. Otherwise it returns
|
||||
// the specified default value.
|
||||
func Get(key, defaultValue string) string {
|
||||
privateMutex.RLock()
|
||||
ok := envOff
|
||||
privateMutex.RUnlock()
|
||||
if ok {
|
||||
return defaultValue
|
||||
}
|
||||
if v, ok := os.LookupEnv(key); ok {
|
||||
return v
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// Lookup retrieves the value of the environment variable named
|
||||
// by the key. If the variable is present in the environment the
|
||||
// value (which may be empty) is returned and the boolean is true.
|
||||
// Otherwise the returned value will be empty and the boolean will
|
||||
// be false.
|
||||
func Lookup(key string) (string, bool) { return os.LookupEnv(key) }
|
||||
|
||||
// List all envs with a given prefix.
|
||||
func List(prefix string) (envs []string) {
|
||||
for _, env := range os.Environ() {
|
||||
|
||||
Reference in New Issue
Block a user