// //! Definition of the core lockchain API // use actix_web::{HttpRequest, Json, Responder}; // use lockchain::{ // traits::{Body, Vault}, Record, // }; // use models::{inputs::*, responses::*, NoneError, Response}; // use state::ApiState; // use std::intrinsics; // use std::sync::{Arc, Mutex}; // type HttpRequestState = HttpRequest>>; // /// GET /vault // /// // /// Check the documentation for more information about how to provide payloads // pub fn get_vaults(req: HttpRequestState>) -> impl Responder // where // B: Body, // V: Vault, // { // let state = req.state().lock().unwrap(); // Json(VaultList { // vaults: state.vaults().iter().map(|s| s.to_string()).collect(), // count: state.count(), // }) // } // /// PUT /vault // /// // /// Check the documentation for more information about how to provide payloads // pub fn create_vault( // (item, req): (Json, HttpRequestState>), // ) -> impl Responder // where // B: Body, // V: Vault, // { // let mut state = req.state().lock().unwrap(); // let location = if state.bound_scope { // state.working_dir.clone().join(&item.location) // } else { // (&item.location).into() // }; // state.add_vault(&item.name, V::new(&item.name, location.to_str().unwrap())); // Json(Response::Success::) // } // pub fn delete_vault( // (item, req): (Json, HttpRequestState>), // ) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::errors::Error as LockError; // Json(OperationFailed:: { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // }) // } // pub fn scope_vault( // (item, req): (Json, HttpRequestState>), // ) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::errors::Error as LockError; // Json(OperationFailed:: { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // }) // } // pub fn unscope_vault( // (item, req): (Json, HttpRequestState>), // ) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::errors::Error as LockError; // Json(Response::Failure::(OperationFailed { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // })) // // Json() // } // /// POST /vault/{vault-id} // pub fn update_vault(_req: HttpRequestState>) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::errors::Error as LockError; // Json(OperationFailed:: { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // }) // } // pub fn get_all_records(_req: HttpRequestState>) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::errors::Error as LockError; // Json(OperationFailed:: { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // }) // } // /// PUT /vault/{vault-id}/records // pub fn create_record(_req: HttpRequestState>) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::errors::Error as LockError; // Json(OperationFailed:: { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // }) // } // /// GET /vault/{vault-id}/records/{record-id} // pub fn get_record( // (item, req): (Json, HttpRequestState>), // ) -> impl Responder // where // B: Body, // V: Vault, // { // let mut state = req.state().lock().unwrap(); // let vault = state.get_vault(""); // use lockchain::errors::Error as LockError; // Json(OperationFailed:: { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // }) // } // /// POST /vault/{vault-id}/records/{record-id} // pub fn update_record(_req: HttpRequestState>) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::errors::Error as LockError; // Json(OperationFailed:: { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // }) // } // /// DELETE /vault/{vault-id}/records/{record-id} // pub fn delete_record(_req: HttpRequestState>) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::errors::Error as LockError; // Json(OperationFailed:: { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // }) // } // /// PUT /authenticate // pub fn authenticate( // (item, req): (Json, HttpRequestState>), // ) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::users::*; // let Authenticate { username, password } = item.into_inner(); // Json(match pam_authenticate(&username, &password) { // Ok(()) => { // /* Store the token for auth later */ // let state = req.state().lock().unwrap(); // let token = String::new(); // state.tokens.insert(token.clone()); // Response::Token(TokenMessage { // username, // token: token, // }) // } // Err(e) => Response::Failure(OperationFailed { // reason: "Failed to authenticate user".into(), // error: e.into(), // }), // }) // } // /// PUT /de-authenticate // pub fn deauthenticate( // (item, req): (Json, HttpRequestState>), // ) -> impl Responder // where // B: Body, // V: Vault, // { // use lockchain::errors::Error as LockError; // Json(OperationFailed:: { // reason: "Not implemented".into(), // error: LockError::UnknownFailure.into(), // }) // } // /// GET /api // /// // /// Check the documentation for more information about how to provide payloads // pub fn api_data>(_: HttpRequestState>) -> impl Responder // where // B: Body, // V: Vault, // { // Json(ApiInformation { // version: "1.0".into(), // providers: vec![ // unsafe { intrinsics::type_name::() }.into(), // unsafe { intrinsics::type_name::() }.into(), // ], // hostname: None, // supported: "1.0".into(), // }) // }