support denoting entry entities in decomposed format (adding URLs)

feat/vaults
Tomáš Mládek 2022-02-07 21:59:30 +01:00
parent 686020e579
commit b5a90ce57c
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
2 changed files with 22 additions and 3 deletions

View File

@ -8,11 +8,18 @@ use std::io::{Cursor, Write};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InEntry {
pub entity: Option<Address>,
pub entity: Option<InAddress>,
pub attribute: String,
pub value: EntryValue,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InAddress {
Address(String),
Components { t: String, c: String },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Entry {
pub entity: Address,
@ -123,8 +130,19 @@ impl TryFrom<InEntry> for Entry {
fn try_from(in_entry: InEntry) -> Result<Self, Self::Error> {
match in_entry.entity {
Some(entity) => Ok(Entry {
entity,
Some(address) => Ok(Entry {
entity: match address {
InAddress::Address(address) => address.parse()?,
InAddress::Components { t, c } => {
// I absolutely cannot handle serde magic right now
// TODO: make this automatically derive from `Address` definition
match t.as_str() {
"Attribute" => Address::Attribute(c),
"Url" => Address::Url(c),
_ => c.parse()?,
}
}
},
attribute: in_entry.attribute,
value: in_entry.value,
}),

View File

@ -217,6 +217,7 @@ pub async fn get_object(
debug!("{:?}", result);
// TODO: make this automatically derive from `Address` definition
let (entity_type, entity_content) = match address {
Address::Hash(_) => ("Hash", None),
Address::Uuid(_) => ("Uuid", None),