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)
| 210 | /// value. This matches real GCE metadata server behavior and is safe because |
| 211 | /// these values are non-secret configuration (project IDs, email addresses). |
| 212 | fn 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 | |
| 242 | fn validate_metadata_headers(headers: &[(String, String)]) -> Result<(), MetadataResponse> { |
| 243 | if headers |
no test coverage detected