1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use serde::{Deserialize, Serialize};
use crate::child_process::ChildPluginProcess;
use crate::proto::*;
use crate::proto::pact_plugin_client::PactPluginClient;
#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub enum PluginDependencyType {
OSPackage,
Plugin,
Library,
Executable
}
impl Default for PluginDependencyType {
fn default() -> Self {
PluginDependencyType::Plugin
}
}
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct PluginDependency {
pub name: String,
pub version: Option<String>,
#[serde(default)]
pub dependency_type: PluginDependencyType
}
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct PactPluginManifest {
#[serde(skip)]
pub plugin_dir: String,
pub plugin_interface_version: u8,
pub name: String,
pub version: String,
pub executable_type: String,
pub minimum_required_version: Option<String>,
pub entry_point: String,
pub dependencies: Option<Vec<PluginDependency>>
}
impl PactPluginManifest {
pub fn as_dependency(&self) -> PluginDependency {
PluginDependency {
name: self.name.clone(),
version: Some(self.version.clone()),
dependency_type: PluginDependencyType::Plugin
}
}
}
#[derive(Debug, Clone)]
pub struct PactPlugin {
pub manifest: PactPluginManifest,
pub child: ChildPluginProcess
}
impl PactPlugin {
pub fn new(manifest: &PactPluginManifest, child: ChildPluginProcess) -> Self {
PactPlugin { manifest: manifest.clone(), child }
}
pub fn port(&self) -> u16 {
self.child.port()
}
pub fn kill(&self) {
self.child.kill();
}
pub async fn init_plugin(&self, request: InitPluginRequest) -> anyhow::Result<InitPluginResponse> {
let mut client = PactPluginClient::connect(format!("http://127.0.0.1:{}", self.child.port())).await?;
let response = client.init_plugin(tonic::Request::new(request)).await?;
Ok(response.get_ref().clone())
}
pub async fn compare_contents(&self, request: CompareContentsRequest) -> anyhow::Result<CompareContentsResponse> {
let mut client = PactPluginClient::connect(format!("http://127.0.0.1:{}", self.child.port())).await?;
let response = client.compare_contents(tonic::Request::new(request)).await?;
Ok(response.get_ref().clone())
}
pub async fn configure_contents(&self, request: ConfigureContentsRequest) -> anyhow::Result<ConfigureContentsResponse> {
let mut client = PactPluginClient::connect(format!("http://127.0.0.1:{}", self.child.port())).await?;
let response = client.configure_contents(tonic::Request::new(request)).await?;
Ok(response.get_ref().clone())
}
pub async fn generate_content(&self, request: GenerateContentRequest) -> anyhow::Result<GenerateContentResponse> {
let mut client = PactPluginClient::connect(format!("http://127.0.0.1:{}", self.child.port())).await?;
let response = client.generate_content(tonic::Request::new(request)).await?;
Ok(response.get_ref().clone())
}
}