Skip to content

Commit

Permalink
Merge pull request #128 from rneswold/pr-issue15
Browse files Browse the repository at this point in the history
Add security to DrMem
  • Loading branch information
rneswold authored Dec 27, 2024
2 parents 32fad78 + 9ce8e79 commit 4817e2a
Show file tree
Hide file tree
Showing 12 changed files with 1,012 additions and 282 deletions.
769 changes: 541 additions & 228 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tokio-stream = { version = "0.1", default-features = false }
tracing = { version = "0.1", default-features = false }
tracing-futures = { version = "0.2", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
serde = { version = "1", default-features = false }
serde = { version = "1", default-features = false, features = ["rc"] }
serde_json = { version = "1", default-features = false }
serde_derive = { version = "1", default-features = false }
palette = { version = "0.7", default-features = false }
Expand Down
5 changes: 3 additions & 2 deletions drmemd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ optional = true
# This section defines the optional dependencies for backend storage.

[dependencies.redis]
version = "0.26"
version = "0.27"
default-features = false
features = ["tokio-comp", "streams"]
optional = true
Expand Down Expand Up @@ -142,10 +142,11 @@ optional = true
[dependencies.warp]
version = "0.3"
default-features = false
features = ["tls"]
optional = true

[dependencies.libmdns]
version = "0.8"
version = "0.9"
default-features = false
optional = true

Expand Down
10 changes: 8 additions & 2 deletions drmemd/src/backends/redis/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ pub struct Config {
pub dbn: Option<i64>,
}

impl<'a> Config {
impl Config {
pub const fn new() -> Config {
Config {
addr: None,
dbn: None,
}
}

pub fn get_addr(&'a self) -> SocketAddr {
pub fn get_addr(&self) -> SocketAddr {
self.addr.unwrap_or_else(|| {
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 6379)
})
Expand All @@ -32,3 +32,9 @@ impl<'a> Config {
}

pub static DEF: Config = Config::new();

impl Default for Config {
fn default() -> Self {
Self::new()
}
}
4 changes: 2 additions & 2 deletions drmemd/src/backends/redis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,14 +656,14 @@ impl RedisStore {
// If a "units" field exists and it's a string, we can
// save it in the `units` field of the reply.

let units = hmap.get("units").map(String::clone);
let units = hmap.get("units").cloned();

// If a "driver" field exists and it's a string, save it
// in the "drivers" field of the reply.

let driver = hmap
.get("driver")
.map(String::clone)
.cloned()
.unwrap_or_else(|| String::from("*missing*"));

Ok(client::DevInfoReply {
Expand Down
6 changes: 6 additions & 0 deletions drmemd/src/backends/simple/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ impl Config {
}

pub static DEF: Config = Config::new();

impl Default for Config {
fn default() -> Self {
Self::new()
}
}
18 changes: 9 additions & 9 deletions drmemd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ longitude = 45.0
) {
Ok(cfg) => {
assert_eq!(cfg.graphql.name, "unknown name");
assert_eq!(cfg.graphql.location, "unknown location");
assert_eq!(cfg.graphql.location, "unknown location".into());
assert_eq!(
cfg.graphql.addr,
(Ipv4Addr::new(0, 0, 0, 0), 3000).into()
Expand All @@ -362,7 +362,7 @@ longitude = 45.0
) {
Ok(cfg) => {
assert_eq!(cfg.graphql.name, "unknown name");
assert_eq!(cfg.graphql.location, "unknown location");
assert_eq!(cfg.graphql.location, "unknown location".into());
assert_eq!(
cfg.graphql.addr,
(Ipv4Addr::new(0, 0, 0, 0), 3000).into()
Expand All @@ -384,7 +384,7 @@ name = "primary-node"
) {
Ok(cfg) => {
assert_eq!(cfg.graphql.name, "primary-node");
assert_eq!(cfg.graphql.location, "unknown location");
assert_eq!(cfg.graphql.location, "unknown location".into());
assert_eq!(
cfg.graphql.addr,
(Ipv4Addr::new(0, 0, 0, 0), 3000).into()
Expand All @@ -406,7 +406,7 @@ location = "basement"
) {
Ok(cfg) => {
assert_eq!(cfg.graphql.name, "unknown name");
assert_eq!(cfg.graphql.location, "basement");
assert_eq!(cfg.graphql.location, "basement".into());
assert_eq!(
cfg.graphql.addr,
(Ipv4Addr::new(0, 0, 0, 0), 3000).into()
Expand All @@ -426,7 +426,7 @@ addr = "10.1.1.0:1234"
) {
Ok(cfg) => {
assert_eq!(cfg.graphql.name, "unknown name");
assert_eq!(cfg.graphql.location, "unknown location");
assert_eq!(cfg.graphql.location, "unknown location".into());
assert_eq!(
cfg.graphql.addr,
(Ipv4Addr::new(10, 1, 1, 0), 1234).into()
Expand All @@ -449,14 +449,14 @@ pref_port = 4000
) {
Ok(cfg) => {
assert_eq!(cfg.graphql.name, "unknown name");
assert_eq!(cfg.graphql.location, "unknown location");
assert_eq!(cfg.graphql.location, "unknown location".into());
assert_eq!(
cfg.graphql.addr,
(Ipv4Addr::new(0, 0, 0, 0), 3000).into()
);
assert_eq!(
cfg.graphql.pref_host,
Some(String::from("www.google.com"))
Some("www.google.com".into())
);
assert_eq!(cfg.graphql.pref_port, 4000)
}
Expand All @@ -474,14 +474,14 @@ pref_host = "www.google.com"
) {
Ok(cfg) => {
assert_eq!(cfg.graphql.name, "unknown name");
assert_eq!(cfg.graphql.location, "unknown location");
assert_eq!(cfg.graphql.location, "unknown location".into());
assert_eq!(
cfg.graphql.addr,
(Ipv4Addr::new(0, 0, 0, 0), 3000).into()
);
assert_eq!(
cfg.graphql.pref_host,
Some(String::from("www.google.com"))
Some("www.google.com".into())
);
assert_eq!(cfg.graphql.pref_port, 3000)
}
Expand Down
25 changes: 19 additions & 6 deletions drmemd/src/graphql/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use serde_derive::Deserialize;
use std::net::{Ipv4Addr, SocketAddr};
use std::{
net::{Ipv4Addr, SocketAddr},
path::Path,
sync::Arc,
};

fn def_name() -> String {
String::from("unknown name")
"unknown name".into()
}

fn def_location() -> String {
String::from("unknown location")
fn def_location() -> Arc<str> {
"unknown location".into()
}

fn def_address() -> SocketAddr {
Expand All @@ -17,17 +21,25 @@ fn def_pref_port() -> u16 {
3000
}

#[derive(Deserialize)]
pub struct Security {
pub clients: Arc<[String]>,
pub cert_file: Arc<Path>,
pub key_file: Arc<Path>,
}

#[derive(Deserialize)]
pub struct Config {
#[serde(default = "def_name")]
pub name: String,
#[serde(default = "def_location")]
pub location: String,
pub location: Arc<str>,
#[serde(default = "def_address")]
pub addr: SocketAddr,
pub pref_host: Option<String>,
pub pref_host: Option<Arc<str>>,
#[serde(default = "def_pref_port")]
pub pref_port: u16,
pub security: Option<Security>,
}

impl Default for Config {
Expand All @@ -38,6 +50,7 @@ impl Default for Config {
addr: def_address(),
pref_host: None,
pref_port: def_pref_port(),
security: None,
}
}
}
Loading

0 comments on commit 4817e2a

Please sign in to comment.