1#[cfg(feature = "hank")]
3pub mod hank {
5 include!("hank.rs");
6 #[cfg(feature = "hank-access_check")]
8 pub mod access_check {
10 include!("hank.access_check.rs");
11 }
13 #[cfg(feature = "hank-channel")]
14 pub mod channel {
16 include!("hank.channel.rs");
17 }
19 #[cfg(feature = "hank-cron")]
20 pub mod cron {
22 include!("hank.cron.rs");
23 }
25 #[cfg(feature = "hank-database")]
26 pub mod database {
28 include!("hank.database.rs");
29 }
31 #[cfg(feature = "hank-message")]
32 pub mod message {
34 include!("hank.message.rs");
35 }
37 #[cfg(feature = "hank-plugin")]
38 pub mod plugin {
40 include!("hank.plugin.rs");
41 }
43 #[cfg(feature = "hank-user")]
44 pub mod user {
46 include!("hank.user.rs");
47 }
49}
50pub use hank::*;
52pub use prost_types::{Timestamp, TimestampError};
53
54impl serde::ser::Serialize for access_check::AccessCheckChain {
55 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
56 where
57 S: serde::ser::Serializer,
58 {
59 use serde::ser::SerializeStruct as _;
60 let mut state = serializer.serialize_struct("AccessCheckChain", 1)?;
61 state.serialize_field(
62 access_check::AccessCheckOperator::try_from(self.operator)
63 .expect("invalid access check operator")
64 .as_str_name(),
65 &self.checks,
66 )?;
67
68 state.end()
69 }
70}
71
72impl<'de> serde::de::Deserialize<'de> for access_check::AccessCheckChain {
73 fn deserialize<D: serde::de::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
74 let d: std::collections::BTreeMap<String, Vec<access_check::AccessCheck>> =
75 std::collections::BTreeMap::deserialize(d)?;
76
77 let (operator, checks) = d.first_key_value().expect("invalid access chain format");
78 Ok(access_check::AccessCheckChain {
79 operator: access_check::AccessCheckOperator::from_str_name(operator)
80 .expect("invalid access check operator")
81 .into(),
82 checks: checks.to_vec(),
83 })
84 }
85}
86
87#[derive(Default)]
88pub struct InstructionBuilder<T>
89where
90 T: Default + prost::Message,
91{
92 kind: plugin::InstructionKind,
93 input: T,
94 target: Option<String>,
95}
96
97impl<T> InstructionBuilder<T>
98where
99 T: Default + prost::Message,
100{
101 pub fn new(kind: plugin::InstructionKind) -> Self {
102 Self {
103 kind,
104 ..Default::default()
105 }
106 }
107
108 pub fn with_input(self, input: T) -> Self {
109 Self { input, ..self }
110 }
111
112 pub fn with_target(self, target: String) -> Self {
113 Self {
114 target: Some(target),
115 ..self
116 }
117 }
118
119 pub fn build(self) -> plugin::Instruction {
120 self.into()
121 }
122}
123
124impl<T> From<InstructionBuilder<T>> for plugin::Instruction
125where
126 T: Default + prost::Message,
127{
128 fn from(value: InstructionBuilder<T>) -> Self {
129 plugin::Instruction {
130 kind: value.kind.into(),
131 input: value.input.encode_to_vec(),
132 target: value.target,
133 }
134 }
135}