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

refactor: Helper function _replace_by_env_in_file() #3526

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

polarathene
Copy link
Member

@polarathene polarathene commented Sep 4, 2023

Description

Some refactoring improvements and fixes to the escaping support:

  • _replace_by_env_in_file():
    • Minor change to add support for usage with saslauthd.conf which differs with : for it's key/value delimiter.
    • Also adopts using the_escape_for_sed() helper function, instead of the inline sed pattern (which for some reason escaped a =? but not actual regex tokens ( + ), thus buggy if ever matching on input with those tokens).
    • Since the value is used regardless in the final sed expression, no need to prepend white-space, and we can additionally preserve the white-space between key and value of the source input while being more DRY.
  • _escape_for_sed():
    • This was not escaping for ( + ) (or even |), which is required for proper escaping support when using sed -E / sed -r with this helper function. It does now.
    • Additionally added escaping support for the & replacement segment token, which seems ok to escape in the regexp segment too (even though it has no meaning there). Increased verbosity to better grok pattern matching expression (easier when broken down, vs all in a single line), clarified an escaping concern with the sed segment delimiter (since the project is not consistent there).

NOTE: Tests will fail, this PR can be rebased upon #3524 which for the mail_with_ldap.bats test at least should pass then, other tests can be updated here after that.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change that does improve existing functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes

Minor change to add support for usage with `saslauthd.conf` which differs with `:` for it's key/value delimiter.

Also adopts the`_escape_for_sed()` method, instead of the inline sed pattern (_which for some reason escaped `=` but not `(` + `)`, thus buggy if ever matching on input with those tokens_).

`_escape_for_sed()` likewise wasn't escaping for `(` + `)` or even `|`, which are required for proper escape support if using `sed -E` / `sed -r` with this method. Additionally added escaping support for `&` replacement segment token, which seems valid. Increased verbosity to better grok pattern matching expression, clarified escaping concern with `sed` delimiter since the project is not consistent there.
No need to check for a non-empty value to prepend a space (_since an empty value is used via sed anyway?_).

Can also be a bit DRY with the sed pattern, matching the key + delimiter (_and all white-space before/after the delimiter until the value_), then capture that for the replacement left-side value while only actually swapping the value for the ENV input value.

Should be an improvement, unless there is a scenario that would differ between `` and ` ` as valid value assignments?
@polarathene polarathene added area/scripts kind/improvement Improve an existing feature, configuration file or the documentation area/configuration (file) kind/bug/fix A fix (PR) for a confirmed bug labels Sep 4, 2023
@polarathene polarathene added this to the v13.0.0 milestone Sep 4, 2023
@polarathene polarathene self-assigned this Sep 4, 2023
georglauterbach
georglauterbach previously approved these changes Sep 5, 2023
target/scripts/helpers/utils.sh Show resolved Hide resolved
target/scripts/helpers/utils.sh Show resolved Hide resolved
target/scripts/helpers/utils.sh Outdated Show resolved Hide resolved
Both should be improvements for usage

Co-authored-by: Casper <[email protected]>
@github-actions github-actions bot added the meta/stale This issue / PR has become stale and will be closed if there is no further activity label Oct 2, 2023
@docker-mailserver docker-mailserver deleted a comment from github-actions bot Oct 2, 2023
@polarathene polarathene added stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI and removed meta/stale This issue / PR has become stale and will be closed if there is no further activity labels Oct 2, 2023
@georglauterbach georglauterbach modified the milestones: v13.0.0, v13.1.0 Oct 23, 2023
@georglauterbach georglauterbach added the meta/feature freeze On hold due to upcoming release process label Nov 8, 2023
@georglauterbach georglauterbach removed the meta/feature freeze On hold due to upcoming release process label Nov 26, 2023
@georglauterbach georglauterbach added the meta/feature freeze On hold due to upcoming release process label Dec 23, 2023
@georglauterbach georglauterbach modified the milestones: v13.1.0, v14.0.0 Dec 29, 2023
@georglauterbach georglauterbach removed the meta/feature freeze On hold due to upcoming release process label Dec 29, 2023
@georglauterbach
Copy link
Member

This is marked for v14.0.0. Will it be addresses for v14.0.0, or should we immediately postpone to v14.1.0?

@polarathene
Copy link
Member Author

or should we immediately postpone to v14.1.0?

Same response to the related LDAP PR, that PR needs to be merged before this one can be.

@georglauterbach georglauterbach modified the milestones: v14.0.0, v15.0.0 Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration (file) area/scripts kind/bug/fix A fix (PR) for a confirmed bug kind/improvement Improve an existing feature, configuration file or the documentation stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants