diff --git a/.gitignore b/.gitignore index 38152671..858577d0 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,4 @@ _bmad-output/* .beads/ .opencode/ .cli-proxy-api/ -.venv/ \ No newline at end of file +.venv/ diff --git a/internal/auth/vertex/vertex_credentials.go b/internal/auth/vertex/vertex_credentials.go index 3ae3288e..9f830994 100644 --- a/internal/auth/vertex/vertex_credentials.go +++ b/internal/auth/vertex/vertex_credentials.go @@ -31,7 +31,8 @@ type VertexCredentialStorage struct { // Type is the provider identifier stored alongside credentials. Always "vertex". 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"` } diff --git a/internal/cmd/vertex_import.go b/internal/cmd/vertex_import.go index 034906ac..4aa0d74b 100644 --- a/internal/cmd/vertex_import.go +++ b/internal/cmd/vertex_import.go @@ -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. 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 storage := &vertex.VertexCredentialStorage{ ServiceAccount: sa, ProjectID: projectID, Email: email, Location: location, - Prefix: strings.TrimSpace(prefix), + Prefix: prefix, } metadata := map[string]any{ "service_account": sa, @@ -77,6 +91,7 @@ func DoVertexImport(cfg *config.Config, keyPath string, prefix string) { "email": email, "location": location, "type": "vertex", + "prefix": prefix, "label": labelForVertex(projectID, email), } record := &coreauth.Auth{