MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / handle_env

Function handle_env

crates/openshell-sandbox/src/google_cloud_metadata.rs:212–240  ·  view source on GitHub ↗

Serve a non-secret config value (project ID, SA email) as plain text. Unlike `handle_token` which serves placeholders, this resolves to the real value. This matches real GCE metadata server behavior and is safe because these values are non-secret configuration (project IDs, email addresses).

(ctx: &MetadataContext, env_key: &str)

Source from the content-addressed store, hash-verified

210/// value. This matches real GCE metadata server behavior and is safe because
211/// these values are non-secret configuration (project IDs, email addresses).
212fn handle_env(ctx: &MetadataContext, env_key: &str) -> MetadataResponse {
213 let Some(resolver) = ctx.credentials.resolver() else {
214 emit_metadata_event(
215 ActivityId::Fail,
216 SeverityId::Medium,
217 StatusId::Failure,
218 &format!("metadata: {env_key} request but no credentials configured"),
219 );
220 return (503, "text/plain", String::new());
221 };
222
223 let placeholder = secrets::placeholder_for_env_key(env_key);
224 resolver.resolve_placeholder(&placeholder).map_or_else(
225 || {
226 emit_metadata_event(
227 ActivityId::Fail,
228 SeverityId::Low,
229 StatusId::Failure,
230 &format!("metadata: {env_key} not configured"),
231 );
232 (
233 404,
234 "application/json",
235 serde_json::json!({"error": "not_found"}).to_string(),
236 )
237 },
238 |value| (200, "text/plain", value.to_string()),
239 )
240}
241
242fn validate_metadata_headers(headers: &[(String, String)]) -> Result<(), MetadataResponse> {
243 if headers

Callers 1

route_requestFunction · 0.85

Calls 4

emit_metadata_eventFunction · 0.85
placeholder_for_env_keyFunction · 0.85
resolve_placeholderMethod · 0.80
resolverMethod · 0.45

Tested by

no test coverage detected