aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api/plugin_command.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-10-20 14:20:00 +0200
committerGitHub <noreply@github.com>2023-10-20 14:20:00 +0200
commitb59b29a534578cb1910a21a394d0279cb423c2b2 (patch)
treea63f926a6ce83b6c7ee113f1088538628f2bd557 /zellij-utils/src/plugin_api/plugin_command.rs
parentdocs(changelog): esc drop to shell in command panes (diff)
downloadsl0ppij-b59b29a534578cb1910a21a394d0279cb423c2b2.tar.gz
sl0ppij-b59b29a534578cb1910a21a394d0279cb423c2b2.tar.xz
sl0ppij-b59b29a534578cb1910a21a394d0279cb423c2b2.zip
feat(plugins): web requests api (#2879)
* feat(plugins): web requests api * fix e2e tests * fix e2e tests again
Diffstat (limited to 'zellij-utils/src/plugin_api/plugin_command.rs')
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.rs80
1 files changed, 76 insertions, 4 deletions
diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs
index 181953d4..84c083ad 100644
--- a/zellij-utils/src/plugin_api/plugin_command.rs
+++ b/zellij-utils/src/plugin_api/plugin_command.rs
@@ -1,24 +1,47 @@
pub use super::generated_api::api::{
action::{PaneIdAndShouldFloat, SwitchToModePayload},
- event::EventNameList as ProtobufEventNameList,
+ event::{EventNameList as ProtobufEventNameList, Header},
input_mode::InputMode as ProtobufInputMode,
plugin_command::{
plugin_command::Payload, CommandName, ContextItem, EnvVariable, ExecCmdPayload,
- IdAndNewName, MovePayload, OpenCommandPanePayload, OpenFilePayload,
- PluginCommand as ProtobufPluginCommand, PluginMessagePayload,
+ HttpVerb as ProtobufHttpVerb, IdAndNewName, MovePayload, OpenCommandPanePayload,
+ OpenFilePayload, PluginCommand as ProtobufPluginCommand, PluginMessagePayload,
RequestPluginPermissionPayload, ResizePayload, RunCommandPayload, SetTimeoutPayload,
SubscribePayload, SwitchSessionPayload, SwitchTabToPayload, UnsubscribePayload,
+ WebRequestPayload,
},
plugin_permission::PermissionType as ProtobufPermissionType,
resize::ResizeAction as ProtobufResizeAction,
};
-use crate::data::{ConnectToSession, PermissionType, PluginCommand};
+use crate::data::{ConnectToSession, HttpVerb, PermissionType, PluginCommand};
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::path::PathBuf;
+impl Into<HttpVerb> for ProtobufHttpVerb {
+ fn into(self) -> HttpVerb {
+ match self {
+ ProtobufHttpVerb::Get => HttpVerb::Get,
+ ProtobufHttpVerb::Post => HttpVerb::Post,
+ ProtobufHttpVerb::Put => HttpVerb::Put,
+ ProtobufHttpVerb::Delete => HttpVerb::Delete,
+ }
+ }
+}
+
+impl Into<ProtobufHttpVerb> for HttpVerb {
+ fn into(self) -> ProtobufHttpVerb {
+ match self {
+ HttpVerb::Get => ProtobufHttpVerb::Get,
+ HttpVerb::Post => ProtobufHttpVerb::Post,
+ HttpVerb::Put => ProtobufHttpVerb::Put,
+ HttpVerb::Delete => ProtobufHttpVerb::Delete,
+ }
+ }
+}
+
impl TryFrom<ProtobufPluginCommand> for PluginCommand {
type Error = &'static str;
fn try_from(protobuf_plugin_command: ProtobufPluginCommand) -> Result<Self, &'static str> {
@@ -577,6 +600,34 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
},
_ => Err("Mismatched payload for RunCommand"),
},
+ Some(CommandName::WebRequest) => match protobuf_plugin_command.payload {
+ Some(Payload::WebRequestPayload(web_request_payload)) => {
+ let context: BTreeMap<String, String> = web_request_payload
+ .context
+ .into_iter()
+ .map(|e| (e.name, e.value))
+ .collect();
+ let headers: BTreeMap<String, String> = web_request_payload
+ .headers
+ .into_iter()
+ .map(|e| (e.name, e.value))
+ .collect();
+ let verb = match ProtobufHttpVerb::from_i32(web_request_payload.verb) {
+ Some(verb) => verb.into(),
+ None => {
+ return Err("Unrecognized http verb");
+ },
+ };
+ Ok(PluginCommand::WebRequest(
+ web_request_payload.url,
+ verb,
+ headers,
+ web_request_payload.body,
+ context,
+ ))
+ },
+ _ => Err("Mismatched payload for WebRequest"),
+ },
None => Err("Unrecognized plugin command"),
}
}
@@ -972,6 +1023,27 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
})),
})
},
+ PluginCommand::WebRequest(url, verb, headers, body, context) => {
+ let context: Vec<_> = context
+ .into_iter()
+ .map(|(name, value)| ContextItem { name, value })
+ .collect();
+ let headers: Vec<_> = headers
+ .into_iter()
+ .map(|(name, value)| Header { name, value })
+ .collect();
+ let verb: ProtobufHttpVerb = verb.into();
+ Ok(ProtobufPluginCommand {
+ name: CommandName::WebRequest as i32,
+ payload: Some(Payload::WebRequestPayload(WebRequestPayload {
+ url,
+ verb: verb as i32,
+ body,
+ headers,
+ context,
+ })),
+ })
+ },
}
}
}