(session: &Service, kind: Kind, id: &str, json: bool)
| 1450 | } |
| 1451 | |
| 1452 | fn validate_entity(session: &Service, kind: Kind, id: &str, json: bool) -> CliResult<bool> { |
| 1453 | let request = pb::ValidateVaultEntityRequest { |
| 1454 | repository: Some(session.reference.clone()), |
| 1455 | kind: kind as i32, |
| 1456 | subject: Some(pb::validate_vault_entity_request::Subject::Id( |
| 1457 | id.to_string(), |
| 1458 | )), |
| 1459 | content_hash: None, |
| 1460 | view: None, |
| 1461 | }; |
| 1462 | let response = session.validate_vault_entity(request)?; |
| 1463 | if json { |
| 1464 | // Same top-level shape the local body's `report_json` prints; the |
| 1465 | // wire carries each violation as one message string, so an entry is |
| 1466 | // its message. |
| 1467 | println!( |
| 1468 | "{}", |
| 1469 | serde_json::to_string_pretty(&serde_json::json!({ |
| 1470 | "conforms": response.valid, |
| 1471 | "results": response |
| 1472 | .issues |
| 1473 | .iter() |
| 1474 | .map(|issue| serde_json::json!({ "message": issue })) |
| 1475 | .collect::<Vec<_>>(), |
| 1476 | })) |
| 1477 | .unwrap() |
| 1478 | ); |
| 1479 | return Ok(true); |
| 1480 | } |
| 1481 | if response.valid { |
| 1482 | println!("conforms: yes"); |
| 1483 | } else { |
| 1484 | println!("conforms: no ({} violation(s))", response.issues.len()); |
| 1485 | for issue in &response.issues { |
| 1486 | println!(" ✗ {issue}"); |
| 1487 | } |
| 1488 | } |
| 1489 | Ok(true) |
| 1490 | } |
| 1491 | |
| 1492 | // --------------------------------------------------------------------------- |
| 1493 | // memory |
no test coverage detected