caelum0x 77324a7b50 feat(ration): split gateway into auth/tenant-registry/card-issuance/webhook-ingestion
Phase 2 service decomposition per docs/SCALE-EXPANSION.md section 1: extracts
internal/{airwallex,bridge,card,tenant,httpserver} out of the monolithic
gateway into four independently deployable gRPC services (each own go.mod,
Dockerfile, and tests), with gateway now a thin BFF that fans out through new
cardissuanceclient/webhookeventsclient gRPC clients. gateway.proto's external
surface is unchanged — agent/tui/cli still talk to gateway exactly as before.

Verified: all 10 go.work modules build and `go test ./...` passes across
every one, including the new gateway client packages against the live split
services (via `make build && make test`).

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

69 lines
2.1 KiB
Go

package main
import (
"context"
"flag"
"fmt"
"time"
commonpb "github.com/caelum0x/ration/pkg/pb/common"
ledgerpb "github.com/caelum0x/ration/pkg/pb/ledger"
"github.com/caelum0x/ration/services/gateway/internal/idgen"
"github.com/caelum0x/ration/services/gateway/internal/ledgerclient"
)
// runSetup creates a fresh tenant with the given reserve floor, credits
// it with --fund minor units (so the subsequent load generator's
// DEBIT/HOLD ops have real headroom to actually contend over instead of
// bouncing off a zero balance every time), and prints exactly the new
// tenant ID to stdout — nothing else — so the calling shell script can
// capture it with `TENANT_ID="$("$LOADER_BIN" setup ...)"`.
func runSetup(args []string) error {
fs := flag.NewFlagSet("setup", flag.ContinueOnError)
addr := fs.String("addr", "", "ledger-core gRPC address")
reserveFloor := fs.Int64("reserve-floor", 10000, "tenant reserve floor, minor units")
fund := fs.Int64("fund", 1_000_000, "initial CREDIT to seed available balance, minor units")
if err := fs.Parse(args); err != nil {
return err
}
if *addr == "" {
return fmt.Errorf("--addr is required")
}
client, err := ledgerclient.Dial(*addr)
if err != nil {
return err
}
defer client.Close()
client.Timeout = 10 * time.Second
ctx := context.Background()
tenant, err := client.CreateTenant(ctx, &ledgerpb.CreateTenantRequest{
Name: idgen.New("chaos-tenant"),
Currency: "USD",
ReserveFloorMinorUnits: *reserveFloor,
})
if err != nil {
return fmt.Errorf("create tenant: %w", err)
}
if *fund > 0 {
if _, err := client.ApplyEntry(ctx, &ledgerpb.ApplyEntryRequest{
TenantId: tenant.GetId(),
Type: commonpb.LedgerEntryType_LEDGER_ENTRY_TYPE_CREDIT,
Amount: &commonpb.Money{
MinorUnits: *fund,
Currency: "USD",
},
Reference: "chaos-setup-fund",
IdempotencyKey: "chaos-setup-fund-" + tenant.GetId(),
Memo: "chaos test initial funding",
}); err != nil {
return fmt.Errorf("fund tenant: %w", err)
}
}
fmt.Println(tenant.GetId())
return nil
}