Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3345005
D8951.id30320.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D8951.id30320.diff
View Options
diff --git a/services/reports/src/main.rs b/services/reports/src/main.rs
--- a/services/reports/src/main.rs
+++ b/services/reports/src/main.rs
@@ -2,8 +2,11 @@
pub mod database;
pub mod http;
pub mod report_types;
+pub mod service;
use anyhow::Result;
+use comm_services_lib::blob::client::BlobServiceClient;
+use service::ReportsService;
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
fn configure_logging() -> Result<()> {
@@ -24,9 +27,12 @@
#[tokio::main]
async fn main() -> Result<()> {
configure_logging()?;
- config::parse_cmdline_args()?;
+ let cfg = config::parse_cmdline_args()?;
+ let aws_config = config::load_aws_config().await;
- let _aws_config = config::load_aws_config().await;
+ let db = database::client::DatabaseClient::new(&aws_config);
+ let blob_client = BlobServiceClient::new(cfg.blob_service_url.clone());
+ let service = ReportsService::new(db, blob_client);
- crate::http::run_http_server().await
+ crate::http::run_http_server(service).await
}
diff --git a/services/reports/src/service.rs b/services/reports/src/service.rs
new file mode 100644
--- /dev/null
+++ b/services/reports/src/service.rs
@@ -0,0 +1,73 @@
+use actix_web::{web::Bytes, FromRequest};
+use comm_services_lib::{
+ auth::UserIdentity,
+ blob::{
+ client::{BlobServiceClient, BlobServiceError},
+ types::BlobInfo,
+ },
+ database,
+};
+use derive_more::{Display, Error, From};
+use std::{
+ collections::HashMap,
+ future::{ready, Ready},
+};
+#[derive(Clone)]
+pub struct ReportsService {
+ db: DatabaseClient,
+ blob_client: BlobServiceClient,
+ requesting_user_id: Option<String>,
+}
+
+impl ReportsService {
+ pub fn new(db: DatabaseClient, blob_client: BlobServiceClient) -> Self {
+ Self {
+ db,
+ blob_client,
+ requesting_user_id: None,
+ }
+ }
+
+ pub fn authenticated(&self, user: UserIdentity) -> Self {
+ let user_id = user.user_id().to_string();
+ Self {
+ db: self.db.clone(),
+ blob_client: self.blob_client.with_user_identity(user),
+ requesting_user_id: Some(user_id),
+ }
+ }
+}
+
+impl FromRequest for ReportsService {
+ type Error = actix_web::Error;
+ type Future = Ready<Result<Self, actix_web::Error>>;
+
+ #[inline]
+ fn from_request(
+ req: &actix_web::HttpRequest,
+ _payload: &mut actix_web::dev::Payload,
+ ) -> Self::Future {
+ use actix_web::HttpMessage;
+
+ let Some(service) = req.app_data::<ReportsService>() else {
+ tracing::error!(
+ "FATAL! Failed to extract ReportsService from actix app_data. \
+ Check HTTP server configuration"
+ );
+ return ready(Err(actix_web::error::ErrorInternalServerError("Internal server error")));
+ };
+
+ let auth_service =
+ if let Some(user_identity) = req.extensions().get::<UserIdentity>() {
+ tracing::trace!("Found user identity. Creating authenticated service");
+ service.authenticated(user_identity.clone())
+ } else {
+ tracing::trace!(
+ "No user identity found. Leaving unauthenticated service"
+ );
+ service.clone()
+ };
+
+ ready(Ok(auth_service))
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 5:04 AM (18 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2569030
Default Alt Text
D8951.id30320.diff (3 KB)
Attached To
Mode
D8951: [reports-service] Add authenticated service
Attached
Detach File
Event Timeline
Log In to Comment