mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
Restructure the provider management system by separating the monolithic Provider model into two distinct entities: - ProviderGroup: defines shared upstream configuration (type, base_url, google settings, models, status) - APIKey: represents individual credentials within a group (api_key, weight, status, auto_ban, ban settings) This change also updates: - Binding model to reference GroupID instead of RouteGroup string - All CRUD handlers for the new provider-group and api-key endpoints - Sync service to rebuild provider snapshots from joined tables - Model registry to aggregate capabilities across group/key pairs - Access handler to validate namespace existence and subset constraints - Migration importer to handle the new schema structure - All related tests to use the new model relationships BREAKING CHANGE: Provider API endpoints replaced with /provider-groups and /api-keys endpoints; Binding.RouteGroup replaced with Binding.GroupID
99 lines
3.2 KiB
Go
99 lines
3.2 KiB
Go
package migrate
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// ExportResult represents the complete export output.
|
|
type ExportResult struct {
|
|
Version string `json:"version"`
|
|
Source Source `json:"source"`
|
|
Data Data `json:"data"`
|
|
Warnings []string `json:"warnings,omitempty"`
|
|
}
|
|
|
|
// Source represents the source system information.
|
|
type Source struct {
|
|
Type string `json:"type"`
|
|
Version string `json:"version"`
|
|
ExportedAt time.Time `json:"exported_at"`
|
|
}
|
|
|
|
// Data contains all exported entities.
|
|
type Data struct {
|
|
Providers []Provider `json:"providers,omitempty"`
|
|
Masters []Master `json:"masters,omitempty"`
|
|
Keys []Key `json:"keys,omitempty"`
|
|
Bindings []Binding `json:"bindings,omitempty"`
|
|
}
|
|
|
|
// Provider represents an EZ-API provider (mapped from New API channel).
|
|
type Provider struct {
|
|
OriginalID int `json:"original_id"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
BaseURL string `json:"base_url,omitempty"`
|
|
APIKey string `json:"api_key"`
|
|
Models []string `json:"models,omitempty"`
|
|
PrimaryGroup string `json:"primary_group"`
|
|
AllGroups []string `json:"all_groups,omitempty"`
|
|
Weight int `json:"weight"`
|
|
Priority int `json:"priority,omitempty"`
|
|
Status string `json:"status"`
|
|
AutoBan bool `json:"auto_ban"`
|
|
|
|
IsMultiKey bool `json:"is_multi_key,omitempty"`
|
|
MultiKeyIndex int `json:"multi_key_index,omitempty"`
|
|
OriginalName string `json:"original_name,omitempty"`
|
|
|
|
Original json.RawMessage `json:"_original,omitempty"`
|
|
}
|
|
|
|
// Master represents an EZ-API master (inferred from New API user).
|
|
type Master struct {
|
|
Name string `json:"name"`
|
|
Group string `json:"group"`
|
|
Namespaces []string `json:"namespaces,omitempty"`
|
|
DefaultNamespace string `json:"default_namespace,omitempty"`
|
|
MaxChildKeys int `json:"max_child_keys,omitempty"`
|
|
GlobalQPS int `json:"global_qps,omitempty"`
|
|
Status string `json:"status"`
|
|
|
|
SourceUserID int `json:"_source_user_id"`
|
|
SourceEmail string `json:"_source_email,omitempty"`
|
|
}
|
|
|
|
// Key represents an EZ-API key (mapped from New API token).
|
|
type Key struct {
|
|
MasterRef string `json:"master_ref"`
|
|
OriginalToken string `json:"original_token"`
|
|
Group string `json:"group,omitempty"`
|
|
Status string `json:"status"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
Namespaces []string `json:"namespaces,omitempty"`
|
|
|
|
ModelLimitsEnabled bool `json:"model_limits_enabled,omitempty"`
|
|
ModelLimits []string `json:"model_limits,omitempty"`
|
|
|
|
ExpiresAt *time.Time `json:"expires_at,omitempty"`
|
|
|
|
AllowIPs []string `json:"allow_ips,omitempty"`
|
|
|
|
QuotaLimit *int64 `json:"quota_limit,omitempty"`
|
|
QuotaUsed *int64 `json:"quota_used,omitempty"`
|
|
UnlimitedQuota bool `json:"unlimited_quota,omitempty"`
|
|
|
|
OriginalID int `json:"_original_id"`
|
|
TokenPlaintextAvailable bool `json:"_token_plaintext_available,omitempty"`
|
|
}
|
|
|
|
// Binding represents an EZ-API binding (optional, from abilities).
|
|
type Binding struct {
|
|
Namespace string `json:"namespace"`
|
|
RouteGroup string `json:"route_group"` // provider group name
|
|
Model string `json:"model"`
|
|
Status string `json:"status"`
|
|
}
|