Skip to content

Commit

Permalink
Make service generic over extra fields
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
  • Loading branch information
mirgee committed Jun 7, 2023
1 parent 7678382 commit 3b5751b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
90 changes: 90 additions & 0 deletions did_resolver_sov/src/resolution/extra_fields.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
pub struct ExtraFieldsSov {
#[serde(default)]
priority: u32,
#[serde(default)]
recipient_keys: Vec<String>,
#[serde(default)]
routing_keys: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
accept: Vec<String>,
}

impl ExtraFieldsSov {
pub fn builder() -> ExtraFieldsSovBuilder {
ExtraFieldsSovBuilder::default()
}

pub fn priority(&self) -> u32 {
self.priority
}

pub fn recipient_keys(&self) -> &[String] {
self.recipient_keys.as_ref()
}

pub fn routing_keys(&self) -> &[String] {
self.routing_keys.as_ref()
}

pub fn accept(&self) -> &[String] {
self.accept.as_ref()
}
}

#[derive(Default)]
pub struct ExtraFieldsSovBuilder {
priority: u32,
recipient_keys: Vec<String>,
routing_keys: Vec<String>,
accept: Vec<String>,
}

impl ExtraFieldsSovBuilder {
pub fn set_priority(&mut self, priority: u32) -> &mut Self {
self.priority = priority;
self
}

pub fn set_recipient_keys(&mut self, recipient_keys: Vec<String>) -> &mut Self {
self.recipient_keys = recipient_keys;
self
}

pub fn add_recipient_key(&mut self, recipient_key: String) -> &mut Self {
self.recipient_keys.push(recipient_key);
self
}

pub fn set_routing_keys(&mut self, routing_keys: Vec<String>) -> &mut Self {
self.routing_keys = routing_keys;
self
}

pub fn add_routing_key(&mut self, routing_key: String) -> &mut Self {
self.routing_keys.push(routing_key);
self
}

pub fn set_accept(&mut self, accept: Vec<String>) -> &mut Self {
self.accept = accept;
self
}

pub fn add_accept(&mut self, accept: String) -> &mut Self {
self.accept.push(accept);
self
}

pub fn build(&self) -> ExtraFieldsSov {
ExtraFieldsSov {
priority: self.priority,
recipient_keys: self.recipient_keys.clone(),
routing_keys: self.routing_keys.clone(),
accept: self.accept.clone(),
}
}
}
2 changes: 2 additions & 0 deletions did_resolver_sov/src/resolution/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod extra_fields;
mod resolver;
mod utils;

pub use extra_fields::ExtraFieldsSov;
pub use resolver::DidSovResolver;
5 changes: 4 additions & 1 deletion did_resolver_sov/src/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use crate::{
reader::AttrReader,
};

use super::utils::{is_valid_sovrin_did_id, ledger_response_to_ddo};
use super::{
utils::{is_valid_sovrin_did_id, ledger_response_to_ddo},
ExtraFieldsSov,
};

pub struct DidSovResolver {
ledger: Arc<dyn AttrReader>,
Expand Down

0 comments on commit 3b5751b

Please sign in to comment.