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

Implement Dump commands #66

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ serde = "1.0.104"
serde_json = "1.0.44"
serde_derive = "1.0.104"
serde_yaml = "0.8.11"
chrono = "0.4.10"
chrono = { version = "0.4.10", features = ["serde"] }
jsonwebtoken = "7.0.0-alpha.2"
app_dirs = "1.2.1"
ring = "0.16.9"
Expand Down
6 changes: 5 additions & 1 deletion src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ subcommands:
- settings:
about: "Manage the Lucid configuration file"
author: *author
template: *template
template: *template
- dump:
about: Dump or restore any data of a node
author: *author
template: *template
10 changes: 7 additions & 3 deletions src/kvstore.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
use block_modes::block_padding::ZeroPadding;
use block_modes::{BlockMode, Cbc};
use chashmap::CHashMap;
use chrono::serde::ts_seconds::serialize as ts_seconds;
use chrono::{DateTime, Utc};

use serpent::Serpent;

type SerpentCbc = Cbc<Serpent, ZeroPadding>;

#[derive(Debug, Clone)]
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct KvElement {
#[serde(skip_serializing)]
pub data: Vec<u8>,
pub mime_type: String,
#[serde(serialize_with = "ts_seconds")]
pub created_at: DateTime<Utc>,
#[serde(serialize_with = "ts_seconds")]
pub updated_at: DateTime<Utc>,
#[serde(serialize_with = "ts_seconds")]
pub expire_at: DateTime<Utc>,
pub update_count: i32,
pub locked: bool,
Expand Down Expand Up @@ -46,7 +51,7 @@ impl KvStore {
kv
}

pub fn set(&self, key: String, mut value: Vec<u8>) -> Option<KvElement> {
pub fn set(&self, key: String, mut value: Vec<u8>, mime_type: String) -> Option<KvElement> {
// TODO: prepare iterative persistence
if let Some(c) = &self.cipher {
let cipher = SerpentCbc::new_var(&c.priv_key, &c.iv).unwrap();
Expand All @@ -55,7 +60,6 @@ impl KvStore {
match &mut self.container.get_mut(&key) {
Some(kv_element) => {
if !kv_element.locked {
let mime_type = tree_magic::from_u8(value.as_ref());
kv_element.data = value;
kv_element.mime_type = mime_type;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#[macro_use]
extern crate clap;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate log;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

extern crate block_modes;
extern crate hex;
Expand Down
5 changes: 3 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ pub fn routes_filter(
.or(fs::dir("assets/webui/dist"))
.and(webui_enabled)
.or(warp::get().map(move || warp::reply::html(WELCOME_PAGE)))
.and(warp::path::end());
.and(warp::path::end())
.with(warp::log("lucid::server::webui"));

let robots = warp::path("robots.txt")
.and(path::end())
.and(warp::get().map(|| "User-agent: *\nDisallow: /"));
.and(warp::get().map(|| "User-agent: *\nDisallow: /api"));

let cors = warp::cors()
.allow_methods(vec!["HEAD", "GET", "PUT", "POST", "PATCH", "DELETE"])
Expand Down