Skip to main content

hank_types/
hank.plugin.rs

1// @generated
2// This file is @generated by prost-build.
3#[derive(serde::Serialize, serde::Deserialize)]
4#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
5#[repr(i32)]
6pub enum EscalatedPrivilege {
7    All = 0,
8    ReloadPlugin = 1,
9    LoadPlugin = 2,
10    UnloadPlugin = 3,
11    InstructPlugin = 4,
12}
13impl EscalatedPrivilege {
14    /// String value of the enum field names used in the ProtoBuf definition.
15    ///
16    /// The values are not transformed in any way and thus are considered stable
17    /// (if the ProtoBuf definition does not change) and safe for programmatic use.
18    pub fn as_str_name(&self) -> &'static str {
19        match self {
20            EscalatedPrivilege::All => "ALL",
21            EscalatedPrivilege::ReloadPlugin => "RELOAD_PLUGIN",
22            EscalatedPrivilege::LoadPlugin => "LOAD_PLUGIN",
23            EscalatedPrivilege::UnloadPlugin => "UNLOAD_PLUGIN",
24            EscalatedPrivilege::InstructPlugin => "INSTRUCT_PLUGIN",
25        }
26    }
27    /// Creates an enum from field names used in the ProtoBuf definition.
28    pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
29        match value {
30            "ALL" => Some(Self::All),
31            "RELOAD_PLUGIN" => Some(Self::ReloadPlugin),
32            "LOAD_PLUGIN" => Some(Self::LoadPlugin),
33            "UNLOAD_PLUGIN" => Some(Self::UnloadPlugin),
34            "INSTRUCT_PLUGIN" => Some(Self::InstructPlugin),
35            _ => None,
36        }
37    }
38}
39/// Arguments for a plugin or a plugins subcommands.
40#[derive(serde::Serialize, serde::Deserialize)]
41#[cfg_attr(feature = "builder", derive(derive_builder::Builder))]
42#[cfg_attr(feature = "builder", builder(default, setter(into, strip_option), custom_constructor, build_fn(name = "fallible_build")))]
43#[serde(default)]
44#[derive(Clone, PartialEq, ::prost::Message)]
45pub struct Argument {
46    /// Argument name.
47    #[prost(string, tag="1")]
48    pub name: ::prost::alloc::string::String,
49    /// Argument description.
50    #[prost(string, tag="2")]
51    pub description: ::prost::alloc::string::String,
52    /// Optional argument default value.
53    #[prost(string, optional, tag="3")]
54    pub default_value: ::core::option::Option<::prost::alloc::string::String>,
55    /// Whether or not this argument is required.
56    #[prost(bool, tag="4")]
57    pub required: bool,
58    /// Sets the short version of the argument without the preceding -.
59    #[prost(string, optional, tag="5")]
60    pub short: ::core::option::Option<::prost::alloc::string::String>,
61    /// Sets the long version of the argument without the preceding --.
62    #[prost(string, optional, tag="6")]
63    pub long: ::core::option::Option<::prost::alloc::string::String>,
64}
65/// Plugin commands.
66#[derive(serde::Serialize, serde::Deserialize)]
67#[cfg_attr(feature = "builder", derive(derive_builder::Builder))]
68#[cfg_attr(feature = "builder", builder(default, setter(into, strip_option), custom_constructor, build_fn(name = "fallible_build")))]
69#[serde(default)]
70#[derive(Clone, PartialEq, ::prost::Message)]
71pub struct Command {
72    /// Command name.
73    #[prost(string, tag="1")]
74    pub name: ::prost::alloc::string::String,
75    /// Command description.
76    #[prost(string, tag="2")]
77    pub description: ::prost::alloc::string::String,
78    /// Command author.
79    #[prost(string, optional, tag="3")]
80    pub author: ::core::option::Option<::prost::alloc::string::String>,
81    /// A version string for the command. Should follow semver.
82    ///
83    /// @see: <https://semver.org/>
84    #[prost(string, optional, tag="4")]
85    pub version: ::core::option::Option<::prost::alloc::string::String>,
86    /// Command aliases.
87    #[prost(string, repeated, tag="5")]
88    pub aliases: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
89    /// Command arguments.
90    #[prost(message, repeated, tag="6")]
91    pub arguments: ::prost::alloc::vec::Vec<Argument>,
92    /// Command subcommands.
93    #[prost(message, repeated, tag="7")]
94    pub subcommands: ::prost::alloc::vec::Vec<Command>,
95    /// Access checks
96    ///
97    /// This command can optionally be gated by access checks.
98    #[prost(message, optional, tag="8")]
99    pub access_checks: ::core::option::Option<super::access_check::AccessCheckChain>,
100    /// Show help if no args are passed to this command.
101    ///
102    /// NOTE: Subcommands count as arguments.
103    #[prost(bool, tag="9")]
104    pub arg_required_else_help: bool,
105}
106/// Metadata for a plugin.
107#[cfg_attr(feature = "kameo", derive(kameo::Reply))]
108#[derive(serde::Serialize, serde::Deserialize)]
109#[cfg_attr(feature = "builder", derive(derive_builder::Builder))]
110#[cfg_attr(feature = "builder", builder(default, setter(into, strip_option), custom_constructor, build_fn(name = "fallible_build")))]
111#[serde(default)]
112#[derive(Clone, PartialEq, ::prost::Message)]
113pub struct Metadata {
114    /// The plguins name.
115    #[prost(string, tag="1")]
116    pub name: ::prost::alloc::string::String,
117    /// A short description of the plugin.
118    #[prost(string, tag="2")]
119    pub description: ::prost::alloc::string::String,
120    /// A version string for the plugin. Should follow semver.
121    ///
122    /// @see: <https://semver.org/>
123    #[prost(string, tag="3")]
124    pub version: ::prost::alloc::string::String,
125    /// When true, a SQLite3 database will be created for the plugin.
126    /// @deprecated All plugins get a database by default now.
127    #[prost(bool, tag="4")]
128    pub database: bool,
129    /// Access checks
130    ///
131    /// All functionality of this plugin can optionally be gated by accses checks.
132    #[prost(message, optional, tag="5")]
133    #[cfg_attr(feature = "builder", builder(setter(custom)))]
134    pub access_checks: ::core::option::Option<super::access_check::AccessCheckChain>,
135    /// A secret escalation key that grants this plugin specific escalated
136    /// privileges.
137    #[prost(string, optional, tag="6")]
138    #[cfg_attr(feature = "builder", builder(setter(custom)))]
139    pub escalation_key: ::core::option::Option<::prost::alloc::string::String>,
140    /// A list of escalated privileges that this plugin requests to use.
141    #[prost(enumeration="EscalatedPrivilege", repeated, tag="7")]
142    #[cfg_attr(feature = "builder", builder(setter(custom)))]
143    pub escalated_privileges: ::prost::alloc::vec::Vec<i32>,
144    /// The author of the plugin.
145    #[prost(string, tag="8")]
146    pub author: ::prost::alloc::string::String,
147    /// Whether or not this plugin handles commands.
148    #[prost(bool, tag="9")]
149    pub handles_commands: bool,
150    /// Whether or not this plugin handles messages.
151    #[prost(bool, tag="10")]
152    pub handles_messages: bool,
153    /// Optionally override the plugin command name.
154    #[prost(string, optional, tag="11")]
155    pub command_name: ::core::option::Option<::prost::alloc::string::String>,
156    /// Optional aliases for the plugin command.
157    #[prost(string, repeated, tag="12")]
158    #[cfg_attr(feature = "builder", builder(setter(custom)))]
159    pub aliases: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
160    /// Arguments for the plugin command.
161    #[prost(message, repeated, tag="13")]
162    pub arguments: ::prost::alloc::vec::Vec<Argument>,
163    /// Plugin subcommands.
164    #[prost(message, repeated, tag="14")]
165    pub subcommands: ::prost::alloc::vec::Vec<Command>,
166    /// Hosts that this plugin requests permissions to access via HTTP.
167    #[prost(string, repeated, tag="15")]
168    #[cfg_attr(feature = "builder", builder(setter(custom)))]
169    pub allowed_hosts: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
170    /// Pool size this plugin requests.
171    #[prost(int32, optional, tag="16")]
172    pub pool_size: ::core::option::Option<i32>,
173    /// Show help if no args are passed to the plugin command.
174    ///
175    /// NOTE: Subcommands count as arguments.
176    #[prost(bool, tag="17")]
177    pub arg_required_else_help: bool,
178}
179/// An argument passed to a commands context.
180#[derive(serde::Serialize, serde::Deserialize)]
181#[serde(default)]
182#[derive(Clone, PartialEq, ::prost::Message)]
183pub struct CommandContextArgument {
184    /// The name of the argument.
185    #[prost(string, tag="1")]
186    pub name: ::prost::alloc::string::String,
187    /// The value of the argument.
188    #[prost(string, tag="2")]
189    pub value: ::prost::alloc::string::String,
190}
191/// Plugin command context.
192#[derive(serde::Serialize, serde::Deserialize)]
193#[serde(default)]
194#[derive(Clone, PartialEq, ::prost::Message)]
195pub struct CommandContext {
196    /// The name of the command.
197    #[prost(string, tag="1")]
198    pub name: ::prost::alloc::string::String,
199    /// Arguments passed to the command.
200    #[prost(message, repeated, tag="2")]
201    pub arguments: ::prost::alloc::vec::Vec<CommandContextArgument>,
202    /// Optional nested subcommand context.
203    #[prost(message, optional, boxed, tag="3")]
204    pub subcommand: ::core::option::Option<::prost::alloc::boxed::Box<CommandContext>>,
205}
206/// \[Internal\] Kinds of instructions that can be sent to hank plugins.
207#[derive(serde::Serialize, serde::Deserialize)]
208#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
209#[repr(i32)]
210pub enum InstructionKind {
211    /// Plugin entry point.
212    Plugin = 0,
213    /// Get the plugins metadata.
214    GetMetadata = 1,
215    /// Call the plugins install function. (only happens once)
216    Install = 2,
217    /// Call the plugins initialize function. (happens on every load)
218    Initialize = 3,
219    /// Call the plugins shutdown function. (happens on reload, unload, uninstall)
220    Shutdown = 4,
221    /// Call the plguins chat message handler.
222    ChatMessage = 5,
223    /// Call the plguins chat command handler.
224    ChatCommand = 6,
225    /// Call the plguins scheduled job handler.
226    ScheduledJob = 7,
227}
228impl InstructionKind {
229    /// String value of the enum field names used in the ProtoBuf definition.
230    ///
231    /// The values are not transformed in any way and thus are considered stable
232    /// (if the ProtoBuf definition does not change) and safe for programmatic use.
233    pub fn as_str_name(&self) -> &'static str {
234        match self {
235            InstructionKind::Plugin => "Plugin",
236            InstructionKind::GetMetadata => "GetMetadata",
237            InstructionKind::Install => "Install",
238            InstructionKind::Initialize => "Initialize",
239            InstructionKind::Shutdown => "Shutdown",
240            InstructionKind::ChatMessage => "ChatMessage",
241            InstructionKind::ChatCommand => "ChatCommand",
242            InstructionKind::ScheduledJob => "ScheduledJob",
243        }
244    }
245    /// Creates an enum from field names used in the ProtoBuf definition.
246    pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
247        match value {
248            "Plugin" => Some(Self::Plugin),
249            "GetMetadata" => Some(Self::GetMetadata),
250            "Install" => Some(Self::Install),
251            "Initialize" => Some(Self::Initialize),
252            "Shutdown" => Some(Self::Shutdown),
253            "ChatMessage" => Some(Self::ChatMessage),
254            "ChatCommand" => Some(Self::ChatCommand),
255            "ScheduledJob" => Some(Self::ScheduledJob),
256            _ => None,
257        }
258    }
259}
260/// \[Internal\] An instruction to send to hank plugin.
261#[derive(serde::Serialize, serde::Deserialize)]
262#[serde(default)]
263#[derive(Clone, PartialEq, ::prost::Message)]
264pub struct Instruction {
265    /// The kind of instruction to send to the hank plugin.
266    #[prost(enumeration="InstructionKind", tag="1")]
267    pub kind: i32,
268    /// An input to send to the hank plugin.
269    #[prost(bytes="vec", tag="2")]
270    pub input: ::prost::alloc::vec::Vec<u8>,
271    /// An optional target plugin name to send the instruciton to.
272    #[prost(string, optional, tag="3")]
273    pub target: ::core::option::Option<::prost::alloc::string::String>,
274}
275// @@protoc_insertion_point(module)
276// Customizations from hank.plugin.customizations.rs
277#[cfg(feature = "builder")]
278#[derive(Debug)]
279pub enum AccessChecks {
280    Array(Vec<crate::access_check::AccessCheck>),
281    Single(crate::access_check::AccessCheck),
282    Full(crate::access_check::AccessCheckChain),
283}
284#[cfg(feature = "builder")]
285impl Metadata {
286    pub fn new(
287        name: impl Into<String>,
288        author: impl Into<String>,
289        description: impl Into<String>,
290        version: impl Into<String>,
291    ) -> MetadataBuilder {
292        MetadataBuilder {
293            name: Some(name.into()),
294            author: Some(author.into()),
295            description: Some(description.into()),
296            version: Some(version.into()),
297            ..MetadataBuilder::create_empty()
298        }
299    }
300}
301#[cfg(feature = "builder")]
302impl MetadataBuilder {
303    pub fn allowed_hosts(
304        &mut self,
305        value: impl IntoIterator<Item = impl Into<String>>,
306    ) -> &mut Self {
307        self.allowed_hosts = Some(value.into_iter().map(Into::into).collect());
308        self
309    }
310    pub fn aliases(&mut self, value: impl IntoIterator<Item = impl Into<String>>) -> &mut Self {
311        self.aliases = Some(value.into_iter().map(Into::into).collect());
312        self
313    }
314    pub fn escalation_key(&mut self, value: impl Into<String>) -> &mut Self {
315        self.escalation_key = Some(Some(value.into()));
316        self
317    }
318    pub fn escalated_privileges(
319        &mut self,
320        value: impl IntoIterator<Item = impl Into<i32>>,
321    ) -> &mut Self {
322        self.escalated_privileges = Some(value.into_iter().map(Into::into).collect());
323        self
324    }
325    pub fn access_checks(&mut self, value: AccessChecks) -> &mut Self {
326        self.access_checks = Some(match value {
327            AccessChecks::Array(checks) => Some(crate::access_check::AccessCheckChain {
328                operator: crate::access_check::AccessCheckOperator::Or.into(),
329                checks,
330            }),
331            AccessChecks::Single(check) => Some(crate::access_check::AccessCheckChain {
332                operator: crate::access_check::AccessCheckOperator::Or.into(),
333                checks: vec![check],
334            }),
335            AccessChecks::Full(full) => Some(full),
336        });
337        self
338    }
339    pub fn build(&self) -> Metadata {
340        self.fallible_build()
341            .expect("All required fields were initialized")
342    }
343}
344#[cfg(feature = "builder")]
345impl Command {
346    pub fn new(name: impl Into<String>, description: impl Into<String>) -> CommandBuilder {
347        CommandBuilder {
348            name: Some(name.into()),
349            description: Some(description.into()),
350            ..CommandBuilder::create_empty()
351        }
352    }
353}
354#[cfg(feature = "builder")]
355impl CommandBuilder {
356    pub fn build(&self) -> Command {
357        self.fallible_build()
358            .expect("All required fields were initialized")
359    }
360}
361#[cfg(feature = "builder")]
362impl Argument {
363    pub fn new(name: impl Into<String>, description: impl Into<String>) -> ArgumentBuilder {
364        ArgumentBuilder {
365            name: Some(name.into()),
366            description: Some(description.into()),
367            ..ArgumentBuilder::create_empty()
368        }
369    }
370}
371#[cfg(feature = "builder")]
372impl ArgumentBuilder {
373    pub fn build(&self) -> Argument {
374        self.fallible_build()
375            .expect("All required fields were initialized")
376    }
377}