git.delta.rocks / remowt / refs/commits / 67b2134d2c68

difftreelog

feat elevation

moyxqxptYaroslav Bolyukin2026-01-25parent: #31b5647.patch.diff
in: trunk

1 file changed

modifiedcrates/remowt-link-shared/src/lib.rsdiffbeforeafterboth
1use bifrostlink::declarative::endpoints;
1use bifrostlink::error::{ErrorT, ListenerForYourRequestHasBeenDeadError, ResponseError};2use bifrostlink::error::{ErrorT, ListenerForYourRequestHasBeenDeadError, ResponseError};
3use bifrostlink::notification;
4use bifrostlink::packet::OpaquePacketWrapper;
2use bifrostlink::AddressT;5use bifrostlink::{AddressT, Config};
6use serde::de::DeserializeOwned;
3use serde::{Deserialize, Serialize};7use serde::{Deserialize, Serialize};
8
9pub mod editor;
410
5#[derive(Clone, Serialize, Hash, Eq, Debug, PartialEq, Deserialize)]11#[derive(Clone, Serialize, Hash, Eq, Debug, PartialEq, Deserialize)]
6pub enum Address {12pub enum Address {
7 User,13 User,
8 Agent,14 Agent,
15 AgentPrivileged,
9}16}
10impl AddressT for Address {}17impl AddressT for Address {}
18
19pub use remowt_fs::{Error as FsError, Fs, FsClient};
20pub use remowt_pty::{Error as PtyError, Pty, PtyClient, ShellId};
21pub use remowt_systemd::{Error as SystemdError, Systemd, SystemdClient};
22
23#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
24pub enum ElevateError {
25 #[error("elevation failed: {0}")]
26 Failed(String),
27}
28
29pub trait Elevator: Send + Sync {
30 fn elevate(&self) -> impl std::future::Future<Output = Result<(), ElevateError>> + Send;
31}
32
33pub struct ElevateEndpoints<E>(pub E);
34
35#[endpoints(ns = 3)]
36impl<E: Elevator + 'static> ElevateEndpoints<E> {
37 #[endpoints(id = 1)]
38 async fn elevate(&self) -> Result<(), ElevateError> {
39 self.0.elevate().await
40 }
41}
1142
12#[derive(thiserror::Error, Debug)]43#[derive(thiserror::Error, Debug)]
13pub enum Error {44pub enum Error {
16 #[error("response: {0}")]47 #[error("response: {0}")]
17 Response(String),48 Response(String),
49
50 #[error(transparent)]
51 Ui(#[from] ui_prompt::Error),
18}52}
53
19impl From<ListenerForYourRequestHasBeenDeadError> for Error {54impl From<ListenerForYourRequestHasBeenDeadError> for Error {
38}73}
39impl ErrorT for Error {}74impl ErrorT for Error {}
75
76#[derive(Serialize, Deserialize, Debug)]
77pub struct TestNotification {
78 pub value: u32,
79}
80notification!((0x0100) TestNotification);
81
82pub struct BifConfig;
83impl bifrostlink::Config for BifConfig {
84 type Address = Address;
85
86 type Error = Error;
87
88 type EncodedData = Vec<u8>;
89
90 fn decode_headers(
91 data_with_headers: bytes::Bytes,
92 ) -> Result<(OpaquePacketWrapper<Self::Address>, Self::EncodedData), Self::Error> {
93 let (header, data): (OpaquePacketWrapper<Self::Address>, Vec<u8>) =
94 serde_json::from_slice(&data_with_headers)?;
95 Ok((header, data))
96 }
97
98 fn decode_data<T: DeserializeOwned>(data: Self::EncodedData) -> Result<T, Self::Error> {
99 let v: T = serde_json::from_slice(&data)?;
100 Ok(v)
101 }
102
103 fn encode_data<T: Serialize>(
104 headers: OpaquePacketWrapper<Self::Address>,
105 data: T,
106 ) -> bytes::Bytes {
107 let data = serde_json::to_vec(&data).expect("serialization shouldn't fail");
108 let o = serde_json::to_vec(&(headers, data)).expect("serialization shouldn't fail");
109 o.into()
110 }
111}
40112