Skip to content

Commit 8fe7fdc

Browse files
authored
profiles,tui: use automatic values for Vertex project/region (#11)
- replace the request for a vertex Project ID from the user - use Aperture magic macros where it will inject the Project ID based on backend auth data
1 parent 0a24371 commit 8fe7fdc

6 files changed

Lines changed: 36 additions & 193 deletions

File tree

internal/profiles/claude_code.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
// ClaudeCodeProfile implements Profile for the `claude` CLI tool.
1313
type ClaudeCodeProfile struct {
14-
vertexProjectID string
1514
}
1615

1716
func (c *ClaudeCodeProfile) Name() string { return "Claude Code" }
@@ -55,8 +54,6 @@ func (c *ClaudeCodeProfile) Uninstall() func() error {
5554
}
5655
}
5756

58-
func (c *ClaudeCodeProfile) SetVertexProjectID(id string) { c.vertexProjectID = id }
59-
6057
func (c *ClaudeCodeProfile) YoloArgs() []string {
6158
return []string{"--dangerously-skip-permissions"}
6259
}
@@ -191,10 +188,10 @@ func (c *ClaudeCodeProfile) Env(apertureHost string, b Backend) (map[string]stri
191188
}, nil
192189
case BackendVertex:
193190
return map[string]string{
194-
"CLOUD_ML_REGION": "global",
191+
"CLOUD_ML_REGION": "_aperture_auto_vertex_region_",
195192
"CLAUDE_CODE_USE_VERTEX": "1",
196193
"CLAUDE_CODE_SKIP_VERTEX_AUTH": "1",
197-
"ANTHROPIC_VERTEX_PROJECT_ID": c.vertexProjectID,
194+
"ANTHROPIC_VERTEX_PROJECT_ID": "_aperture_auto_vertex_project_id_",
198195
"ANTHROPIC_VERTEX_BASE_URL": apertureHost + "/v1",
199196
}, nil
200197
default:

internal/profiles/opencode.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
// OpenCodeProfile implements Profile for the `opencode` CLI tool.
1212
type OpenCodeProfile struct {
13-
vertexProjectID string
1413
}
1514

1615
func (o *OpenCodeProfile) Name() string { return "OpenCode" }
@@ -49,8 +48,6 @@ func (o *OpenCodeProfile) Uninstall() func() error {
4948
}
5049
}
5150

52-
func (o *OpenCodeProfile) SetVertexProjectID(id string) { o.vertexProjectID = id }
53-
5451
func (o *OpenCodeProfile) SupportedBackends() []Backend {
5552
return []Backend{
5653
{Type: BackendAnthropic, DisplayName: "Anthropic API"},
@@ -92,8 +89,8 @@ func (o *OpenCodeProfile) Env(apertureHost string, b Backend) (map[string]string
9289
}, nil
9390
case BackendVertex:
9491
return map[string]string{
95-
"GOOGLE_CLOUD_PROJECT": o.vertexProjectID,
96-
"GOOGLE_CLOUD_LOCATION": "global",
92+
"GOOGLE_CLOUD_PROJECT": "_aperture_auto_vertex_project_id_",
93+
"GOOGLE_CLOUD_LOCATION": "_aperture_auto_vertex_region_",
9794
}, nil
9895
case BackendOpenAI:
9996
return map[string]string{
@@ -134,8 +131,8 @@ func (o *OpenCodeProfile) WriteConfig(apertureHost string, b Backend) (string, s
134131
case BackendVertex:
135132
providerKey = "google-vertex"
136133
options = map[string]string{
137-
"project": o.vertexProjectID,
138-
"location": "global",
134+
"project": "_aperture_auto_vertex_project_id_",
135+
"location": "_aperture_auto_vertex_region_",
139136
"baseURL": apertureHost + "/v1",
140137
}
141138
case BackendOpenAI:

internal/profiles/profiles.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ type YoloProfile interface {
4545
YoloArgs() []string
4646
}
4747

48-
// VertexConfigurer is implemented by profiles that use a Google Cloud
49-
// project ID for the Vertex backend.
50-
type VertexConfigurer interface {
51-
SetVertexProjectID(id string)
52-
}
53-
5448
// ProviderInfo mirrors the JSON response from GET /api/providers.
5549
type ProviderInfo struct {
5650
ID string `json:"id"`

internal/profiles/profiles_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func TestLauncher_ClaudeCode_Env_Bedrock(t *testing.T) {
6262

6363
func TestLauncher_ClaudeCode_Env_Vertex(t *testing.T) {
6464
p := &profiles.ClaudeCodeProfile{}
65-
p.SetVertexProjectID("my-test-project")
6665
b := profiles.Backend{Type: profiles.BackendVertex, DisplayName: "Google Vertex"}
6766

6867
env, err := p.Env(testHost, b)
@@ -71,9 +70,9 @@ func TestLauncher_ClaudeCode_Env_Vertex(t *testing.T) {
7170
}
7271

7372
want := map[string]string{
74-
"CLOUD_ML_REGION": "global",
73+
"CLOUD_ML_REGION": "_aperture_auto_vertex_region_",
7574
"CLAUDE_CODE_USE_VERTEX": "1",
76-
"ANTHROPIC_VERTEX_PROJECT_ID": "my-test-project",
75+
"ANTHROPIC_VERTEX_PROJECT_ID": "_aperture_auto_vertex_project_id_",
7776
"ANTHROPIC_VERTEX_BASE_URL": testHost + "/v1",
7877
}
7978
for k, wantV := range want {
@@ -159,16 +158,15 @@ func TestLauncher_OpenCode_Env_Bedrock(t *testing.T) {
159158

160159
func TestLauncher_OpenCode_Env_Vertex(t *testing.T) {
161160
p := &profiles.OpenCodeProfile{}
162-
p.SetVertexProjectID("my-test-project")
163161
env, err := p.Env(testHost, profiles.Backend{Type: profiles.BackendVertex})
164162
if err != nil {
165163
t.Fatalf("Env returned error: %v", err)
166164
}
167-
if got := env["GOOGLE_CLOUD_PROJECT"]; got != "my-test-project" {
168-
t.Errorf("GOOGLE_CLOUD_PROJECT = %q, want %q", got, "my-test-project")
165+
if got := env["GOOGLE_CLOUD_PROJECT"]; got != "_aperture_auto_vertex_project_id_" {
166+
t.Errorf("GOOGLE_CLOUD_PROJECT = %q, want %q", got, "_aperture_auto_vertex_project_id_")
169167
}
170-
if got := env["GOOGLE_CLOUD_LOCATION"]; got != "global" {
171-
t.Errorf("GOOGLE_CLOUD_LOCATION = %q, want %q", got, "global")
168+
if got := env["GOOGLE_CLOUD_LOCATION"]; got != "_aperture_auto_vertex_region_" {
169+
t.Errorf("GOOGLE_CLOUD_LOCATION = %q, want %q", got, "_aperture_auto_vertex_region_")
172170
}
173171
}
174172

@@ -189,7 +187,6 @@ func TestLauncher_OpenCode_WriteConfig(t *testing.T) {
189187
t.Setenv("XDG_CONFIG_HOME", filepath.Join(tmp, ".config"))
190188

191189
p := &profiles.OpenCodeProfile{}
192-
p.SetVertexProjectID("my-test-project")
193190

194191
cw, ok := profiles.Profile(p).(profiles.ConfigWriter)
195192
if !ok {
@@ -225,8 +222,8 @@ func TestLauncher_OpenCode_WriteConfig(t *testing.T) {
225222
backend: profiles.Backend{Type: profiles.BackendVertex},
226223
wantKey: "google-vertex",
227224
wantOptions: map[string]string{
228-
"project": "my-test-project",
229-
"location": "global",
225+
"project": "_aperture_auto_vertex_project_id_",
226+
"location": "_aperture_auto_vertex_region_",
230227
"baseURL": testHost + "/v1",
231228
},
232229
},

internal/profiles/settings.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const defaultLocation = "http://ai"
1010

1111
// Endpoint holds the URL and per-endpoint configuration for an Aperture proxy.
1212
type Endpoint struct {
13-
URL string `json:"url"`
14-
VertexProjectID string `json:"vertexProjectID,omitempty"`
13+
URL string `json:"url"`
1514
}
1615

1716
// Settings holds persistent launcher configuration managed by the user.

0 commit comments

Comments
 (0)