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

Function handle_get_draft_policy

crates/openshell-server/src/grpc/policy.rs:2462–2518  ·  view source on GitHub ↗
(
    state: &Arc<ServerState>,
    request: Request<GetDraftPolicyRequest>,
)

Source from the content-addressed store, hash-verified

2460}
2461
2462pub(super) async fn handle_get_draft_policy(
2463 state: &Arc<ServerState>,
2464 request: Request<GetDraftPolicyRequest>,
2465) -> Result<Response<GetDraftPolicyResponse>, Status> {
2466 let principal = request
2467 .extensions()
2468 .get::<Principal>()
2469 .cloned()
2470 .ok_or_else(|| Status::unauthenticated("missing principal"))?;
2471 let req = request.into_inner();
2472 if req.name.is_empty() {
2473 return Err(Status::invalid_argument("name is required"));
2474 }
2475
2476 let sandbox =
2477 resolve_sandbox_by_name_for_principal(state.store.as_ref(), &principal, &req.name).await?;
2478 let sandbox_id = sandbox.object_id().to_string();
2479
2480 let status_filter = if req.status_filter.is_empty() {
2481 None
2482 } else {
2483 Some(req.status_filter.as_str())
2484 };
2485
2486 let records = state
2487 .store
2488 .list_draft_chunks(&sandbox_id, status_filter)
2489 .await
2490 .map_err(|e| Status::internal(format!("list draft chunks failed: {e}")))?;
2491
2492 let draft_version = state
2493 .store
2494 .get_draft_version(&sandbox_id)
2495 .await
2496 .map_err(|e| Status::internal(format!("get draft version failed: {e}")))?;
2497
2498 let chunks: Vec<PolicyChunk> = records
2499 .into_iter()
2500 .map(|r| draft_chunk_record_to_proto(&r))
2501 .collect::<Result<Vec<_>, _>>()?;
2502
2503 let last_analyzed_at_ms = chunks.iter().map(|c| c.created_at_ms).max().unwrap_or(0);
2504
2505 debug!(
2506 sandbox_id = %sandbox_id,
2507 chunk_count = chunks.len(),
2508 draft_version = draft_version,
2509 "GetDraftPolicy: served draft chunks"
2510 );
2511
2512 Ok(Response::new(GetDraftPolicyResponse {
2513 chunks,
2514 rolling_summary: String::new(),
2515 draft_version: u64::try_from(draft_version).unwrap_or(0),
2516 last_analyzed_at_ms,
2517 }))
2518}
2519

Calls 7

object_idMethod · 0.80
is_emptyMethod · 0.45
as_strMethod · 0.45
list_draft_chunksMethod · 0.45
get_draft_versionMethod · 0.45

Tested by

no test coverage detected