Skip to content

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

Merged
thaJeztah merged 1 commit into
docker:masterfrom
thaJeztah:separate_kvfile
Oct 4, 2024
Merged

move parsing key-value files to a separate package#5502
thaJeztah merged 1 commit into
docker:masterfrom
thaJeztah:separate_kvfile

Conversation

@thaJeztah

@thaJeztahthaJeztah commented Oct 4, 2024

Copy link
Copy Markdown
Member

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)

@thaJeztahthaJeztah 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
@thaJeztahthaJeztah added this to the 28.0.0 milestone Oct 4, 2024
@codecov-commenter

codecov-commenter commented Oct 4, 2024

Copy link
Copy Markdown

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 <nicolas.deloof@gmail.com>
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

@laurazardlaurazard left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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

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

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
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
Copy Markdown
MemberAuthor

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.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/go-sdkChanges affecting the Go SDKimpact/go-sdkNoteworthy (compatibility changes) in the Go SDKkind/enhancementkind/refactorPR's that refactor, or clean-up codeprocess/cherry-pickedstatus/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@thaJeztah@codecov-commenter@ndeloof@laurazard