Merge pull request #1643 from thaJeztah/simplify_env_handling

secretsprovider.NewStore() simplify env handling
v0.8
Tõnis Tiigi 2020-08-14 09:22:58 -07:00 committed by GitHub
commit 91067efc28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 22 deletions

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
}