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

Function handle_token

crates/openshell-sandbox/src/google_cloud_metadata.rs:150–185  ·  view source on GitHub ↗
(ctx: &MetadataContext)

Source from the content-addressed store, hash-verified

148}
149
150fn 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
187fn handle_service_account_recursive(ctx: &MetadataContext) -> MetadataResponse {
188 let resolver = ctx.credentials.resolver();

Callers 1

route_requestFunction · 0.85

Calls 3

emit_metadata_eventFunction · 0.85
gcp_token_responseMethod · 0.80
resolverMethod · 0.45

Tested by

no test coverage detected