Commit Graph

79 Commits

Author SHA1 Message Date
zenfun
96e1fe41a5 feat(models): add kind and models_meta snapshot 2025-12-17 23:15:12 +08:00
zenfun
2b0ed3d3d5 feat(api): align provider creation with presets/custom/google sdk 2025-12-17 22:19:17 +08:00
zenfun
174735f152 feat(api): add provider creation endpoints and weight support
- Add `POST /admin/providers/preset` for streamlined creation of official providers (OpenAI, Anthropic, Gemini)
- Add `POST /admin/providers/custom` for generic OpenAI-compatible providers
- Add `weight` field to provider model and DTOs to enable weighted routing
- Update sync service to propagate provider weights
- Add unit tests for new creation handlers
2025-12-17 21:40:54 +08:00
zenfun
5a4e63b75d test(service): add specs for binding synchronization
Add unit tests for the SyncBindings service covering exact matching,
regex selectors, and normalized matching logic using in-memory
dependencies (SQLite and MiniRedis) to ensure correct upstream
resolution.
2025-12-17 01:18:02 +08:00
zenfun
6d8a12df34 feat(api): add access control and binding endpoints
Add endpoints for master and key access management to configure default
and allowed namespaces, including propagation options.
Implement GET and DELETE operations for individual bindings.
Update sync service to persist bindings snapshots even when no upstreams
are available.
2025-12-17 01:08:01 +08:00
zenfun
16fceec8e7 style(core): align struct tags and fields
Standardize alignment of struct tags in models and field assignments in
services for better readability. Additionally, include the Binding model
in the test database auto-migration.
2025-12-17 00:51:02 +08:00
zenfun
ed6446e586 feat(api): add admin endpoints for binding management
Implement handlers for creating, listing, and updating model bindings.
Register new routes in the admin server group and add DTO definitions.
Update provider handlers to trigger binding synchronization on changes
to ensure upstream mappings remain current.
2025-12-17 00:37:02 +08:00
zenfun
2e3b471533 feat(core): implement namespace support and routing bindings
Introduce namespace-aware routing capabilities through a new Binding
model and updates to Master/Key entities.

- Add Binding model for configuring model routes per namespace
- Add DefaultNamespace and Namespaces fields to Master and Key models
- Update auto-migration to include Binding table
- Implement Redis synchronization for binding configurations
- Propagate namespace settings during master creation and key issuance
2025-12-17 00:33:36 +08:00
zenfun
aa69ce3659 feat(api): add admin endpoint to issue keys for masters
Add `POST /admin/masters/{id}/keys` allowing admins to issue child keys
on behalf of a master. Introduce an `issued_by` field in the Key model
to audit whether a key was issued by the master or an admin.

Refactor master service to use typed errors for consistent HTTP status
mapping and ensure validation logic (active status, group check) is
shared.
2025-12-15 15:59:33 +08:00
zenfun
11f6e81798 feat(api): add feature flag management endpoints
Add FeatureHandler to manage lightweight runtime configuration toggles
stored in the Redis `meta:features` hash. This enables dynamic control
over system behavior (e.g., storage backends) via the admin API.

- Add `GET /admin/features` to list flags
- Add `PUT /admin/features` to update flags
- Update README with feature flag documentation
2025-12-15 15:01:01 +08:00
zenfun
d1d1b1c42a refactor(deps): use foundation shared utilities 2025-12-14 23:52:46 +08:00
zenfun
71c183a480 test(service): add golden file validation and master key tests
- Update TESTING.md to reflect current testing status and future plans
- Add golden file comparison for provider snapshot validation in sync_test.go
- Introduce master_test.go for testing Master/Key functionality
- Add testdata directory for contract testing snapshots
2025-12-14 23:37:16 +08:00
zenfun
d0011f3eb2 test: add comprehensive unit tests for provider, middleware, and sync service
- Add TESTING.md documentation explaining unit test conventions and integration testing setup
- Add miniredis and sqlite dependencies to go.mod for in-memory testing
- Add provider_handler_test.go ensuring Vertex providers default google_location to "global"
- Add request_id_test.go verifying request ID generation and header preservation
- Add sync_test.go validating Redis snapshot writes and routing key generation
- Update README.md with testing section referencing new documentation
2025-12-14 00:35:35 +08:00
zenfun
531ac6e5a8 feat(telemetry): implement request tracing identifier
Introduce a middleware layer to attach a unique identifier to each HTTP request for observability purposes. The identifier is propagated via the X-Request-ID header, allowing for correlation of logs and events across distributed system components.
2025-12-13 23:49:58 +08:00
zenfun
a6b4306d08 feat(server): add request ID middleware
Add request ID middleware to trace requests through the system. The middleware checks for existing X-Request-ID headers, generates a new UUID if not present, and sets the ID in both request/response headers and Gin context.
2025-12-13 22:24:37 +08:00
zenfun
67df74e09a feat(provider): add google project and location fields
Add support for Google Cloud-specific configuration in provider models.
New fields `GoogleProject` and `GoogleLocation` are now included in the
Provider DTO, database model, API handlers, and sync service snapshots.

- Extend Provider struct in model with gorm/json tags
- Update ProviderDTO with omitempty JSON tags
- Include fields in handler create/update logic with trim
- Add fields to providerSnapshot for sync operations
2025-12-13 20:24:44 +08:00
zenfun
89cb74ba6e refactor(log): migrate from zerolog to structured slog with bridge
- Replace direct zerolog usage with standard library `log/slog` in business code
- Add `internal/logging` package with zerolog bridge handler for structured output
- Create `internal/jsoncodec` package to centralize JSON encoding/decoding using Sonic
- Update all services and main entry point to use new logging interface
- Maintain backward compatibility with existing zerolog console output
- Remove custom logger setup in favor of structured logging bridge
2025-12-13 16:50:56 +08:00
zenfun
305f2ebf18 feat(provider): add update endpoint and enforce status checks
Add `PUT /admin/providers/{id}` endpoint to allow updating provider
configurations, including status and ban details. Update synchronization
logic to exclude inactive or banned providers from routing tables to
ensure traffic is not routed to them.
2025-12-12 23:44:52 +08:00
zenfun
2407afe0e6 feat(provider): add status and banning mechanism
Introduce fields for managing provider status (active, auto_disabled,
manual_disabled) and banning logic.

- Add Status, AutoBan, BanReason, and BanUntil to Provider model and DTO
- Update CreateProvider handler to process new fields with defaults
- Extend sync service to propagate status and ban information in snapshots
- Serialize BanUntil as Unix timestamp for sync compatibility
2025-12-12 23:40:18 +08:00
zenfun
eaf99e1582 feat(config): migrate configuration management to viper
Replace manual environment variable parsing with Viper to support
file-based configuration.

- Enable loading config from `config.yaml` or `./config/config.yaml`
- Allow custom config path via `EZ_CONFIG_FILE` environment variable
- Bind existing environment variables to maintain backward compatibility
- Update documentation with configuration examples and precedence rules
2025-12-12 22:50:54 +08:00
zenfun
5891722526 feat(log): replace standard logger with zerolog
- Integrate `rs/zerolog` for structured and leveled logging
- Add `EZ_LOG_LEVEL` environment variable support (default: info)
- Configure console output with timestamps and service fields
- Migrate `main.go` and `LogWriter` to use the new logger instance
- Update README with logging configuration and design details
2025-12-12 22:39:10 +08:00
zenfun
5826db3954 perf(json): replace encoding/json with bytedance/sonic
Migrate all JSON marshaling and unmarshaling operations to use
github.com/bytedance/sonic for improved performance. This affects
adapters, middleware, proxy handlers, and the sync store.
2025-12-10 23:21:51 +08:00
770a9fef2b feat: Add Swagger documentation for admin and master API endpoints
- Added Swagger documentation for the following admin endpoints:
  - Create a new master tenant
  - Create a new provider
  - Register a new model
  - List all models
  - Update a model
  - Force sync snapshot
  - Ingest logs

- Added Swagger documentation for the master endpoint:
  - Issue a child key

- Updated go.mod and go.sum to include necessary dependencies for Swagger.
2025-12-05 15:01:35 +08:00
zenfun
25e5e105b3 feat(auth): enhance security with token hashing and sync integration
- Add token hash fields to Master and Key models for indexed lookups
- Implement SyncService integration in admin and master handlers
- Update master key validation with backward-compatible digest lookup
- Hash child keys in database and store token digests for Redis sync
- Add master metadata sync to Redis for balancer validation
- Ensure backward compatibility with legacy rows during migration
2025-12-05 00:17:22 +08:00
zenfun
8645b22b83 feat(auth): implement master key authentication system with child key issuance
Add admin and master authentication layers with JWT support. Replace direct
key creation with hierarchical master/child key system. Update database
schema to support master accounts with configurable limits and epoch-based
key revocation. Add health check endpoint with system status monitoring.

BREAKING CHANGE: Removed direct POST /keys endpoint in favor of master-based
key issuance through /v1/tokens. Database migration requires dropping old User
table and creating Master table with new relationships.
2025-12-05 00:16:47 +08:00
b8bd613f77 feat(provider): add Models field to ProviderDTO and update provider handling 2025-12-02 16:32:03 +08:00
zenfun
aa57af874c feat(core): implement group-based routing and optimize sync
Replace direct provider linkage with group-based routing for Keys and
Providers. This allows for more flexible load balancing and tiering
strategies.

Changes include:
- Remove `ProviderID` from Key model and DTO
- Add `Group` field to Key and Provider models
- Refactor Redis sync to use Hashes for O(1) partial updates
- Update API handlers to perform incremental syncs

BREAKING CHANGE: Key API payload no longer accepts `provider_id`. Redis
configuration storage format has changed from JSON strings to Hashes.
2025-12-02 14:49:03 +08:00
zenfun
64d71953a6 feat(server): implement management endpoints and redis sync
Enable full resource management via API and support data plane
synchronization.

- Add CRUD handlers for Providers, Models, and Keys using DTOs
- Implement LogWriter service for asynchronous, batched audit logging
- Update SyncService to snapshot full configuration state to Redis
- Register new API routes and initialize background services
- Add configuration options for logging performance tuning
2025-12-02 14:26:16 +08:00
zenfun
58dfe5e9ac feat(server): initialize project skeleton with db and api setup
Establish the foundational structure for the ez-api server.

Key changes include:
- Set up main entry point with graceful shutdown and Gin router
- Configure database connections for PostgreSQL (GORM) and Redis
- Define core data models (User, Provider, Key, Model)
- Implement configuration loading and basic key creation handler
- Add Dockerfile for multi-stage builds and .gitignore
2025-12-02 13:35:17 +08:00