mirror of
https://github.com/fluencelabs/fluent-pad
synced 2025-04-25 00:42:14 +00:00
refactoring, docs, fmt
This commit is contained in:
parent
b53d1e52b2
commit
191184c974
@ -15,10 +15,9 @@
|
||||
*/
|
||||
|
||||
use crate::message::Message;
|
||||
use crate::service_api::GetMessagesServiceResult;
|
||||
use crate::service_api::{AddServiceResult, EmptyResult};
|
||||
use crate::Result;
|
||||
|
||||
use crate::results::{AddServiceResult, EmptyResult, GetMessagesServiceResult};
|
||||
use std::convert::From;
|
||||
use std::error::Error;
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
mod errors;
|
||||
mod message;
|
||||
mod results;
|
||||
mod service_api;
|
||||
mod storage_api;
|
||||
mod utils;
|
||||
|
38
services/history-inmemory/src/results.rs
Normal file
38
services/history-inmemory/src/results.rs
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::message::Message;
|
||||
use fluence::fce;
|
||||
|
||||
#[fce]
|
||||
pub struct AddServiceResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
pub msg_id: u64,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct GetMessagesServiceResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
pub messages: Vec<Message>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct EmptyResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
}
|
@ -14,22 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::message::Message;
|
||||
use crate::storage_api::*;
|
||||
|
||||
use crate::results::{AddServiceResult, EmptyResult, GetMessagesServiceResult};
|
||||
use crate::utils::u64_to_usize;
|
||||
use crate::Result;
|
||||
use fluence::{fce, CallParameters, SecurityTetraplet};
|
||||
|
||||
pub const SUCCESS_CODE: i32 = 0;
|
||||
|
||||
#[fce]
|
||||
pub struct AddServiceResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
pub msg_id: u64,
|
||||
}
|
||||
|
||||
// add a message if authenticated, return an error if not
|
||||
#[fce]
|
||||
fn add(msg: String, auth: bool) -> AddServiceResult {
|
||||
fn add_impl(msg: String, auth: bool) -> Result<u64> {
|
||||
@ -40,35 +34,19 @@ fn add(msg: String, auth: bool) -> AddServiceResult {
|
||||
add_impl(msg, auth).into()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct GetMessagesServiceResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
pub messages: Vec<Message>,
|
||||
}
|
||||
|
||||
// get all messages
|
||||
#[fce]
|
||||
fn get_all() -> GetMessagesServiceResult {
|
||||
get_all_messages().into()
|
||||
}
|
||||
|
||||
// get last message
|
||||
#[fce]
|
||||
fn get_last(last: u64) -> GetMessagesServiceResult {
|
||||
get_messages_with_limit(last).into()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct EmptyResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn get_current_tetraplet(auth: bool) -> Vec<Vec<SecurityTetraplet>> {
|
||||
let call_parameters: CallParameters = fluence::get_call_parameters();
|
||||
call_parameters.tetraplets
|
||||
}
|
||||
|
||||
// set tetraplet to check on the authentication process. Only the service owner could set it
|
||||
#[fce]
|
||||
pub fn set_tetraplet(
|
||||
peer_id: String,
|
||||
@ -84,6 +62,7 @@ pub fn set_tetraplet(
|
||||
set_impl(peer_id, service_id, fn_name, path).into()
|
||||
}
|
||||
|
||||
// check if a calles is an owner of the service
|
||||
pub fn is_owner() -> Result<()> {
|
||||
use crate::errors::HistoryError::Unauthorized;
|
||||
use boolinator::Boolinator;
|
||||
@ -95,6 +74,7 @@ pub fn is_owner() -> Result<()> {
|
||||
.ok_or_else(|| Unauthorized("This operation could be processed only by owner.".to_string()))
|
||||
}
|
||||
|
||||
// check if a caller is authenticated
|
||||
pub fn is_authenticated(auth: bool, index: u64) -> Result<()> {
|
||||
use crate::errors::HistoryError::Unauthorized;
|
||||
use boolinator::Boolinator;
|
||||
|
@ -17,9 +17,9 @@
|
||||
use crate::user::User;
|
||||
use crate::Result;
|
||||
|
||||
use crate::results::{AuthResult, EmptyServiceResult, ExistsServiceResult, GetUsersServiceResult};
|
||||
use std::convert::From;
|
||||
use std::error::Error;
|
||||
use crate::results::{EmptyServiceResult, AuthResult, GetUsersServiceResult, ExistsServiceResult};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UserListError {
|
||||
|
@ -43,4 +43,3 @@ pub struct AuthResult {
|
||||
pub err_msg: String,
|
||||
pub is_authenticated: bool,
|
||||
}
|
||||
|
||||
|
@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::results::{AuthResult, EmptyServiceResult, ExistsServiceResult, GetUsersServiceResult};
|
||||
use crate::storage_api::*;
|
||||
use crate::user::User;
|
||||
use crate::Result;
|
||||
use fluence::{fce, CallParameters};
|
||||
use crate::results::{GetUsersServiceResult, ExistsServiceResult, AuthResult, EmptyServiceResult};
|
||||
|
||||
pub const SUCCESS_CODE: i32 = 0;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user