Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move parsing key-value files to a separate package #5502

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Oct 4, 2024

Move the code for parsing key-value files, such as used for env-files and label-files to a separate package. This allows other projects (such as compose) to use the same parsing logic, but provide custom lookup functions for their situation (which is slightly different).

The new package provides utilities for parsing key-value files for either a file or an io.Reader. Most tests for EnvFile were now testing functionality that's already tested in the new package, so were (re)moved.

- What I did

Screenshot 2024-10-04 at 11 46 30

- How I did it

- How to verify it

- Description for the changelog

move parsing key-value files to a separate package (pkg/kvfile)

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added kind/enhancement status/2-code-review kind/refactor PR's that refactor, or clean-up code area/go-sdk Changes affecting the Go SDK impact/go-sdk Noteworthy (compatibility changes) in the Go SDK labels Oct 4, 2024
@thaJeztah thaJeztah added this to the 28.0.0 milestone Oct 4, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 4, 2024

Codecov Report

Attention: Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.

Project coverage is 60.09%. Comparing base (9dee12f) to head (9ecfe4f).
Report is 10 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5502   +/-   ##
=======================================
  Coverage   60.09%   60.09%           
=======================================
  Files         345      345           
  Lines       23441    23448    +7     
=======================================
+ Hits        14086    14091    +5     
- Misses       8381     8382    +1     
- Partials      974      975    +1     

Move the code for parsing key-value files, such as used for
env-files and label-files to a separate package. This allows
other projects (such as compose) to use the same parsing
logic, but provide custom lookup functions for their situation
(which is slightly different).

The new package provides utilities for parsing key-value files
for either a file or an io.Reader. Most tests for EnvFile were
now testing functionality that's already tested in the new package,
so were (re)moved.

Co-authored-by: Nicolas De Loof <[email protected]>
Signed-off-by: Nicolas De Loof <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! This seems like a good place for this for now.

@thaJeztah
Copy link
Member Author

@ndeloof I decided to spend some time Yesterday to move that code after all; does this work for you (as alternative to #5491)?

Comment on lines +32 to +33
// recommended to use a subset of the POSIX portable character set, as
// outlined in [Environment Variables].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I remember having a discussion about this some time ago and while some programs will only accept a subset of the portable character set, there's no guarantees and often applications that people run rely on other random characters, so we shouldn't do much validating here ourselves.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, compose recently ran into some of these. And, yes, Linux accepts "just about anything" (anything except NUL terminator). And, just because it does doesn't mean you should ... but some systems do, which is why we don't do validation on any of these.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might've been on Compose, yeah 😅

Comment on lines 921 to 924
// UTF16 with BOM
e := "contains invalid utf8 bytes at line"
e := "invalid utf8 bytes at line"
if _, _, _, err := parseRun([]string{"--env-file=testdata/utf16.env", "img", "cmd"}); err == nil || !strings.Contains(err.Error(), e) {
t.Fatalf("Expected an error with message '%s', got %v", e, err)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW; perhaps some of these tests should be moved to the new package as well, but didn't look at that yet.

@thaJeztah thaJeztah merged commit ff3f94a into docker:master Oct 4, 2024
89 checks passed
@thaJeztah thaJeztah deleted the separate_kvfile branch October 4, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/go-sdk Changes affecting the Go SDK impact/go-sdk Noteworthy (compatibility changes) in the Go SDK kind/enhancement kind/refactor PR's that refactor, or clean-up code process/cherry-picked status/2-code-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants