Environment parsing done with Serde Envy #5

Merged
quentin merged 3 commits from adrien/diplonat:feature/config-handling into main 2021-08-19 06:32:55 +00:00
Owner

Solves #2

I replaced src/environment.rs with a src/config/ dir containing three files:

  • options.rs defines the parameters deserialised from the environment using Serde Envy;

  • runtime.rs parses the ConfigOpts struct (from options.rs) into a RuntimeConfig struct, applying business logic;

  • options_test.rs provides four unit tests:

    • an empty environment fails;
    • default options are proprely applied;
    • expiration time must be at least twice bigger than refresh time;
    • options are interpreted as expected.
Solves #2 I replaced `src/environment.rs` with a `src/config/` dir containing three files: * `options.rs` defines the parameters deserialised from the environment using [Serde Envy](https://docs.rs/envy/0.4.2/envy/index.html); * `runtime.rs` parses the `ConfigOpts` struct (from `options.rs`) into a `RuntimeConfig` struct, applying business logic; * `options_test.rs` provides four unit tests: * an empty environment fails; * default options are proprely applied; * expiration time must be at least twice bigger than refresh time; * options are interpreted as expected.
adrien added the
enhancement
label 2021-08-16 09:45:12 +00:00
adrien added 3 commits 2021-08-16 09:45:13 +00:00
ae9550ce23 New configuration parsing using envy. Added minimal functionnality for
the future ACME parameters. Tests written and passing.

WIP: added envy dependncy and ConfigOpts structs that will constitute Diplonat's configuration

WIP: ConfigOpts from_env() and validate() methods written. No API change (the env names remain unchanged)! Now need to use our new ConfigOpts struct instead of Environment, and update references to the environment variables in the code.

WIP: RuntimeConfig with business logic done. Tests written, but they are all running from the same process - setting environment variables in each test produces incoherent results. Another solution for testing is needed.

WIP: tests are fully written using 'from_iter' and all passing
Author
Owner

Be aware that the config/ implementation is future-proof: it would be super simple to have a configuration file in addition to the environment variables.

Becauuuse I took inspiration from the Trunk crate, which does exactly that, and even command-line parameters: CLI superseedes env that superseedes configuration file.

Be aware that the `config/` implementation is future-proof: it would be super simple to have a configuration file in addition to the environment variables. Becauuuse I took inspiration from [the Trunk crate](https://github.com/thedodd/trunk/blob/master/src/config/models_test.rs), which does exactly that, and even command-line parameters: `CLI` superseedes `env` that superseedes configuration file.
Owner

LGTM :)

LGTM :)
Owner

LGTM, thanks !

LGTM, thanks !
quentin merged commit fa25c54e47 into main 2021-08-19 06:32:55 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Deuxfleurs/diplonat#5
No description provided.