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

Expand env variables in volume paths in configuration file #192

Merged
merged 6 commits into from
Jan 12, 2022

Conversation

xanarin
Copy link
Collaborator

@xanarin xanarin commented Jan 10, 2022

For more context on this change, see #191.

@github-actions
Copy link

github-actions bot commented Jan 10, 2022

Unit Test Results

    5 files      5 suites   1m 54s ⏱️
157 tests 155 ✔️   2 💤 0
785 runs  775 ✔️ 10 💤 0

Results for commit 2405ed8.

♻️ This comment has been updated with latest results.

While working on this feature, I hit a case where the 'warnings' module
was referenced, but this caused a NameError because the module was never
imported. AFAICT this issue has been present since the code was
introduced, but it was never noticed because it was behind a conditional
that was never satisfied.
@xanarin xanarin marked this pull request as ready for review January 10, 2022 00:48
scuba/config.py Outdated Show resolved Hide resolved
Responding to a comment on GH-192, the code now calls
string.Template.substitute, which has more correct behavior because it
won't skip expanding any unset environmental variables. Now, the
behavior is to raise an exception, similar to bash's nounset (set -u)
option.

This code was placed in 'utils.py' so that it can be used elsewhere in
Scuba and not just config-parsing code.
Copy link
Owner

@JonathonReinhart JonathonReinhart left a comment

Choose a reason for hiding this comment

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

Thanks for the update. I found a few more issues.

scuba/config.py Outdated Show resolved Hide resolved
scuba/utils.py Outdated Show resolved Hide resolved
tests/test_config.py Outdated Show resolved Hide resolved
scuba/config.py Outdated Show resolved Hide resolved
scuba/config.py Outdated Show resolved Hide resolved
scuba/utils.py Show resolved Hide resolved
tests/test_config.py Outdated Show resolved Hide resolved
tests/test_config.py Outdated Show resolved Hide resolved
tests/test_config.py Outdated Show resolved Hide resolved
Also, change all instances of 'environmental variables' to 'environment
variables', as that is the accepted terminology (which I didn't know up
to this point!)
This includes mocking the environment variables instead of modifying the
global environment during unit tests, and adding extra tests for the
underlying expansion function in `utils.py`.
@xanarin
Copy link
Collaborator Author

xanarin commented Jan 12, 2022

I added documentation for this functionality change in 850f6b0.

The only backward-incompatability issue we may have is that if any users have the $ character in their volume mapping strings that they don't want to be expanded, they will now have to write $$. However, given that the volume feature is pretty new and having $ in the name of directories or files on Linux is a nightmare, I don't expect this to be an issue for anyone.

@JonathonReinhart
Copy link
Owner

Thanks a lot @xanarin for your patience and the high-quality code!

@JonathonReinhart JonathonReinhart merged commit 3d7ef6d into master Jan 12, 2022
@JonathonReinhart JonathonReinhart deleted the 191-expand-vars-in-volumes branch January 12, 2022 20:49
@@ -166,6 +166,19 @@ of volume options:
hostpath: /host/foo
options: ro,cached

The keys used in volume mappings can contain environment variables **that are
Copy link
Owner

Choose a reason for hiding this comment

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

It's actually not just the keys (container path), but also the host path, which can contain environment vars (as shown in the example)

Copy link
Owner

Choose a reason for hiding this comment

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

Opened #214 to fix

volumes:
$TEST_HOME/.config/application1: $TEST_HOME/.config/application1

Note that because variable expansion is now applied to all volume keys, if one
Copy link
Owner

Choose a reason for hiding this comment

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

keys -> paths

Copy link
Owner

Choose a reason for hiding this comment

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

Opened #214 to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants