Skip to content

Commit 77962fc

Browse files
committed
sentry - routes - /cfg
1 parent 8f2cdcc commit 77962fc

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

primitives/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ lazy_static! {
1515
}
1616

1717
#[derive(Serialize, Deserialize, Debug, Clone)]
18+
#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE"))]
1819
pub struct Config {
1920
pub identity: Option<String>, // should not be here maybe?
2021
pub max_channels: u32,

sentry/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22
#![deny(rust_2018_idioms)]
33

44
use hyper::service::{make_service_fn, service_fn};
5-
use hyper::{Body, Error, Request, Response, Server, StatusCode};
5+
use hyper::{Body, Error, Request, Response, Server, StatusCode, Method};
66
use primitives::adapter::Adapter;
77
use primitives::Config;
88
use slog::{error, info, Logger};
99

1010
pub mod routes {
1111
pub mod channel;
12+
pub mod cfg {
13+
use hyper::{Body, Response};
14+
use crate::ResponseError;
15+
use primitives::Config;
16+
17+
pub fn return_config(config: &Config) -> Result<Response<Body>, ResponseError> {
18+
let config_str = serde_json::to_string(config)?;
19+
20+
Ok(Response::builder().body(Body::from(config_str)).unwrap())
21+
}
22+
}
1223
}
1324

1425
pub mod access;
@@ -43,7 +54,7 @@ impl<A: Adapter + 'static> Application<A> {
4354
async move {
4455
Ok::<_, Error>(service_fn(move |req| {
4556
let adapter_config = adapter_config.clone();
46-
async move { Ok::<_, Error>(handle_routing(req, adapter_config.0).await) }
57+
async move { Ok::<_, Error>(handle_routing(req, adapter_config).await) }
4758
}))
4859
}
4960
});
@@ -71,8 +82,10 @@ where
7182
}
7283
}
7384

74-
async fn handle_routing(req: Request<Body>, adapter: impl Adapter) -> Response<Body> {
75-
if req.uri().path().starts_with("/channel") {
85+
async fn handle_routing(req: Request<Body>, (adapter, config): (impl Adapter, Config)) -> Response<Body> {
86+
if req.uri().path().starts_with("/cfg") && req.method() == Method::GET {
87+
crate::routes::cfg::return_config(&config)
88+
}else if req.uri().path().starts_with("/channel") {
7689
crate::routes::channel::handle_channel_routes(req, adapter).await
7790
} else {
7891
Err(ResponseError::NotFound)

0 commit comments

Comments
 (0)