Skip to content

Commit

Permalink
Update Collection::new()
Browse files Browse the repository at this point in the history
Updated how Collection objectpath is generated.
Introduced created: u64, parameter to supply the date, rather than create
it inside new()

Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
  • Loading branch information
warusadura committed Feb 16, 2024
1 parent 758f4be commit b23a796
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 7 additions & 9 deletions server/src/daemon/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use zvariant::{ObjectPath, OwnedObjectPath};

use super::{error::ServiceError, prompt::Prompt, Result, Service};

const SECRET_COLLECTION_OBJECTPATH: &str = "/org/freedesktop/secrets.Devel/collection/";

#[derive(Debug)]
pub struct Collection {
keyring: Arc<Keyring>,
Expand Down Expand Up @@ -123,20 +125,16 @@ impl Collection {
}

impl Collection {
// temporarily creates a generic Collection object
pub fn new(label: &str, alias: &str, keyring: Arc<Keyring>) -> Self {
pub fn new(label: &str, alias: &str, created: u64, keyring: Arc<Keyring>) -> Self {
Self {
items: Default::default(),
label: label.to_owned(),
alias: RwLock::new(alias.to_owned()),
locked: AtomicBool::new(false),
created: Duration::from_secs(23123),
modified: Duration::from_secs(23123),
path: OwnedObjectPath::try_from(format!(
"/org/freedesktop/secrets/collection/{}",
label
))
.unwrap(),
created: Duration::from_secs(created),
modified: Duration::from_secs(created),
path: OwnedObjectPath::try_from(format!("{}{}", SECRET_COLLECTION_OBJECTPATH, alias))
.unwrap(),
keyring,
}
}
Expand Down
11 changes: 10 additions & 1 deletion server/src/daemon/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{
collections::HashMap,
sync::{Arc, Mutex},
time::SystemTime,
};

use oo7::{
Expand Down Expand Up @@ -57,7 +58,15 @@ impl Service {
alias: &str,
#[zbus(object_server)] object_server: &ObjectServer,
) -> Result<(OwnedObjectPath, Prompt)> {
let collection = Collection::new(properties.label(), alias, Arc::clone(&self.keyring)); // temporarily
let collection = Collection::new(
properties.label(),
alias,
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs(),
Arc::clone(&self.keyring),
);
let path = OwnedObjectPath::from(collection.path());
object_server.at(&path, collection).await?;
let prompt = Prompt::default(); // temp Prompt
Expand Down

0 comments on commit b23a796

Please sign in to comment.