diff --git a/services/identity/Cargo.lock b/services/identity/Cargo.lock --- a/services/identity/Cargo.lock +++ b/services/identity/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "1.0.1" @@ -76,9 +91,9 @@ [[package]] name = "anyhow" -version = "1.0.70" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "59d2a3357dde987206219e78ecfbbb6e8dad06cbb65292758d3270e6254f7355" [[package]] name = "argon2" @@ -107,7 +122,7 @@ "polling", "rustix", "slab", - "socket2", + "socket2 0.4.9", "waker-fn", ] @@ -262,6 +277,32 @@ "tracing", ] +[[package]] +name = "aws-sdk-secretsmanager" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502ccd2a5469223f03116ed1ef8d310bfe3caa0e8398b968439cd8e76e4ae91c" +dependencies = [ + "aws-credential-types", + "aws-endpoint", + "aws-http", + "aws-sig-auth", + "aws-smithy-async", + "aws-smithy-client", + "aws-smithy-http", + "aws-smithy-http-tower", + "aws-smithy-json", + "aws-smithy-types", + "aws-types", + "bytes", + "fastrand", + "http", + "regex", + "tokio-stream", + "tower", + "tracing", +] + [[package]] name = "aws-sdk-sso" version = "0.28.0" @@ -522,6 +563,21 @@ "tower-service", ] +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base16ct" version = "0.1.1" @@ -737,6 +793,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "comm-lib" +version = "0.1.0" +dependencies = [ + "anyhow", + "aws-config", + "aws-sdk-dynamodb", + "aws-sdk-secretsmanager", + "base64", + "chrono", + "constant_time_eq 0.3.0", + "derive_more", + "grpc_clients", + "rand 0.8.5", + "serde", + "serde_json", + "tokio", + "tracing", +] + [[package]] name = "comm-opaque2" version = "0.2.0" @@ -770,6 +846,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13418e745008f7349ec7e449155f419a61b92b58a99cc3616942b926825ec76b" +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + [[package]] name = "convert_case" version = "0.4.0" @@ -1284,6 +1366,12 @@ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + [[package]] name = "glob" version = "0.3.1" @@ -1461,7 +1549,7 @@ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -1523,13 +1611,12 @@ name = "identity" version = "0.1.0" dependencies = [ - "aws-config", - "aws-sdk-dynamodb", "base64", "chrono", "clap", + "comm-lib", "comm-opaque2", - "constant_time_eq", + "constant_time_eq 0.2.5", "derive_more", "ed25519-dalek", "grpc_clients", @@ -1646,9 +1733,9 @@ [[package]] name = "libc" -version = "0.2.141" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "link-cplusplus" @@ -1735,16 +1822,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + [[package]] name = "mio" -version = "0.8.6" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", - "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -1828,6 +1923,15 @@ "libc", ] +[[package]] +name = "object" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.17.1" @@ -1958,9 +2062,9 @@ [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -2244,6 +2348,12 @@ "winapi", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustc_version" version = "0.4.0" @@ -2580,6 +2690,16 @@ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "spin" version = "0.5.2" @@ -2712,19 +2832,19 @@ [[package]] name = "tokio" -version = "1.27.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ - "autocfg", + "backtrace", "bytes", "libc", "mio", "num_cpus", "pin-project-lite", - "socket2", + "socket2 0.5.5", "tokio-macros", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -2739,9 +2859,9 @@ [[package]] name = "tokio-macros" -version = "2.0.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", diff --git a/services/identity/Cargo.toml b/services/identity/Cargo.toml --- a/services/identity/Cargo.toml +++ b/services/identity/Cargo.toml @@ -11,8 +11,7 @@ ed25519-dalek = "1" clap = { version = "4.4", features = ["derive", "env"] } derive_more = "0.99" -aws-config = "0.55.0" -aws-sdk-dynamodb = "0.27.0" +comm-lib = { path = "../../shared/comm-lib", features = ["aws"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } chrono = "0.4.31" diff --git a/services/identity/src/client_service.rs b/services/identity/src/client_service.rs --- a/services/identity/src/client_service.rs +++ b/services/identity/src/client_service.rs @@ -2,7 +2,7 @@ use std::str::FromStr; // External crate imports -use aws_sdk_dynamodb::Error as DynamoDBError; +use comm_lib::aws::DynamoDBError; use comm_opaque2::grpc::protocol_error_to_grpc_status; use moka::future::Cache; use rand::rngs::OsRng; diff --git a/services/identity/src/database.rs b/services/identity/src/database.rs --- a/services/identity/src/database.rs +++ b/services/identity/src/database.rs @@ -1,12 +1,12 @@ -use aws_sdk_dynamodb::operation::delete_item::DeleteItemOutput; -use aws_sdk_dynamodb::operation::get_item::GetItemOutput; -use aws_sdk_dynamodb::operation::put_item::PutItemOutput; -use aws_sdk_dynamodb::operation::query::QueryOutput; -use aws_sdk_dynamodb::primitives::Blob; -use aws_sdk_dynamodb::types::{ - AttributeValue, PutRequest, ReturnConsumedCapacity, WriteRequest, +use comm_lib::aws::ddb::{ + operation::{ + delete_item::DeleteItemOutput, get_item::GetItemOutput, + put_item::PutItemOutput, query::QueryOutput, + }, + primitives::Blob, + types::{AttributeValue, PutRequest, ReturnConsumedCapacity, WriteRequest}, }; -use aws_sdk_dynamodb::Client; +use comm_lib::aws::{AwsConfig, DynamoDBClient}; use constant_time_eq::constant_time_eq; use std::collections::{HashMap, HashSet}; use std::str::FromStr; @@ -16,7 +16,6 @@ create_one_time_key_partition_key, into_one_time_put_requests, OlmAccountType, }; use crate::error::{consume_error, DBItemAttributeError, DBItemError, Error}; -use aws_config::SdkConfig; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use tracing::{debug, error, info, warn}; @@ -116,11 +115,11 @@ #[derive(Clone)] pub struct DatabaseClient { - client: Arc, + client: Arc, } impl DatabaseClient { - pub fn new(aws_config: &SdkConfig) -> Self { + pub fn new(aws_config: &AwsConfig) -> Self { let client = match &CONFIG.localstack_endpoint { Some(endpoint) => { info!( @@ -128,11 +127,11 @@ endpoint ); let ddb_config_builder = - aws_sdk_dynamodb::config::Builder::from(aws_config) + comm_lib::aws::ddb::config::Builder::from(aws_config) .endpoint_url(endpoint); - Client::from_conf(ddb_config_builder.build()) + DynamoDBClient::from_conf(ddb_config_builder.build()) } - None => Client::new(aws_config), + None => DynamoDBClient::new(aws_config), }; DatabaseClient { diff --git a/services/identity/src/database/device_list.rs b/services/identity/src/database/device_list.rs --- a/services/identity/src/database/device_list.rs +++ b/services/identity/src/database/device_list.rs @@ -1,13 +1,16 @@ use std::collections::HashMap; -use aws_sdk_dynamodb::{ - operation::{get_item::GetItemOutput, query::builders::QueryFluentBuilder}, - types::{ - error::TransactionCanceledException, AttributeValue, DeleteRequest, Put, - TransactWriteItem, Update, WriteRequest, +use chrono::{DateTime, Utc}; +use comm_lib::{ + aws::ddb::{ + operation::{get_item::GetItemOutput, query::builders::QueryFluentBuilder}, + types::{ + error::TransactionCanceledException, AttributeValue, DeleteRequest, Put, + TransactWriteItem, Update, WriteRequest, + }, }, + database::{AttributeMap, DynamoDBError}, }; -use chrono::{DateTime, Utc}; use tracing::{error, warn}; use crate::{ @@ -28,8 +31,6 @@ use super::{parse_date_time_attribute, DatabaseClient}; -type RawAttributes = HashMap; - #[derive(Clone, Debug)] pub struct DeviceRow { pub user_id: String, @@ -164,10 +165,10 @@ } } -impl TryFrom for DeviceRow { +impl TryFrom for DeviceRow { type Error = DBItemError; - fn try_from(mut attrs: RawAttributes) -> Result { + fn try_from(mut attrs: AttributeMap) -> Result { let user_id = parse_string_attribute(ATTR_USER_ID, attrs.remove(ATTR_USER_ID))?; let DeviceIDAttribute(device_id) = attrs.remove(ATTR_ITEM_ID).try_into()?; @@ -215,7 +216,7 @@ } } -impl From for RawAttributes { +impl From for AttributeMap { fn from(value: DeviceRow) -> Self { HashMap::from([ (ATTR_USER_ID.to_string(), AttributeValue::S(value.user_id)), @@ -259,9 +260,9 @@ } } -impl TryFrom for IdentityKeyInfo { +impl TryFrom for IdentityKeyInfo { type Error = DBItemError; - fn try_from(mut attrs: RawAttributes) -> Result { + fn try_from(mut attrs: AttributeMap) -> Result { let key_payload = parse_string_attribute(ATTR_KEY_PAYLOAD, attrs.remove(ATTR_KEY_PAYLOAD))?; let key_payload_signature = parse_string_attribute( @@ -295,9 +296,9 @@ } } -impl TryFrom for PreKey { +impl TryFrom for PreKey { type Error = DBItemError; - fn try_from(mut attrs: RawAttributes) -> Result { + fn try_from(mut attrs: AttributeMap) -> Result { let pre_key = parse_string_attribute(ATTR_PREKEY, attrs.remove(ATTR_PREKEY))?; let pre_key_signature = parse_string_attribute( @@ -311,10 +312,10 @@ } } -impl TryFrom for DeviceListRow { +impl TryFrom for DeviceListRow { type Error = DBItemError; - fn try_from(mut attrs: RawAttributes) -> Result { + fn try_from(mut attrs: AttributeMap) -> Result { let user_id = parse_string_attribute(ATTR_USER_ID, attrs.remove(ATTR_USER_ID))?; let DeviceListKeyAttribute(timestamp) = @@ -358,7 +359,7 @@ } } -impl From for RawAttributes { +impl From for AttributeMap { fn from(device_list: DeviceListRow) -> Self { let mut attrs = HashMap::new(); attrs.insert( @@ -618,8 +619,8 @@ .transact_items(timestamp_update_operation) .send() .await - .map_err(|e| match aws_sdk_dynamodb::Error::from(e) { - aws_sdk_dynamodb::Error::TransactionCanceledException( + .map_err(|e| match DynamoDBError::from(e) { + DynamoDBError::TransactionCanceledException( TransactionCanceledException { cancellation_reasons: Some(reasons), .. diff --git a/services/identity/src/ddb_utils.rs b/services/identity/src/ddb_utils.rs --- a/services/identity/src/ddb_utils.rs +++ b/services/identity/src/ddb_utils.rs @@ -1,5 +1,5 @@ -use aws_sdk_dynamodb::types::{AttributeValue, PutRequest, WriteRequest}; use chrono::{DateTime, NaiveDateTime, Utc}; +use comm_lib::aws::ddb::types::{AttributeValue, PutRequest, WriteRequest}; use std::collections::HashMap; use std::iter::IntoIterator; diff --git a/services/identity/src/error.rs b/services/identity/src/error.rs --- a/services/identity/src/error.rs +++ b/services/identity/src/error.rs @@ -1,5 +1,5 @@ -use aws_sdk_dynamodb::types::AttributeValue; -use aws_sdk_dynamodb::Error as DynamoDBError; +use comm_lib::aws::ddb::types::AttributeValue; +use comm_lib::aws::DynamoDBError; use std::collections::hash_map::HashMap; use std::fmt::{Display, Formatter, Result as FmtResult}; use tracing::error; diff --git a/services/identity/src/main.rs b/services/identity/src/main.rs --- a/services/identity/src/main.rs +++ b/services/identity/src/main.rs @@ -1,5 +1,6 @@ use std::time::Duration; +use comm_lib::aws; use config::Command; use database::DatabaseClient; use moka::future::Cache; @@ -50,7 +51,7 @@ Command::Server => { config::load_server_config(); let addr = IDENTITY_SERVICE_SOCKET_ADDR.parse()?; - let aws_config = aws_config::from_env().region("us-east-2").load().await; + let aws_config = aws::config::from_env().region("us-east-2").load().await; let database_client = DatabaseClient::new(&aws_config); let workflow_cache = Cache::builder() .time_to_live(Duration::from_secs(10))