Skip to content

Commit 2dfa79a

Browse files
authored
Merge pull request #443 from AmbireTech/sentry-api-documentation
AdEx V5: Init Sentry REST API documentation (using rustdoc)
2 parents c9434a0 + 274e2c3 commit 2dfa79a

12 files changed

+320
-331
lines changed

primitives/src/sentry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub struct FetchedAnalytics {
312312
pub segment: Option<String>,
313313
}
314314

315-
/// The value of the requested analytics [`Metric`].
315+
/// The value of the requested analytics [`crate::analytics::Metric`].
316316
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
317317
#[serde(untagged)]
318318
pub enum FetchedMetric {

sentry/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Sentry
22

3+
## REST API documentation for AdEx Protocol V5
4+
5+
For full details see [AIP #61](https://github.com/AmbireTech/aips/issues/61) and the tracking issue for this implementation https://github.com/AmbireTech/adex-validator-stack-rust/issues/377.
6+
7+
REST API documentation can be generated using `rustdoc`:
8+
9+
`cargo doc --all-features --open --lib`
10+
11+
and checking the `sentry::routes` module.
12+
313
## Development
414

515
### Migrations

sentry/src/analytics.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ pub async fn record(
6363
(None, None) => None,
6464
};
6565

66-
// TODO: tidy up this operation
6766
batch_update
6867
.entry(event)
6968
.and_modify(|analytics| {

sentry/src/analytics_recorder.rs

Lines changed: 0 additions & 122 deletions
This file was deleted.

sentry/src/lib.rs

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,22 @@ use {
2727
routes::{
2828
campaign,
2929
campaign::{campaign_list, create_campaign, update_campaign},
30-
cfg::config,
30+
get_cfg,
31+
get_analytics,
3132
channel::{
32-
add_spender_leaf, channel_list, create_validator_messages, get_accounting_for_channel,
33-
get_all_spender_limits, get_spender_limits, last_approved,
33+
add_spender_leaf, channel_list, get_accounting_for_channel, get_all_spender_limits,
34+
get_spender_limits, last_approved,
35+
validator_message::{
36+
create_validator_messages, extract_params, list_validator_messages,
37+
},
3438
},
35-
event_aggregate::list_channel_event_aggregates,
36-
validator_message::{extract_params, list_validator_messages},
3739
},
3840
};
3941

4042
pub mod analytics;
4143
pub mod middleware;
42-
pub mod routes {
43-
pub mod analytics;
44-
pub mod campaign;
45-
pub mod cfg;
46-
pub mod channel;
47-
pub mod event_aggregate;
48-
pub mod validator_message;
49-
}
50-
44+
pub mod routes;
5145
pub mod access;
52-
pub mod analytics_recorder;
5346
pub mod application;
5447
pub mod db;
5548
pub mod payout;
@@ -59,15 +52,12 @@ static LAST_APPROVED_BY_CHANNEL_ID: Lazy<Regex> = Lazy::new(|| {
5952
Regex::new(r"^/v5/channel/0x([a-zA-Z0-9]{64})/last-approved/?$")
6053
.expect("The regex should be valid")
6154
});
62-
// Only the initial Regex to be matched.
55+
56+
/// Only the initial Regex to be matched.
6357
static CHANNEL_VALIDATOR_MESSAGES: Lazy<Regex> = Lazy::new(|| {
6458
Regex::new(r"^/v5/channel/0x([a-zA-Z0-9]{64})/validator-messages(/.*)?$")
6559
.expect("The regex should be valid")
6660
});
67-
static CHANNEL_EVENTS_AGGREGATES: Lazy<Regex> = Lazy::new(|| {
68-
Regex::new(r"^/v5/channel/0x([a-zA-Z0-9]{64})/events-aggregates/?$")
69-
.expect("The regex should be valid")
70-
});
7161
static CHANNEL_SPENDER_LEAF_AND_TOTAL_DEPOSITED: Lazy<Regex> = Lazy::new(|| {
7262
Regex::new(r"^/v5/channel/0x([a-zA-Z0-9]{64})/spender/0x([a-zA-Z0-9]{40})/?$")
7363
.expect("This regex should be valid")
@@ -91,6 +81,8 @@ static CHANNEL_ACCOUNTING: Lazy<Regex> = Lazy::new(|| {
9181
.expect("The regex should be valid")
9282
});
9383

84+
/// Regex extracted parameters.
85+
/// This struct is created manually on each of the matched routes.
9486
#[derive(Debug, Clone)]
9587
pub struct RouteParams(pub Vec<String>);
9688

@@ -104,8 +96,7 @@ impl RouteParams {
10496
}
10597
}
10698

107-
// #[derive(Clone)]
108-
// pub struct Application<C: Locked + 'static> {
99+
/// The Sentry REST web application
109100
pub struct Application<C: Locked + 'static> {
110101
/// For sentry to work properly, we need an [`adapter::Adapter`] in a [`adapter::LockedState`] state.
111102
pub adapter: Adapter<C>,
@@ -152,7 +143,7 @@ where
152143
};
153144

154145
let mut response = match (req.uri().path(), req.method()) {
155-
("/cfg", &Method::GET) => config(req, self).await,
146+
("/cfg", &Method::GET) => get_cfg(req, self).await,
156147
("/channel/list", &Method::GET) => channel_list(req, self).await,
157148
(route, _) if route.starts_with("/analytics") => analytics_router(req, self).await,
158149
// This is important because it prevents us from doing
@@ -226,7 +217,6 @@ async fn analytics_router<C: Locked + 'static>(
226217
mut req: Request<Body>,
227218
app: &Application<C>,
228219
) -> Result<Response<Body>, ResponseError> {
229-
use routes::analytics::analytics;
230220

231221
let (route, method) = (req.uri().path(), req.method());
232222

@@ -235,7 +225,7 @@ async fn analytics_router<C: Locked + 'static>(
235225
let allowed_keys_for_request = vec![AllowedKey::Country, AllowedKey::AdSlotType]
236226
.into_iter()
237227
.collect();
238-
analytics(req, app, Some(allowed_keys_for_request), None).await
228+
get_analytics(req, app, Some(allowed_keys_for_request), None).await
239229
}
240230
("/analytics/for-advertiser", &Method::GET) => {
241231
let req = AuthRequired.call(req, app).await?;
@@ -246,7 +236,7 @@ async fn analytics_router<C: Locked + 'static>(
246236
.map(|auth| AuthenticateAs::Advertiser(auth.uid))
247237
.ok_or(ResponseError::Unauthorized)?;
248238

249-
analytics(req, app, None, Some(authenticate_as)).await
239+
get_analytics(req, app, None, Some(authenticate_as)).await
250240
}
251241
("/analytics/for-publisher", &Method::GET) => {
252242
let authenticate_as = req
@@ -256,15 +246,15 @@ async fn analytics_router<C: Locked + 'static>(
256246
.ok_or(ResponseError::Unauthorized)?;
257247

258248
let req = AuthRequired.call(req, app).await?;
259-
analytics(req, app, None, Some(authenticate_as)).await
249+
get_analytics(req, app, None, Some(authenticate_as)).await
260250
}
261251
("/analytics/for-admin", &Method::GET) => {
262252
req = Chain::new()
263253
.chain(AuthRequired)
264254
.chain(IsAdmin)
265255
.apply(req, app)
266256
.await?;
267-
analytics(req, app, None, None).await
257+
get_analytics(req, app, None, None).await
268258
}
269259
_ => Err(ResponseError::NotFound),
270260
}
@@ -328,20 +318,6 @@ async fn channels_router<C: Locked + 'static>(
328318
.await?;
329319

330320
create_validator_messages(req, app).await
331-
} else if let (Some(caps), &Method::GET) = (CHANNEL_EVENTS_AGGREGATES.captures(&path), method) {
332-
req = AuthRequired.call(req, app).await?;
333-
334-
let param = RouteParams(vec![
335-
caps.get(1)
336-
.map_or("".to_string(), |m| m.as_str().to_string()),
337-
caps.get(2)
338-
.map_or("".to_string(), |m| m.as_str().trim_matches('/').to_string()),
339-
]);
340-
req.extensions_mut().insert(param);
341-
342-
req = ChannelLoad.call(req, app).await?;
343-
344-
list_channel_event_aggregates(req, app).await
345321
} else if let (Some(caps), &Method::GET) = (
346322
CHANNEL_SPENDER_LEAF_AND_TOTAL_DEPOSITED.captures(&path),
347323
method,
@@ -512,7 +488,7 @@ pub fn epoch() -> f64 {
512488
Utc::now().timestamp() as f64 / 2_628_000_000.0
513489
}
514490

515-
// @TODO: Make pub(crate)
491+
/// Sentry [`Application`] Session
516492
#[derive(Debug, Clone)]
517493
pub struct Session {
518494
pub ip: Option<String>,
@@ -521,6 +497,7 @@ pub struct Session {
521497
pub os: Option<String>,
522498
}
523499

500+
/// Sentry [`Application`] Auth (Authentication)
524501
#[derive(Debug, Clone)]
525502
pub struct Auth {
526503
pub era: i64,

0 commit comments

Comments
 (0)