Skip to content

Configure directory with config & clap#927

Merged
spacebear21 merged 1 commit intopayjoin:masterfrom
nothingmuch:directory-config
Aug 29, 2025
Merged

Configure directory with config & clap#927
spacebear21 merged 1 commit intopayjoin:masterfrom
nothingmuch:directory-config

Conversation

@nothingmuch
Copy link
Copy Markdown
Contributor

@nothingmuch nothingmuch commented Aug 4, 2025

This uses the same approach to configuration as payjoin-cli does, with the addition of clap's env feature used for backwards compatibility with existing 12-factor style configuration.

Depends on #981

@nothingmuch nothingmuch requested a review from DanGould August 4, 2025 22:40
config = add_defaults(config, cli)?;

// what directory should this reside in? require explicit --config-file? ~/.config? /etc?
config = config.add_source(File::new("config.toml", FileFormat::Toml).required(false));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should follow the same pattern as payjoin-cli for configuration file handling:

first, check for config file in xdg-compliant default directory
fall back to current working directory if no XDG directory is found
allow --config-file flag to override both defaults when specified

This would provide a consistent user experience across the codebase and follow established conventions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that's definitely one option, but i'm not sure, since payjoin-directory is a service, not a command line application intended to be run by users, so conventions are a bit different

usually system services store configurations in /etc not ~/.config, and state in /var/lib, but that requires system level setup of those files & directories, so perhaps it should just be easy to override those paths and still default to xdg ones

however i think i would prefer just errorring if an explicit path is not given, at least for state storage, it's less confusing than running it without error but not knowing where any state data ended up

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Aug 5, 2025

Pull Request Test Coverage Report for Build 17330651492

Details

  • 0 of 35 (0.0%) changed or added relevant lines in 2 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.05%) to 85.913%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin-directory/src/main.rs 0 14 0.0%
payjoin-directory/src/config.rs 0 21 0.0%
Files with Coverage Reduction New Missed Lines %
payjoin-directory/src/main.rs 3 0.0%
Totals Coverage Status
Change from base Build 17330477248: -0.05%
Covered Lines: 8166
Relevant Lines: 9505

💛 - Coveralls

Copy link
Copy Markdown
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

This seems mostly fine but I do wonder what inspired the increased complexity. Is this something you found yourself needing?

cACK

init_logging();

let dir_port =
env::var("PJ_DIR_PORT").map_or(DEFAULT_DIR_PORT, |s| s.parse().expect("Invalid port"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const DEFAULT_DIR_PORT definition may be removed

Comment on lines +32 to +42
env = "PJ_DB_HOST",
default_value = "localhost:6379",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use default const or remove

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it'll removed with redis, but i didn't want to break compat with the current behavior just yet in case we need to do a release for some reason this PR should behave exactly the same as before except also support a config file and -- style options

#[arg(
long,
env = "PJ_DIR_TIMEOUT_SECS",
default_value = "30",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

DEFAULT_TIMEOUT_SECS.to_string() can be used here or otherwise its definition removed. I think this is self-documenting so prefer removal.

use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::EnvFilter;

const DEFAULT_KEY_CONFIG_DIR: &str = "ohttp_keys";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you removed this one but not those in lib.rs. The others are pub but I'm not sure they need to be.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch, thanks

@nothingmuch
Copy link
Copy Markdown
Contributor Author

Is this something you found yourself needing?

ish, setting environment variables is fine, but they're all in one flat namespace, and we will eventually need to have flags and args for:

  1. redis stuff being removed
  2. new params for in memory and on disk storage
  3. acme requires a hostname and an email
  4. port is insufficient, we need both port and host, but tokio-listener style --listen-addr would be much more useful, especially with multiple listen directives
  5. ohttp key rotation behavior
  6. relay behavior
  7. tor support (HS and bridgeing)
  8. multihop relaying

so it seems to me we're starting to accumulate enough complexity that 12 factor maxxing approach can get a a bit unwieldly and a config file can be helpful, especially for manual testing (no need to make a script which is actually a config file in disguise)

and from a code pov IMO it would be easier to maintain all that if it's more structured and makes use of types, just for the 4 existing options main.rs i think there's kinda excessive boilerplate

@nothingmuch nothingmuch mentioned this pull request Aug 7, 2025
29 tasks
@nothingmuch nothingmuch force-pushed the directory-config branch 2 times, most recently from 7943fff to efc45ad Compare August 29, 2025 12:07
@nothingmuch nothingmuch marked this pull request as ready for review August 29, 2025 12:50
@nothingmuch nothingmuch marked this pull request as draft August 29, 2025 12:57
@nothingmuch
Copy link
Copy Markdown
Contributor Author

converted back to draft because of #981 dependency

@nothingmuch nothingmuch marked this pull request as ready for review August 29, 2025 13:10
Copy link
Copy Markdown
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

utACK efc45ad

The other 4 commits are already in master so this may need a rebase?

Copy link
Copy Markdown
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

reACK

@spacebear21 spacebear21 merged commit 2852395 into payjoin:master Aug 29, 2025
10 checks passed
@nothingmuch nothingmuch mentioned this pull request Aug 30, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants