Skip to content

Commit

Permalink
feat: Be more clear and consistent about features around dual (#557)
Browse files Browse the repository at this point in the history
This patch makes the feature sets consistent between the major crates.

Closes #SYNC-4075
  • Loading branch information
jrconlin committed Jan 23, 2024
1 parent 03afd7c commit 60c8b33
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions .cargo/audit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ ignore = [
"RUSTSEC-2023-0052", # Bound by Rusoto 0.47, Rustls 0.20, hyper-rustls 0.22, a2 0.8
"RUSTSEC-2023-0065", # Bound by tokio-tungstenite
"RUSTSEC-2024-0003", # Bound by hyper 0.12
"RUSTSEC-2024-0006", # Bound by Rusoto 0.42
]
5 changes: 4 additions & 1 deletion autoconnect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ actix-service = "2.0"
docopt = "1.1"

[features]
emulator = ["bigtable"]
default = ["dynamodb"]
bigtable = ["autopush_common/bigtable", "autoconnect_settings/bigtable"]
dynamodb = ["autopush_common/dynamodb", "autoconnect_settings/dynamodb"]
dual = ["bigtable", "dynamodb"]
emulator = ["bigtable"]
log_vapid = []
3 changes: 3 additions & 0 deletions autoconnect/autoconnect-settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ autoconnect_common.workspace = true
autopush_common.workspace = true

[features]
default = ["dynamodb"]
dynamodb = []
bigtable = ["autopush_common/bigtable"]
emulator = ["bigtable"]
dual = ["bigtable", "dynamodb"]
10 changes: 9 additions & 1 deletion autoconnect/autoconnect-settings/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use std::{sync::Arc, time::Duration};

#[cfg(feature = "bigtable")]
use autopush_common::db::bigtable::BigTableClientImpl;
#[cfg(all(feature = "bigtable", feature = "dynamodb"))]
use autopush_common::db::dual::DualClientImpl;
#[cfg(feature = "dynamodb")]
use autopush_common::db::dynamodb::DdbClientImpl;
use cadence::StatsdClient;
use fernet::{Fernet, MultiFernet};
use tokio::sync::RwLock;
Expand All @@ -10,7 +14,7 @@ use autoconnect_common::{
broadcast::BroadcastChangeTracker, megaphone::init_and_spawn_megaphone_updater,
registry::ClientRegistry,
};
use autopush_common::db::{client::DbClient, dynamodb::DdbClientImpl, DbSettings, StorageType};
use autopush_common::db::{client::DbClient, DbSettings, StorageType};
use autopush_common::errors::{ApcErrorKind, Result};

use crate::{Settings, ENV_PREFIX};
Expand Down Expand Up @@ -71,12 +75,16 @@ impl AppState {
db_settings: settings.db_settings.clone(),
};
let storage_type = StorageType::from_dsn(&db_settings.dsn);
#[allow(unused)]
let db: Box<dyn DbClient> = match storage_type {
#[cfg(feature = "dynamodb")]
StorageType::DynamoDb => Box::new(DdbClientImpl::new(metrics.clone(), &db_settings)?),
#[cfg(feature = "bigtable")]
StorageType::BigTable => {
Box::new(BigTableClientImpl::new(metrics.clone(), &db_settings)?)
}
#[cfg(all(feature = "bigtable", feature = "dynamodb"))]
StorageType::Dual => Box::new(DualClientImpl::new(metrics.clone(), &db_settings)?),
_ => panic!(
"Invalid Storage type {:?}. Check {}__DB_DSN.",
storage_type,
Expand Down
4 changes: 2 additions & 2 deletions autoendpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ tokio = { workspace = true, features = ["fs", "macros"] }

[features]
default = ["dynamodb"]
bigtable = ["autopush_common/bigtable"]
dynamodb = ["autopush_common/dynamodb"]
emulator = ["bigtable"]
dual = ["bigtable", "dynamodb"]
bigtable = ["autopush_common/bigtable"]
emulator = ["bigtable"]
6 changes: 3 additions & 3 deletions autoendpoint/src/extractors/authorization_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mod test {
// hopefully no-op type test to check locally generated tokens.
let uaid: Uuid = "729e5104f5f04abc9196085340317dea".parse().unwrap();
let auth_keys = ["HJVPy4ZwF4Yz_JdvXTL8hRcwIhv742vC60Tg5Ycrvw8=".to_owned()].to_vec();
let token = AuthorizationCheck::generate_token(auth_keys.get(0).unwrap(), &uaid).unwrap();
let token = AuthorizationCheck::generate_token(auth_keys.first().unwrap(), &uaid).unwrap();

AuthorizationCheck::validate_token(&token, &uaid, &auth_keys)?;
Ok(())
Expand All @@ -115,7 +115,7 @@ mod test {
// the following token was generated using the old python application.
let legacy_token = "f694963453adf5dedcc379bbdd6900d692b6e09f1c91f44169bfcd2f941bf36c";
// pop the firstkey off of the auth_key list.
let selected = auth_keys.get(0).unwrap();
let selected = auth_keys.first().unwrap();
let token = AuthorizationCheck::generate_token(selected, &uaid).unwrap();

assert_eq!(&token, legacy_token);
Expand All @@ -126,7 +126,7 @@ mod test {
fn test_token_extractor() -> ApiResult<()> {
let uaid: Uuid = "729e5104f5f04abc9196085340317dea".parse().unwrap();
let auth_keys = ["HJVPy4ZwF4Yz_JdvXTL8hRcwIhv742vC60Tg5Ycrvw8=".to_owned()].to_vec();
let token = AuthorizationCheck::generate_token(auth_keys.get(0).unwrap(), &uaid).unwrap();
let token = AuthorizationCheck::generate_token(auth_keys.first().unwrap(), &uaid).unwrap();

assert!(get_token_from_auth_header(&format!("bearer {}", &token)).is_some());
assert!(get_token_from_auth_header(&format!("webpush {}", &token)).is_some());
Expand Down
1 change: 1 addition & 0 deletions autopush-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ actix-rt = "2.8"
default = ["dynamodb"]
bigtable = ["dep:google-cloud-rust-raw", "dep:grpcio", "dep:protobuf"]
dynamodb = ["dep:rusoto_core", "dep:rusoto_credential", "dep:rusoto_dynamodb"]
dual = ["dynamodb", "bigtable"]
emulator = [
"bigtable",
] # used for testing big table, requires an external bigtable emulator running.
7 changes: 6 additions & 1 deletion autopush-common/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ pub enum StorageType {
}

/// The type of storage to use.
#[allow(clippy::vec_init_then_push)] // Because we are only pushing on feature flags.
impl StorageType {
fn available<'a>() -> Vec<&'a str> {
#[allow(unused_mut)]
let mut result = ["DynamoDB"].to_vec();
let mut result: Vec<&str> = Vec::new();
#[cfg(feature = "dynamodb")]
result.push("DynamoDB");
#[cfg(feature = "bigtable")]
result.push("Bigtable");
#[cfg(all(feature = "bigtable", feature = "dynamodb"))]
result.push("Dual");
result
}

Expand Down

0 comments on commit 60c8b33

Please sign in to comment.