Skip to content

Commit e650803

Browse files
committed
opts: deprecate ParseEnvFile
It was a wrapper around kvfile.Load, which should be used instead. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 4d93a64 commit e650803

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
package opts
1+
package loader
22

33
import (
44
"os"
55

66
"github.com/docker/cli/pkg/kvfile"
77
)
88

9-
// ParseEnvFile reads a file with environment variables enumerated by lines
9+
// parseEnvFile reads a file with environment variables enumerated by lines
1010
//
1111
// “Environment variable names used by the utilities in the Shell and
12-
// Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase
12+
// Utilities volume of [IEEE Std 1003.1-2001] consist solely of uppercase
1313
// letters, digits, and the '_' (underscore) from the characters defined in
1414
// Portable Character Set and do not begin with a digit. *But*, other
1515
// characters may be permitted by an implementation; applications shall
1616
// tolerate the presence of such names.”
17-
// -- http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
1817
//
19-
// As of #16585, it's up to application inside docker to validate or not
18+
// As of [moby-16585], it's up to application inside docker to validate or not
2019
// environment variables, that's why we just strip leading whitespace and
2120
// nothing more.
22-
func ParseEnvFile(filename string) ([]string, error) {
21+
//
22+
// [IEEE Std 1003.1-2001]: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
23+
// [moby-16585]: https://github.com/moby/moby/issues/16585
24+
func parseEnvFile(filename string) ([]string, error) {
2325
return kvfile.Parse(filename, os.LookupEnv)
2426
}

‎opts/envfile_test.go‎ renamed to ‎cli/compose/loader/envfile_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package opts
1+
package loader
22

33
import (
44
"os"
@@ -17,13 +17,13 @@ func tmpFileWithContent(t *testing.T, content string) string {
1717
return fileName
1818
}
1919

20-
// Test ParseEnvFile for a non existent file
20+
// Test parseEnvFile for a non existent file
2121
func TestParseEnvFileNonExistentFile(t *testing.T) {
22-
_, err := ParseEnvFile("no_such_file")
22+
_, err := parseEnvFile("no_such_file")
2323
assert.Check(t, is.ErrorType(err, os.IsNotExist))
2424
}
2525

26-
// ParseEnvFile with environment variable import definitions
26+
// parseEnvFile with environment variable import definitions
2727
func TestParseEnvVariableDefinitionsFile(t *testing.T) {
2828
content := `# comment=
2929
UNDEFINED_VAR
@@ -32,7 +32,7 @@ DEFINED_VAR
3232
tmpFile := tmpFileWithContent(t, content)
3333

3434
t.Setenv("DEFINED_VAR", "defined-value")
35-
variables, err := ParseEnvFile(tmpFile)
35+
variables, err := parseEnvFile(tmpFile)
3636
assert.NilError(t, err)
3737

3838
expectedLines := []string{"DEFINED_VAR=defined-value"}

‎cli/compose/loader/loader.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func resolveEnvironment(serviceConfig *types.ServiceConfig, workingDir string, l
469469

470470
for _, file := range serviceConfig.EnvFile {
471471
filePath := absPath(workingDir, file)
472-
fileVars, err := opts.ParseEnvFile(filePath)
472+
fileVars, err := parseEnvFile(filePath)
473473
if err != nil {
474474
return err
475475
}

‎opts/env.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
)
88

99
// ValidateEnv validates an environment variable and returns it.
10-
// If no value is specified, it obtains its value from the current environment
10+
// If no value is specified, it obtains its value from the current environment.
1111
//
12-
// As on ParseEnvFile and related to #16585, environment variable names
13-
// are not validated, and it's up to the application inside the container
14-
// to validate them or not.
12+
// Environment variable names are not validated, and it's up to the application
13+
// inside the container to validate them (see [moby-16585]). The only validation
14+
// here is to check if name is empty, per [moby-25099].
1515
//
16-
// The only validation here is to check if name is empty, per #25099
16+
// [moby-16585]: https://github.com/moby/moby/issues/16585
17+
// [moby-25099]: https://github.com/moby/moby/issues/25099
1718
func ValidateEnv(val string) (string, error) {
1819
k, _, hasValue := strings.Cut(val, "=")
1920
if k == "" {

‎opts/envfile_deprecated.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package opts
2+
3+
import (
4+
"os"
5+
6+
"github.com/docker/cli/pkg/kvfile"
7+
)
8+
9+
// ParseEnvFile reads a file with environment variables enumerated by lines
10+
//
11+
// Deprecated: use [kvfile.Parse] and pass [os.LookupEnv] to lookup env-vars from the current environment.
12+
func ParseEnvFile(filename string) ([]string, error) {
13+
return kvfile.Parse(filename, os.LookupEnv)
14+
}

0 commit comments

Comments
 (0)