Skip to content
Snippets Groups Projects
Commit 749b115c authored by jm's avatar jm
Browse files

[ref] gva: : add srv and resources folder

parent 50abdca1
No related branches found
No related tags found
No related merge requests found
......@@ -838,13 +838,13 @@ dependencies = [
name = "dup-crypto-tests-tools"
version = "0.1.0"
dependencies = [
"durs-core 0.1.0-a0.1",
"durs-core 0.2.0-a",
"durs-gva 0.1.0",
"durs-module 0.1.0-a0.1",
"durs-network 0.1.0-a0.1",
"durs-tui 0.1.0-a0.1",
"durs-ws2p 0.1.0-a0.1",
"durs-ws2p-v1-legacy 0.1.0-a0.1",
"durs-module 0.2.0-a",
"durs-network 0.2.0-a",
"durs-tui 0.2.0-a",
"durs-ws2p 0.2.0-a",
"durs-ws2p-v1-legacy 0.2.0-a",
]
[[package]]
......@@ -1006,10 +1006,12 @@ dependencies = [
"actix-web 1.0.0-beta.3 (registry+https://github.com/rust-lang/crates.io-index)",
"dubp-documents 0.12.0",
"dup-crypto 0.6.0",
"durs-conf 0.1.0-a0.1",
"durs-message 0.1.0-a0.1",
"durs-module 0.1.0-a0.1",
"durs-network 0.1.0-a0.1",
"durs-common-tools 0.1.0",
"durs-conf 0.2.0-a",
"durs-message 0.2.0-a",
"durs-module 0.2.0-a",
"durs-network 0.2.0-a",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
"futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.12.28 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -3170,6 +3172,15 @@ dependencies = [
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "uuid"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "vcpkg"
version = "0.2.7"
......
......@@ -7,7 +7,7 @@ license = "AGPL-3.0"
edition = "2018"
[lib]
path = "lib.rs"
path = "src/lib.rs"
[dependencies]
durs-conf = { path = "../../core/conf" }
......@@ -15,7 +15,9 @@ durs-message = { path = "../../core/message" }
durs-module = { path = "../../core/module" }
durs-network = { path = "../../core/network" }
dup-crypto = { path = "../../tools/crypto" }
durs-common-tools = { path = "../../tools/common-tools" }
dubp-documents= { path = "../../tools/documents" }
failure = "0.1.5"
log = "0.4.*"
serde = "1.0.*"
serde_derive = "1.0.*"
......
File moved
......@@ -41,12 +41,8 @@ extern crate juniper;
mod schema;
// use futures::future;
//use hyper::rt::Future;
//use hyper::service::service_fn;
//use hyper::Method;
//use hyper::{Body, Response, Server, StatusCode};
use durs_common_tools::fatal_error;
use durs_common_tools::traits::merge::Merge;
use durs_conf::DuRsConf;
use durs_message::events::*;
use durs_message::*;
......@@ -54,6 +50,7 @@ use durs_module::*;
use durs_network::events::NetworkEvent;
//use futures_cpupool::Builder as CpuPoolBuilder;
//use juniper::RootNode;
use futures::future::Future;
use std::net::SocketAddr;
use std::ops::Deref;
use std::sync::mpsc;
......@@ -71,12 +68,30 @@ use juniper::http::GraphQLRequest;
pub static MODULE_NAME: &'static str = "gva";
fn graphiql() -> HttpResponse {
let html = graphiql_source("http://127.0.0.1:8080/graphql");
let html = graphiql_source("http://127.0.0.1:3000/graphiql");
println!("html { }", &html);
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(html)
}
fn graphql(
st: web::Data<Arc<Schema>>,
data: web::Json<GraphQLRequest>,
) -> impl Future<Item = HttpResponse, Error = Error> {
let context = Context::new();
web::block(move || {
let res = data.execute(&st, &context);
Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?)
})
.map_err(Error::from)
.and_then(|user| {
Ok(HttpResponse::Ok()
.content_type("application/json")
.body(user))
})
}
fn start_web_server() -> std::io::Result<()> {
println!("Server start!!",);
let addr: SocketAddr = ([127, 0, 0, 1], 3000).into();
......@@ -92,6 +107,7 @@ fn start_web_server() -> std::io::Result<()> {
App::new()
.data(schema.clone())
.wrap(middleware::Logger::default())
.service(web::resource("/graphql").route(web::post().to_async(graphql)))
.service(web::resource("/graphiql").route(web::get().to(graphiql)))
})
.bind(addr)?
......@@ -118,6 +134,14 @@ pub struct GvaUserConf {
test_fake_conf_field: Option<String>,
}
impl Merge for GvaUserConf {
fn merge(self, other: Self) -> Self {
GvaUserConf {
test_fake_conf_field: self.test_fake_conf_field.or(other.test_fake_conf_field),
}
}
}
#[derive(Debug, Copy, Clone)]
/// Message from others thread of gva module
pub enum GvaThreadMsg {}
......@@ -213,27 +237,9 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule {
_keys: RequiredKeysContent,
_conf: Self::ModuleConf,
router_sender: mpsc::Sender<RouterThreadMessage<DursMsg>>,
load_conf_only: bool,
) -> Result<(), ModuleInitError> {
) -> Result<(), failure::Error> {
let _start_time = SystemTime::now();
// load conf
if load_conf_only {
// Check conf validity
// ...
let conf_valid = true;
// If the configuration is valid, we return OK.
if conf_valid {
return Ok(());
} else {
// If the configuration is invalid, an error message is returned
return Err(ModuleInitError::FailToLoadConf(
"write the details of the error here",
));
}
}
// Instanciate Gva module datas
let datas = GvaModuleDatas {
child_threads: Vec::new(),
......@@ -254,14 +260,14 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule {
thread::spawn(move || {
// Send gva module registration to router thread
router_sender_clone
.send(RouterThreadMessage::ModuleRegistration(
ModuleStaticName(MODULE_NAME),
proxy_sender, // Messages sent by the router will be received by your proxy thread
vec![ModuleRole::UserInterface], // Roles assigned to your module
vec![ModuleEvent::NewValidBlock], // Events to which your module subscribes
vec![],
vec![],
))
.send(RouterThreadMessage::ModuleRegistration {
static_name: ModuleStaticName(MODULE_NAME),
sender: proxy_sender, // Messages sent by the router will be received by your proxy thread
roles: vec![ModuleRole::UserInterface], // Roles assigned to your module
events_subscription: vec![ModuleEvent::NewValidBlock], // Events to which your module subscribes
reserved_apis_parts: vec![],
endpoints: vec![],
})
.expect("Fatal error : gva module fail to register to router !"); // The registration of your module must be successful, in case of failure the program must be interrupted.
// If we are here it means that your module has successfully registered, we indicate it in the debug level log, it can be helpful.
......@@ -361,7 +367,7 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule {
},
Err(e) => match e {
mpsc::RecvTimeoutError::Disconnected => {
panic!("Disconnected gva module !");
fatal_error!("Disconnected gva module !");
}
mpsc::RecvTimeoutError::Timeout => {
// If you arrive here it's because your main thread did not receive anything at the end of the timeout.
......
//use dubp_documents::documents::identity::IdentityDocument;
//use juniper::*;
use juniper::Executor;
use juniper::FieldResult;
use juniper_from_schema::graphql_schema_from_file;
graphql_schema_from_file!("lib/modules/gva/schema.gql");
graphql_schema_from_file!("lib/modules/gva/resources/schema.gql");
pub struct Context;
impl juniper::Context for Context {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment