[27.x backport] move parsing key-value files to a separate package#5503
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 27.x #5503 +/- ##
==========================================
- Coverage 59.78% 59.77% -0.01%
==========================================
Files 345 345
Lines 23442 23443 +1
==========================================
- Hits 14015 14014 -1
- Misses 8453 8454 +1
- Partials 974 975 +1 |
|
Can you also cherry-pick the other related changes, so that it's a clean cherry-pick? I probably should've done them together instead of as 3 separate PRs; |
This error was originally introduced `ErrBadEnvVariable` in [moby/moby@500c8ba], but merely for convenience, and not used as a sentinel error. After the code was moved from the daemon to the cli repository, it was renamed to be more generic `ErrBadKey` in commit 2b17f4c. A search on GitHub shows that there's no consumers using this error as sentinel error, and it's not used in our own code as such, so it should be safe to remove this error. This patch removes the `ErrBadKey` error-type; it also removes the prefix (`poorly formatted environment:`) to make the error more generic, because the same function was used both for env-files and label-files. [moby/moby@500c8ba]: vdemeester/moby@500c8ba Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 95e221e) Signed-off-by: Austin Vazquez <macedonv@amazon.com>
- the function already trimmed leading whitespace from each line before parsing. keys with trailing whitespace would be invalidated, and values have whitespace preserved, so there's no need to trim whitespace for the key. - if a line is validated (key is valid), we don't need to reconstruct the key=value by concatenating, and we can add the line as-is. - check if the key is empty before checking if it contains whitespace - touch-up comments - rename some variables for readability - slight cleanup to use early returns / early continues to reduce nesting Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 76196db) Signed-off-by: Austin Vazquez <macedonv@amazon.com>
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> (cherry picked from commit 9ecfe4f) Signed-off-by: Austin Vazquez <macedonv@amazon.com>
d075f97 to
9ab3d3a
Compare
Oof good catch, I missed that. 😅 |
Yeah, the straight backport would probably still have worked (because the changes were made before the file was (re)moved), but it makes for a slightly accurate history. |
- What I did
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.
(cherry picked from commit 9ecfe4f)
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)