Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OOB Invitation #74

Merged
merged 23 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions did-endpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ edition = "2021"
[dependencies]
axum = { version = "0.6.20", features = ["macros"] }
chrono = { version = "0.4.26" }
did-utils = { path = "../did-utils"}
did-utils = { path = "../did-utils" }
dotenv-flow = "0.15.0"
hyper = { version = "0.14.27", features = ["full"] }
multibase = { version = "0.8.0" } # earlier version due to 'did-utils'
multibase = { version = "0.8.0" } # earlier version due to 'did-utils'
serde_json = "1.0.104"
thiserror = "1.0.49"
tokio = { version = "1.30.0", features = ["full"] }
tracing = "0.1.37"
url = { version = "2.4.0" }
uuid = { version = "1.4.1", features = ["v4"] }
zeroize = { version = "1.6.0" }
nix = "0.22.0"

# Plugins traits
server-plugin = { path = "../server-plugin" }
Expand Down
29 changes: 29 additions & 0 deletions did-endpoint/src/util/filesystem.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use nix::fcntl::{flock, FlockArg};
use std::fs::OpenOptions;
use std::io::{Error as IoError, ErrorKind, Result as IoResult};
use std::os::unix::io::AsRawFd;

// Define a trait for file system operations
pub trait FileSystem: Send + 'static {
fn read_to_string(&self, path: &str) -> IoResult<String>;
fn write(&mut self, path: &str, content: &str) -> IoResult<()>;
fn read_dir_files(&self, path: &str) -> IoResult<Vec<String>>;
fn create_dir_all(&mut self, path: &str) -> IoResult<()>;
fn write_with_lock(&self, path: &str, content: &str) -> IoResult<()>;
// Add other file system operations as needed
}

Expand Down Expand Up @@ -42,6 +46,25 @@ impl FileSystem for StdFileSystem {
std::fs::create_dir_all(path)
}

fn write_with_lock(&self, path: &str, content: &str) -> IoResult<()> {
let mut options = OpenOptions::new();
options.read(true);
options.write(true);
options.create(true);

let file = options.open(path)?;

// Acquire an exclusive lock before writing to the file
flock(file.as_raw_fd(), FlockArg::LockExclusive)
.map_err(|_| IoError::new(ErrorKind::Other, "Error acquiring file lock"))?;

std::fs::write(&path, &content).expect("Error saving base64-encoded image to file");

// Release the lock after writing to the file
flock(file.as_raw_fd(), FlockArg::Unlock).expect("Error releasing file lock");
Ok(())
}

// Implement other file system operations as needed
}

Expand Down Expand Up @@ -74,8 +97,14 @@ mod tests {
fn create_dir_all(&mut self, _path: &str) -> IoResult<()> {
Ok(())
}

fn write_with_lock(&self, _path: &str, _content: &str) -> IoResult<()>{
Ok(())
}
}



#[test]
fn can_mock_fs_operations() {
let mut mock_fs = MockFileSystem::default();
Expand Down
4 changes: 4 additions & 0 deletions did-endpoint/src/util/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ mod tests {
fn create_dir_all(&mut self, _path: &str) -> IoResult<()> {
Ok(())
}

fn write_with_lock(&self, _path: &str, _content: &str) -> IoResult<()>{
Ok(())
}
}

#[test]
Expand Down
4 changes: 3 additions & 1 deletion generic-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ server-plugin = { path = "../server-plugin" }
# optional
chrono = { version = "0.4.26", optional = true }
did-endpoint = { path = "../did-endpoint", optional = true }
oob-messages = { path = "../oob-messages", optional = true }

[dev-dependencies]
tower = { version = "0.4.13", features = ["util"] }

[features]
default = ["plugin-index", "plugin-did_endpoint"]
default = ["plugin-index", "plugin-did_endpoint", "plugin-oob_messages"]

# plugins
plugin-index = ["dep:chrono"]
plugin-did_endpoint = ["dep:did-endpoint"]
plugin-oob_messages = ["dep:oob-messages"]
4 changes: 2 additions & 2 deletions generic-server/src/plugin/index/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::util::crate_name;

pub fn routes() -> Router {
Router::new() //
.route("/", get(index))
.route("/about", get(index))
}

pub async fn index() -> Json<Value> {
Expand Down Expand Up @@ -36,7 +36,7 @@ mod tests {
let app = routes();

let response = app
.oneshot(Request::builder().uri("/").body(Body::empty()).unwrap())
.oneshot(Request::builder().uri("/about").body(Body::empty()).unwrap())
.await
.unwrap();

Expand Down
2 changes: 2 additions & 0 deletions generic-server/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ lazy_static! {
Box::<index::IndexPlugin>::default(),
#[cfg(feature = "plugin-did_endpoint")]
Box::<did_endpoint::plugin::DidEndpointPlugin>::default(),
#[cfg(feature = "plugin-oob_messages")]
Box::<oob_messages::plugin::OOBMessagesPlugin>::default(),
];
}
4 changes: 4 additions & 0 deletions mediator-coordination/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,8 @@ impl FileSystem for MockFileSystem {
fn create_dir_all(&mut self, _path: &str) -> IoResult<()> {
Ok(())
}

fn write_with_lock(&self, _path: &str, _content: &str) -> IoResult<()>{
Ok(())
}
}
2 changes: 1 addition & 1 deletion mediator-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lazy-regex = "2"
async-trait = "0.1"
strum = "0.24"
strum_macros = "0.24"
uuid = { version = "1", features = ["fast-rng", "v4",] }
uuid = { version = "1", features = ["fast-rng", "v4"] }

csv = "1.1.6"

Expand Down
3 changes: 3 additions & 0 deletions oob-messages/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SERVER_PUBLIC_DOMAIN=https://example.com
SERVER_LOCAL_PORT=3000
STORAGE_DIRPATH="target/storage"
32 changes: 32 additions & 0 deletions oob-messages/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "oob-messages"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
uuid = { version = "1", features = ["fast-rng", "v4"] }
multibase = "0.9.1"
serde_json = "1"
serde = { version = "1", features = ["derive"] }
dotenv-flow = "0.16.0"
url = { version = "2.4.0" }
axum = { version = "0.6.20" }
tracing = "0.1.37"
qrcode = "0.12.0"
image = "0.23"
base64 = "0.13.0"
reqwest = "0.11"
tempdir = "0.3.7"
headers = "0.3"
lazy_static = "1.4.0"
# Plugins traits
server-plugin = { path = "../server-plugin" }
did-endpoint = { path = "../did-endpoint" }

[dev-dependencies]
tokio = { version = "1.30.0", features = ["full"] }
tower-http = { version = "0.4.3", features = ["catch-panic", "trace"] }
hyper = { version = "0.14.27", features = ["full"] }
tower = "0.4"
1 change: 1 addition & 0 deletions oob-messages/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const OOB_INVITATION_2_0: &str = "https://didcomm.org/out-of-band/2.0/invitation";
5 changes: 5 additions & 0 deletions oob-messages/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod models;
mod constants;
mod util;
pub mod plugin;
pub mod web;
Loading
Loading