mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
- Route Vertex partner/open MaaS models and explicit openapi-enabled credentials through the OpenAI-compatible endpoints/openapi endpoint while reusing service-account OAuth token acquisition and supporting openapi_location overrides. - Register Vertex service-account MaaS models and aliases from credential metadata and OAuth alias rules so partner models are discoverable and routable. - Normalize Vertex OpenAPI model identifiers and reject static API keys against official Google Vertex OpenAPI hosts that require OAuth tokens. Closes: #6763
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package auth
|
|
|
|
// CanonicalCredentialMetadataKey returns the canonical snake_case name for
|
|
// credential metadata keys that previously also accepted config-style aliases.
|
|
func CanonicalCredentialMetadataKey(key string) string {
|
|
switch key {
|
|
case "api-key":
|
|
return "api_key"
|
|
case "base-url":
|
|
return "base_url"
|
|
case "disable-cooling":
|
|
return "disable_cooling"
|
|
case "excluded-models":
|
|
return "excluded_models"
|
|
case "fingerprint-profile":
|
|
return "fingerprint_profile"
|
|
case "model-aliases":
|
|
return "model_aliases"
|
|
case "openapi-location":
|
|
return "openapi_location"
|
|
case "openapi-models":
|
|
return "openapi_models"
|
|
case "proxy-url":
|
|
return "proxy_url"
|
|
case "request-retry":
|
|
return "request_retry"
|
|
case "request-scoped-errors":
|
|
return "request_scoped_errors"
|
|
case "tool-prefix-disabled":
|
|
return "tool_prefix_disabled"
|
|
default:
|
|
return key
|
|
}
|
|
}
|
|
|
|
// NormalizeCredentialMetadata rewrites recognized legacy keys to their
|
|
// canonical snake_case names. An explicitly present canonical value wins.
|
|
func NormalizeCredentialMetadata(metadata map[string]any) {
|
|
for key, value := range metadata {
|
|
canonical := CanonicalCredentialMetadataKey(key)
|
|
if canonical == key {
|
|
continue
|
|
}
|
|
if _, exists := metadata[canonical]; !exists {
|
|
metadata[canonical] = value
|
|
}
|
|
delete(metadata, key)
|
|
}
|
|
}
|