(ctx: &MetadataContext)
| 148 | } |
| 149 | |
| 150 | fn handle_token(ctx: &MetadataContext) -> MetadataResponse { |
| 151 | let Some((placeholder, expires_in)) = ctx.credentials.gcp_token_response() else { |
| 152 | let has_resolver = ctx.credentials.resolver().is_some(); |
| 153 | let (msg, error_key) = if has_resolver { |
| 154 | ( |
| 155 | "metadata: no GCP access token available or expired", |
| 156 | "token_unavailable", |
| 157 | ) |
| 158 | } else { |
| 159 | ( |
| 160 | "metadata: token request but no credentials configured", |
| 161 | "credentials_unavailable", |
| 162 | ) |
| 163 | }; |
| 164 | emit_metadata_event(ActivityId::Fail, SeverityId::Medium, StatusId::Failure, msg); |
| 165 | return ( |
| 166 | 503, |
| 167 | "application/json", |
| 168 | serde_json::json!({"error": error_key}).to_string(), |
| 169 | ); |
| 170 | }; |
| 171 | |
| 172 | emit_metadata_event( |
| 173 | ActivityId::Open, |
| 174 | SeverityId::Informational, |
| 175 | StatusId::Success, |
| 176 | "metadata: token placeholder served", |
| 177 | ); |
| 178 | |
| 179 | let body = serde_json::json!({ |
| 180 | "access_token": placeholder, |
| 181 | "expires_in": expires_in, |
| 182 | "token_type": "Bearer" |
| 183 | }); |
| 184 | (200, "application/json", body.to_string()) |
| 185 | } |
| 186 | |
| 187 | fn handle_service_account_recursive(ctx: &MetadataContext) -> MetadataResponse { |
| 188 | let resolver = ctx.credentials.resolver(); |
no test coverage detected