Skip to content

fix(database): post-#122 review followups - #184

Merged
chmmou merged 2 commits into
mainfrom
fix/database-write-followups
May 20, 2026
Merged

fix(database): post-#122 review followups#184
chmmou merged 2 commits into
mainfrom
fix/database-write-followups

Conversation

@chmmou

@chmmou chmmou commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses the Nice-to-haves the post-merge review of #122 (PR #183) surfaced for the database write slice.

  • Disjoint add/update flag bindings (databaseAddFlags / databaseUpdateFlags) — same wire-key surface, per-subcommand help text, unknown flag is a parse error.
  • Drop omitempty from Database.in_progress; align with majority of read modules.
  • Introduce database.InProgressFalse / database.InProgressTrue constants.
  • Align used_database_space rendering: list cells carry the " MB" suffix (matching singular); header is bare USED.
  • Per-field validation errors in database.Client.Add (replaces the combined message).
  • Extract databaseDeleteConfirm helper + export ConfirmAction.SummaryTestDatabasesDeleteConfirmIsLouder pins the louder "permanently delete" verb.
  • TestDatabasesDeleteDryRunEmitsAuditLine seals the runWriteE → WriteAudit glue for database delete (dry-run audit emission on stderr).

Pure refactor + test add — no behavioural change for any previously-valid CLI invocation.

Cross-slice parity for the same findings (ddns omitempty, account " MB" suffix, per-field validation across cronjob/ddns/ftpuser/mailforward/mailinglist/sambauser, docs/usage/destructive-writes.md page refactor) lands separately in the follow-up PR-B.

chmmou added 2 commits May 20, 2026 21:14
Address the Nice-to-haves the post-merge review of PR #183 surfaced:

- Split databases add/update flag bindings into disjoint
  databaseAddFlags / databaseUpdateFlags structs, mirroring the
  ddnsuser slice. The flag names stay identical, but each subcommand's
  --help describes the flags from its own perspective (initial vs
  replacement, required vs optional) and cobra rejects an unknown flag
  at parse time. New TestDatabasesFlagSetsAreDisjoint pins the
  boundary structurally.

- Drop omitempty from Database.in_progress so the JSON/YAML shape
  matches the majority of read modules (mailaccount, mailinglist,
  sambauser, ftpuser, account). The KAS API has returned in_progress
  on every captured fixture row, so the previous omitempty added
  drift without shielding callers from a missing key.

- Introduce database.InProgressFalse / .InProgressTrue constants for
  the literal "FALSE" / "TRUE" strings so mapping code and tests
  share one source of truth; the read tests now reference these
  constants instead of repeating the literal.

- Align the used_database_space rendering across views: the list
  cell now carries the " MB" unit as part of the value (matching the
  singular detail row), and the list header is now bare "USED" rather
  than the unit-bearing "USED_MB". One convention across both
  formats.

- Replace database.Client.Add's combined "non-empty password, comment
  and allowed_hosts" validation with per-field errors, so a caller
  hitting the domain validator (rather than the CLI's per-flag
  checks) can tell which field broke. The matching write_test
  asserts the per-field error substring.

- Extract databaseDeleteConfirm helper and export ConfirmAction.Summary
  so the louder "permanently delete" verb is pinned by a test
  (TestDatabasesDeleteConfirmIsLouder) rather than only a source-code
  comment. A subsequent refactor of either the slice or the shared
  ConfirmAction template cannot silently weaken the loudness contract.

- Add TestDatabasesDeleteDryRunEmitsAuditLine: pins that the runWriteE
  seam emits the #131 audit record on stderr even on --dry-run
  (outcome=dry-run action=delete_database target=<login>
  database_login=<login>), sealing the audit-emission path for the
  database delete subcommand without requiring an HTTP test scaffold.

Pure refactor + test add: behaviour for any previously-valid CLI
invocation is unchanged.
User-flagged correction on top of the post-#122 followups: the KAS
API treats an empty database_allowed_hosts as the documented "any
host may connect" wildcard, not as a missing parameter. The
domain-level Add validation and the CLI's --allowed-hosts required
check both rejected the empty value, which was wrong.

- internal/database/write.go: drop the AllowedHosts == "" check; doc
  on Spec records the wildcard semantics.
- internal/database/write_test.go: drop the "missing allowed_hosts"
  validation case; add a positive test asserting Add accepts an empty
  AllowedHosts and dispatches the wire call verbatim.
- internal/cli/databases.go: --allowed-hosts is now optional; the add
  command's --help (and the regenerated docs/cli/) documents that an
  omitted / empty value is the wildcard.
- internal/cli/databases_test.go: drop the "missing --allowed-hosts"
  rejection case; add TestDatabasesAddOptionalAllowedHosts pinning
  that the empty value reaches the dry-run preview's params with
  database_allowed_hosts = "" (the wildcard sent verbatim on the
  wire).
- CHANGELOG.md: amend the per-field-validation bullet to note the
  wildcard semantics change.
@chmmou
chmmou merged commit 75310be into main May 20, 2026
6 checks passed
@chmmou
chmmou deleted the fix/database-write-followups branch May 20, 2026 19:34
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.

1 participant