4 Commits

Author SHA1 Message Date
9b4e470dce feat(sdk): rust-client had no credential story at all; add CloseCard to both SDKs
services/gateway's tenantauth interceptor defaults
RATION_GATEWAY_REQUIRE_TENANT_AUTH to true, but sdk/rust/ration-client
had zero way to attach any credential — no WithAPIKey/WithBearerToken
equivalent of what sdk/go/ration got in round 3. Every RPC the Rust SDK
made against a default-config gateway failed Unauthenticated; its own
doc.go-equivalent example never worked. Added CredentialInterceptor
(tonic Interceptor) plus Client::connect_with_api_key/
connect_with_bearer_token and from_channel_with_api_key/
from_channel_with_bearer_token, mirroring the Go SDK's dial-option
pattern.

Also closed a smaller parity gap found along the way: CloseCard
(round 11) was wired into gateway.proto/CLI but never added to either
official SDK, so an external platform customer importing sdk/go/ration
or sdk/rust/ration-client had no way to shut off a leaked/offboarded
card's spending via the SDK itself. Added Client.CloseCard (Go) and
Client::close_card (Rust).

Verified live against the real bare-metal 8-service stack
(scripts/start-individually.sh): a throwaway Go program using the real
sdk/go/ration module (replace-directive to this repo) issued a card
through the gateway, closed it, confirmed idempotent re-close, confirmed
AdjustCardLimit now correctly rejects the closed card, and confirmed an
unknown card_id fails the same way GetCard/AdjustCardLimit already do.
`ration status` showed the full $100 hold released back to Available.
Separately, a throwaway Rust binary against the real ration-client
crate (path dependency) first proved the pre-fix gap live (Client::connect
with zero credential against the real auth-required gateway ->
Unauthenticated), then used connect_with_api_key to run the identical
issue/close/idempotent-close/adjust-limit-rejected/unknown-card cycle
successfully, independently confirmed via `ration status` that the
$75 hold was released.

make build (full Rust+Go+SDK), go vet across every Go module, cargo
build --release, cargo clippy, cargo fmt all clean, 0 regressions.
cargo test for ration-client remains pre-existing-broken only on its
FakeGateway test fixture missing close_card/get_dashboard_snapshot
(round 3's already-flagged, intentionally-not-fixed gap, per the
no-test-infra-work standing rule) — unaffected by this change since
make build never runs cargo test for this crate.
2026-10-29 12:19:19 +03:00
92370eba5e feat(sdk,cli): self-serve API keys for Go SDK callers; fix(infra): docker-compose's missing AUTH_GRPC_ADDR/AUTH_ADDR broke every service but ledger-core
sdk/go/ration had no way to attach a credential, so its own README/doc.go
"Typical use" example was rejected with codes.Unauthenticated against any
default-config gateway (RATION_GATEWAY_REQUIRE_TENANT_AUTH defaults to
true) — nothing in this repo even called auth.IssueAPIKey before this.
Adds ration.WithAPIKey/WithBearerToken dial options (mirroring every
internal services/*/internal/authclient package's own interceptor
pattern) and a new `ration apikey issue` CLI command that actually mints
one via auth.IssueAPIKey. Verified live against a real running
auth+gateway+ledger-core+tenant-registry+card-issuance+webhook-ingestion
stack: no credential -> Unauthenticated, bad credential -> Unauthenticated
"invalid credential: not found", real minted credential -> IssueCard
succeeds end to end.

Also found, live, by actually running `docker compose up --build` for
real (not by reading code): gateway, card-issuance, tenant-registry,
webhook-ingestion, and agent all crash-looped forever in a plain
`docker compose up --build` — every one of them mints an operator JWT
from auth at startup and os.Exit(1)s if that fails, and none of their
compose service blocks set the env var each one's own config actually
reads (AUTH_GRPC_ADDR for all but gateway, which uniquely reads
AUTH_ADDR). Only ledger-core had this fixed previously (round 2). This
meant the entire containerized stack was non-functional end to end, not
just ledger-core's corner of it. Fixed all five; re-verified by tearing
the whole stack down and bringing it back up from scratch, seeding
tenants via `docker compose run --rm cli seed`, minting a real API key
via `docker compose run --rm cli apikey issue`, and issuing a card via
the Go SDK against the real containerized gateway on localhost:7002.

Also fixed a separate real bug in scripts/run-demo.sh's .env loader,
found live the same way: `IFS='=' read -r key value` silently drops a
single trailing IFS character, truncating any .env value ending in
exactly one '=' by one character — which is *every* `openssl rand
-base64 32` key (the exact command this repo's own docs recommend for
RATION_LEDGER_ENCRYPTION_KEY/AUTH_JWT_SIGNING_KEY), since a 32-byte
input always base64-encodes with exactly one padding '='. Reproduced
live: a real generated key crashed ledger-core at startup with
InvalidBase64(InvalidPadding) on a plain scripts/run-demo.sh run.
Switched to parameter-expansion splitting on the first '=' only;
re-verified the full run-demo.sh -> seed -> status cycle with a real
generated key, confirmed ledger.wal/ledger.db are genuine ciphertext
under the correct, untruncated key.

cargo test/go test/go vet all still pass (pre-existing, unrelated:
sdk/rust/ration-client's own #[cfg(test)] FakeGateway fixture doesn't
implement a newer Gateway trait method and fails to compile under
`cargo test` — a test-fixture-only gap, left alone per standing no-new-
test-work policy; production cargo build is unaffected).
2026-10-28 21:10:09 +03:00
8215fb82de feat(ration): add sdk/rust/ration-client, a typed Rust client for gateway.proto
Phase 2 section 7 (docs/SCALE-EXPANSION.md): the Rust counterpart to
sdk/go/ration — client-only tonic stubs for gateway.proto/common.proto
(build.rs also generates server stubs, same as ledger-core's build.rs does
for audit.proto, so this crate's own tests can stand up a fake Gateway
server with no network).

Verified: cargo build, cargo clippy --all-targets -- -D warnings (clean),
cargo fmt --check, cargo test (7 unit tests against an in-process duplex-pipe
gateway server + 1 doc-test), all passing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 12:54:25 +03:00
c5297e4466 feat(ration): add sdk/go/ration, a typed Go client for gateway.proto
Phase 2 section 7 (docs/SCALE-EXPANSION.md): thin ergonomic wrapper over
the generated Gateway gRPC client — IssueCard/AdjustCardLimit/GetCard/
ListCards/RequestBridgeFunding/SimulateDeposit/StreamActivity, re-exporting
Card/ActivityEvent/CardStatus directly from pkg/pb so callers never import
the generated stubs themselves.

Verified: go build/vet/test -race clean (7 tests against a bufconn-backed
fake Gateway server), and the full 11-module go.work still builds clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 12:47:59 +03:00