aboutsummaryrefslogtreecommitdiff
path: root/lockchain-http
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-06-12 01:24:27 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-06-12 01:24:27 +0200
commit5e4a2c1df2aceef1ad736f6ddd9d3170711a8510 (patch)
tree36ed4a8b83ed2d6e061d2622e26420a30e8f6aa3 /lockchain-http
parent8cbd45f0af5fda64c409c9486b7a6d40814ef2d7 (diff)
Adding /api and /vault endpoints as first working routes ✨
Diffstat (limited to 'lockchain-http')
-rw-r--r--lockchain-http/src/handlers.rs27
-rw-r--r--lockchain-http/src/lib.rs6
-rw-r--r--lockchain-http/src/model.rs20
3 files changed, 48 insertions, 5 deletions
diff --git a/lockchain-http/src/handlers.rs b/lockchain-http/src/handlers.rs
index 77bc823..4fc3c27 100644
--- a/lockchain-http/src/handlers.rs
+++ b/lockchain-http/src/handlers.rs
@@ -5,14 +5,25 @@ use lockchain::{
traits::{Body, Vault}, Record,
};
-use model::CarrierMessage;
+use model::*;
use std::sync::{Arc, Mutex};
type HttpRequestState<T> = HttpRequest<Arc<Mutex<T>>>;
+/// GET /vault
+///
+/// Check the documentation for more information about how to provide payloads
+pub fn get_vaults<B: Body>(req: HttpRequestState<impl Vault<B>>) -> impl Responder {
+ let meta = req.state().lock().unwrap().metadata();
+ Json(VaultList {
+ vaults: vec![meta.name],
+ count: meta.size,
+ })
+}
+
/// PUT /vault
-///
+///
/// Check the documentation for more information about how to provide payloads
pub fn create_vault<B: Body>(_req: HttpRequestState<impl Vault<B>>) -> impl Responder {
format!("Unimplemented!")
@@ -64,3 +75,15 @@ pub fn authenticate<B: Body>(_req: HttpRequestState<impl Vault<B>>) -> impl Resp
pub fn deauthenticate<B: Body>(_req: HttpRequestState<impl Vault<B>>) -> impl Responder {
format!("Unimplemented!")
}
+
+/// GET /api
+///
+/// Check the documentation for more information about how to provide payloads
+pub fn api_data<B: Body>(_: HttpRequestState<impl Vault<B>>) -> impl Responder {
+ Json(ApiInformation {
+ version: "1.0".into(),
+ providers: vec!["FileVault".into(), "EncryptedBody".into()],
+ hostname: None,
+ supported: "1.0".into(),
+ })
+}
diff --git a/lockchain-http/src/lib.rs b/lockchain-http/src/lib.rs
index a3872e1..6468967 100644
--- a/lockchain-http/src/lib.rs
+++ b/lockchain-http/src/lib.rs
@@ -62,6 +62,9 @@ pub fn create_server<B: Body + 'static>(
vec![
App::with_state(Arc::clone(&state))
.resource("/vault", |r| {
+ r.method(http::Method::GET).with(handlers::get_vaults)
+ })
+ .resource("/vault", |r| {
r.method(http::Method::PUT).with(handlers::create_vault)
})
.resource("/vault/{vaultid}", |r| r.f(handlers::update_vault))
@@ -77,7 +80,8 @@ pub fn create_server<B: Body + 'static>(
r.f(handlers::delete_record)
})
.resource("/authenticate", |r| r.f(handlers::authenticate))
- .resource("/deauthenticate", |r| r.f(handlers::deauthenticate)),
+ .resource("/deauthenticate", |r| r.f(handlers::deauthenticate))
+ .resource("/api", |r| r.f(handlers::api_data)),
]
}).bind(format!("{}:{}", bind, port))
.expect("Oh no!")
diff --git a/lockchain-http/src/model.rs b/lockchain-http/src/model.rs
index f9e2665..ce92e1a 100644
--- a/lockchain-http/src/model.rs
+++ b/lockchain-http/src/model.rs
@@ -15,9 +15,25 @@ pub struct CarrierMessage<T: Serialize + DeserializeOwned> {
pub data: Option<T>,
}
+/// **Returns** Api information
+#[derive(Serialize, Deserialize)]
+pub struct ApiInformation {
+ pub version: String,
+ pub providers: Vec<String>,
+ pub hostname: Option<String>,
+ pub supported: String,
+}
+
+/// **Returns** List existing vaults
+#[derive(Serialize, Deserialize)]
+pub struct VaultList {
+ pub vaults: Vec<String>,
+ pub count: usize,
+}
+
/// Fields provided when creating a new vault
#[derive(Serialize, Deserialize)]
pub struct VaultCreate {
- name: String,
- location: String,
+ pub name: String,
+ pub location: String,
}