signstar_yubihsm2/automation/
scenario.rs1#[cfg(all(feature = "serde", feature = "cli"))]
4use serde::Deserialize;
5
6use crate::automation::command::AuthenticatedCommandChain;
7#[cfg(feature = "cli")]
8use crate::{
9 Credentials,
10 automation::{Command, command::FileBackedAuthenticatedCommandChain},
11};
12
13#[derive(Debug)]
17pub struct Scenario(Vec<AuthenticatedCommandChain>);
18
19impl AsRef<[AuthenticatedCommandChain]> for Scenario {
20 fn as_ref(&self) -> &[AuthenticatedCommandChain] {
21 self.0.as_slice()
22 }
23}
24
25#[cfg(feature = "cli")]
29#[cfg_attr(feature = "serde", derive(Deserialize))]
30#[derive(Debug)]
31pub struct FileBackedScenario(Vec<FileBackedAuthenticatedCommandChain>);
32
33#[cfg(feature = "cli")]
34impl AsRef<[FileBackedAuthenticatedCommandChain]> for FileBackedScenario {
35 fn as_ref(&self) -> &[FileBackedAuthenticatedCommandChain] {
36 self.0.as_slice()
37 }
38}
39
40#[cfg(feature = "cli")]
41impl TryFrom<&FileBackedScenario> for Scenario {
42 type Error = crate::Error;
43
44 fn try_from(value: &FileBackedScenario) -> Result<Self, Self::Error> {
45 let mut output = Vec::new();
46
47 for authenticated_command_chain in value.0.iter() {
48 let creds = Credentials::try_from(&authenticated_command_chain.auth)?;
49 let commands = {
50 let mut commands = Vec::new();
51 for file_backed_command in authenticated_command_chain.commands.iter() {
52 commands.push(Command::try_from(file_backed_command)?);
53 }
54 commands
55 };
56 output.push(AuthenticatedCommandChain::new(creds, commands));
57 }
58
59 Ok(Self(output))
60 }
61}