@@ -27,29 +27,22 @@ use {
27
27
routes:: {
28
28
campaign,
29
29
campaign:: { campaign_list, create_campaign, update_campaign} ,
30
- cfg:: config,
30
+ get_cfg,
31
+ get_analytics,
31
32
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
+ } ,
34
38
} ,
35
- event_aggregate:: list_channel_event_aggregates,
36
- validator_message:: { extract_params, list_validator_messages} ,
37
39
} ,
38
40
} ;
39
41
40
42
pub mod analytics;
41
43
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;
51
45
pub mod access;
52
- pub mod analytics_recorder;
53
46
pub mod application;
54
47
pub mod db;
55
48
pub mod payout;
@@ -59,15 +52,12 @@ static LAST_APPROVED_BY_CHANNEL_ID: Lazy<Regex> = Lazy::new(|| {
59
52
Regex :: new ( r"^/v5/channel/0x([a-zA-Z0-9]{64})/last-approved/?$" )
60
53
. expect ( "The regex should be valid" )
61
54
} ) ;
62
- // Only the initial Regex to be matched.
55
+
56
+ /// Only the initial Regex to be matched.
63
57
static CHANNEL_VALIDATOR_MESSAGES : Lazy < Regex > = Lazy :: new ( || {
64
58
Regex :: new ( r"^/v5/channel/0x([a-zA-Z0-9]{64})/validator-messages(/.*)?$" )
65
59
. expect ( "The regex should be valid" )
66
60
} ) ;
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
- } ) ;
71
61
static CHANNEL_SPENDER_LEAF_AND_TOTAL_DEPOSITED : Lazy < Regex > = Lazy :: new ( || {
72
62
Regex :: new ( r"^/v5/channel/0x([a-zA-Z0-9]{64})/spender/0x([a-zA-Z0-9]{40})/?$" )
73
63
. expect ( "This regex should be valid" )
@@ -91,6 +81,8 @@ static CHANNEL_ACCOUNTING: Lazy<Regex> = Lazy::new(|| {
91
81
. expect ( "The regex should be valid" )
92
82
} ) ;
93
83
84
+ /// Regex extracted parameters.
85
+ /// This struct is created manually on each of the matched routes.
94
86
#[ derive( Debug , Clone ) ]
95
87
pub struct RouteParams ( pub Vec < String > ) ;
96
88
@@ -104,8 +96,7 @@ impl RouteParams {
104
96
}
105
97
}
106
98
107
- // #[derive(Clone)]
108
- // pub struct Application<C: Locked + 'static> {
99
+ /// The Sentry REST web application
109
100
pub struct Application < C : Locked + ' static > {
110
101
/// For sentry to work properly, we need an [`adapter::Adapter`] in a [`adapter::LockedState`] state.
111
102
pub adapter : Adapter < C > ,
@@ -152,7 +143,7 @@ where
152
143
} ;
153
144
154
145
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 ,
156
147
( "/channel/list" , & Method :: GET ) => channel_list ( req, self ) . await ,
157
148
( route, _) if route. starts_with ( "/analytics" ) => analytics_router ( req, self ) . await ,
158
149
// This is important because it prevents us from doing
@@ -226,7 +217,6 @@ async fn analytics_router<C: Locked + 'static>(
226
217
mut req : Request < Body > ,
227
218
app : & Application < C > ,
228
219
) -> Result < Response < Body > , ResponseError > {
229
- use routes:: analytics:: analytics;
230
220
231
221
let ( route, method) = ( req. uri ( ) . path ( ) , req. method ( ) ) ;
232
222
@@ -235,7 +225,7 @@ async fn analytics_router<C: Locked + 'static>(
235
225
let allowed_keys_for_request = vec ! [ AllowedKey :: Country , AllowedKey :: AdSlotType ]
236
226
. into_iter ( )
237
227
. collect ( ) ;
238
- analytics ( req, app, Some ( allowed_keys_for_request) , None ) . await
228
+ get_analytics ( req, app, Some ( allowed_keys_for_request) , None ) . await
239
229
}
240
230
( "/analytics/for-advertiser" , & Method :: GET ) => {
241
231
let req = AuthRequired . call ( req, app) . await ?;
@@ -246,7 +236,7 @@ async fn analytics_router<C: Locked + 'static>(
246
236
. map ( |auth| AuthenticateAs :: Advertiser ( auth. uid ) )
247
237
. ok_or ( ResponseError :: Unauthorized ) ?;
248
238
249
- analytics ( req, app, None , Some ( authenticate_as) ) . await
239
+ get_analytics ( req, app, None , Some ( authenticate_as) ) . await
250
240
}
251
241
( "/analytics/for-publisher" , & Method :: GET ) => {
252
242
let authenticate_as = req
@@ -256,15 +246,15 @@ async fn analytics_router<C: Locked + 'static>(
256
246
. ok_or ( ResponseError :: Unauthorized ) ?;
257
247
258
248
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
260
250
}
261
251
( "/analytics/for-admin" , & Method :: GET ) => {
262
252
req = Chain :: new ( )
263
253
. chain ( AuthRequired )
264
254
. chain ( IsAdmin )
265
255
. apply ( req, app)
266
256
. await ?;
267
- analytics ( req, app, None , None ) . await
257
+ get_analytics ( req, app, None , None ) . await
268
258
}
269
259
_ => Err ( ResponseError :: NotFound ) ,
270
260
}
@@ -328,20 +318,6 @@ async fn channels_router<C: Locked + 'static>(
328
318
. await ?;
329
319
330
320
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
345
321
} else if let ( Some ( caps) , & Method :: GET ) = (
346
322
CHANNEL_SPENDER_LEAF_AND_TOTAL_DEPOSITED . captures ( & path) ,
347
323
method,
@@ -512,7 +488,7 @@ pub fn epoch() -> f64 {
512
488
Utc :: now ( ) . timestamp ( ) as f64 / 2_628_000_000.0
513
489
}
514
490
515
- // @TODO: Make pub(crate)
491
+ /// Sentry [`Application`] Session
516
492
#[ derive( Debug , Clone ) ]
517
493
pub struct Session {
518
494
pub ip : Option < String > ,
@@ -521,6 +497,7 @@ pub struct Session {
521
497
pub os : Option < String > ,
522
498
}
523
499
500
+ /// Sentry [`Application`] Auth (Authentication)
524
501
#[ derive( Debug , Clone ) ]
525
502
pub struct Auth {
526
503
pub era : i64 ,
0 commit comments