1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00
Files
dozzle/internal/support/cli/valid_env.go
2024-08-14 17:04:18 +00:00

33 lines
695 B
Go

package cli
import (
"os"
"reflect"
"strings"
"github.com/rs/zerolog/log"
)
func ValidateEnvVars(types ...interface{}) {
expectedEnvs := make(map[string]bool)
for _, t := range types {
typ := reflect.TypeOf(t)
for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i)
for _, tag := range strings.Split(field.Tag.Get("arg"), ",") {
if strings.HasPrefix(tag, "env:") {
expectedEnvs[strings.TrimPrefix(tag, "env:")] = true
}
}
}
}
for _, env := range os.Environ() {
actual := strings.Split(env, "=")[0]
if strings.HasPrefix(actual, "DOZZLE_") && !expectedEnvs[actual] {
log.Warn().Str("env", actual).Msg("Unexpected environment variable")
}
}
}