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

Fix behavior regression when no decryption needed #12

Merged
merged 5 commits into from
Jul 1, 2024

Conversation

claraberendsen
Copy link
Contributor

By adding the integration to Mage tool for decryption a behavior regression was introduced where it would fail if no MAGE related variables where configured.
This was first addressed by @j-rivero on #11 by adding a flag to bypass this.
This PR removes that option and restores the behavior to be:

  • If no MAGE related ENV variable is present, then keep execution as normal.
  • If MAGE variables are present, then verifies validity of setup and decrypts.

configure Outdated
@@ -1,5 +1,5 @@
#!/usr/bin/bash

MAGE_KEY=
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed due to set nounset below making the script fail if there is no definition of MAGE_KEY

Copy link
Contributor

Choose a reason for hiding this comment

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

umm this is going to create the MAGE_KEY variable as always empty unless I'm missing something. Either we define the default like MAGE_KEY=${MAGE_KEY:-} to preserve possible env variables values or we remove the nounset options which is quite weird to use nowadays in bash due to some controversy: https://mywiki.wooledge.org/BashFAQ/112

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to remove it, WDYT @nuclearsandwich since that has been there since the first creation of the script.

Copy link
Contributor

Choose a reason for hiding this comment

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

These scripts get enough attention that I don't think we need it. If we get the POSIX sh PRs in I think it will make even more sense to remove since a lot of the techniques for mitigating nounset usage are Bash-specific or harder in POSIX sh.

@claraberendsen claraberendsen self-assigned this May 24, 2024
configure Outdated Show resolved Hide resolved
configure Outdated
@@ -1,5 +1,5 @@
#!/usr/bin/bash

MAGE_KEY=
Copy link
Contributor

Choose a reason for hiding this comment

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

umm this is going to create the MAGE_KEY variable as always empty unless I'm missing something. Either we define the default like MAGE_KEY=${MAGE_KEY:-} to preserve possible env variables values or we remove the nounset options which is quite weird to use nowadays in bash due to some controversy: https://mywiki.wooledge.org/BashFAQ/112

claraberendsen and others added 2 commits June 11, 2024 10:53
configure Outdated
@@ -77,15 +76,16 @@ freshen_chef_repo
pushd chef_repo
wd="$(pwd)"

if test \( -n "$CHEF_MAGE_PROFILE" -a test -z "$MAGE_KEY" \) -o \( test -z "$CHEF_MAGE_PROFILE" -a test -n "$MAGE_KEY" \); then
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if test \( -n "$CHEF_MAGE_PROFILE" -a test -z "$MAGE_KEY" \) -o \( test -z "$CHEF_MAGE_PROFILE" -a test -n "$MAGE_KEY" \); then
if test \( -n "$CHEF_MAGE_PROFILE" -a -z "$MAGE_KEY" \) -o \( -z "$CHEF_MAGE_PROFILE" -a -n "$MAGE_KEY" \); then

I don't recall if these were there in my original suggestion but they are spurious.
This should be the thing which might also work in bash where the other thing doesn't.
If not, just switch to [[ ]] and we'll port it when we finish the posix switch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This indeed work. Tested the script with these changes and see that behavior is restored if no MAGE variable is enabled and faults if MAGE is present

Co-authored-by: Steven! Ragnarök <[email protected]>
@claraberendsen claraberendsen merged commit 1cb9212 into latest Jul 1, 2024
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.

3 participants