Commit Graph

215 Commits

Author SHA1 Message Date
Ian Jackson 23c352b96b clippy: Consolidate many lints in maint/add_warning
Found these by disabling the nightly dbg macro special case.  Now, we
have a mechanism for globally adding suppressions to tests, we can use
that instead.
2022-06-24 14:23:38 +01:00
Ian Jackson 589c6e52bb Run maint/add_warning crates/*/src/{lib,main}.rs
Update all lint blocks
2022-06-23 19:15:42 +01:00
Nick Mathewson c39631af27 tor-config: style fixes on CfgPathError. 2022-06-22 08:36:13 -04:00
Nick Mathewson 37cbd38abc tor-config: Don't format source error as part of error message
This is one I missed earlier.
2022-06-22 08:23:33 -04:00
Ian Jackson 90ba8b15de impl_standard_builder: Allow for !Default 2022-06-16 15:42:06 +01:00
Ian Jackson c895057cb9 tor-config: impl_standard_builder: handle contexts with local Result 2022-06-16 15:27:00 +01:00
Ian Jackson baca49e087 config: Suppose that we might extend resolve_option to non-T::Default
As per point 3 in
  https://gitlab.torproject.org/tpo/core/arti/-/issues/488
2022-06-10 14:23:16 +01:00
Ian Jackson 77f33176c3 config: Do not strip_option for journald (and in future)
As per point 1 in
  https://gitlab.torproject.org/tpo/core/arti/-/issues/488
2022-06-10 14:23:13 +01:00
Dimitris Apostolou 8488192ba1
Fix typos 2022-06-05 18:47:51 +03:00
Ian Jackson 9f4fe6a484 tor-config: Fix a doc link
Nightly cargo doc complaints about this.
2022-06-01 15:48:45 +01:00
Ian Jackson 98ccd7e7e2 Merge branch 'lint' into 'main'
lints: Make lint blocks consistent and ensure they stay that way

Closes #469

See merge request tpo/core/arti!557
2022-05-31 18:27:53 +00:00
Ian Jackson 9aec60871c Merge branch 'config-test' into 'main'
arti config: Check that example config is exhaustive

See merge request tpo/core/arti!546
2022-05-31 16:33:27 +00:00
Ian Jackson 89c4f76b6c tor-config: Suppress unwrap lint in tests
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/546#note_2808892
2022-05-31 16:58:14 +01:00
Ian Jackson 5b684020ed tor-config: resolve_option tests: disable rsutfmt 2022-05-31 16:06:32 +01:00
Ian Jackson c2fa37c56a tor-config: Add comprehensive tests for resolve_option 2022-05-31 16:06:32 +01:00
Ian Jackson 4f42101554 lints: Add let_unit_value allow to all crates
From running add_warning, with manual picking of the right
hunks/lines.
2022-05-31 15:23:52 +01:00
Nick Mathewson f67c0eaf50 Merge branch 'tor-config-tests' into 'main'
Add a few coverage-based tests to tor-config.

See merge request tpo/core/arti!540
2022-05-31 14:08:51 +00:00
Nick Mathewson ca94ec72ef Add a few coverage-based tests to tor-config.
There's nothing major here, but it does fill in a few gaps.
2022-05-31 08:59:30 -04:00
Nick Mathewson 9fed0b39fa Merge branch 'dbg' into 'main'
Revert "Remove dbg!()s in tor-config"

See merge request tpo/core/arti!552
2022-05-31 12:38:59 +00:00
Ian Jackson ba0843da4a lints: Add lint block delimiters to every crate
This was the result of:
  maint/add_warning crates/*/src/{lib,main}.rs
and then manually curating the results.
2022-05-31 13:00:31 +01:00
Ian Jackson fbfaecdf72 config: Provide tor_config::resolve_option and resolve journald
Canonicalise the `logging.journald` setting in the validated
configuration.  Now it will never be `Some("")`, even if that is what
was written in the config file.

This allows us to write `journald = ""` in the example configuration.
(Without the canonicalisation the default builder produces `None` and
the example would produce `Some("")`, which are semantically identical
but fail the test.)

See https://gitlab.torproject.org/tpo/core/arti/-/issues/488 for some
background.
2022-05-30 16:00:45 +01:00
Ian Jackson b88c1c1093 tor-config: Drop Serialize and Deserialize from a test type
These violate our rule that *built* structs ought not to be desr.
But this is just in a test.
2022-05-30 16:00:45 +01:00
Orhun Parmaksız bfd41ddb5f
Lexically sort Cargo.toml dependencies
Utilize cargo-sort: https://github.com/DevinR528/cargo-sort

Signed-off-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2022-05-28 20:05:51 +03:00
Ian Jackson 35e3841e4c Revert "Remove dbg!()s in tor-config"
This was done because Nightly Rust complained about these, despite
them all being in tests.  That is now fixed upstream:
  https://github.com/rust-lang/rust-clippy/issues/8758
  https://github.com/rust-lang/rust-clippy/pull/8838

This reverts commit 9d26a91886.
2022-05-27 18:14:03 +01:00
Nick Mathewson 4326aa1de9 Regenerate version bump from previous commit.
This commit was made by reverting the previous commit, then
re-running the script I used to generate it.  In theory there should
be no semantic changes: only changes due to improved formatting from
cargo edit.
2022-05-27 10:18:52 -04:00
Nick Mathewson b232365a75 Semantic version changes for Arti 0.4.0 release
I followed the following procedure to make these changes:

* I used maint/changed_crates to find out which crates had changed
  since 0.3.0.
* I used grep and maint/list_crates to sort those crates in
  topological (dependency) order.
* I looked through semver_status to find which crates were listed as
  having semver-relevant changes (new APIs and breaking changes).
* I scanned through the git logs of the crates with no
  semver-relevant changes listed to confirm that, indeed, they had
  no changes.  For those crates, I incremented their patch-level
  version _without_ changing the version that other crates depend on.
* I scanned through the git logs of the crates with no
  semver-relevant changes listed to confirm that, indeed, they had
  no obvious breaking changes.
* I treated all crates that depend on `arti` and/or `arti-client` as
  having breaking changes.
* I identified crates that depend on crates that have changed, even
  if they have not changed themselves, and identified them as having
  a non-breaking change.
* For all of the crates, I used `cargo set-version -p $CRATE --bump
  $STATUS` (where `STATUS` is `patch` or `minor`) to update the
  versions, and the depended-upon versions.
2022-05-27 09:01:20 -04:00
Nick Mathewson fbc5218af6 Update tor-config README.md. 2022-05-27 08:34:52 -04:00
Nick Mathewson b4a87687f5 Fix a link with nightly rustdoc 2022-05-26 15:40:39 -04:00
Ian Jackson 4bf87d61ca Merge branch 'config-split' into 'main'
Break TorClientConfig out of ArtiConfig and warn on unknown config keys

Closes #459 and #417

See merge request tpo/core/arti!529
2022-05-26 10:40:43 +00:00
Ian Jackson c5a8e453b9 tor-config: load: clippy: adopt two suggestions
We can have mem::take, hooray.
2022-05-26 11:03:48 +01:00
Ian Jackson 42ccb68446 tor-config: load: Add missing "not".
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807331
2022-05-26 10:57:26 +01:00
Ian Jackson f5561c8cdb tor-config: load: Make UnrecognizedKeys not pub
This was a slip.

As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807330
2022-05-26 10:57:04 +01:00
Ian Jackson ed95d50d49 tor-config: load: Add reversed test 2022-05-25 19:15:47 +01:00
Ian Jackson ce96f0d9ce tor-config: Add duplicative doc comments as per review 2022-05-25 19:15:47 +01:00
Ian Jackson 21a064d4f8 tor-config: load: example: Document what it does and who might write it 2022-05-25 19:15:47 +01:00
Ian Jackson 3eab61603a tor-config: load: Add a newline
This makes the function a tiny bit clearer.
2022-05-25 19:15:47 +01:00
Ian Jackson bf97190a9f tor-config: load: Write actual definition of the Resolvable trait
This is not a doc comment because we don't want it to be public: it
must refer to private fields, etc.
2022-05-25 19:15:47 +01:00
Ian Jackson 2b65e1250e tor-config: load: Explain why not write out macro call n times 2022-05-25 19:15:47 +01:00
Ian Jackson 1ee2be9d6d tor-config: docs: add more docs about load, esp. traits 2022-05-25 19:15:47 +01:00
Ian Jackson 337b4a7231 tor-config: docs: add a lot of context and overview and xrefs 2022-05-25 19:15:47 +01:00
Ian Jackson 40b433d4ba tor-config: load: Avoid destructuring assignment
Not available in our MSRV.
2022-05-25 19:15:47 +01:00
Ian Jackson b552c4e2bf tor-config: load: Intersection: add more commentary 2022-05-25 19:15:47 +01:00
Ian Jackson 5661df823f tor-config: load: Drop a needless call to .into_iter()
I think this is a leftover from a previous version of this expression.
2022-05-25 19:15:47 +01:00
Ian Jackson a8a3661503 tor-config: load: Fix a misleading comment
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807070
2022-05-25 19:15:47 +01:00
Ian Jackson 964794bfa0 tor-config: load: Rename shorter_let
Instead of the wrong "prefix_len".  As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807068
2022-05-25 19:15:47 +01:00
Ian Jackson 26715c5550 tor-config: load: Docs 2022-05-25 19:15:47 +01:00
Ian Jackson 4f62c3ded1 tor-config: Typo fixes (as per review comments) 2022-05-25 19:15:47 +01:00
Ian Jackson 28c1f707a1 tor-config: load: Introduce UnrecognizedKeys enum
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807078

This is in fact much clearer than the Option.
2022-05-25 19:15:47 +01:00
Ian Jackson 151d28c90f Run rustfmt following renaming
Split into its own commit to avoid churn in the rename commits.
2022-05-25 16:41:50 +01:00
Ian Jackson 0803296bd6 tor-config: Rename resolve_return_unrecognized, ..._ignore_...
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807077
2022-05-25 16:41:05 +01:00
Ian Jackson 9f426e2c57 tor-config: Rename "ignored" to "unrecognized" throughout
As per review comments
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807076
2022-05-25 16:40:02 +01:00
Ian Jackson 4b0459d204 Merge branch 'bug475' into 'main'
ConfigurationSources: Allow config files to be world-readable.

Closes #475

See merge request tpo/core/arti!528
2022-05-25 14:23:12 +00:00
Ian Jackson 9c88158740 tor-config: Example for load module 2022-05-24 20:14:57 +01:00
Ian Jackson bb8e205b0d tor-config: Tests for ignored config key handling 2022-05-24 20:14:57 +01:00
Ian Jackson 09f26f2d68 tor-config: Track and (by default) warn on ignored config keys 2022-05-24 20:14:57 +01:00
Ian Jackson e1bc599db2 tor-config: Tests for support functions for tracking ignored keys 2022-05-24 20:14:57 +01:00
Ian Jackson 865ae13502 tor-config: Support functions for tracking ignored config keys
This turns out to need quite a complicated algorithm.
2022-05-24 20:14:57 +01:00
Ian Jackson 9e526aad7c Split TorClientConfig out of ArtiConfig, and Resolvable trait
This gets rid of `#[serde(flatten)]` which prevents serde_ignored (and
other kinds of introspection) from working properly.

The price is now that the toplevel has to deal with two configuration
objects.

The Resolvable trait is overkill right now, but is going to do More
Things in a moment.  In particular, we need the impl on tuples, so
that the whole config can be processed in one go.
2022-05-24 20:14:57 +01:00
Ian Jackson 687e5c369e tor-config: Introduce Builder trait and ConfigReolveError
We are going to need this for some generic code which is going to
appear shortly.  Having it produced by impl_standard_builder seems
best.  But that does mean being able to disable it, so extra stuff in
the macro.  Nothing uses this trait yet.

ConfigResolveError is not used now either, but will be in a moment.
2022-05-24 20:08:40 +01:00
Ian Jackson fcdac71be7 tor-config: Add a lint allow
I don't understand why this isn't tripping all the time.  Maybe
because this is in a macro.  Anyway, I am going to add a new
invocation of this macro from within a test where, empirically, it
trips.
2022-05-24 20:08:40 +01:00
Nick Mathewson 5a5a828db6 ConfigurationSources: Allow config files to be world-readable.
Fixes #475.
2022-05-24 11:05:57 -04:00
Nick Mathewson 95200383b5 fs-mistrust: make Mistrust have a corresponding Builder type.
This is an approximately minimal revision to get Builder in place;
subsequent commits will clean up the API.
2022-05-24 10:54:02 -04:00
Nick Mathewson 994426d18c Add a couple of "pub use" to make nightly rustdoc pass. 2022-05-20 12:12:23 -04:00
Nick Mathewson 9d26a91886 Remove dbg!()s in tor-config
This should satisfy our CI and turn it green again.
2022-05-20 10:34:32 -04:00
Nick Mathewson 934de16098 Merge branch 'arti-config-2' into 'main'
Abolish arti-config, replacing with tombstone crate

See merge request tpo/core/arti!508
2022-05-13 12:30:24 +00:00
Ian Jackson b6b5d05e1b tor-config: Provide useful documentation for sources module 2022-05-13 12:42:30 +01:00
Ian Jackson 44d2f5ccfd arti-config abolition: Move functionality to tor-config
This crate no longer has any reason to exist.  All its remaining
functionality is generic enough to go into tor-config.

In this commit, we move the contents of lib.rs into a new file in
tor-config.  It contains:

 * Code motion
 * The minimal "mod" and "use" changes
 * The minimal doc comment
 * A new a compat alias for ConfigurationSources.

The compat alias is there because various crates currently speak of
arti_config::ConfigurationSources and it is most convenient to fix
them up after the type is available in tor_config.
2022-05-13 12:42:30 +01:00
Ian Jackson 9a3205aeba arti-config abolition: Add deps to tor-config
These are needed to support the code which is moving.
2022-05-13 12:41:27 +01:00
Ian Jackson 8f724ad767 impl_standard_builder: Better comments explaining the parser 2022-05-13 10:46:31 +01:00
Ian Jackson be5bc04c02 impl_standard_builder: Have it generate FooConfig::builder
This deletes many handcoded impls.  It also generates lots of impls
that we previously didn't have.
2022-05-12 18:50:26 +01:00
Ian Jackson 86a3e006d3 impl_standard_builder: Test the Deserialize impl
Test the Deserialize impl of every config struct.

This detects bugs like the one fixed in !502.

The macro now becomes more complex because it needs to take options.
Right now this tt-munching option parser is overkill, but this
leave space for further options in the future.
2022-05-12 18:50:26 +01:00
Ian Jackson c1c6f2b376 Rename impl_standard_builder from impl_default_via_builder
I have Plans for this macro.  In particular:

 * I have a wip branch which tests that the Builder can be
   deserialised from an empty config (ie, that config reading
   of a config with a blank section for this item works).

 * I think we should autogenerate $Config::builder(),
   and promote that, rather than $ConfigBuilder::default().
   This macro could do that.
2022-05-12 15:59:13 +01:00
eta 5990df53fe Merge branch 'arti-config-1' into 'main'
arti-config: Move cmdline to tor-config

See merge request tpo/core/arti!498
2022-05-12 13:07:43 +00:00
Ian Jackson 3420fe735d Define and use impl_default_via_builder 2022-05-11 18:27:15 +01:00
Ian Jackson ab3bd9d6d5 arti-config: Move cmdline to tor-config
This does not know anything about arti, only about TOML and Config.

Code motion, plus necessary import adjustments.
2022-05-11 18:23:05 +01:00
Ian Jackson 26b3115586 tor-config: Export CfgPathError
It is not clear to me how this `pub enum` survived the "inaccessible
pub" lint.
2022-05-11 15:53:03 +01:00
Nick Mathewson 7b93091f57 Bump the version of every* crate to 0.3.0
* Except for safelog and fs-mistrust, which are new.
2022-05-06 10:03:15 -04:00
Ian Jackson 030289481f Switch to derive_builder_arti_fork
For reference, the git source for this crate (and the others in its
workspace) currently lives in my personal github account (ijackson).
If this fork turns out to be long-lived and gains features and/or
users, it would be good to move it to a gitlab somewhere.

I have granted Nick crate ownership on the crates.io system.
2022-05-06 13:36:40 +01:00
eta de2b23642d Merge branch 'typos-20220504' into 'main'
Fix typos (using the typos-cli tool).

See merge request tpo/core/arti!486
2022-05-05 15:55:22 +00:00
Ian Jackson d47e94b459 config derive attrs: Make builders serde, and validated structs not
* Builders additionally derive: Debug, Serialize, Deserialize.

 * Validated structs no longer derive: Serialize, Deserialize
   and all related attributes deleted.

 * As a consequence, all the `#[serde(deny_unknown_fields)]`
   are gone.  That means that right now unknown fields are totally
   ignored.  This is good for compatibility but poor for useability.
   Doing something better here is arti#417, in progress.

 * As a consequence, delete tor_dirmgr::retry::default_parallelism.
   (The default value was already duplicated into a builder attr.)
2022-05-05 10:35:52 +01:00
Nick Mathewson fc33fc3efb Fix typos (using the typos-cli tool). 2022-05-04 14:41:50 -04:00
Ian Jackson df2813ed55 list_builder: Add some xrefs about macro_rules limitations
Apropos
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/474#note_2800481
2022-05-04 18:35:33 +01:00
Nick Mathewson cb892116dc Fix typo 2022-05-04 17:34:47 +00:00
Ian Jackson 2487a46ef0 list_builder: Provide VecBuilder
This is for lists of plain types (non-builder types).
2022-05-04 17:18:55 +01:00
Ian Jackson 221fe63430 list_builder: Use Educe to derive Default
This allows us to use this with an item builder type which doesn't
impl Default.  (Obviously this only makes sense for items which aren't
actually builders.)
2022-05-04 17:18:05 +01:00
Ian Jackson 578684f290 list_builder: Make helper capable of handling generics
It is Quite Vexing that we have to use [ ] rather than the < > around
the generics, particularly given that we are also using [ ] to signal
"this is arrayish".

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-05-04 17:17:46 +01:00
Ian Jackson 0c001ed60e list_builder: Actually honour attributes
The docs were a lie.  $docs_and_attrs was missing from the expander.

And add a note about how any supplied docs are handled.
2022-05-04 17:16:36 +01:00
Nick Mathewson d0330d2c95 Fix typos 2022-05-04 13:50:12 +01:00
Ian Jackson 4bca912715 Change builder list API
The new API is (roughly) as discussed in
  https://gitlab.torproject.org/tpo/core/arti/-/issues/451

This is quite a large commit and it is not convenient to split it up.
It contains the following changes:

 * Redo the list builder and accessor macros implemnetation,
   including docs and tests.

 * Change uses of define_list_config_builder.  In each case:
   - Move the docs about the default value to the containing field.
   - Remove the other docs (which were just recapitulations, and
     are now not needed since the ListBuilder is no longer public).
   - Rewmove or replace `pub` in the define_list_builder_helper call,
     so that the builder is no longer public.
   - Change the main macro call site to use define_list_builder_helper.
   - Add a call to define_list_builder_accessors.

 * Make the module `list_builder` pub so that we have somewhere to
   put the overview documentation.

 * Consequential changes:
   - Change `outer.inner().replace(X)` to `outer.set_inner(X)`
   - Consequential changes to imports (`use` statements).
2022-05-04 13:50:10 +01:00
Ian Jackson 71911d2921 Introduce ThingListBuilder::default_list
This removes a caveat from the API and will be convenient for what is
coming.
2022-05-04 13:48:30 +01:00
Ian Jackson 8ad4735d58 Add dependency on paste crate
The list accessor macro is going to want this.
2022-05-04 13:48:30 +01:00
Ian Jackson f4088a755c Fix config version
This matches Cargo.lock.  I suspect a mismerge in arti!478.
2022-05-04 13:39:18 +01:00
Ian Jackson 2da84857a5 CfgPath: Test serialisation round-trip with a binary format
Use MessagePack.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-05-03 17:42:54 +01:00
Ian Jackson 1e6c6169a8 CfgPath: Make it Serialize
And provide round-trip tests.

As per https://gitlab.torproject.org/tpo/core/arti/-/issues/371
2022-05-03 17:42:54 +01:00
Ian Jackson ed970310e2 CfgPath: Overhaul API
Document that this can contain either a string for expansion, or a
literal PathBuf not for expansion.

Rename the `from_path` method to `new_literal`: a very important
difference is whether it gets expanded - less important than the Rust
type.  Also, now it takes `Into<PathBuf>`, which avoids a needless
clone.

(We don't change the API in `arti-client` because
`&tempfile::Tempdir()` doesn't implement `Into<PathBuf>`, so
`arti-client` has to have some new `as_ref` calls.)

Provide accessors `as_unexpanded_str` and `as_literal_path`.  The
deserialisation already makes this part of the stable API,l so not
pvoding accessors seems just obstructive.  They are useful for tests,
too.

Add tests for the new entrypoints, and for deserialisation of both
variants from TOML (via config, or directly) and JSON.
2022-05-03 17:42:14 +01:00
Ian Jackson ae776392fa CfgPath: Change deserialisaation of Literal variant
We introduce LiteralPath struct, so that a literal path deserialises
from
    some_path = { literal: "actual path string" }

This makes the deserialisation unambiguous.
2022-05-03 17:42:14 +01:00
Ian Jackson a97ad69855 derive_builder: Use git dep everywhere, rather than cargo patch
The `[patch]` approach causes the tree not to build when used as a
dependency, unless the `[patch]` is replicated into the depending
project.

Instead, replace our `derive_builer =` dependencies with a reference
to a specific git commit:

  perl -i~ -pe 'next unless m/^derive_builder/; s#"(0\.11\.2)"#{ version = "$1", git = "https://github.com/ijackson/rust-derive-builder", rev = "ba0c1a5311bd9f93ddf5f5b8ec2a5f6f03b22fbe" }#' crates/*/Cargo.toml

Note that the commitid has changed.  This is because derive_builder is
in fact a workspace of 4 crates.  3 of them are of interest to arti
itself (the 4th exists only for testing).  So the same "add git
revision" treatment had to be done to the `derive_builder` and
`derive_builder_macro` crates.  Each dependency edge involves a new
commit in the derive_builder workspace, since we can't create a git
commit containing its own commitid.  (We want to use commits, rather
than a branch, so that what we are depending on is actually properly
defined, and not subject to the whims of my personal github
namespace.)

There are no actual code changes in derive_builder.
2022-04-27 14:57:59 +01:00
Nick Mathewson c1ea419477 Merge branch 'main' into 'msrv_1_56'
# Conflicts:
#   crates/tor-config/Cargo.toml
#   crates/tor-dirmgr/src/state.rs
#   doc/semver_status.md
2022-04-26 12:45:16 +00:00
Ian Jackson e81d215787 list-builder: Provide tests of all methods
Because the macro output is private, if we miss one out of the tests,
it doesn't fail due to dead code :-).
2022-04-25 18:24:28 +01:00
Ian Jackson c71046294b list_builder: Allow the struct to not be pub
Really, we probably don't want any of these not to be pub, but it
triggers "unreachable pub" in my test cases, and making it not pub by
mistake seems not very serious, and likely to be noticed.

Making the struct private in the test cases has the useful effect of
checking that all the methods are tested.
2022-04-25 18:24:06 +01:00