aboutsummaryrefslogtreecommitdiff
path: root/lockchain-http
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-07-10 20:47:13 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-07-10 20:47:13 +0200
commite1e9c73476ba2792c3582ee7ecd14d0b39c3eef4 (patch)
tree39237e46485669260da5038cb011d8382f879a7a /lockchain-http
parent7dfaacb94c8e4a37fb68fcaa7435c8cc8a08e7f9 (diff)
Adding an example of how to register a user and adding new metadata
vault endpoints functions
Diffstat (limited to 'lockchain-http')
-rw-r--r--lockchain-http/src/handlers.rs81
-rw-r--r--lockchain-http/src/lib.rs17
2 files changed, 87 insertions, 11 deletions
diff --git a/lockchain-http/src/handlers.rs b/lockchain-http/src/handlers.rs
index f68f158..8ce44da 100644
--- a/lockchain-http/src/handlers.rs
+++ b/lockchain-http/src/handlers.rs
@@ -165,8 +165,85 @@ where
})
}
+pub fn get_all_metadata<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+where
+ B: Body,
+ V: Vault<B>,
+{
+ Json(OperationFailed {
+ explain: "Not implemented".into(),
+ error: LockError::Unknown,
+ })
+}
+
+pub fn put_metadata<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+where
+ B: Body,
+ V: Vault<B>,
+{
+ Json(OperationFailed {
+ explain: "Not implemented".into(),
+ error: LockError::Unknown,
+ })
+}
+
+pub fn get_metadata<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+where
+ B: Body,
+ V: Vault<B>,
+{
+ Json(OperationFailed {
+ explain: "Not implemented".into(),
+ error: LockError::Unknown,
+ })
+}
+
+pub fn update_metadata<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+where
+ B: Body,
+ V: Vault<B>,
+{
+ Json(OperationFailed {
+ explain: "Not implemented".into(),
+ error: LockError::Unknown,
+ })
+}
+
+pub fn vault_register<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+where
+ B: Body,
+ V: Vault<B>,
+{
+ Json(OperationFailed {
+ explain: "Not implemented".into(),
+ error: LockError::Unknown,
+ })
+}
+
+pub fn vault_login<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+where
+ B: Body,
+ V: Vault<B>,
+{
+ Json(OperationFailed {
+ explain: "Not implemented".into(),
+ error: LockError::Unknown,
+ })
+}
+
+pub fn vault_logout<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+where
+ B: Body,
+ V: Vault<B>,
+{
+ Json(OperationFailed {
+ explain: "Not implemented".into(),
+ error: LockError::Unknown,
+ })
+}
+
/// PUT /authenticate
-pub fn authenticate<B, V>(
+pub fn login<B, V>(
(item, req): (Json<Authenticate>, HttpRequestState<ApiState<B, V>>),
) -> impl Responder
where
@@ -196,7 +273,7 @@ where
}
/// PUT /de-authenticate
-pub fn deauthenticate<B, V>(
+pub fn logout<B, V>(
(item, req): (Json<Deauthenticate>, HttpRequestState<ApiState<B, V>>),
) -> impl Responder
where
diff --git a/lockchain-http/src/lib.rs b/lockchain-http/src/lib.rs
index 3adb503..961ad21 100644
--- a/lockchain-http/src/lib.rs
+++ b/lockchain-http/src/lib.rs
@@ -75,10 +75,8 @@ where
.resource("/vaults", |r| {
// Get existing vaults
r.method(http::Method::GET).with(handlers::get_vaults);
-
// Create new vault (if authorised)
r.method(http::Method::PUT).with(handlers::create_vault);
-
// Delete entire vault (if authorised)
r.method(http::Method::DELETE).with(handlers::delete_vault);
})
@@ -115,31 +113,32 @@ where
})
.resource("/vaults/{vaultid}/metadata/{metaid}", |r| {
// Get a specific metadata field
- r.method(http::Method::GET).with(handlers::get_all_records);
+ r.method(http::Method::GET).with(handlers::get_metadata);
// Update a specific metadata field
- r.method(http::Method::POST).with(handlers::get_all_records);
+ r.method(http::Method::POST).with(handlers::update_metadata);
})
.resource("/vaults/{vaultid}/register", |r| {
// Register a new user in a vault (with a registry token)
- r.method(http::Method::POST).with(handlers::deauthenticate)
+ r.method(http::Method::POST).with(handlers::vault_register)
})
.resource("/vaults/{vaultid}/login", |r| {
// Login as a user for this vault
- r.method(http::Method::POST).with(handlers::authenticate)
+ r.method(http::Method::POST).with(handlers::vault_login)
})
.resource("/vaults/{vaultid}/logout", |r| {
// Logout, closing an existing session
- r.method(http::Method::POST).with(handlers::deauthenticate)
+ r.method(http::Method::POST).with(handlers::vault_logout)
})
.resource("/users/login", |r| {
// Request a new auth token
- r.method(http::Method::POST).with(handlers::authenticate)
+ r.method(http::Method::POST).with(handlers::login)
})
.resource("/users/logout", |r| {
// Hand-in active auth token
- r.method(http::Method::POST).with(handlers::deauthenticate)
+ r.method(http::Method::POST).with(handlers::logout)
})
.resource("/api", |r| {
+ // Get information about this API endpoint
r.method(http::Method::GET).with(handlers::api_data);
}),
]