Skip to content

refactor: Share a common helper (vhost builder) for sourcing domains#2620

Merged
polarathene merged 8 commits intodocker-mailserver:masterfrom
polarathene:refactor/share-common-vhost-builder-helper
Jun 9, 2022
Merged

refactor: Share a common helper (vhost builder) for sourcing domains#2620
polarathene merged 8 commits intodocker-mailserver:masterfrom
polarathene:refactor/share-common-vhost-builder-helper

Conversation

@polarathene
Copy link
Copy Markdown
Member

@polarathene polarathene commented Jun 5, 2022

Description

bin/open-dkim and helpers/accounts.sh + helpers/aliases.sh have roughly duplicate code for collecting domains to process. This code is now in sync by updating methods in helpers/postfix.sh.

Commit messages (first to last) for quick reference

chore: Split vhost helper method and use filepath vars

  • Helpers accounts.sh and aliases.sh can move their vhost code into this helper.
  • They share duplicate code with bin/open-dkim which will also leverage this vhost helper going forward.

chore: Sync vhost generation logic into helper

  • Chunky commit, but mostly copy/paste of logic into a common method.
  • bin/open-dkim additionally wrapped relevant logic in a function call and revised inline docs.

chore: Include LDAP vhost support

  • Revises notes for LDAP vhost support.
  • This now ensures LDAP users get vhost rebuilt to match the startup script for when change detection support is enabled.
  • bin/open-dkim will additionally be able to support the default DOMAINNAME var (set via helpers/dns.sh) for LDAP users instead of requiring them to provide one explicitly.

chore(bin/open-dkim): Ensure DOMAINNAME is properly set

  • This will ensure LDAP users insert the same DOMAINNAME value as used during container startup.
  • The container itself should panic at startup (during helpers/dns.sh) if this isn't configured correctly already, thus it should not introduce any breaking change to users of this utility?

  • We use this functionality for populating /etc/postfix/vhost used by Postfix main.cf:virtual_mailbox_domains setting. bin/open-dkim leverages it to acquire domains relevant to Postfix.
  • This PR will additionally benefit check-for-changes.sh to generate vhost config when helpers/accounts.sh or helpers/aliases.sh is not affected by the changed file. That support will be covered in refactor: Revise check-for-changes.sh #2615

Relevant history - bin/open-dkim arg DOMAINS

Additional info regarding bin/open-dkim (most of this isn't useful in the context of this PR, but helps understand the background of the alternative support via DOMAINS arg):

Type of change

  • 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

@polarathene polarathene added area/scripts kind/improvement Improve an existing feature, configuration file or the documentation pr/waiting for other PR to get merged This PR is waiting for another / other PR(s) to get merged labels Jun 5, 2022
@polarathene polarathene added this to the v11.1.0 milestone Jun 5, 2022
@polarathene polarathene self-assigned this Jun 5, 2022
@polarathene
Copy link
Copy Markdown
Member Author

polarathene commented Jun 5, 2022

helpers/aliases.sh has a maintenance comment (which I carried over into helpers/postfix.sh):

# the `to` is important, don't delete it

Originally this FROM TO syntax was introduced in an Oct 2015 PR #26, but no explanation for to var usage. Later in April 2016, this was duplicated into opendkim support: bin/generate-dkim-config, albeit no PR (direct commit by original project author).

The maintainer comment instructing the importance of TO was added by @georglauterbach in Sep 2020 large refactor PR, no additional context in the PR discussion or commit messages.

Can we better clarify why it's important here?

@polarathene polarathene force-pushed the refactor/share-common-vhost-builder-helper branch 2 times, most recently from b25d6d5 to 12d7921 Compare June 5, 2022 10:03
@polarathene

This comment was marked as outdated.

@polarathene polarathene force-pushed the refactor/share-common-vhost-builder-helper branch 2 times, most recently from ea1b434 to 5df0e26 Compare June 7, 2022 00:17
@polarathene polarathene removed the pr/waiting for other PR to get merged This PR is waiting for another / other PR(s) to get merged label Jun 7, 2022
@polarathene polarathene marked this pull request as ready for review June 7, 2022 00:18
@polarathene polarathene marked this pull request as draft June 7, 2022 01:53
- Helpers `accounts.sh` and `aliases.sh` can move their vhost code into this helper.
- They share duplicate code with `bin/open-dkim` which will also leverage this vhost helper going forward.
- Chunky commit, but mostly copy/paste of logic into a common method.
- `bin/open-dkim` additionally wrapped relevant logic in a function call and revised inline docs.
- Revises notes for LDAP vhost support.
- This now ensures LDAP users get vhost rebuilt to match the startup script for when change detection support is enabled.
- `bin/open-dkim` will additionally be able to support the default `DOMAINNAME` var (set via `helpers/dns.sh`) for LDAP users instead of requiring them to provide one explicitly.
- This will ensure LDAP users insert the same `DOMAINNAME` value as used during container startup.
- The container itself should panic at startup (during `helpers/dns.sh`) if this isn't configured correctly already, thus it should not introduce any breaking change to users of this utility?
@polarathene polarathene force-pushed the refactor/share-common-vhost-builder-helper branch from 5df0e26 to 3c44ed1 Compare June 7, 2022 02:03
@polarathene polarathene marked this pull request as ready for review June 7, 2022 03:03
@georglauterbach

This comment was marked as resolved.

@georglauterbach

This comment was marked as resolved.

Comment thread target/scripts/helpers/postfix.sh Outdated
Comment thread target/scripts/helpers/postfix.sh Outdated
Comment thread target/scripts/helpers/postfix.sh Outdated
Line is split by a delimiter such as white-space (or via IFS: `|`), the blank `_` var is to indicate we're not interested in that value, but still leverage how `read -r` works, instead of splitting the var ourselves first thing.
Comment thread target/scripts/helpers/postfix.sh Outdated
Comment thread target/scripts/helpers/postfix.sh Outdated
Copy link
Copy Markdown
Member Author

@polarathene polarathene left a comment

Choose a reason for hiding this comment

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

Good catch with those two lint lines! 😀

Comment thread target/scripts/helpers/postfix.sh Outdated
Comment thread target/scripts/helpers/postfix.sh Outdated
No longer applicable with the switch to `_`
@polarathene polarathene requested a review from a team June 7, 2022 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/scripts kind/improvement Improve an existing feature, configuration file or the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants