mirror of
https://github.com/fluencelabs/fluent-pad
synced 2025-04-24 16:32:13 +00:00
msg -> entry, add auth check to get
functions
This commit is contained in:
parent
e225a7818d
commit
641e4da281
16
services/history-inmemory/Cargo.lock
generated
16
services/history-inmemory/Cargo.lock
generated
@ -26,9 +26,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.2.16"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e65d9ffa281a0e9328fa6eb2468b8235a197013b9b5032aa9c2d2c0d54f99442"
|
||||
checksum = "27d9a5e4292d7bbd809a0e968e3c3aacac91cbc5acab3e26ee1e1d726f0aab24"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"fluence-sdk-main",
|
||||
@ -36,18 +36,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.2.16"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e5402cf99199b025bd41f52b4e77c58f6b76a8c34ae33a2c3612f024af28d32"
|
||||
checksum = "ea1a7c75a617f827d1ba9a17b4d84e1565ab239915c63f5a85c41f89a9f1d4ba"
|
||||
dependencies = [
|
||||
"fluence-sdk-wit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-main"
|
||||
version = "0.2.16"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "584cc07494112ad39d04fc8c0f6fb687f6c03c4908c7739c46c79ae112df083d"
|
||||
checksum = "6edcc983f9517c1b6bf9f851ef27f2894a3159aaa4a2fb6c9deb2ae8ecb603fa"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"log",
|
||||
@ -56,9 +56,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.2.16"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91c6e8b4da4bb732a744fd625de39e5f9faaf41d3919c8391a11d8528dad22e5"
|
||||
checksum = "b75dbdd0275160f3818db3218563d791e6c612b616cd3c5d6e66283f207f648d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -18,7 +18,7 @@ use fluence::fce;
|
||||
|
||||
#[fce]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
|
||||
pub struct Message {
|
||||
pub struct Entry {
|
||||
pub id: u64,
|
||||
pub body: String,
|
||||
}
|
@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::message::Message;
|
||||
use crate::entry::Entry;
|
||||
use crate::Result;
|
||||
|
||||
use crate::results::{AddServiceResult, EmptyResult, GetMessagesServiceResult};
|
||||
use crate::results::{AddServiceResult, EmptyResult, GetEntriesServiceResult};
|
||||
use std::convert::From;
|
||||
use std::error::Error;
|
||||
|
||||
@ -57,15 +57,15 @@ fn to_error_core(err: &HistoryError) -> i32 {
|
||||
impl From<Result<u64>> for AddServiceResult {
|
||||
fn from(result: Result<u64>) -> Self {
|
||||
match result {
|
||||
Ok(msg_id) => Self {
|
||||
Ok(entry_id) => Self {
|
||||
ret_code: crate::service_api::SUCCESS_CODE,
|
||||
err_msg: String::new(),
|
||||
msg_id: msg_id,
|
||||
entry_id,
|
||||
},
|
||||
Err(err) => Self {
|
||||
ret_code: to_error_core(&err),
|
||||
err_msg: format!("{}", err),
|
||||
msg_id: u64::max_value(),
|
||||
entry_id: u64::max_value(),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -86,18 +86,18 @@ impl From<Result<()>> for EmptyResult {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Result<Vec<Message>>> for GetMessagesServiceResult {
|
||||
fn from(result: Result<Vec<Message>>) -> Self {
|
||||
impl From<Result<Vec<Entry>>> for GetEntriesServiceResult {
|
||||
fn from(result: Result<Vec<Entry>>) -> Self {
|
||||
match result {
|
||||
Ok(messages) => Self {
|
||||
Ok(entries) => Self {
|
||||
ret_code: crate::service_api::SUCCESS_CODE,
|
||||
err_msg: String::new(),
|
||||
messages,
|
||||
entries,
|
||||
},
|
||||
Err(err) => Self {
|
||||
ret_code: to_error_core(&err),
|
||||
err_msg: format!("{}", err),
|
||||
messages: vec![],
|
||||
entries: vec![],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
mod errors;
|
||||
mod message;
|
||||
mod entry;
|
||||
mod results;
|
||||
mod service_api;
|
||||
mod storage_api;
|
||||
|
@ -14,21 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::message::Message;
|
||||
use crate::entry::Entry;
|
||||
use fluence::fce;
|
||||
|
||||
#[fce]
|
||||
pub struct AddServiceResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
pub msg_id: u64,
|
||||
pub entry_id: u64,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct GetMessagesServiceResult {
|
||||
pub struct GetEntriesServiceResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
pub messages: Vec<Message>,
|
||||
pub entries: Vec<Entry>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
|
@ -16,34 +16,43 @@
|
||||
|
||||
use crate::storage_api::*;
|
||||
|
||||
use crate::results::{AddServiceResult, EmptyResult, GetMessagesServiceResult};
|
||||
use crate::results::{AddServiceResult, EmptyResult, GetEntriesServiceResult};
|
||||
use crate::utils::u64_to_usize;
|
||||
use crate::Result;
|
||||
use fluence::{fce, CallParameters, SecurityTetraplet};
|
||||
use crate::entry::Entry;
|
||||
|
||||
pub const SUCCESS_CODE: i32 = 0;
|
||||
|
||||
// add a message if authenticated, return an error if not
|
||||
// add an entry if authenticated, return an error if not
|
||||
#[fce]
|
||||
fn add(msg: String, auth: bool) -> AddServiceResult {
|
||||
fn add_impl(msg: String, auth: bool) -> Result<u64> {
|
||||
fn add(entry: String, auth: bool) -> AddServiceResult {
|
||||
fn add_impl(entry: String, auth: bool) -> Result<u64> {
|
||||
is_authenticated(auth, 1)?;
|
||||
add_message(msg)
|
||||
add_entry(entry)
|
||||
}
|
||||
|
||||
add_impl(msg, auth).into()
|
||||
add_impl(entry, auth).into()
|
||||
}
|
||||
|
||||
// get all messages
|
||||
// get all entries
|
||||
#[fce]
|
||||
fn get_all() -> GetMessagesServiceResult {
|
||||
get_all_messages().into()
|
||||
fn get_all(auth: bool) -> GetEntriesServiceResult {
|
||||
fn get_all_impl(auth: bool) -> Result<Vec<Entry>> {
|
||||
is_authenticated(auth, 0)?;
|
||||
get_all_entries()
|
||||
}
|
||||
get_all_impl(auth).into()
|
||||
}
|
||||
|
||||
// get last message
|
||||
// get last entry
|
||||
#[fce]
|
||||
fn get_last(last: u64) -> GetMessagesServiceResult {
|
||||
get_messages_with_limit(last).into()
|
||||
fn get_last(last: u64, auth: bool) -> GetEntriesServiceResult {
|
||||
fn get_last_impl(last: u64, auth: bool) -> Result<Vec<Entry>> {
|
||||
is_authenticated(auth, 1)?;
|
||||
get_entries_with_limit(last)
|
||||
}
|
||||
get_last_impl(last, auth).into()
|
||||
}
|
||||
|
||||
// set tetraplet to check on the authentication process. Only the service owner could set it
|
||||
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::message::Message;
|
||||
use crate::entry::Entry;
|
||||
use crate::Result;
|
||||
|
||||
use crate::utils::{u64_to_usize, usize_to_u64};
|
||||
@ -31,7 +31,7 @@ pub struct Tetraplet {
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||
pub struct Data {
|
||||
messages: Vec<Message>,
|
||||
entries: Vec<Entry>,
|
||||
tetraplet: Option<Tetraplet>,
|
||||
}
|
||||
|
||||
@ -45,36 +45,36 @@ fn get_data() -> &'static Mutex<Data> {
|
||||
INSTANCE.get_or_init(|| <_>::default())
|
||||
}
|
||||
|
||||
pub fn add_message(msg: String) -> Result<u64> {
|
||||
pub fn add_entry(entry: String) -> Result<u64> {
|
||||
let mut data = get_data().lock();
|
||||
|
||||
let id = usize_to_u64(data.messages.len())?;
|
||||
let id = usize_to_u64(data.entries.len())?;
|
||||
|
||||
data.messages.push(Message { id, body: msg });
|
||||
data.entries.push(Entry { id, body: entry });
|
||||
|
||||
return Ok(id);
|
||||
}
|
||||
|
||||
pub fn get_messages_with_limit(limit: u64) -> Result<Vec<Message>> {
|
||||
pub fn get_entries_with_limit(limit: u64) -> Result<Vec<Entry>> {
|
||||
let data = get_data().lock();
|
||||
let limit = u64_to_usize(limit)?;
|
||||
|
||||
let msgs: Vec<Message> = data
|
||||
.messages
|
||||
let entries: Vec<Entry> = data
|
||||
.entries
|
||||
.to_vec()
|
||||
.iter()
|
||||
.rev()
|
||||
.take(limit)
|
||||
.map(|msg| msg.clone())
|
||||
.map(|entry| entry.clone())
|
||||
.collect();
|
||||
|
||||
Ok(msgs)
|
||||
Ok(entries)
|
||||
}
|
||||
|
||||
pub fn get_all_messages() -> Result<Vec<Message>> {
|
||||
pub fn get_all_entries() -> Result<Vec<Entry>> {
|
||||
let data = get_data().lock();
|
||||
|
||||
Ok(data.messages.to_vec())
|
||||
Ok(data.entries.to_vec())
|
||||
}
|
||||
|
||||
pub fn store_tetraplet(peer_id: String, service_id: String, fn_name: String, path: String) {
|
||||
|
16
services/user-list-inmemory/Cargo.lock
generated
16
services/user-list-inmemory/Cargo.lock
generated
@ -26,9 +26,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.2.16"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e65d9ffa281a0e9328fa6eb2468b8235a197013b9b5032aa9c2d2c0d54f99442"
|
||||
checksum = "27d9a5e4292d7bbd809a0e968e3c3aacac91cbc5acab3e26ee1e1d726f0aab24"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"fluence-sdk-main",
|
||||
@ -36,18 +36,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.2.16"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e5402cf99199b025bd41f52b4e77c58f6b76a8c34ae33a2c3612f024af28d32"
|
||||
checksum = "ea1a7c75a617f827d1ba9a17b4d84e1565ab239915c63f5a85c41f89a9f1d4ba"
|
||||
dependencies = [
|
||||
"fluence-sdk-wit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-main"
|
||||
version = "0.2.16"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "584cc07494112ad39d04fc8c0f6fb687f6c03c4908c7739c46c79ae112df083d"
|
||||
checksum = "6edcc983f9517c1b6bf9f851ef27f2894a3159aaa4a2fb6c9deb2ae8ecb603fa"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro",
|
||||
"log",
|
||||
@ -56,9 +56,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.2.16"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91c6e8b4da4bb732a744fd625de39e5f9faaf41d3919c8391a11d8528dad22e5"
|
||||
checksum = "b75dbdd0275160f3818db3218563d791e6c612b616cd3c5d6e66283f207f648d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
Loading…
x
Reference in New Issue
Block a user