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