|
| 1 | +# AGENTS.md — Notes for AI coding agents |
| 2 | + |
| 3 | +## Project overview |
| 4 | + |
| 5 | +**fbadmin** is a Rust CLI for Firebase Authentication administration. It wraps the `rs-firebase-admin-sdk` crate and provides subcommands for user management, custom claims, auth action links, and emulator utilities. |
| 6 | + |
| 7 | +## Repository layout |
| 8 | + |
| 9 | +``` |
| 10 | +src/ |
| 11 | + main.rs # CLI struct (clap derive), arg parsing, command dispatch |
| 12 | + config.rs # Profile/config management (confy, TOML, local overrides) |
| 13 | + firebase.rs # AuthBackend enum, init_firebase() — SDK initialization |
| 14 | + output.rs # Render helpers: table, JSON, CSV, colored messages |
| 15 | + prompt.rs # Interactive prompts (dialoguer) for missing args |
| 16 | + errors.rs # IntoAnyhow trait for error-stack → anyhow conversion |
| 17 | + commands/ |
| 18 | + mod.rs # Re-exports |
| 19 | + users.rs # users get/create/disable/enable/remove/list/list-inactive/count |
| 20 | + claims.rs # claims get/merge/remove/clear/find |
| 21 | + links.rs # links password-reset/email-verify/sign-in |
| 22 | + emulator.rs # emulator clear-users/config |
| 23 | + config_cmd.rs # config init/add/remove/default/list/show/which/path |
| 24 | + info.rs # info — resolved connection + connectivity check |
| 25 | +build.rs # vergen-gitcl: embeds git SHA + build date into --version |
| 26 | +dist-workspace.toml # cargo-dist release configuration |
| 27 | +Cargo.toml # Dependencies, package metadata, profiles |
| 28 | +``` |
| 29 | + |
| 30 | +## Key patterns |
| 31 | + |
| 32 | +- **CLI structure**: All args are defined in `main.rs` via clap derive. Each command module has a `pub async fn run(cli: &Cli, command: &XxxCommand)` entry point. |
| 33 | +- **Error handling**: SDK calls return `Result<T, error_stack::Report<ApiClientError>>`. Use the `IntoAnyhow` trait (`.into_anyhow()`) to convert, then chain `.context("human-readable message")` for user-facing errors. |
| 34 | +- **Interactive prompts**: When a required arg is `None`, command modules call `prompt::resolve_email()` or similar. These use `dialoguer` and are TTY-aware. |
| 35 | +- **Output**: Always go through `output.rs` helpers (`render_single_record`, `render_table`, `render_success`, etc.) — they handle `--format` switching (table/json/csv) and colored output. |
| 36 | +- **Config resolution**: Profile is resolved from CLI flag → `FBADMIN_PROFILE` env → `default_profile` in config. Connection merges profile settings with CLI overrides. See `config::resolve_connection()`. |
| 37 | +- **Firebase init**: `firebase::init_firebase()` takes an `AuthBackend` enum (Emulator or Live with optional credentials/project). The `build_auth` helper in command modules wires config → AuthBackend → FirebaseAuth. |
| 38 | +- **Logging**: `tracing` with `tracing-subscriber`. Controlled by `-v` flag count. Logs go to stderr. Use `tracing::debug!` for internal details, `tracing::info!` for notable operations. |
| 39 | + |
| 40 | +## Build and run |
| 41 | + |
| 42 | +```bash |
| 43 | +cargo build # Debug build |
| 44 | +cargo run -- users list # Run with args |
| 45 | +cargo clippy # Lint |
| 46 | +cargo fmt # Format |
| 47 | +``` |
| 48 | + |
| 49 | +The project requires Rust 1.94+ (edition 2024). |
| 50 | + |
| 51 | +## Releasing |
| 52 | + |
| 53 | +See [docs/RELEASING.md](docs/RELEASING.md) for the full release process. Short version: |
| 54 | + |
| 55 | +1. Bump `version` in `Cargo.toml` |
| 56 | +2. Update `RELEASES.md` |
| 57 | +3. `git tag vX.Y.Z && git push origin main --tags` |
| 58 | + |
| 59 | +## Dependencies of note |
| 60 | + |
| 61 | +| Crate | Purpose | |
| 62 | +|-------|---------| |
| 63 | +| `rs-firebase-admin-sdk` | Firebase Auth SDK (community) | |
| 64 | +| `google-cloud-auth` | ADC / service account auth | |
| 65 | +| `clap` (derive) | CLI argument parsing | |
| 66 | +| `confy` | OS-appropriate config file management | |
| 67 | +| `dialoguer` | Interactive terminal prompts | |
| 68 | +| `comfy-table` | Table rendering | |
| 69 | +| `console` | TTY detection, colored/styled output | |
| 70 | +| `anyhow` + `error-stack` | Error handling layers | |
| 71 | +| `tracing` | Structured logging | |
| 72 | +| `vergen-gitcl` | Build-time git metadata | |
| 73 | + |
| 74 | +## Things to watch out for |
| 75 | + |
| 76 | +- **`rs-firebase-admin-sdk` is community-maintained** — check for API changes when updating. There is no official Rust Firebase SDK. |
| 77 | +- **`IntoAnyhow` trait** in `errors.rs` is the bridge between `error-stack` (used by the SDK) and `anyhow` (used everywhere else). Always use it for SDK calls. |
| 78 | +- **`build.rs`** uses `vergen-gitcl` which shells out to `git`. CI builds need git available. |
| 79 | +- **The `.docs/` directory** contains internal design documents and is gitignored. It's not shipped or published. |
| 80 | +- **Config file paths** are OS-dependent (managed by `confy`). Don't hardcode paths. |
| 81 | +- **Destructive commands** (`remove`, `clear`, `disable`) should always respect `--dry-run` and `--yes` flags. |
| 82 | + |
| 83 | +## License |
| 84 | + |
| 85 | +AGPL-3.0-only |
0 commit comments