Skip to content

Commit

Permalink
server: Add Error
Browse files Browse the repository at this point in the history
And implement zbus::Error and oo7::portal::Error for Error

Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
  • Loading branch information
warusadura committed Oct 24, 2024
1 parent 467f354 commit f00cc41
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 34 deletions.
15 changes: 10 additions & 5 deletions server/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ use std::{
};

use oo7::{
dbus::api::{Properties, SecretInner},
dbus::{
api::{Properties, SecretInner},
ServiceError,
},
portal::Keyring,
};
use tokio::sync::{Mutex, RwLock};
use zbus::{interface, zvariant};
use zvariant::{ObjectPath, OwnedObjectPath};

use super::Result;
use crate::{item, service_manager::ServiceManager};

#[derive(Debug)]
Expand All @@ -38,12 +40,15 @@ pub struct Collection {
#[interface(name = "org.freedesktop.Secret.Collection")]
impl Collection {
#[zbus(out_args("prompt"))]
pub async fn delete(&self) -> Result<ObjectPath> {
pub async fn delete(&self) -> Result<ObjectPath, ServiceError> {
todo!()
}

#[zbus(out_args("results"))]
pub async fn search_items(&self, _attributes: HashMap<String, String>) -> Vec<OwnedObjectPath> {
pub async fn search_items(
&self,
_attributes: HashMap<String, String>,
) -> Result<Vec<OwnedObjectPath>, ServiceError> {
todo!()
}

Expand All @@ -53,7 +58,7 @@ impl Collection {
_properties: Properties,
_secret: SecretInner,
_replace: bool,
) -> Result<(OwnedObjectPath, ObjectPath)> {
) -> Result<(OwnedObjectPath, ObjectPath), ServiceError> {
todo!()
}
}
Expand Down
10 changes: 4 additions & 6 deletions server/src/item.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
// org.freedesktop.Secret.Item

use oo7::dbus::api::SecretInner;
use oo7::dbus::{api::SecretInner, ServiceError};
use zbus::zvariant::ObjectPath;

use super::Result;

#[derive(Debug)]
pub struct Item {}

#[zbus::interface(name = "org.freedesktop.Secret.Item")]
impl Item {
#[zbus(out_args("prompt"))]
pub async fn delete(&self) -> Result<ObjectPath> {
pub async fn delete(&self) -> Result<ObjectPath, ServiceError> {
todo!()
}

#[zbus(out_args("secret"))]
pub async fn get_secret(&self, _session: ObjectPath<'_>) -> Result<SecretInner> {
pub async fn get_secret(&self, _session: ObjectPath<'_>) -> Result<SecretInner, ServiceError> {
todo!()
}

pub async fn set_secret(&self, _secret: SecretInner) -> Result<()> {
pub async fn set_secret(&self, _secret: SecretInner) -> Result<(), ServiceError> {
todo!()
}
}
6 changes: 4 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
mod collection;
mod error;
mod item;
mod prompt;
mod service;
mod service_manager;
mod session;

use service::{Result, Service};
use error::Error;
use service::Service;

const BINARY_NAME: &str = env!("CARGO_BIN_NAME");

#[tokio::main]
async fn main() -> Result<()> {
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt::init();
tracing::info!("Starting {}", BINARY_NAME);

Expand Down
7 changes: 3 additions & 4 deletions server/src/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// org.freedesktop.Secret.Prompt

use oo7::dbus::ServiceError;
use zbus::interface;

use super::Result;

#[derive(Debug)]
pub struct Prompt {}

#[interface(name = "org.freedesktop.Secret.Prompt")]
impl Prompt {
pub async fn prompt(&self, _window_id: &str) -> Result<()> {
pub async fn prompt(&self, _window_id: &str) -> Result<(), ServiceError> {
todo!()
}

pub async fn dismiss(&self) -> Result<()> {
pub async fn dismiss(&self) -> Result<(), ServiceError> {
todo!()
}
}
32 changes: 18 additions & 14 deletions server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use zbus::{
zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Value},
};

use crate::{collection::Collection, service_manager::ServiceManager, session::Session};

pub type Result<T> = std::result::Result<T, ServiceError>;
use crate::{
collection::Collection, error::Error, service_manager::ServiceManager, session::Session,
};

#[derive(Debug)]
pub struct Service {
Expand All @@ -38,7 +38,7 @@ impl Service {
algorithm: Algorithm,
input: Value<'_>,
#[zbus(object_server)] object_server: &zbus::ObjectServer,
) -> Result<(OwnedValue, OwnedObjectPath)> {
) -> Result<(OwnedValue, OwnedObjectPath), ServiceError> {
let (public_key, aes_key) = match algorithm {
Algorithm::Plain => (None, None),
Algorithm::Encrypted => {
Expand Down Expand Up @@ -76,31 +76,31 @@ impl Service {
&self,
_properties: Properties,
_alias: &str,
) -> Result<(OwnedObjectPath, ObjectPath)> {
) -> Result<(OwnedObjectPath, ObjectPath), ServiceError> {
todo!()
}

#[zbus(out_args("unlocked", "locked"))]
pub async fn search_items(
&self,
_attributes: HashMap<&str, &str>,
) -> Result<(Vec<OwnedObjectPath>, Vec<OwnedObjectPath>)> {
) -> Result<(Vec<OwnedObjectPath>, Vec<OwnedObjectPath>), ServiceError> {
todo!()
}

#[zbus(out_args("unlocked", "prompt"))]
pub async fn unlock(
&mut self,
_objects: Vec<OwnedObjectPath>,
) -> Result<(Vec<OwnedObjectPath>, ObjectPath)> {
) -> Result<(Vec<OwnedObjectPath>, ObjectPath), ServiceError> {
todo!()
}

#[zbus(out_args("locked", "prompt"))]
pub async fn lock(
&mut self,
_objects: Vec<OwnedObjectPath>,
) -> Result<(Vec<OwnedObjectPath>, ObjectPath)> {
) -> Result<(Vec<OwnedObjectPath>, ObjectPath), ServiceError> {
todo!()
}

Expand All @@ -109,22 +109,26 @@ impl Service {
&self,
_items: Vec<OwnedObjectPath>,
_session: ObjectPath<'_>,
) -> Result<HashMap<OwnedObjectPath, SecretInner>> {
) -> Result<HashMap<OwnedObjectPath, SecretInner>, ServiceError> {
todo!()
}

#[zbus(out_args("collection"))]
pub async fn read_alias(&self, _name: &str) -> Result<ObjectPath> {
pub async fn read_alias(&self, _name: &str) -> Result<ObjectPath, ServiceError> {
todo!()
}

pub async fn set_alias(&self, _name: &str, _collection: ObjectPath<'_>) -> Result<()> {
pub async fn set_alias(
&self,
_name: &str,
_collection: ObjectPath<'_>,
) -> Result<(), ServiceError> {
todo!()
}
}

impl Service {
pub async fn run() -> Result<()> {
pub async fn run() -> Result<(), Error> {
let connection = zbus::connection::Builder::session()?
.name(oo7::dbus::api::Service::DESTINATION.as_deref().unwrap())?
.build()
Expand All @@ -149,13 +153,13 @@ impl Service {
Ok(())
}

pub async fn fetch_session(&self) -> Result<Collection> {
pub async fn fetch_session(&self) -> Result<Collection, Error> {
let secret = Secret::random();
let session = Collection::new(
"session",
"session",
Arc::clone(&self.manager),
Arc::new(Keyring::temporary(secret).await.unwrap()),
Arc::new(Keyring::temporary(secret).await?),
);
self.collections.lock().await.push(session.path().clone());

Expand Down
5 changes: 2 additions & 3 deletions server/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use std::sync::Arc;

use oo7::Key;
use oo7::{dbus::ServiceError, Key};
use tokio::sync::Mutex;
use zbus::{interface, zvariant::OwnedObjectPath};

use super::Result;
use crate::service_manager::ServiceManager;

#[derive(Debug, Clone)]
Expand All @@ -21,7 +20,7 @@ impl Session {
pub async fn close(
&self,
#[zbus(object_server)] object_server: &zbus::ObjectServer,
) -> Result<()> {
) -> Result<(), ServiceError> {
self.manager.lock().await.remove_session(&self.path);
object_server.remove::<Self, _>(&self.path).await?;

Expand Down

0 comments on commit f00cc41

Please sign in to comment.