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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2020-08-14 17:27:41 +02:00
parent 661cafc09d
commit f0e241905e

View File

@@ -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
}