Page MenuHomePhabricator

D7441.diff
No OneTemporary

D7441.diff

diff --git a/services/blob/src/config.rs b/services/blob/src/config.rs
--- a/services/blob/src/config.rs
+++ b/services/blob/src/config.rs
@@ -1,18 +1,23 @@
+use anyhow::{ensure, Result};
use aws_sdk_dynamodb::Region;
use clap::{builder::FalseyValueParser, Parser};
use once_cell::sync::Lazy;
use tracing::info;
use crate::constants::{
- AWS_REGION, GRPC_SERVER_DEFAULT_PORT, LOCALSTACK_URL, SANDBOX_ENV_VAR,
+ AWS_REGION, DEFAULT_GRPC_PORT, DEFAULT_HTTP_PORT, LOCALSTACK_URL,
+ SANDBOX_ENV_VAR,
};
#[derive(Parser)]
#[command(version, about, long_about = None)]
pub struct AppConfig {
/// gRPC server listening port
- #[arg(long = "port", default_value_t = GRPC_SERVER_DEFAULT_PORT)]
- pub grpc_port: u64,
+ #[arg(long, default_value_t = DEFAULT_GRPC_PORT)]
+ pub grpc_port: u16,
+ /// HTTP server listening port
+ #[arg(long, default_value_t = DEFAULT_HTTP_PORT)]
+ pub http_port: u16,
/// Run the service in sandbox
#[arg(long = "sandbox", default_value_t = false)]
// support the env var for compatibility reasons
@@ -30,9 +35,17 @@
/// Processes the command-line arguments and environment variables.
/// Should be called at the beginning of the `main()` function.
-pub(super) fn parse_cmdline_args() {
+pub(super) fn parse_cmdline_args() -> Result<()> {
// force evaluation of the lazy initialized config
- Lazy::force(&CONFIG);
+ let cfg = Lazy::force(&CONFIG);
+
+ // Perform some additional validation for CLI args
+ ensure!(
+ cfg.grpc_port != cfg.http_port,
+ "gRPC and HTTP ports cannot be the same: {}",
+ cfg.grpc_port
+ );
+ Ok(())
}
/// Provides region/credentials configuration for AWS SDKs
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,6 +1,7 @@
// Assorted constants
-pub const GRPC_SERVER_DEFAULT_PORT: u64 = 50051;
+pub const DEFAULT_GRPC_PORT: u16 = 50051;
+pub const DEFAULT_HTTP_PORT: u16 = 51001;
pub const AWS_REGION: &str = "us-east-2";
pub const LOCALSTACK_URL: &str = "http://localstack:4566";
pub const MPSC_CHANNEL_BUFFER_CAPACITY: usize = 1;
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
@@ -22,7 +22,7 @@
#[tokio::main]
async fn main() -> Result<()> {
configure_logging()?;
- config::parse_cmdline_args();
+ config::parse_cmdline_args()?;
let aws_config = config::load_aws_config().await;
let db = database::DatabaseClient::new(&aws_config);

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 9, 11:54 AM (9 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2834319
Default Alt Text
D7441.diff (2 KB)

Event Timeline