mirror of
https://github.com/rancher/rke.git
synced 2025-09-01 23:16:22 +00:00
Log proxy environment variables if set
This commit is contained in:
committed by
Alena Prokharchyk
parent
d094535add
commit
e923730388
26
util/util.go
26
util/util.go
@@ -3,6 +3,7 @@ package util
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rancher/rke/metadata"
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -108,3 +109,28 @@ func GetImageTagFromImage(image string) (string, error) {
|
||||
logrus.Debugf("Extracted version [%s] from image [%s]", imageTag, image)
|
||||
return imageTag, nil
|
||||
}
|
||||
|
||||
func StripPasswordFromURL(URL string) (string, error) {
|
||||
u, err := url.Parse(URL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, passSet := u.User.Password()
|
||||
if passSet {
|
||||
return strings.Replace(u.String(), u.User.String()+"@", u.User.Username()+":***@", 1), nil
|
||||
}
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
// GetEnvVar will lookup a given environment variable by key and return the key and value (to show what case got matched) with uppercase key being preferred
|
||||
func GetEnvVar(key string) (string, string, bool) {
|
||||
// Uppercase (has precedence over lowercase)
|
||||
if value, ok := os.LookupEnv(strings.ToUpper(key)); ok {
|
||||
return strings.ToUpper(key), value, true
|
||||
}
|
||||
// Lowercase
|
||||
if value, ok := os.LookupEnv(strings.ToLower(key)); ok {
|
||||
return strings.ToLower(key), value, true
|
||||
}
|
||||
return "", "", false
|
||||
}
|
||||
|
Reference in New Issue
Block a user