Skip to content

Commit

Permalink
wip: add Secret Prompt implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
  • Loading branch information
warusadura committed May 12, 2024
1 parent b0b7d28 commit a2b198b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
56 changes: 53 additions & 3 deletions server/src/daemon/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,63 @@
use serde::{Serialize, Serializer};
use zbus::zvariant::{self, OwnedObjectPath};
use zbus::{
fdo, interface,
zvariant::{self, ObjectPath, OwnedObjectPath},
SignalContext,
};

#[derive(Debug, Default, zvariant::Type)]
use crate::SECRET_PROMPT_PREFIX;

#[derive(Clone, Debug, Default, zvariant::Type)]
#[zvariant(signature = "o")]
pub struct Prompt {
path: OwnedObjectPath,
}

impl Prompt {}
#[interface(name = "org.freedesktop.Secret.Prompt")]
impl Prompt {
pub async fn prompt(
&self,
window_id: &str,
#[zbus(object_server)] object_server: &zbus::ObjectServer,
) -> fdo::Result<()> {
let prompt = Prompt::new(1); // temporarily
object_server
.at(prompt.path().to_owned(), prompt.to_owned())
.await?;

Ok(())
}

pub async fn dismiss(
&self,
#[zbus(object_server)] object_server: &zbus::ObjectServer,
) -> fdo::Result<()> {
object_server.remove::<Self, _>(&self.path).await?;

Ok(())
}

#[zbus(signal)]
pub async fn completed(ctxt: &SignalContext<'_>) -> zbus::Result<()> {
Ok(())
}
}

impl Prompt {
pub fn new(prompts_counter: i32) -> Self {
Self {
path: OwnedObjectPath::try_from(format!(
"{}s{}",
SECRET_PROMPT_PREFIX, prompts_counter
))
.unwrap(),
}
}

pub fn path(&self) -> ObjectPath<'_> {
self.path.as_ref()
}
}

impl Serialize for Prompt {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
4 changes: 4 additions & 0 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const SECRET_SESSION_PREFIX: &str = "/org/freedesktop/secrets/session/";
const SECRET_COLLECTION_PREFIX: &str = "/org/freedesktop/secrets_Devel/collection/";
#[cfg(not(debug_assertions))]
const SECRET_COLLECTION_PREFIX: &str = "/org/freedesktop/secrets/collection/";
#[cfg(debug_assertions)]
const SECRET_PROMPT_PREFIX: &str = "/org/freedesktop/secrets_Devel/prompt/";
#[cfg(not(debug_assertions))]
const SECRET_PROMPT_PREFIX: &str = "/org/freedesktop/secrets/prompt/";

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
Expand Down

0 comments on commit a2b198b

Please sign in to comment.