Repository navigation
feat(registry): configurable driver registries via TOML config - #360
Conversation
5a8bf36 to
5ac1ddd
Compare
0813c82 to
79e6f5c
Compare
79e6f5c to
40e5ad2
Compare
amoeba
left a comment
There was a problem hiding this comment.
I did a quick code review over the new pieces and left some comments. Even if we don't have an immediate use case for this, I think having it in dbc is useful.
Some other more general thoughts:
- Would we want CLI integration for this? I think it would be useful for dbc to be able to do all the work to show/add/remove registries from the project and user config.
- I didn't see any tests for how
dbc installwill work with this. Presumably dbc install will respect the new fields in the user config. - Do we need to define a default priority order for registries to handle name conflicts? We have a lot of the same concerns as conda does with channels. I'm wishing for more tests in this PR for the interaction between the default, user, and project registries around name conflicts.
Introduce RegistryEntry, GlobalConfig, LoadGlobalConfig, WithGlobalConfig, and WithProjectRegistries. NewClient now merges project, global, and default registries (project wins, then global, then defaults) with deduplication by scheme+host+path. WithBaseURL still overrides all other registry sources. Validation (empty URL, missing host, non-http scheme, replace_defaults=true with no entries) runs at NewClient time so malformed configuration surfaces immediately rather than at first request.
Extend DriversList with omitempty Registries and ReplaceDefaults fields so projects can pin or override driver registries inline in dbc.toml. Existing dbc.toml files without those keys continue to decode unchanged. applyProjectRegistries rebuilds the process-wide dbc client with the merged registry list; callers (add, sync) invoke it after decoding the list.
Load ~/.config/dbc/config.toml once at startup and thread it into the default client via WithGlobalConfig. Project commands (add, sync) rebuild the client with WithProjectRegistries after parsing dbc.toml so driver lookups use the merged registry list. DBC_BASE_URL continues to short circuit all registry merging. Tests cover project-registry wiring, invalid project URLs, and backwards-compatibility with dbc.toml files that omit the new fields.
a41a2ad to
5f8660a
Compare
Two issues from roborev review: - DriversList.ReplaceDefaults is now *bool so a project can explicitly set replace_defaults = false to override a global config's replace_defaults = true (previously collapsed into unset vs false). - NewClient now validates GlobalConfig.Registries URLs with the same path used for project registries, and rejects any configuration that produces an empty registry list (e.g. global replace_defaults = true with zero entries), so malformed config surfaces at NewClient time instead of at first request with silent zero-registry lookups. - LoadGlobalConfig applies the same no-entries check when decoding config.toml so CLI users see the error at startup.
…ries The existing TestAdd/TestSync project-registry tests route through testBaseModel, whose getDriverRegistry stub bypasses dbcClient entirely. Add direct coverage that swaps in a lookup routed to the real dbcClient against an httptest server, proving applyProjectRegistries genuinely rewires driver resolution to the merged registry list and that: - a project [[registries]] entry routes Search() to that server; - an explicit project replace_defaults=false restores built-in defaults even when the global config declared replace_defaults=true; - DBC_BASE_URL continues to short-circuit project registry overrides.
LoadGlobalConfig rejecting global replace_defaults=true with zero entries made the CLI diverge from NewClient: the CLI dropped the global config with only a warning, silently re-enabling the built-in defaults even when the project dbc.toml supplied the registries the user actually wanted. Remove that premature check; the post-merge empty-list guard in NewClient already catches the genuinely broken config (global replace_defaults=true with no entries AND no project entries), while letting the valid combination through. Adds both a library test and a CLI wiring test for the project-supplies-entries case.
Eager initDBCClient() in main() failed startup for the valid
'global replace_defaults=true + project supplies registries' case —
NewClient was called before the project dbc.toml could merge in.
Remove the eager call and rely on lazy init via getDriverRegistry /
initDBCClient, so project commands get a chance to rebuild the client
via applyProjectRegistries first.
Non-project commands (search, info, install) still fail fast on the
broken case (global replace_defaults=true with no entries and no
project override) because NewClient rejects the empty merge — now
surfaced at first use rather than startup.
auth.go's requestDeviceCode now ensures init before touching
dbcClient.HTTPClient(). dbcClientOnce is a pointer so tests can simulate
fresh startup.
Adds TestAddCmdEndToEndThroughRealClient which runs AddCmd.GetModel()
against an httptest registry — proves the production getDriverRegistry
closure routes through the rebuilt dbcClient. Adds TestStartupDeferred*
tests for the main() ordering invariants.
Also replaces 'switch { case err == ... }' with 'switch err' in main().
…in GetDriverList Two findings from roborev review of the branch: MEDIUM: OAuth device-code login ran through initDBCClient just to get an HTTPClient. A misconfigured global registry (e.g. replace_defaults=true with no entries) broke 'dbc auth login' — the very recovery path the user would run to fix the config. Add authHTTPClient() that builds a bare HTTP client without touching registry validation, and route device-code calls through it. LOW: GetDriverList decoded the new [[registries]] / replace_defaults fields but never called applyProjectRegistries, so library consumers using that helper silently ignored project registry overrides. Call it immediately after decoding. Regression tests pin both behaviors: - TestAuthHTTPClientDoesNotRequireRegistryConfig - TestGetDriverListHonorsProjectRegistries
Three findings from review of the branch: MEDIUM (1632): GetDriverList mutated the process-wide dbcClient via applyProjectRegistries, which leaked registry state across calls — a later invocation on a dbc.toml without [[registries]] would silently reuse the previous call's client. Switch GetDriverList to build a per-call dbc.Client scoped to the decoded file, so each call sees a fresh registry merge. Test exercises two sequential calls against two different servers to prove no leakage. MEDIUM (1630): NewClient's pre-merge guard rejected project replace_defaults=true with no project entries, even when the global config supplied registries. Remove the pre-merge guard; the post-merge empty-list check is the correct gate and lets 'drop defaults, keep globals' through. Test updated and new test pins the global-entries+project-replace_defaults case. LOW (1629): startup tests didn't exercise the real main() loading path. Extract loadStartupRegistryConfig() and add TestStartupEndToEndGlobalReplaceDefaultsWithProjectEntries that writes a real config.toml + dbc.toml, runs the full startup sequence, and drives AddCmd.GetModel() against an httptest server.
Addresses review 1633: MEDIUM: extract parseStartupArgs() and have main() use it, so the same config-load + argv-parse helper runs under test. The startup regression test now asserts at each step that dbcClient remains nil — if anyone reintroduces eager initDBCClient() between config load and subcommand dispatch the test fails at whichever step broke. LOW: update WithProjectRegistries doc comment to match the actual semantics: an error only when the MERGED registry list is empty. The old text claimed replace_defaults=true with no entries is always rejected, which contradicts the post-merge-only validation.
Addresses review 1634: the previous parseStartupArgs extraction only covered the parser bit. Anyone reintroducing an eager initDBCClient() between p.Parse() and GetModel() would still not have failed the test. Extract a single runStartup() that covers the full path main() runs: config load, argv parse, subcommand selection, and GetModel() for model commands. main() now calls runStartup() and switches on the returned startupKind for its exit cases. Tests drive runStartup() end-to-end, asserting dbcClient remains nil throughout. No functional change to main()'s behavior — same exit codes, same help and version paths, same subcommand dispatch.
Addresses review 1635: after the runStartup refactor, main() always
called runStartup(configDir, ...) even when internal.GetUserConfigPath
failed, leaving configDir = "". runStartup then forwarded that to
LoadGlobalConfig(""), which reads ./config.toml from the current
working directory. That changed registry resolution based on cwd — a
regression against the pre-refactor behavior that simply skipped the
load on this error path.
Guard runStartup to skip the load when configDir is empty. Document the
sentinel in the helper's doc comment. Add TestRunStartupSkipsLoadWhenConfigDirEmpty
that plants a hostile ./config.toml and asserts runStartup leaves
globalRegistryConfig nil.
Addresses review 1636: runStartup("", ...) skipped the load but did not
clear an already-primed globalRegistryConfig, so a second in-process
call would silently reuse the previous invocation's global registries.
Set globalRegistryConfig = nil explicitly in the empty-configDir branch
and add TestRunStartupClearsStaleGlobalConfigWhenConfigDirEmpty, which
primes the global before calling runStartup("") and asserts the
state is cleared.
…efault
Pins behavior at the boundary where the project, global (user), and
built-in default registry tiers interact. Covers both URL conflicts
(merge-level dedup) and driver-name conflicts (Search-level priority).
Library tests (registry_config_test.go):
- Extend TestMergeRegistries with cross-tier URL collision cases:
- project URL collides with default URL — project wins, default
URL dedup'd, project's Name kept;
- global URL collides with default URL — global wins;
- all three tiers share a URL — project wins, others dedup'd;
- project URL matches second default — only that one default URL
is dropped, the rest of the merge is preserved.
- TestSearchPriorityAcrossRegistryTiers — Client.Search returns
drivers in registry-priority order across three httptest servers
acting as project/global/default tiers. Confirms first-match-wins
in cmd/dbc.findDriver and Client.Install resolves cross-tier name
conflicts to the highest-priority tier. Constructs the Client
directly so the test isn't sensitive to whether the real built-in
default URLs are reachable from CI.
CLI tests (cmd/dbc/registry_wiring_test.go):
- TestApplyProjectRegistriesPreservesAllThreeTiersInOrder — when no
replace_defaults is set, dbcClient.Registries() exposes all three
tiers in [project, global, defaults...] order. Asserts the tail
is exactly the built-in defaults (project/global URLs are not
duplicated into it).
- TestApplyProjectRegistriesProjectReplaceDefaultsKeepsGlobal — pins
the asymmetric semantics of project replace_defaults=true: it
drops only the built-in defaults, NOT the global tier. A project
opting out of defaults still inherits the user's global registries.
- TestProjectRegistryShadowsGlobalOnDriverNameConflict — full CLI
wiring (applyProjectRegistries -> dbcClient.Search -> findDriver):
when project and global both publish a driver with the same path,
project wins and the resolved package URL comes from the project
tier's index. replace_defaults=true is set on the project so the
built-in defaults stay out of the merge — the all-three-tiers
case is covered by the ordering test above and by the library
TestSearchPriorityAcrossRegistryTiers.
|
@amoeba I addressed the comments, updated this, and added the tests that were mentioned. Let me know what you think |
Resolves conflict in cmd/dbc/main.go: ports the initVTProcessing() call added on main (#383) into the new main() that calls runStartup(), instead of the pre-refactor main() body that no longer exists on this branch.
|
the failing snapshot CI is an upstream snapd problem |
|
I pushed a tiny safeguard in 7cb0e41 since we now have user-injectable registry labels. Feel free to tweak. I think the last thing I'm not sure I like is that and they try to dbc add it, we suggest 'dbc search' but dbc search won't list drivers in the Is there any downside to simplifying the logic so the behavior is more consistent between the project-level and global dbc config? |
|
Can't think of a downside offhand, I agree that the behavior should be more consistent. I'll fix that |
Previously only `dbc add` and `dbc sync` applied the [[registries]] and replace_defaults configured in a project's dbc.toml; the read-only discovery commands (search, info, docs) queried only the global config and built-in defaults. This was confusing: when a driver isn't found, `dbc add` suggests running `dbc search`, but search couldn't see a driver served only by a project-configured registry, and replace_defaults in dbc.toml had no effect on search. search, info, and docs now load ./dbc.toml (when present) and apply its registries before querying, via a shared applyProjectRegistriesFromCWD helper. A missing dbc.toml is a no-op so these commands still work outside a project; a malformed one is a hard error naming the file. dbc install intentionally remains user-scope and does not read a project dbc.toml, since it installs into a user- or system-level config rather than the project.
applyProjectRegistriesFromCWD opened and decoded ./dbc.toml before newDBCClient could apply the DBC_BASE_URL short-circuit, so a malformed project dbc.toml made dbc search/info/docs fail even when the user had set DBC_BASE_URL to bypass registry configuration -- blocking the documented escape hatch in exactly the scenario where registry config may be broken. Return early (no-op) when DBC_BASE_URL is set, before touching dbc.toml. Adds a regression test covering DBC_BASE_URL plus a malformed dbc.toml.
|
@amoeba good call — addressed in 59a3514 (+ a follow-up in 2171cdf).
A missing On scope: I deliberately left One nuance worth flagging: Docs updated in |
amoeba
left a comment
There was a problem hiding this comment.
I just checked the final thing I noted was addressed. Can we back out the docs changes before merge and do the docs updates in a separate pr?
Move the driver-registry documentation to a separate PR (#393) so the docs can be reviewed and merged independently, per review feedback.
…uiltin_registries` (#598) Follow-up to #360. `replace_defaults` is named for replacing the built-in registries, which is no longer needed: with #595 a third-party registry can name its signing key and works like the built-in ones, and with #577 the built-in registries can be reached through a mirror. What the setting does is remove the built-in registries (the public and the private Columnar registry) while keeping the `[[registries]]` entries, so this renames it to `exclude_builtin_registries`. The user config now wins when it excludes them. ```toml exclude_builtin_registries = true [[registries]] url = "https://drivers.example.com" name = "example" ``` - **Semantics:** the built-in registries are excluded when either the user `config.toml` or the project's `dbc.toml` sets `exclude_builtin_registries = true`, and a project's `false` no longer adds them back. The CLI warns when a `dbc.toml` sets `false` that the user config overrides, and keeps that `false` when it writes the file back. The setting only stops dbc from adding the built-in registries to the list; it is not an access control, so a `[[registries]]` entry with a built-in registry's URL is still used. Omitting the key and `false` now mean the same thing in both files. - **Migration:** `replace_defaults` has not been released, so there is no alias. The old key is ignored like any other unknown key, so a `replace_defaults = true` written for a development build has to be renamed or the built-in registries are used again. - **Go API:** `GlobalConfig.ReplaceDefaults` becomes `ExcludeBuiltinRegistries`. `LoadProjectRegistries` returns a `bool` instead of a `*bool`, and `WithProjectRegistries` takes a `bool`, since there is no longer an "inherit" state. - **Docs:** adds a "Configuring registries" section to the driver registry concepts page and a "Registries" section to the driver list reference with the same content as #393, updated for the new key and semantics, so this supersedes #393. For drivers that several registries publish, they describe the behavior since #584 (the highest-priority registry that has a matching version).
Follow-up to #576. Custom registries (#360) can name the key their packages are signed with, so drivers from them no longer need `--no-verify`. This also turns on the signer check of #601 for these keys. Closes #613. ```toml [signing_keys.acme] type = "openpgp" public_key_file = "keys/acme.asc" # or public_key = "-----BEGIN PGP PUBLIC KEY BLOCK-----..." [[registries]] url = "https://drivers.acme.example.com" signing_key = "acme" # omitted: built-in Columnar key; false: unsigned registry ``` - **Config:** in the user `config.toml` and in `dbc.toml`. A `signing_key` name is resolved only in the file that declares the registry, so adding a key to the user config never changes what a project trusts. A project cannot declare a registry from the user config or a default registry (compared without query, user information or default port) with a different signing policy; that is an error. An omitted `signing_key` always means the built-in Columnar key. `columnar` is reserved. Registry URLs in these files reject empty interior path segments, `.` or `..` segments even when escaped, and escaped slashes, so that another spelling of a trusted registry's path cannot get past this check. Registry identities, including lockfile sources, omit default ports and normalize path escapes by decoding unreserved characters and uppercasing the remaining hex digits, preserving the distinction between escaped and literal reserved characters. - **Keys:** exactly one public certificate, armored (or binary in a file). Private keys, several keys or armor blocks, unknown packets and trailing data are rejected instead of skipped. A relative `public_key_file` is relative to the file that defines it; in `dbc.toml` it must stay inside the project directory (no absolute or UNC paths or `..` that leaves it, read through `os.Root`). The file is read only when its key is needed, also for the signer check, and the certificate read is reused for the rest of the operation; a failure is an error, never a fallback to another key. - **Signer check:** when several registries list a driver, or an index is missing, their signers must match (#601). Keys match only when their certificates are identical, and every unsigned registry is a signer of its own, so a missing index of an unsigned registry, or of one with a key the others do not share, stops new resolution of drivers without a `source`. The signer check, the verification and the lock pin of one operation use the same certificate, even if a `public_key_file` changes meanwhile. - **Lockfile:** the selected key's fingerprint is pinned as in #576, or `type = 'none'` for `signing_key = false`. Replay requires the registry's current configuration to select the same signer, also with `--no-verify`, so a lock entry can neither switch keys nor turn verification off on its own. Each unsigned registry counts as a separate signer, so a driver locked from one is not resolved again from another unsigned registry, even with a changed `source`. - **Install:** `dbc install` and `Client.Install` select the key from the registry of the chosen package before downloading it, so a driver that a later registry with the same key serves (#584) is verified with that registry's key. `--no-verify` / `AllowUnsigned` skip the signature check, but not the signer check of an implicit selection; local archives keep using the Columnar key. The `install` and `sync` JSON report `signature_verified`, and `verify.start` / `verify.complete` are only emitted when a signature is checked. - **API:** `Registry.Signing` (`RegistrySigningPolicy`, zero value = Columnar key) with `SignWith` / `Unsigned`, plus `NewSigningKey` and `Registry.ResolveSigningKey`. `RegistrySigningOperation` keeps the keys of one operation; its `ResolvePackage` replaces the unreleased function of the same name (#584, #601). The unreleased `LoadProjectRegistries` / `WithProjectRegistries` become `LoadProjectConfig` / `WithProjectConfig`, so key definitions and their file path travel with the registries. Bindings take `signingKey` on explicit registries (`registry.<n>.signing_key` in the C API). The policy only covers detached OpenPGP signatures of registry packages; another source such as Packslip would get its own policy and lock signer type.
dbc used registry priority for overrides (#360), and #584 kept that order when choosing the first registry with a matching version. This gave order precedence over version, much as uv's default `first-index` does to limit dependency confusion. The review of per-registry signing keys (#595) showed that registry order could also determine the signer, so #601 made cross-signer name collisions an error during implicit resolution. Within that signer boundary, dbc now picks the highest eligible version across registries, as pip does across indexes, so drivers keep getting updates after moving to another registry. - **Selection.** A candidate must satisfy the version requirements and have builds for every required target in one record. Registry order breaks ties at the highest SemVer precedence. In the winning registry, a second eligible record of the same precedence or any duplicate of the winning full version is an error. Exact requests include build metadata and reject duplicate exact records even when none covers all required targets. Errors in a selected artifact stop resolution. - **CLI.** New resolutions can select a newer version from a lower-priority registry. To take a driver from a specific registry, set its `source`. Compatible lock entries still replay from their recorded source. Successful CLI selections warn on stderr when a same-signer index was skipped. Registry version constraints now reject build metadata. - **v1 lock files.** If the recorded version is no longer listed, migration stops with or without `platforms`. A recorded version that lacks a build for a declared platform is still resolved again. - **Go API.** `Client.FetchIndex`, `Client.FetchRegistryIndex`, and `SelectRegistry` replace `SigningOperation.ResolvePackage`. Requests take a constraint or an exact version. The project planner decides whether to keep a locked version. `Index` aliases an internal type so public callers get complete snapshots from the client and cannot pass filtered search results; tests outside the module can serve an index through `NewClient` with `WithRegistries` and `WithHTTPClient`. - **Bindings.** `Resolve` reports the highest eligible stable version as `latest` and lists versions for the requested platform across reachable same-signer registries, including prereleases. Go and npm-wasm expose skipped indexes in `warning`. C and Rust warning support follows in #633. `Client.FetchRegistryIndex` requires exactly one configured endpoint match before fetching. This prevents it from picking a signing policy by list order when `WithRegistries` lists the same endpoint under different policies. The released `Driver` methods remain single-driver lookups. #634 aligns `GetPackage` with exact version matching and deprecates `GetWithConstraint`.
Summary
Adds support for configuring driver registries via TOML config files, allowing users to add custom registries at both the global (
~/.config/columnar/dbc/config.toml) and project (dbc.toml) level.What's New
~/.config/columnar/dbc/config.toml): loaded on every command viaConfigureRegistries()called inmain()dbc.toml):[[registries]]section respected bysyncandaddcommandsreplace_defaults = true: opt-in flag to suppress built-in registries entirelyDBC_BASE_URLenv var: still overrides everything (unchanged behavior)dbc.tomlfiles without[[registries]]work unchangedConfig Format
Global (
~/.config/columnar/dbc/config.toml):Project (
dbc.toml):Implementation Notes
http/httpsscheme and non-empty hostdefaultRegistriesis snapshotted eagerly ininit()(afterdrivers.goinit runs); env-sensitivity documented in commentsadd.godecodesdbc.tomlonce (single file open) for both registry config and driver listremoveintentionally omits registry wiring — it never queries a registry