From f0e241905e81e0a01a4bec2fb4f80f10f5f5c19f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 14 Aug 2020 17:27:41 +0200 Subject: [PATCH] secretsprovider.NewStore() simplify env handling The `doesEnvExist()` utility was copied from the classic builder, and was developed when `os.LookupEnv()` did not yet exist. Now that it's available, replace our custom implementation in favor of Golang's function. Signed-off-by: Sebastiaan van Stijn --- session/secrets/secretsprovider/store.go | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/session/secrets/secretsprovider/store.go b/session/secrets/secretsprovider/store.go index db827972..3a846f84 100644 --- a/session/secrets/secretsprovider/store.go +++ b/session/secrets/secretsprovider/store.go @@ -4,8 +4,6 @@ import ( "context" "io/ioutil" "os" - "runtime" - "strings" "github.com/moby/buildkit/session/secrets" "github.com/pkg/errors" @@ -25,7 +23,7 @@ func NewStore(files []Source) (secrets.SecretStore, error) { return nil, errors.Errorf("secret missing ID") } if f.Env == "" && f.FilePath == "" { - if hasEnv(f.ID) { + if _, ok := os.LookupEnv(f.ID); ok { f.Env = f.ID } else { f.FilePath = f.ID @@ -65,22 +63,3 @@ func (fs *fileStore) GetSecret(ctx context.Context, id string) ([]byte, error) { } return dt, nil } - -func hasEnv(name string) bool { - for _, entry := range os.Environ() { - idx := strings.IndexRune(entry, '=') - if idx == -1 { - continue - } - if runtime.GOOS == "windows" { - // Environment variable are case-insensitive on Windows. PaTh, path and PATH are equivalent. - if strings.EqualFold(entry[:idx], name) { - return true - } - } - if entry[:idx] == name { - return true - } - } - return false -}