11// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4- //! Shared GCP constants for the metadata emulator, provider env injection,
5- //! and credential resolution.
4+ //! Shared destinations and environment keys used by the GCP metadata emulator.
65//!
7- //! This module is the single source of truth for GCP naming: env var aliases,
8- //! provider config keys, token search order, and Vertex-specific env vars.
9- //! `openshell-server`, `openshell-providers`, and `openshell-sandbox`
10- //! import from here.
6+ //! Provider environment defaults and discovery keys belong to imported
7+ //! profiles; this module holds only the names required by the supervisor's
8+ //! metadata protocol.
119
1210// ── Metadata emulator ───────────────────────────────────────────────────────
1311
@@ -23,72 +21,24 @@ pub fn is_metadata_destination(destination: std::net::SocketAddr) -> bool {
2321 destination == std:: net:: SocketAddr :: from ( ( [ 127 , 0 , 0 , 1 ] , 8174 ) )
2422}
2523
26- // ── Env var alias arrays ───── ───────────────────────────────────────────────
24+ // ── Metadata environment keys ───────────────────────────────────────────────
2725
2826/// Env vars that carry the GCP project ID inside sandboxes.
2927pub const PROJECT_ID_ENV_VARS : & [ & str ] = & [ "GCP_PROJECT_ID" , "GOOGLE_CLOUD_PROJECT" ] ;
3028
31- /// Env vars that carry the GCP region/location inside sandboxes.
32- pub const REGION_ENV_VARS : & [ & str ] = & [ "CLOUD_ML_REGION" , "GCP_LOCATION" ] ;
33-
3429/// Env vars that carry the GCP service account email inside sandboxes.
3530pub const SERVICE_ACCOUNT_EMAIL_ENV_VARS : & [ & str ] = & [ "GCP_SERVICE_ACCOUNT_EMAIL" ] ;
3631
37- // ── Provider config keys ────────────────────────────────────────────────────
38-
39- /// Config key for project ID in `gcp` providers.
40- pub const GCP_PROJECT_ID_CONFIG_KEY : & str = "project_id" ;
41-
42- /// Config key for region in `gcp` providers.
43- pub const GCP_REGION_CONFIG_KEY : & str = "region" ;
44-
45- /// Config key for service account email in `gcp` providers.
46- pub const GCP_SERVICE_ACCOUNT_EMAIL_CONFIG_KEY : & str = "service_account_email" ;
47-
4832// ── Token search order ──────────────────────────────────────────────────────
4933
5034/// GCP token env vars searched in priority order by the metadata emulator.
5135/// SA token wins over ADC if both are configured, matching GCP's own
5236/// credential precedence.
5337pub const TOKEN_ENV_KEYS : & [ & str ] = & [ "GCP_SA_ACCESS_TOKEN" , "GCP_ADC_ACCESS_TOKEN" ] ;
5438
55- // ── Vertex-specific env vars ────────────────────────────────────────────────
56-
57- /// Env var injected to signal Vertex AI usage to Goose.
58- pub const GOOSE_PROVIDER_ENV_VAR : & str = "GOOSE_PROVIDER" ;
59-
60- /// Env var for Anthropic Vertex project ID (consumed by Claude Code SDK).
61- pub const ANTHROPIC_VERTEX_PROJECT_ID_ENV_VAR : & str = "ANTHROPIC_VERTEX_PROJECT_ID" ;
62-
63- /// Env var for Vertex location (consumed by Claude Code SDK).
64- pub const VERTEX_LOCATION_ENV_VAR : & str = "VERTEX_LOCATION" ;
65-
66- /// Non-secret GCP/Vertex config vars that must be resolved to real values
67- /// in the child environment. Everything else stays as placeholders for
68- /// proxy-time resolution.
69- ///
70- /// This list MUST be the union of all alias arrays above plus all
71- /// Vertex-specific env vars. If you add an alias to `PROJECT_ID_ENV_VARS`,
72- /// `REGION_ENV_VARS`, or a Vertex constant, add it here too.
73- pub const STATIC_CONFIG_KEYS : & [ & str ] = & [
74- // project_id aliases
75- "GCP_PROJECT_ID" ,
76- "GOOGLE_CLOUD_PROJECT" ,
77- // region aliases
78- "CLOUD_ML_REGION" ,
79- "GCP_LOCATION" ,
80- // service account email
81- "GCP_SERVICE_ACCOUNT_EMAIL" ,
82- // Vertex-specific non-secret config
83- GOOSE_PROVIDER_ENV_VAR ,
84- ANTHROPIC_VERTEX_PROJECT_ID_ENV_VAR ,
85- VERTEX_LOCATION_ENV_VAR ,
86- ] ;
87-
8839#[ cfg( test) ]
8940mod tests {
9041 use super :: * ;
91- use std:: collections:: HashSet ;
9242
9343 #[ test]
9444 fn metadata_destination_matches_only_reserved_loopback_endpoint ( ) {
@@ -104,28 +54,4 @@ mod tests {
10454 assert ! ( !is_metadata_destination( address. parse( ) . unwrap( ) ) ) ;
10555 }
10656 }
107-
108- #[ test]
109- fn static_config_keys_matches_alias_arrays_and_vertex_vars ( ) {
110- let expected: HashSet < & str > = PROJECT_ID_ENV_VARS
111- . iter ( )
112- . chain ( REGION_ENV_VARS )
113- . chain ( SERVICE_ACCOUNT_EMAIL_ENV_VARS )
114- . copied ( )
115- . chain ( [
116- GOOSE_PROVIDER_ENV_VAR ,
117- ANTHROPIC_VERTEX_PROJECT_ID_ENV_VAR ,
118- VERTEX_LOCATION_ENV_VAR ,
119- ] )
120- . collect ( ) ;
121- let actual: HashSet < & str > = STATIC_CONFIG_KEYS . iter ( ) . copied ( ) . collect ( ) ;
122- assert_eq ! (
123- expected,
124- actual,
125- "STATIC_CONFIG_KEYS must be the union of all alias arrays + Vertex vars. \
126- Missing: {:?}, Extra: {:?}",
127- expected. difference( & actual) . collect:: <Vec <_>>( ) ,
128- actual. difference( & expected) . collect:: <Vec <_>>( ) ,
129- ) ;
130- }
13157}
0 commit comments