Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3504802
D5682.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
D5682.diff
View Options
diff --git a/services/blob/src/constants.rs b/services/blob/src/constants.rs
--- a/services/blob/src/constants.rs
+++ b/services/blob/src/constants.rs
@@ -1,7 +1,25 @@
-pub const GRPC_SERVER_DEFAULT_PORT: u64 = 50051;
+// Assorted constants
+pub const GRPC_SERVER_DEFAULT_PORT: u64 = 50051;
pub const AWS_REGION: &str = "us-east-2";
-
pub const LOCALSTACK_URL: &str = "http://localhost:4566";
+// DynamoDB constants
+
+pub const BLOB_TABLE_NAME: &str = "blob-service-blob";
+pub const BLOB_TABLE_BLOB_HASH_FIELD: &str = "blobHash";
+pub const BLOB_TABLE_S3_PATH_FIELD: &str = "s3Path";
+pub const BLOB_TABLE_CREATED_FIELD: &str = "created";
+
+pub const BLOB_REVERSE_INDEX_TABLE_NAME: &str = "blob-service-reverse-index";
+pub const BLOB_REVERSE_INDEX_TABLE_HOLDER_FIELD: &str = "holder";
+pub const BLOB_REVERSE_INDEX_TABLE_BLOB_HASH_FIELD: &str = "blobHash";
+pub const BLOB_REVERSE_INDEX_TABLE_HASH_INDEX_NAME: &str = "blobHash-index";
+
+// Environment variables
+
pub const SANDBOX_ENV_VAR: &str = "COMM_SERVICES_SANDBOX";
+
+// S3 constants
+
+pub const BLOB_S3_BUCKET_NAME: &str = "commapp-blob";
diff --git a/services/blob/src/main.rs b/services/blob/src/main.rs
--- a/services/blob/src/main.rs
+++ b/services/blob/src/main.rs
@@ -6,11 +6,12 @@
use anyhow::Result;
use aws_sdk_dynamodb::{Endpoint, Region};
+use database::DatabaseClient;
use service::{blob::blob_service_server::BlobServiceServer, MyBlobService};
use std::net::SocketAddr;
use tonic::transport::{Server, Uri};
-async fn _get_aws_config() -> aws_types::SdkConfig {
+async fn get_aws_config() -> aws_types::SdkConfig {
let mut config_builder =
aws_config::from_env().region(Region::new(constants::AWS_REGION));
@@ -23,10 +24,13 @@
return config_builder.load().await;
}
-async fn run_grpc_server() -> Result<()> {
+async fn run_grpc_server(
+ db_client: DatabaseClient,
+ s3_client: aws_sdk_s3::Client,
+) -> Result<()> {
let addr: SocketAddr =
format!("[::]:{}", constants::GRPC_SERVER_DEFAULT_PORT).parse()?;
- let blob_service = MyBlobService::default();
+ let blob_service = MyBlobService::new(db_client, s3_client);
println!("Starting gRPC server at port {}", addr.port());
Server::builder()
@@ -39,5 +43,9 @@
#[tokio::main]
async fn main() -> Result<()> {
- run_grpc_server().await
+ let aws_config = get_aws_config().await;
+ let db = database::DatabaseClient::new(&aws_config);
+ let s3 = aws_sdk_s3::Client::new(&aws_config);
+
+ run_grpc_server(db, s3).await
}
diff --git a/services/blob/src/service.rs b/services/blob/src/service.rs
--- a/services/blob/src/service.rs
+++ b/services/blob/src/service.rs
@@ -1,15 +1,28 @@
use anyhow::Result;
use blob::blob_service_server::BlobService;
-use std::pin::Pin;
+use std::{pin::Pin, sync::Arc};
use tokio_stream::Stream;
use tonic::{Request, Response, Status};
+use crate::database::DatabaseClient;
+
pub mod blob {
tonic::include_proto!("blob");
}
-#[derive(Default)]
-pub struct MyBlobService {}
+pub struct MyBlobService {
+ db: DatabaseClient,
+ s3: Arc<aws_sdk_s3::Client>,
+}
+
+impl MyBlobService {
+ pub fn new(db_client: DatabaseClient, s3_client: aws_sdk_s3::Client) -> Self {
+ MyBlobService {
+ db: db_client,
+ s3: Arc::new(s3_client),
+ }
+ }
+}
// gRPC implementation
#[tonic::async_trait]
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 10:31 AM (20 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2687431
Default Alt Text
D5682.diff (3 KB)
Attached To
Mode
D5682: [services][blob] Provide S3 and DB to service, add more constants
Attached
Detach File
Event Timeline
Log In to Comment