mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
feat(vertex): add usage source resolution for Vertex projects
Extend `resolveUsageSource` to support Vertex projects by extracting and normalizing `project_id` or `project` from the metadata for accurate source resolution.
This commit is contained in:
@@ -129,6 +129,21 @@ func apiKeyFromContext(ctx context.Context) string {
|
|||||||
|
|
||||||
func resolveUsageSource(auth *cliproxyauth.Auth, ctxAPIKey string) string {
|
func resolveUsageSource(auth *cliproxyauth.Auth, ctxAPIKey string) string {
|
||||||
if auth != nil {
|
if auth != nil {
|
||||||
|
provider := strings.TrimSpace(auth.Provider)
|
||||||
|
if strings.EqualFold(provider, "vertex") {
|
||||||
|
if auth.Metadata != nil {
|
||||||
|
if projectID, ok := auth.Metadata["project_id"].(string); ok {
|
||||||
|
if trimmed := strings.TrimSpace(projectID); trimmed != "" {
|
||||||
|
return trimmed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if project, ok := auth.Metadata["project"].(string); ok {
|
||||||
|
if trimmed := strings.TrimSpace(project); trimmed != "" {
|
||||||
|
return trimmed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if _, value := auth.AccountInfo(); value != "" {
|
if _, value := auth.AccountInfo(); value != "" {
|
||||||
return strings.TrimSpace(value)
|
return strings.TrimSpace(value)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user