-
Notifications
You must be signed in to change notification settings - Fork 585
Add support for configuring domains starting with a number via environment variables (by using _ prefix)
#3414
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -49,7 +49,7 @@ def __init__( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.__compiled_regexes = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Pre-defined exclusion sets for config processing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.__excluded_prefixes = ("_", "PYTHON", "KUBERNETES_", "SVC_", "LB_", "SUPERVISOR_") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.__excluded_prefixes = ("PYTHON", "KUBERNETES_", "NOMAD_", "SVC_", "LB_", "SUPERVISOR_") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.__excluded_vars = frozenset( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "DOCKER_HOST", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -111,6 +111,21 @@ def __init__( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.__variables = variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Allow a leading underscore prefix on env var names so that domain names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # starting with a digit can be configured (bash forbids var names starting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # with a digit, e.g. 1nteresting.io). Users write _1nteresting.io_USE_... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # and we strip the single leading underscore here before any other processing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stripped: Dict[str, str] = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for k, v in self.__variables.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new_key = k.removeprefix("_") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not new_key: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Skip bare "_" or similar empty-after-strip keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if new_key in stripped: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.__logger.warning(f"Variable collision after stripping leading underscore: both {k!r} and {new_key!r} exist, keeping last value") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stripped[new_key] = v | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.__variables = stripped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+118
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial "Last wins" collision resolution is iteration-order dependent. As per coding guidelines for Consider a deterministic tie-breaker, such as always preferring the explicit (non-underscore) key over the underscore-prefixed form. ♻️ Possible deterministic approach for k, v in self.__variables.items():
new_key = k.removeprefix("_")
if not new_key:
continue
- if new_key in stripped:
- self.__logger.warning(f"Variable collision after stripping leading underscore: both {k!r} and {new_key!r} exist, keeping last value")
- stripped[new_key] = v
+ if new_key in stripped:
+ # Prefer explicit (non-prefixed) key; only overwrite if current key is non-prefixed
+ if k == new_key:
+ self.__logger.warning(
+ f"Variable collision: {new_key!r} overrides previously stripped key"
+ )
+ stripped[new_key] = v
+ else:
+ self.__logger.warning(
+ f"Variable collision: keeping explicit {new_key!r}, ignoring {k!r}"
+ )
+ else:
+ stripped[new_key] = v📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.__multisite = self.__variables.get("MULTISITE", "no") == "yes" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.__servers = self.__map_servers() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collision warning message is misleading when the non-prefixed key is processed second.
When iteration order means
_FOOis processed beforeFOO, the stripped keyFOOis already instripped. The current log reads:This doesn't identify the original underscore-prefixed key that caused the collision. Consider tracking which original key produced each entry in
strippedso the warning can report both original names accurately.🔧 Suggested fix
🤖 Prompt for AI Agents