1use std::collections::BTreeMap;
2
3use async_trait::async_trait;
4
5use crate::{common::crypto::hash::Hash, protocol::Protocol};
6
7use super::{host_rpc_call, Error};
8
9pub const LOCAL_RPC_ENDPOINT_BUNDLE_MANAGER: &str = "bundle-manager";
11
12pub const METHOD_BUNDLE_TEMPORARY_WRITE: &str = "BundleTemporaryWrite";
14pub const METHOD_BUNDLE_TEMPORARY_DELETE: &str = "BundleTemporaryDelete";
16pub const METHOD_BUNDLE_ADD: &str = "BundleAdd";
18pub const METHOD_BUNDLE_REMOVE: &str = "BundleRemove";
20pub const METHOD_BUNDLE_LIST: &str = "BundleList";
22
23pub const LABEL_INSTANCE_ID: &str = "net.oasis.instance_id";
25
26#[allow(clippy::double_must_use)]
28#[async_trait]
29pub trait BundleManager: Send + Sync {
30 async fn bundle_temporary_write(
34 &self,
35 args: BundleTemporaryWriteRequest,
36 ) -> Result<BundleTemporaryWriteResponse, Error>;
37
38 async fn bundle_temporary_delete(
42 &self,
43 args: BundleTemporaryDeleteRequest,
44 ) -> Result<BundleTemporaryDeleteResponse, Error>;
45
46 async fn bundle_add(&self, args: BundleAddRequest) -> Result<BundleAddResponse, Error>;
50
51 async fn bundle_remove(&self, args: BundleRemoveRequest)
56 -> Result<BundleRemoveResponse, Error>;
57
58 async fn bundle_list(&self, args: BundleListRequest) -> Result<BundleListResponse, Error>;
62}
63
64#[allow(clippy::double_must_use)]
65#[async_trait]
66impl BundleManager for Protocol {
67 async fn bundle_temporary_write(
68 &self,
69 args: BundleTemporaryWriteRequest,
70 ) -> Result<BundleTemporaryWriteResponse, Error> {
71 host_rpc_call(
72 self,
73 LOCAL_RPC_ENDPOINT_BUNDLE_MANAGER,
74 METHOD_BUNDLE_TEMPORARY_WRITE,
75 args,
76 )
77 .await
78 }
79
80 async fn bundle_temporary_delete(
81 &self,
82 args: BundleTemporaryDeleteRequest,
83 ) -> Result<BundleTemporaryDeleteResponse, Error> {
84 host_rpc_call(
85 self,
86 LOCAL_RPC_ENDPOINT_BUNDLE_MANAGER,
87 METHOD_BUNDLE_TEMPORARY_DELETE,
88 args,
89 )
90 .await
91 }
92
93 async fn bundle_add(&self, args: BundleAddRequest) -> Result<BundleAddResponse, Error> {
94 host_rpc_call(
95 self,
96 LOCAL_RPC_ENDPOINT_BUNDLE_MANAGER,
97 METHOD_BUNDLE_ADD,
98 args,
99 )
100 .await
101 }
102
103 async fn bundle_remove(
104 &self,
105 args: BundleRemoveRequest,
106 ) -> Result<BundleRemoveResponse, Error> {
107 host_rpc_call(
108 self,
109 LOCAL_RPC_ENDPOINT_BUNDLE_MANAGER,
110 METHOD_BUNDLE_REMOVE,
111 args,
112 )
113 .await
114 }
115
116 async fn bundle_list(&self, args: BundleListRequest) -> Result<BundleListResponse, Error> {
117 host_rpc_call(
118 self,
119 LOCAL_RPC_ENDPOINT_BUNDLE_MANAGER,
120 METHOD_BUNDLE_LIST,
121 args,
122 )
123 .await
124 }
125}
126
127#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
131pub struct BundleTemporaryWriteRequest {
132 pub temporary_name: String,
134 pub create: bool,
138 pub data: Vec<u8>,
140}
141
142#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
144pub struct BundleTemporaryWriteResponse {}
145
146#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
150pub struct BundleTemporaryDeleteRequest {
151 pub temporary_name: String,
153}
154
155#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
157pub struct BundleTemporaryDeleteResponse {}
158
159#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
163pub struct BundleAddRequest {
164 pub temporary_name: String,
169 pub manifest_hash: Hash,
171 pub labels: BTreeMap<String, String>,
178 pub volumes: BTreeMap<String, String>,
180}
181
182#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
184pub struct BundleAddResponse {}
185
186#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
191pub struct BundleRemoveRequest {
192 pub labels: BTreeMap<String, String>,
194}
195
196#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
198pub struct BundleRemoveResponse {}
199
200#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
204pub struct BundleListRequest {
205 pub labels: BTreeMap<String, String>,
207}
208
209#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
211pub struct BundleListResponse {
212 #[cbor(optional)]
214 pub bundles: Vec<BundleInfo>,
215}
216
217#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
219pub struct BundleInfo {
220 pub manifest_hash: Hash,
222 pub components: Vec<ComponentInfo>,
224 pub labels: BTreeMap<String, String>,
226}
227
228#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
230pub struct ComponentInfo {
231 pub name: String,
233}