Conditionally emit rocket::http_verb attr macros if lib/bin
parent
b82fd02ee3
commit
42e0102a2a
|
@ -261,7 +261,6 @@ checksum = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd"
|
||||||
name = "conduit"
|
name = "conduit"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.12.3",
|
|
||||||
"directories",
|
"directories",
|
||||||
"http",
|
"http",
|
||||||
"image",
|
"image",
|
||||||
|
@ -276,7 +275,6 @@ dependencies = [
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sled",
|
"sled",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
44
Cargo.toml
44
Cargo.toml
|
@ -12,19 +12,31 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67", features = ["tls"] }
|
# TODO: This can become optional as soon as proper configs are supported
|
||||||
http = "0.2.1"
|
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67", features = ["tls"], optional = false } # Used to handle requests
|
||||||
log = "0.4.8"
|
ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "e047c647ddcb368e7eb1e05ae8823a9494273457" } # Used for matrix spec type definitions and helpers
|
||||||
sled = "0.32.0"
|
sled = "0.32.0" # Used for storing data permanently
|
||||||
directories = "2.0.2"
|
log = "0.4.8" # Used for emitting log entries
|
||||||
js_int = "0.1.5"
|
http = "0.2.1" # Used for rocket<->ruma conversions
|
||||||
serde_json = { version = "1.0.53", features = ["raw_value"] }
|
directories = "2.0.2" # Used to find data directory for default db path
|
||||||
serde = "1.0.111"
|
js_int = "0.1.5" # Used for number types for ruma
|
||||||
tokio = { version = "0.2.21", features = ["macros"] }
|
serde_json = { version = "1.0.53", features = ["raw_value"] } # Used for ruma wrapper
|
||||||
rand = "0.7.3"
|
serde = "1.0.111" # Used for pdu definition
|
||||||
rust-argon2 = "0.8.2"
|
rand = "0.7.3" # Used for secure identifiers
|
||||||
reqwest = "0.10.6"
|
rust-argon2 = "0.8.2" # Used to hash passwords
|
||||||
base64 = "0.12.1"
|
reqwest = "0.10.6" # Used to send requests
|
||||||
thiserror = "1.0.19"
|
thiserror = "1.0.19" # Used for conduit::Error type
|
||||||
image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] }
|
image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] } # Used to generate thumbnails for images
|
||||||
ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "e047c647ddcb368e7eb1e05ae8823a9494273457" }
|
|
||||||
|
[features]
|
||||||
|
default = ["conduit_bin"]
|
||||||
|
conduit_bin = [] # TODO: add rocket to this when it is optional
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "conduit"
|
||||||
|
path = "src/main.rs"
|
||||||
|
required-features = ["conduit_bin"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "conduit"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
23
src/error.rs
23
src/error.rs
|
@ -1,16 +1,18 @@
|
||||||
use crate::RumaResponse;
|
|
||||||
use http::StatusCode;
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use rocket::{
|
use ruma::api::client::{error::ErrorKind, r0::uiaa::UiaaInfo};
|
||||||
response::{self, Responder},
|
|
||||||
Request,
|
|
||||||
};
|
|
||||||
use ruma::api::client::{
|
|
||||||
error::{Error as RumaError, ErrorKind},
|
|
||||||
r0::uiaa::{UiaaInfo, UiaaResponse},
|
|
||||||
};
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[cfg(feature = "conduit_bin")]
|
||||||
|
use {
|
||||||
|
crate::RumaResponse,
|
||||||
|
http::StatusCode,
|
||||||
|
rocket::{
|
||||||
|
response::{self, Responder},
|
||||||
|
Request,
|
||||||
|
},
|
||||||
|
ruma::api::client::{error::Error as RumaError, r0::uiaa::UiaaResponse},
|
||||||
|
};
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
@ -46,6 +48,7 @@ impl Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "conduit_bin")]
|
||||||
impl<'r, 'o> Responder<'r, 'o> for Error
|
impl<'r, 'o> Responder<'r, 'o> for Error
|
||||||
where
|
where
|
||||||
'o: 'r,
|
'o: 'r,
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
pub mod client_server;
|
||||||
|
mod database;
|
||||||
|
mod error;
|
||||||
|
mod pdu;
|
||||||
|
pub mod push_rules;
|
||||||
|
mod ruma_wrapper;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
|
pub use database::Database;
|
||||||
|
pub use error::{Error, Result};
|
||||||
|
pub use pdu::PduEvent;
|
||||||
|
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
pub struct State<'r, T: Send + Sync + 'static>(&'r T);
|
||||||
|
|
||||||
|
impl<'r, T: Send + Sync + 'static> Deref for State<'r, T> {
|
||||||
|
type Target = T;
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn deref(&self) -> &T {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ mod utils;
|
||||||
pub use database::Database;
|
pub use database::Database;
|
||||||
pub use error::{Error, Result};
|
pub use error::{Error, Result};
|
||||||
pub use pdu::PduEvent;
|
pub use pdu::PduEvent;
|
||||||
|
pub use rocket::State;
|
||||||
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
|
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
|
||||||
|
|
||||||
use rocket::{fairing::AdHoc, routes};
|
use rocket::{fairing::AdHoc, routes};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use js_int::uint;
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
push::{
|
push::{
|
||||||
Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule,
|
Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule,
|
||||||
|
@ -185,7 +184,7 @@ pub fn encrypted_room_one_to_one_rule() -> ConditionalPushRule {
|
||||||
rule_id: ".m.rule.encrypted_room_one_to_one".to_owned(),
|
rule_id: ".m.rule.encrypted_room_one_to_one".to_owned(),
|
||||||
conditions: vec![
|
conditions: vec![
|
||||||
PushCondition::RoomMemberCount {
|
PushCondition::RoomMemberCount {
|
||||||
is: RoomMemberCountIs::from(uint!(2)..),
|
is: RoomMemberCountIs::from(2_u32.into()..),
|
||||||
},
|
},
|
||||||
PushCondition::EventMatch {
|
PushCondition::EventMatch {
|
||||||
key: "type".to_owned(),
|
key: "type".to_owned(),
|
||||||
|
@ -208,7 +207,7 @@ pub fn room_one_to_one_rule() -> ConditionalPushRule {
|
||||||
rule_id: ".m.rule.room_one_to_one".to_owned(),
|
rule_id: ".m.rule.room_one_to_one".to_owned(),
|
||||||
conditions: vec![
|
conditions: vec![
|
||||||
PushCondition::RoomMemberCount {
|
PushCondition::RoomMemberCount {
|
||||||
is: RoomMemberCountIs::from(uint!(2)..),
|
is: RoomMemberCountIs::from(2_u32.into()..),
|
||||||
},
|
},
|
||||||
PushCondition::EventMatch {
|
PushCondition::EventMatch {
|
||||||
key: "type".to_owned(),
|
key: "type".to_owned(),
|
||||||
|
|
|
@ -1,15 +1,24 @@
|
||||||
use crate::{utils, Error};
|
use crate::Error;
|
||||||
use log::warn;
|
use ruma::identifiers::{DeviceId, UserId};
|
||||||
use rocket::{
|
use std::{convert::TryInto, ops::Deref};
|
||||||
data::{Data, FromDataFuture, FromTransformedData, Transform, TransformFuture, Transformed},
|
|
||||||
http::Status,
|
#[cfg(feature = "conduit_bin")]
|
||||||
response::{self, Responder},
|
use {
|
||||||
Outcome::*,
|
crate::utils,
|
||||||
Request, State,
|
log::warn,
|
||||||
|
rocket::{
|
||||||
|
data::{
|
||||||
|
Data, FromDataFuture, FromTransformedData, Transform, TransformFuture, Transformed,
|
||||||
|
},
|
||||||
|
http::Status,
|
||||||
|
response::{self, Responder},
|
||||||
|
tokio::io::AsyncReadExt,
|
||||||
|
Outcome::*,
|
||||||
|
Request, State,
|
||||||
|
},
|
||||||
|
ruma::api::Endpoint,
|
||||||
|
std::io::Cursor,
|
||||||
};
|
};
|
||||||
use ruma::{api::Endpoint, DeviceId, UserId};
|
|
||||||
use std::{convert::TryInto, io::Cursor, ops::Deref};
|
|
||||||
use tokio::io::AsyncReadExt;
|
|
||||||
|
|
||||||
/// This struct converts rocket requests into ruma structs by converting them into http requests
|
/// This struct converts rocket requests into ruma structs by converting them into http requests
|
||||||
/// first.
|
/// first.
|
||||||
|
@ -20,6 +29,7 @@ pub struct Ruma<T> {
|
||||||
pub json_body: Option<Box<serde_json::value::RawValue>>, // This is None when body is not a valid string
|
pub json_body: Option<Box<serde_json::value::RawValue>>, // This is None when body is not a valid string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "conduit_bin")]
|
||||||
impl<'a, T: Endpoint> FromTransformedData<'a> for Ruma<T> {
|
impl<'a, T: Endpoint> FromTransformedData<'a> for Ruma<T> {
|
||||||
type Error = (); // TODO: Better error handling
|
type Error = (); // TODO: Better error handling
|
||||||
type Owned = Data;
|
type Owned = Data;
|
||||||
|
@ -119,6 +129,7 @@ impl<T: TryInto<http::Response<Vec<u8>>>> From<T> for RumaResponse<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "conduit_bin")]
|
||||||
impl<'r, 'o, T> Responder<'r, 'o> for RumaResponse<T>
|
impl<'r, 'o, T> Responder<'r, 'o> for RumaResponse<T>
|
||||||
where
|
where
|
||||||
T: Send + TryInto<http::Response<Vec<u8>>>,
|
T: Send + TryInto<http::Response<Vec<u8>>>,
|
||||||
|
|
Loading…
Reference in New Issue