Page MenuHomePhabricator

D6178.diff
No OneTemporary

D6178.diff

diff --git a/services/backup/src/config.rs b/services/backup/src/config.rs
--- a/services/backup/src/config.rs
+++ b/services/backup/src/config.rs
@@ -1,9 +1,12 @@
+use aws_sdk_dynamodb::{Endpoint, Region};
use clap::{builder::FalseyValueParser, Parser};
use once_cell::sync::Lazy;
+use tonic::transport::Uri;
+use tracing::info;
use crate::constants::{
- DEFAULT_BLOB_SERVICE_URL, DEFAULT_GRPC_SERVER_PORT, DEFAULT_LOCALSTACK_URL,
- SANDBOX_ENV_VAR,
+ AWS_REGION, DEFAULT_BLOB_SERVICE_URL, DEFAULT_GRPC_SERVER_PORT,
+ DEFAULT_LOCALSTACK_URL, SANDBOX_ENV_VAR,
};
#[derive(Parser)]
@@ -36,3 +39,21 @@
// force evaluation of the lazy initialized config
Lazy::force(&CONFIG);
}
+
+/// Provides region/credentials configuration for AWS SDKs
+pub async fn load_aws_config() -> aws_types::SdkConfig {
+ let mut config_builder =
+ aws_config::from_env().region(Region::new(AWS_REGION));
+
+ if CONFIG.is_sandbox {
+ info!(
+ "Running in sandbox environment. Localstack URL: {}",
+ &CONFIG.localstack_url
+ );
+ config_builder = config_builder.endpoint_resolver(Endpoint::immutable(
+ Uri::from_static(&CONFIG.localstack_url),
+ ));
+ }
+
+ config_builder.load().await
+}
diff --git a/services/backup/src/constants.rs b/services/backup/src/constants.rs
--- a/services/backup/src/constants.rs
+++ b/services/backup/src/constants.rs
@@ -1,5 +1,6 @@
// Assorted constants
+pub const AWS_REGION: &str = "us-east-2";
pub const MPSC_CHANNEL_BUFFER_CAPACITY: usize = 1;
// Configuration defaults
diff --git a/services/backup/src/main.rs b/services/backup/src/main.rs
--- a/services/backup/src/main.rs
+++ b/services/backup/src/main.rs
@@ -26,9 +26,9 @@
Ok(())
}
-async fn run_grpc_server() -> Result<()> {
+async fn run_grpc_server(db: database::DatabaseClient) -> Result<()> {
let addr: SocketAddr = format!("[::]:{}", CONFIG.listening_port).parse()?;
- let backup_service = MyBackupService::default();
+ let backup_service = MyBackupService::new(db);
info!("Starting gRPC server listening at {}", addr.to_string());
Server::builder()
@@ -44,5 +44,8 @@
config::parse_cmdline_args();
configure_logging()?;
- run_grpc_server().await
+ let aws_config = config::load_aws_config().await;
+ let db = database::DatabaseClient::new(&aws_config);
+
+ run_grpc_server(db).await
}
diff --git a/services/backup/src/service/mod.rs b/services/backup/src/service/mod.rs
--- a/services/backup/src/service/mod.rs
+++ b/services/backup/src/service/mod.rs
@@ -4,13 +4,22 @@
use tonic::{Request, Response, Status};
use tracing::instrument;
+use crate::database::DatabaseClient;
+
mod proto {
tonic::include_proto!("backup");
}
pub use proto::backup_service_server::BackupServiceServer;
-#[derive(Default)]
-pub struct MyBackupService {}
+pub struct MyBackupService {
+ db: DatabaseClient,
+}
+
+impl MyBackupService {
+ pub fn new(db_client: DatabaseClient) -> Self {
+ MyBackupService { db: db_client }
+ }
+}
// gRPC implementation
#[tonic::async_trait]

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 7:35 PM (20 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678589
Default Alt Text
D6178.diff (2 KB)

Event Timeline