mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-04-26 02:56:11 +00:00
fix(vertex): include prefix in auth filename and validate at import
Address two blocking issues from PR review:
- Auth file now named vertex-{prefix}-{project}.json so importing the
same project with different prefixes no longer overwrites credentials
- Prefix containing "/" is rejected at import time instead of being
silently ignored at runtime
- Add prefix to in-memory metadata map for consistency
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -54,4 +54,4 @@ _bmad-output/*
|
|||||||
.beads/
|
.beads/
|
||||||
.opencode/
|
.opencode/
|
||||||
.cli-proxy-api/
|
.cli-proxy-api/
|
||||||
.venv/
|
.venv/
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ type VertexCredentialStorage struct {
|
|||||||
// Type is the provider identifier stored alongside credentials. Always "vertex".
|
// Type is the provider identifier stored alongside credentials. Always "vertex".
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
|
||||||
// Prefix optionally namespaces models for this credential (e.g., "teamA/gemini-2.0-flash").
|
// Prefix optionally namespaces models for this credential (e.g., "teamA").
|
||||||
|
// This results in model names like "teamA/gemini-2.0-flash".
|
||||||
Prefix string `json:"prefix,omitempty"`
|
Prefix string `json:"prefix,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,14 +62,28 @@ func DoVertexImport(cfg *config.Config, keyPath string, prefix string) {
|
|||||||
// Default location if not provided by user. Can be edited in the saved file later.
|
// Default location if not provided by user. Can be edited in the saved file later.
|
||||||
location := "us-central1"
|
location := "us-central1"
|
||||||
|
|
||||||
fileName := fmt.Sprintf("vertex-%s.json", sanitizeFilePart(projectID))
|
// Normalize and validate prefix: must be a single segment (no "/" allowed).
|
||||||
|
prefix = strings.TrimSpace(prefix)
|
||||||
|
prefix = strings.Trim(prefix, "/")
|
||||||
|
if prefix != "" && strings.Contains(prefix, "/") {
|
||||||
|
log.Errorf("vertex-import: prefix must be a single segment (no '/' allowed): %q", prefix)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include prefix in filename so importing the same project with different
|
||||||
|
// prefixes creates separate credential files instead of overwriting.
|
||||||
|
baseName := sanitizeFilePart(projectID)
|
||||||
|
if prefix != "" {
|
||||||
|
baseName = sanitizeFilePart(prefix) + "-" + baseName
|
||||||
|
}
|
||||||
|
fileName := fmt.Sprintf("vertex-%s.json", baseName)
|
||||||
// Build auth record
|
// Build auth record
|
||||||
storage := &vertex.VertexCredentialStorage{
|
storage := &vertex.VertexCredentialStorage{
|
||||||
ServiceAccount: sa,
|
ServiceAccount: sa,
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
Email: email,
|
Email: email,
|
||||||
Location: location,
|
Location: location,
|
||||||
Prefix: strings.TrimSpace(prefix),
|
Prefix: prefix,
|
||||||
}
|
}
|
||||||
metadata := map[string]any{
|
metadata := map[string]any{
|
||||||
"service_account": sa,
|
"service_account": sa,
|
||||||
@@ -77,6 +91,7 @@ func DoVertexImport(cfg *config.Config, keyPath string, prefix string) {
|
|||||||
"email": email,
|
"email": email,
|
||||||
"location": location,
|
"location": location,
|
||||||
"type": "vertex",
|
"type": "vertex",
|
||||||
|
"prefix": prefix,
|
||||||
"label": labelForVertex(projectID, email),
|
"label": labelForVertex(projectID, email),
|
||||||
}
|
}
|
||||||
record := &coreauth.Auth{
|
record := &coreauth.Auth{
|
||||||
|
|||||||
Reference in New Issue
Block a user