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

config: Support falsy numeric and boolean values… #746

Merged
merged 5 commits into from
Nov 3, 2023

Conversation

tsibley
Copy link
Member

@tsibley tsibley commented Nov 2, 2023

…instead of considering them missing.

The values considered missing are now more clear:

  1. undefined (i.e. not present)
  2. null (i.e. present but explicitly null)
  3. "" (i.e. present but empty, particularly for env vars)

This allows falsy values¹ like the number 0 and boolean false to be
configurable values², as expected to be for OIDC_IAT_BACKDATED_BY and
REDIS_REQUIRED.

For example, setting REDIS_REQUIRED=false is now functional as intended
by "Allow and document how to run safely in production mode without
Redis" (64f7d92). And setting OIDC_IAT_BACKDATED_BY=0 in the
environment now overrides any value from the config file instead of
being ignored.

Related-to: #739

¹ https://developer.mozilla.org/en-US/docs/Glossary/Falsy

² Other falsy values like NaN and 0n are also now considered
non-missing, but there's no way to express those in our current config
sources, which permit only strings or JSON values. We may find
ourselves wanting to treat NaN as missing too if config sources
change.

Checklist

  • Checks pass

@tsibley tsibley requested a review from a team November 2, 2023 22:23
@nextstrain-bot nextstrain-bot temporarily deployed to nextstrain-s-trs-falsy--bybzul November 2, 2023 22:23 Inactive
… tests

To be fixed in the next commit.

There's other config behaviours it would likely be useful to test, but
this is a small start.
…instead of considering them missing.

The values considered missing are now more clear:

  1. undefined (i.e. not present)
  2. null (i.e. present but explicitly null)
  3. "" (i.e. present but empty, particularly for env vars)

This allows falsy values¹ like the number 0 and boolean false to be
configurable values², as expected to be for OIDC_IAT_BACKDATED_BY and
REDIS_REQUIRED.

For example, setting REDIS_REQUIRED=false is now functional as intended
by "Allow and document how to run safely in production mode without
Redis" (64f7d92).  And setting OIDC_IAT_BACKDATED_BY=0 in the
environment now overrides any value from the config file instead of
being ignored.

Related-to: <#739>

¹ <https://developer.mozilla.org/en-US/docs/Glossary/Falsy>

² Other falsy values like NaN and 0n are also now considered
  non-missing, but there's no way to express those in our current config
  sources, which permit only strings or JSON values.  We may find
  ourselves wanting to treat NaN as missing too if config sources
  change.
@tsibley tsibley temporarily deployed to nextstrain-s-trs-falsy--bybzul November 2, 2023 22:27 Inactive
@tsibley tsibley mentioned this pull request Nov 2, 2023
1 task
Copy link
Member

@jameshadfield jameshadfield left a comment

Choose a reason for hiding this comment

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

Works for setting an env variable to false, which will be immediately useful for my work in nextstrain.org

@tsibley tsibley merged commit 1e344a4 into master Nov 3, 2023
4 checks passed
@tsibley tsibley deleted the trs/falsy-config-vars branch November 3, 2023 00:11
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