aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-09-06 20:23:27 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-09-06 20:23:27 +0200
commitf3824b79256133374aacd910f34ed2764640b1b7 (patch)
tree704727ea734eb793c320b06f0ea2e6ce31f424a8
parentc86cd21da7e5797a33f22c06004ec5c32bdeac05 (diff)
Various smol changes around the new Generator API
-rw-r--r--lockchain-core/src/init.rs79
-rw-r--r--lockchain-core/src/initialise.rs55
-rw-r--r--lockchain-core/src/lib.rs4
-rw-r--r--lockchain-files/examples/create.rs39
-rw-r--r--lockchain-files/src/lib.rs3
5 files changed, 102 insertions, 78 deletions
diff --git a/lockchain-core/src/init.rs b/lockchain-core/src/init.rs
new file mode 100644
index 0000000..f7f2d5d
--- /dev/null
+++ b/lockchain-core/src/init.rs
@@ -0,0 +1,79 @@
+use traits::{Body, Vault};
+
+/// Describes the internal permission layout of a vault
+pub enum VaultType {
+ /// Create an all-powerful root user which can access everything
+ Administrated {
+ /// Set a root password
+ secret: String,
+ },
+ /// Similar to `Administrated`
+ /// but only allows a single-user for a vault
+ SoloUser { username: String, secret: String },
+}
+
+/// A shared initialisation generator for vaults
+///
+/// All vaults, regardless of backends
+/// or persistence layer
+/// share the same common principles
+/// of users and permissions.
+///
+/// This means that intiailisation is shared,
+/// regardless of what backend implements it.
+///
+/// A `VaultGenerator` takes arguments
+/// for a generic backend,
+/// calls functions provided by said backend
+/// and then returns the actual backend.
+pub struct Generator {
+ #[doc(hidden)]
+ pub name: Option<String>,
+ #[doc(hidden)]
+ pub location: Option<String>,
+ #[doc(hidden)]
+ pub user_type: Option<VaultType>,
+}
+
+impl Generator {
+ /// Start a new generator for a generic type
+ pub fn new() -> Self {
+ Self {
+ name: None,
+ location: None,
+ user_type: None,
+ }
+ }
+
+ pub fn path<N, L>(self, name: N, location: L) -> Self
+ where
+ N: Into<String>,
+ L: Into<String>,
+ {
+ Self {
+ name: Some(name.into()),
+ location: Some(location.into()),
+ ..self
+ }
+ }
+
+ /// Specify the internal user permission structure for this vault
+ ///
+ /// If you don't know what this means, please consult
+ /// the `VaultType` enum documentation
+ pub fn user_type(self, t: VaultType) -> Self {
+ Self {
+ user_type: Some(t),
+ ..self
+ }
+ }
+
+ /// Finally call this function to construct the vault
+ pub fn finalise<V, B>(self) -> V
+ where
+ V: Vault<B>,
+ B: Body,
+ {
+ V::new(self)
+ }
+}
diff --git a/lockchain-core/src/initialise.rs b/lockchain-core/src/initialise.rs
deleted file mode 100644
index 6ae48a9..0000000
--- a/lockchain-core/src/initialise.rs
+++ /dev/null
@@ -1,55 +0,0 @@
-//! A shared initialisation block for vaults
-//!
-//! All vaults, regardless of backends
-//! or persistence layer
-//! share the same common principles
-//! of users and permissions.
-//!
-//! This means that intiailisation is shared,
-//! regardless of what backend implements it.
-//!
-//! A `VaultGenerator` takes arguments
-//! for a generic backend,
-//! calls functions provided by said backend
-//! and then returns the actual backend.
-
-use traits::{Body, Vault};
-
-/// A generator is initialised with a generic backend
-/// which can then chain-call functions to setup the
-/// base functionality of a Vault, and then yield
-/// a working and initialised instance of the
-/// generic vault backend.
-pub struct Generator {
- #[doc(hidden)]
- pub name: Option<String>,
- #[doc(hidden)]
- pub location: Option<String>,
-}
-
-impl Generator {
- /// Start a new generator for a generic type
- pub fn new() -> Self {
- Self {
- name: None,
- location: None,
- }
- }
-
- pub fn path<S: Into<String>>(self, name: S, location: S) -> Self {
- Self {
- name: Some(name.into()),
- location: Some(location.into()),
- ..self
- }
- }
-
- /// Finally call this function to construct the vault
- pub fn finalise<V, B>(self) -> V
- where
- V: Vault<B>,
- B: Body,
- {
- V::new(self)
- }
-}
diff --git a/lockchain-core/src/lib.rs b/lockchain-core/src/lib.rs
index b3d0931..52139bb 100644
--- a/lockchain-core/src/lib.rs
+++ b/lockchain-core/src/lib.rs
@@ -76,15 +76,17 @@ mod record;
pub mod traits;
pub mod users;
-pub mod initialise;
+mod init;
pub use self::crypto::PackedData;
pub use self::meta::{MetaDomain, VaultMetadata};
pub use self::record::{EncryptedBody, Header, Payload, Record};
+pub use self::init::Generator;
/// Export commonly used types via the prelude
pub mod prelude {
pub use super::crypto::PackedData;
pub use super::meta::{MetaDomain, VaultMetadata};
pub use super::record::{EncryptedBody, Header, Payload, Record};
+ pub use super::init::Generator;
}
diff --git a/lockchain-files/examples/create.rs b/lockchain-files/examples/create.rs
index b152cac..b1c6a94 100644
--- a/lockchain-files/examples/create.rs
+++ b/lockchain-files/examples/create.rs
@@ -3,8 +3,8 @@ extern crate lockchain_files as files;
use files::DataVault;
use lcc::traits::Vault;
-use lcc::users::{User, UserStore};
-use lcc::{EncryptedBody, Payload, Record};
+use lcc::users::User;
+use lcc::{Generator, EncryptedBody, Payload, Record};
use std::env;
fn main() {
@@ -12,29 +12,28 @@ fn main() {
let path = env::args().nth(1).unwrap();
let name = env::args().nth(2).unwrap();
- let vault: DataVault<EncryptedBody> = DataVault::new(&name, &path);
+ let mut vault: DataVault<EncryptedBody> = Generator::new().path(name, path).finalise();
+ vault.sync();
-
+ // let vault: DataVault<EncryptedBody> = DataVault::new(&name, &path);
+ // let mut store = match (
+ // vault.meta_pull_domain("userstore"),
+ // vault.meta_pull_domain("registry"),
+ // ) {
+ // (Some(users), Some(registry)) => (users.clone(), registry.clone()).into(),
+ // _ => UserStore::default(),
+ // };
+ // /* Some users of our vault have the same password :S */
+ // store.add(User::register("alice", "password"));
+ // let token = store.get_token(vec!());
- // let mut store = match (
- // vault.meta_pull_domain("userstore"),
- // vault.meta_pull_domain("registry"),
- // ) {
- // (Some(users), Some(registry)) => (users.clone(), registry.clone()).into(),
- // _ => UserStore::default(),
- // };
+ // let (users, registry) = store.into();
- // /* Some users of our vault have the same password :S */
- // store.add(User::register("alice", "password"));
- // let token = store.get_token(vec!());
-
- // let (users, registry) = store.into();
-
- // vault.meta_push_domain(users);
- // vault.meta_push_domain(registry);
- // vault.sync();
+ // vault.meta_push_domain(users);
+ // vault.meta_push_domain(registry);
+ // vault.sync();
} else {
eprintln!("Usage: create <path> <name> [FLAGS] (there are no flags)")
}
diff --git a/lockchain-files/src/lib.rs b/lockchain-files/src/lib.rs
index 97912be..5926355 100644
--- a/lockchain-files/src/lib.rs
+++ b/lockchain-files/src/lib.rs
@@ -56,9 +56,8 @@ extern crate serde;
use lcc::traits::{Body, LoadRecord, Vault};
use lcc::{
- initialise::Generator,
users::{Access, Token},
- MetaDomain, Payload, Record, VaultMetadata,
+ Generator, MetaDomain, Payload, Record, VaultMetadata,
};
use std::collections::HashMap;