diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,6 @@ desktop/assets/ desktop/dist/ desktop/*.provisionprofile + +# Cargo workspace +target/ diff --git a/keyserver/Dockerfile b/keyserver/Dockerfile --- a/keyserver/Dockerfile +++ b/keyserver/Dockerfile @@ -28,15 +28,15 @@ USER root RUN \ if [ -z "`getent group $HOST_GID`" ]; then \ - addgroup --system --gid $HOST_GID comm; \ + addgroup --system --gid $HOST_GID comm; \ else \ - groupmod --new-name comm `getent group $HOST_GID | cut -d: -f1`; \ + groupmod --new-name comm `getent group $HOST_GID | cut -d: -f1`; \ fi && \ if [ -z "`getent passwd $HOST_UID`" ]; then \ - adduser --system --uid $HOST_UID --ingroup comm --shell /bin/bash comm; \ + adduser --system --uid $HOST_UID --ingroup comm --shell /bin/bash comm; \ else \ - usermod --login comm --gid $HOST_GID --home /home/comm --move-home \ - `getent passwd $HOST_UID | cut -d: -f1`; \ + usermod --login comm --gid $HOST_GID --home /home/comm --move-home \ + `getent passwd $HOST_UID | cut -d: -f1`; \ fi #------------------------------------------------------------------------------- @@ -142,6 +142,9 @@ COPY --chown=comm web/backup-client-wasm/Cargo.toml \ web/backup-client-wasm/ +# Copy cargo workspace root Cargo.toml +COPY --chown=comm Cargo.toml Cargo.toml + # Copy in local dependencies of rust-node-addon COPY --chown=comm shared/comm-opaque2 shared/comm-opaque2/ diff --git a/keyserver/addons/rust-node-addon/Cargo.toml b/keyserver/addons/rust-node-addon/Cargo.toml --- a/keyserver/addons/rust-node-addon/Cargo.toml +++ b/keyserver/addons/rust-node-addon/Cargo.toml @@ -1,8 +1,9 @@ [package] -edition = "2021" name = "rust-node-addon" version = "0.1.0" -license = "BSD-3-Clause" +edition.workspace = true +license.workspace = true +homepage.workspace = true [lib] crate-type = ["cdylib"] @@ -14,12 +15,12 @@ "tokio_rt", ] } napi-derive = { version = "2.9.1", default-features = false } -tonic = { version = "0.9.1", features = ["tls"]} -tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } +tonic = { version = "0.9.1", features = ["tls"] } +tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } tokio-stream = "0.1" tracing = "0.1" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -comm-opaque2 = {path = "../../../shared/comm-opaque2"} +comm-opaque2 = { path = "../../../shared/comm-opaque2" } grpc_clients = { path = "../../../shared/grpc_clients" } lazy_static = "1.4" serde_json = "1.0" @@ -29,5 +30,5 @@ napi-build = "2.0.1" regex = "1" -[profile.release] -lto = true +# [profile.release] +# lto = true diff --git a/native/native_rust_library/Cargo.toml b/native/native_rust_library/Cargo.toml --- a/native/native_rust_library/Cargo.toml +++ b/native/native_rust_library/Cargo.toml @@ -6,7 +6,7 @@ [dependencies] cxx = "1.0" -tokio = { version = "1.24", features = ["macros", "rt-multi-thread"] } +tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } tonic = "0.9.1" lazy_static = "1.4" tracing = "0.1" diff --git a/native/native_rust_library/src/backup.rs b/native/native_rust_library/src/backup.rs --- a/native/native_rust_library/src/backup.rs +++ b/native/native_rust_library/src/backup.rs @@ -250,10 +250,10 @@ } pub async fn create_siwe_backup_msg_compaction( - backup_id: &String, + backup_id: &str, siwe_backup_msg: String, ) -> Result<(), Box> { - let siwe_backup_msg_file = get_siwe_backup_message_path(&backup_id)?; + let siwe_backup_msg_file = get_siwe_backup_message_path(backup_id)?; tokio::fs::write(siwe_backup_msg_file, siwe_backup_msg).await?; Ok(()) diff --git a/native/native_rust_library/src/identity/login.rs b/native/native_rust_library/src/identity/login.rs --- a/native/native_rust_library/src/identity/login.rs +++ b/native/native_rust_library/src/identity/login.rs @@ -15,6 +15,7 @@ use crate::utils::jsi_callbacks::handle_string_result_as_callback; use crate::{Error, CODE_VERSION, DEVICE_TYPE, IDENTITY_SOCKET_ADDR, RUNTIME}; +#[allow(clippy::too_many_arguments)] pub mod ffi { use crate::identity::{ DeviceKeys, LogInPasswordUserInfo, LogInWalletUserInfo, diff --git a/native/native_rust_library/src/identity/registration.rs b/native/native_rust_library/src/identity/registration.rs --- a/native/native_rust_library/src/identity/registration.rs +++ b/native/native_rust_library/src/identity/registration.rs @@ -19,6 +19,7 @@ RegisterWalletUserInfo, UserIDAndDeviceAccessToken, }; +#[allow(clippy::too_many_arguments)] pub mod ffi { use crate::identity::{ DeviceKeys, RegisterPasswordUserInfo, RegisterReservedPasswordUserInfo, diff --git a/native/native_rust_library/src/identity/x3dh.rs b/native/native_rust_library/src/identity/x3dh.rs --- a/native/native_rust_library/src/identity/x3dh.rs +++ b/native/native_rust_library/src/identity/x3dh.rs @@ -86,6 +86,7 @@ }); } + #[allow(clippy::too_many_arguments)] pub fn refresh_user_prekeys( auth_user_id: String, auth_device_id: String, diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -41,6 +41,7 @@ use identity::ffi::*; use utils::future_manager::ffi::*; +#[allow(clippy::too_many_arguments)] #[cxx::bridge] mod ffi { diff --git a/services/backup/Cargo.toml b/services/backup/Cargo.toml --- a/services/backup/Cargo.toml +++ b/services/backup/Cargo.toml @@ -12,7 +12,7 @@ aws-config = "0.55" aws-sdk-dynamodb = "0.27" aws-types = "0.55" -chrono = "0.4.31" +chrono.workspace = true clap = { version = "4.0", features = ["derive", "env"] } comm-lib = { path = "../../shared/comm-lib", features = [ "http", @@ -21,7 +21,7 @@ "grpc_clients", ] } once_cell = "1.17" -tokio = { version = "1.24", features = ["rt-multi-thread", "macros"] } +tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } tokio-stream = "0.1" tracing = "0.1" tracing-futures = { version = "0.2", features = ["futures-03"] } diff --git a/services/backup/Dockerfile b/services/backup/Dockerfile --- a/services/backup/Dockerfile +++ b/services/backup/Dockerfile @@ -12,11 +12,17 @@ ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse +# Copy and prepare cargo workspace +COPY Cargo.toml ../../Cargo.toml +COPY Cargo.lock ../../Cargo.lock +# Remove rust-node-addon and native_rust_library from cargo workspace +RUN sed -i -E '/rust-node-addon|native_rust_library/d' ../../Cargo.toml + # Copy actual application sources COPY shared ../../shared/ COPY services/backup ./ -RUN cargo install --locked --path . +RUN cargo build --release --target-dir /out # Runner stage FROM debian:bullseye-slim as runner @@ -27,7 +33,7 @@ && rm -rf /var/lib/apt/lists/* # Only copy built binary from builder stage -COPY --from=builder /usr/local/cargo/bin/backup /usr/local/bin/backup +COPY --from=builder /out/release/backup /usr/local/bin/backup WORKDIR /home/comm/app/backup # Create a new user comm and use it to run subsequent commands diff --git a/services/blob/Cargo.toml b/services/blob/Cargo.toml --- a/services/blob/Cargo.toml +++ b/services/blob/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "blob" description = "Blob service" -homepage = "https://comm.app" -license = "BSD-3-Clause" version = "1.0.0" -edition = "2021" +edition.workspace = true +license.workspace = true +homepage.workspace = true [dependencies] actix-multipart = "0.6" @@ -14,7 +14,7 @@ aws-config = "0.55" aws-sdk-dynamodb = "0.27" aws-sdk-s3 = "0.27" -chrono = "0.4.31" +chrono.workspace = true clap = { version = "4.0", features = ["derive", "env"] } comm-lib = { path = "../../shared/comm-lib", features = [ "http", @@ -27,7 +27,7 @@ prost = "0.11" regex = "1.10.3" serde = { version = "1.0", features = ["derive"] } -tokio = { version = "1.24", features = ["rt-multi-thread"] } +tokio = { workspace = true, features = ["rt-multi-thread"] } tokio-stream = "0.1" tonic = "0.8" tracing = "0.1" diff --git a/services/blob/Dockerfile b/services/blob/Dockerfile --- a/services/blob/Dockerfile +++ b/services/blob/Dockerfile @@ -4,7 +4,7 @@ build-essential cmake git libgtest-dev libssl-dev zlib1g-dev \ && rm -rf /var/lib/apt/lists/* -WORKDIR /home/root/app/blob +WORKDIR /home/root/services/blob # Install more recent version of protobuf, must be ran as root COPY scripts/install_protobuf.sh ../../scripts/install_protobuf.sh @@ -13,11 +13,17 @@ ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse +# Copy and prepare cargo workspace +COPY Cargo.toml ../../Cargo.toml +COPY Cargo.lock ../../Cargo.lock +# Remove rust-node-addon and native_rust_library from cargo workspace +RUN sed -i -E '/rust-node-addon|native_rust_library/d' ../../Cargo.toml + # Copy actual application sources COPY shared ../../shared/ COPY services/blob ./ -RUN cargo install --locked --path . +RUN cargo build --release --target-dir /out # Runner stage FROM debian:bullseye-slim as runner @@ -28,7 +34,7 @@ && rm -rf /var/lib/apt/lists/* # Only copy built binary from builder stage -COPY --from=builder /usr/local/cargo/bin/blob /usr/local/bin/blob +COPY --from=builder /out/release/blob /usr/local/bin/blob WORKDIR /home/comm/app/blob # Create a new user comm and use it to run subsequent commands 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 @@ -168,7 +168,7 @@ if let Some(invite_secret) = blob_hash.strip_prefix(INVITE_LINK_BLOB_HASH_PREFIX) { - Self::validate_invite_link_blob_hash(&invite_secret)?; + Self::validate_invite_link_blob_hash(invite_secret)?; } let mut upload_session = diff --git a/services/commtest/Cargo.toml b/services/commtest/Cargo.toml --- a/services/commtest/Cargo.toml +++ b/services/commtest/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "commtest" version = "0.1.0" -edition = "2021" -license = "BSD-3-Clause" +edition.workspace = true +license.workspace = true [dependencies] comm-opaque2 = { path = "../../shared/comm-opaque2" } @@ -11,7 +11,7 @@ base64 = "0.21.2" ed25519-dalek = "1" tonic = "0.8" -tokio = { version = "1.24", features = ["macros", "rt-multi-thread"] } +tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } prost = "0.11" async-stream = "0.3.2" derive_more = "0.99.16" diff --git a/services/commtest/Dockerfile b/services/commtest/Dockerfile --- a/services/commtest/Dockerfile +++ b/services/commtest/Dockerfile @@ -24,7 +24,7 @@ RUN unzip -q awscliv2.zip && ./aws/install \ && rm -rf awscliv2.zip aws -WORKDIR /home/root/app/commtest +WORKDIR /home/root/services/commtest # Install cargo lambda RUN pip3 install cargo-lambda @@ -34,6 +34,12 @@ RUN ../../scripts/install_protobuf.sh ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse +# Copy and prepare cargo workspace +COPY Cargo.toml ../../Cargo.toml +COPY Cargo.lock ../../Cargo.lock +# Remove rust-node-addon and native_rust_library from cargo workspace +RUN sed -i -E '/rust-node-addon|native_rust_library/d' ../../Cargo.toml + # Copy actual application sources COPY shared ../../shared/ COPY services/terraform/dev ../terraform/dev diff --git a/services/commtest/src/identity/mod.rs b/services/commtest/src/identity/mod.rs --- a/services/commtest/src/identity/mod.rs +++ b/services/commtest/src/identity/mod.rs @@ -1,5 +1,5 @@ use base64::Engine; -use ed25519_dalek::{ed25519::signature::SignerMut, Keypair, Signature}; +use ed25519_dalek::{ed25519::signature::Signer, Keypair, Signature}; use rand::rngs::OsRng; use self::olm_account_infos::{ @@ -37,7 +37,7 @@ } /// signs message, returns signature - pub fn sign_message(&mut self, message: &str) -> String { + pub fn sign_message(&self, message: &str) -> String { let signature: Signature = self.signing_key.sign(message.as_bytes()); base64::engine::general_purpose::STANDARD_NO_PAD .encode(signature.to_bytes()) diff --git a/services/commtest/tests/identity_access_tokens_tests.rs b/services/commtest/tests/identity_access_tokens_tests.rs --- a/services/commtest/tests/identity_access_tokens_tests.rs +++ b/services/commtest/tests/identity_access_tokens_tests.rs @@ -43,7 +43,7 @@ .await .expect("Couldn't connect to identity service"); - let mut account = SigningCapableAccount::new(); + let account = SigningCapableAccount::new(); let client_keys = account.public_keys(); let user = register_user_device(Some(&client_keys), None).await; diff --git a/services/commtest/tests/identity_one_time_key_tests.rs b/services/commtest/tests/identity_one_time_key_tests.rs --- a/services/commtest/tests/identity_one_time_key_tests.rs +++ b/services/commtest/tests/identity_one_time_key_tests.rs @@ -81,8 +81,8 @@ (0..20).map(|_| generate_random_olm_key()).collect(); if request_num == 0 { - expected_first_retrieved_content_key = content_keys.get(0).cloned(); - expected_first_retrieved_notif_key = notif_keys.get(0).cloned(); + expected_first_retrieved_content_key = content_keys.first().cloned(); + expected_first_retrieved_notif_key = notif_keys.first().cloned(); expected_second_retrieved_content_key = content_keys.get(5).cloned(); expected_second_retrieved_notif_key = notif_keys.get(5).cloned(); } diff --git a/services/feature-flags/Cargo.toml b/services/feature-flags/Cargo.toml --- a/services/feature-flags/Cargo.toml +++ b/services/feature-flags/Cargo.toml @@ -20,6 +20,6 @@ http = "0.2" once_cell = "1.17" serde = { version = "1.0", features = ["derive"] } -tokio = { version = "1.24", features = ["rt-multi-thread", "macros"] } +tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/services/feature-flags/Dockerfile b/services/feature-flags/Dockerfile --- a/services/feature-flags/Dockerfile +++ b/services/feature-flags/Dockerfile @@ -8,11 +8,17 @@ ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse +# Copy and prepare cargo workspace +COPY Cargo.toml ../../Cargo.toml +COPY Cargo.lock ../../Cargo.lock +# Remove rust-node-addon and native_rust_library from cargo workspace +RUN sed -i -E '/rust-node-addon|native_rust_library/d' ../../Cargo.toml + # Copy actual application sources COPY shared ../../shared/ COPY services/feature-flags ./ -RUN cargo install --locked --path . +RUN cargo build --release --target-dir /out # Runner stage FROM debian:bullseye-slim as runner @@ -23,7 +29,7 @@ && rm -rf /var/lib/apt/lists/* # Only copy built binary from builder stage -COPY --from=builder /usr/local/cargo/bin/feature-flags /usr/local/bin/feature-flags +COPY --from=builder /out/release/feature-flags /usr/local/bin/feature-flags WORKDIR /home/comm/app/feature-flags # Create a new user comm and use it to run subsequent commands diff --git a/services/identity/Cargo.toml b/services/identity/Cargo.toml --- a/services/identity/Cargo.toml +++ b/services/identity/Cargo.toml @@ -8,7 +8,7 @@ tonic = "0.9.1" prost = "0.11" futures-util = "0.3" -tokio = { version = "1.24", features = ["macros", "rt-multi-thread"] } +tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } ed25519-dalek = "1" clap = { version = "4.4", features = ["derive", "env"] } derive_more = "0.99" @@ -18,7 +18,7 @@ ] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } -chrono = "0.4.31" +chrono.workspace = true rand = "0.8" constant_time_eq = "0.2.2" siwe = "0.3" diff --git a/services/identity/Dockerfile b/services/identity/Dockerfile --- a/services/identity/Dockerfile +++ b/services/identity/Dockerfile @@ -15,16 +15,17 @@ WORKDIR /home/comm/app/identity RUN cargo init --bin -COPY services/identity/Cargo.toml services/identity/Cargo.lock ./ -COPY shared/ ../../shared/ - -# Cache build dependencies in a new layer -RUN cargo build --release -RUN rm src/*.rs +# Copy and prepare cargo workspace +COPY Cargo.toml ../../Cargo.toml +COPY Cargo.lock ../../Cargo.lock +# Remove rust-node-addon and native_rust_library from cargo workspace +RUN sed -i -E '/rust-node-addon|native_rust_library/d' ../../Cargo.toml +# Copy actual application sources +COPY shared/ ../../shared/ COPY services/identity . -RUN cargo install --locked --path . +RUN cargo build --release --target-dir /out FROM debian:bullseye-slim @@ -35,7 +36,7 @@ WORKDIR /home/comm/app/identity -COPY --from=builder /usr/local/cargo/bin/identity \ +COPY --from=builder /out/release/identity \ /usr/local/bin/identity # For test/debug builds, optionally generate OPAQUE keypair file 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 @@ -189,6 +189,7 @@ Ok(user_id) } + #[allow(clippy::too_many_arguments)] pub async fn add_wallet_user_to_users_table( &self, flattened_device_key_upload: FlattenedDeviceKeyUpload, 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,4 +1,4 @@ -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, Utc}; use comm_lib::{ aws::{ ddb::types::{ @@ -160,17 +160,6 @@ transactions } -pub trait DateTimeExt { - fn from_utc_timestamp_millis(timestamp: i64) -> Option>; -} - -impl DateTimeExt for DateTime { - fn from_utc_timestamp_millis(timestamp: i64) -> Option { - let naive = NaiveDateTime::from_timestamp_millis(timestamp)?; - Some(Self::from_naive_utc_and_offset(naive, Utc)) - } -} - pub struct DBIdentity { pub identifier: Identifier, pub farcaster_id: Option, diff --git a/services/identity/src/device_list.rs b/services/identity/src/device_list.rs --- a/services/identity/src/device_list.rs +++ b/services/identity/src/device_list.rs @@ -5,7 +5,6 @@ use crate::{ constants::{error_types, DEVICE_LIST_TIMESTAMP_VALID_FOR}, database::{DeviceListRow, DeviceListUpdate}, - ddb_utils::DateTimeExt, error::DeviceListError, grpc_services::protos::auth::UpdateDeviceListRequest, }; @@ -102,14 +101,14 @@ devices, timestamp: raw_timestamp, } = signed_list.as_raw()?; - let timestamp = DateTime::::from_utc_timestamp_millis(raw_timestamp) - .ok_or_else(|| { - error!( - errorType = error_types::GRPC_SERVICES_LOG, - "Failed to parse RawDeviceList timestamp!" - ); - tonic::Status::invalid_argument("invalid timestamp") - })?; + let timestamp = + DateTime::from_timestamp_millis(raw_timestamp).ok_or_else(|| { + error!( + errorType = error_types::GRPC_SERVICES_LOG, + "Failed to parse RawDeviceList timestamp!" + ); + tonic::Status::invalid_argument("invalid timestamp") + })?; Ok(DeviceListUpdate { devices, timestamp, @@ -445,7 +444,7 @@ .expect("Failed to parse DeviceListUpdate from signed list"); let expected_timestamp = - DateTime::::from_utc_timestamp_millis(123456789).unwrap(); + DateTime::from_timestamp_millis(123456789).unwrap(); assert_eq!(update.timestamp, expected_timestamp); assert_eq!( @@ -492,8 +491,7 @@ DeviceListRow { user_id: "".to_string(), device_ids: raw_list.devices, - timestamp: DateTime::::from_utc_timestamp_millis(raw_list.timestamp) - .unwrap(), + timestamp: DateTime::from_timestamp_millis(raw_list.timestamp).unwrap(), current_primary_signature: None, last_primary_signature: None, } diff --git a/services/identity/src/grpc_services/authenticated.rs b/services/identity/src/grpc_services/authenticated.rs --- a/services/identity/src/grpc_services/authenticated.rs +++ b/services/identity/src/grpc_services/authenticated.rs @@ -7,10 +7,9 @@ client_service::{handle_db_error, UpdateState, WorkflowInProgress}, constants::{error_types, request_metadata}, database::DatabaseClient, - ddb_utils::DateTimeExt, grpc_services::shared::get_value, }; -use chrono::{DateTime, Utc}; +use chrono::DateTime; use comm_opaque2::grpc::protocol_error_to_grpc_status; use tonic::{Request, Response, Status}; use tracing::{debug, error, trace, warn}; @@ -445,7 +444,7 @@ let since = since_timestamp .map(|timestamp| { - DateTime::::from_utc_timestamp_millis(timestamp) + DateTime::from_timestamp_millis(timestamp) .ok_or_else(|| tonic::Status::invalid_argument("Invalid timestamp")) }) .transpose()?; diff --git a/services/identity/src/grpc_services/shared.rs b/services/identity/src/grpc_services/shared.rs --- a/services/identity/src/grpc_services/shared.rs +++ b/services/identity/src/grpc_services/shared.rs @@ -1,6 +1,6 @@ use grpc_clients::error::unsupported_version; -use tonic::{IntoRequest, Request, Status}; -use tracing::{trace, Instrument}; +use tonic::{Request, Status}; +use tracing::trace; use crate::constants::{request_metadata, MIN_SUPPORTED_NATIVE_VERSION}; diff --git a/services/identity/src/regex.rs b/services/identity/src/regex.rs --- a/services/identity/src/regex.rs +++ b/services/identity/src/regex.rs @@ -29,11 +29,13 @@ )); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_username_too_short() { assert_eq!(is_valid_username(""), false); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_username_too_long() { assert_eq!( @@ -42,11 +44,13 @@ ); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_username_first_char_non_alphanumeric() { assert_eq!(is_valid_username("-asdf"), false); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_username_invalid_symbol() { assert_eq!(is_valid_username("asdf$"), false); diff --git a/services/identity/src/siwe.rs b/services/identity/src/siwe.rs --- a/services/identity/src/siwe.rs +++ b/services/identity/src/siwe.rs @@ -121,6 +121,7 @@ )); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_ethereum_address() { // Shorter than 42 characters diff --git a/services/reports/Cargo.toml b/services/reports/Cargo.toml --- a/services/reports/Cargo.toml +++ b/services/reports/Cargo.toml @@ -7,11 +7,12 @@ edition = "2021" [dependencies] +uuid = { version = "1.2", features = ["v4"] } actix-web = "4.3" anyhow = "1.0" aws-config = "0.55" aws-sdk-dynamodb = "0.27" -chrono = { version = "0.4.31", features = ["serde"] } +chrono = { workspace = true, features = ["serde"] } clap = { version = "4.0", features = ["derive", "env"] } comm-lib = { path = "../../shared/comm-lib", features = [ "blob-client", @@ -30,10 +31,9 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_repr = "0.1" -tokio = { version = "1.32", features = ["macros", "rt-multi-thread"] } +tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } tokio-stream = "0.1" tracing = "0.1" tracing-log = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-actix-web = "0.7.3" -uuid = { version = "1.2", features = ["v4"] } diff --git a/services/reports/Dockerfile b/services/reports/Dockerfile --- a/services/reports/Dockerfile +++ b/services/reports/Dockerfile @@ -12,11 +12,17 @@ ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse +# Copy and prepare cargo workspace +COPY Cargo.toml ../../Cargo.toml +COPY Cargo.lock ../../Cargo.lock +# Remove rust-node-addon and native_rust_library from cargo workspace +RUN sed -i -E '/rust-node-addon|native_rust_library/d' ../../Cargo.toml + # Copy actual application sources COPY shared ../../shared/ COPY services/reports ./ -RUN cargo install --locked --path . +RUN cargo build --release --target-dir /out # Runner stage FROM debian:bullseye-slim as runner @@ -27,7 +33,7 @@ && rm -rf /var/lib/apt/lists/* # Only copy built binary from builder stage -COPY --from=builder /usr/local/cargo/bin/reports /usr/local/bin/reports +COPY --from=builder /out/release/reports /usr/local/bin/reports WORKDIR /home/comm/app/reports # Create a new user comm and use it to run subsequent commands diff --git a/services/tunnelbroker/Cargo.toml b/services/tunnelbroker/Cargo.toml --- a/services/tunnelbroker/Cargo.toml +++ b/services/tunnelbroker/Cargo.toml @@ -21,14 +21,14 @@ once_cell = "1.17" prost = "0.11" serde_json = "1.0" -tokio = { version = "1.24", features = ["rt-multi-thread"] } +tokio = { workspace = true, features = ["rt-multi-thread"] } tonic = "0.8" tracing = "0.1" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } tunnelbroker_messages = { path = "../../shared/tunnelbroker_messages" } derive_more = "0.99.17" lapin = "2.2.1" -chrono = "0.4.31" +chrono.workspace = true uuid = { version = "1.2", features = ["v4"] } [build-dependencies] diff --git a/services/tunnelbroker/Dockerfile b/services/tunnelbroker/Dockerfile --- a/services/tunnelbroker/Dockerfile +++ b/services/tunnelbroker/Dockerfile @@ -11,11 +11,16 @@ COPY scripts/install_protobuf.sh ../../scripts/install_protobuf.sh RUN ../../scripts/install_protobuf.sh -COPY services/tunnelbroker . +# Copy and prepare cargo workspace +COPY Cargo.toml ../../Cargo.toml +COPY Cargo.lock ../../Cargo.lock +# Remove rust-node-addon and native_rust_library from cargo workspace +RUN sed -i -E '/rust-node-addon|native_rust_library/d' ../../Cargo.toml +COPY services/tunnelbroker . COPY shared ../../shared/ -RUN cargo install --locked --path . +RUN cargo build --release --target-dir /out FROM debian:bullseye-slim as runner @@ -27,7 +32,7 @@ WORKDIR /home/comm/app/tunnelbroker -COPY --from=builder /usr/local/cargo/bin/tunnelbroker \ +COPY --from=builder /out/release/tunnelbroker \ /usr/local/bin/tunnelbroker USER comm diff --git a/shared/backup_client/Cargo.toml b/shared/backup_client/Cargo.toml --- a/shared/backup_client/Cargo.toml +++ b/shared/backup_client/Cargo.toml @@ -21,7 +21,7 @@ bincode = "1.3.3" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -tokio = "1.24" +tokio.workspace = true tokio-tungstenite = "0.20.1" [target.'cfg(target_arch = "wasm32")'.dependencies] @@ -34,4 +34,7 @@ [features] default = ["native-tls"] native-tls = ["reqwest/native-tls", "tokio-tungstenite/native-tls"] -rustls-tls-webpki-roots = ["reqwest/rustls-tls-webpki-roots", "tokio-tungstenite/rustls-tls-webpki-roots"] +rustls-tls-webpki-roots = [ + "reqwest/rustls-tls-webpki-roots", + "tokio-tungstenite/rustls-tls-webpki-roots", +] diff --git a/shared/comm-lib/Cargo.toml b/shared/comm-lib/Cargo.toml --- a/shared/comm-lib/Cargo.toml +++ b/shared/comm-lib/Cargo.toml @@ -30,12 +30,12 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" base64 = "0.21" -chrono = "0.4.31" +chrono.workspace = true constant_time_eq = "0.3" derive_more = "0.99" grpc_clients = { path = "../grpc_clients", optional = true } rand = "0.8" -tokio = "1.32" +tokio.workspace = true tracing = "0.1" anyhow = "1.0.74" hex = "0.4" diff --git a/shared/comm-lib/src/auth/service.rs b/shared/comm-lib/src/auth/service.rs --- a/shared/comm-lib/src/auth/service.rs +++ b/shared/comm-lib/src/auth/service.rs @@ -131,8 +131,7 @@ let duration = result .last_rotated_date() .and_then(|date| date.to_millis().ok()) - .and_then(NaiveDateTime::from_timestamp_millis) - .map(|naive| DateTime::::from_naive_utc_and_offset(naive, Utc)) + .and_then(DateTime::from_timestamp_millis) .map(|last_rotated| Utc::now().signed_duration_since(last_rotated)); Ok(duration) } diff --git a/shared/comm-lib/src/database.rs b/shared/comm-lib/src/database.rs --- a/shared/comm-lib/src/database.rs +++ b/shared/comm-lib/src/database.rs @@ -408,15 +408,13 @@ attribute_name.clone(), attribute_value.clone(), )?; - let naive_datetime = chrono::NaiveDateTime::from_timestamp_millis(timestamp) - .ok_or_else(|| { - DBItemError::new( - attribute_name, - Value::AttributeValue(attribute_value), - DBItemAttributeError::TimestampOutOfRange, - ) - })?; - Ok(DateTime::from_naive_utc_and_offset(naive_datetime, Utc)) + chrono::DateTime::from_timestamp_millis(timestamp).ok_or_else(|| { + DBItemError::new( + attribute_name, + Value::AttributeValue(attribute_value), + DBItemAttributeError::TimestampOutOfRange, + ) + }) } pub fn parse_integer( diff --git a/shared/comm-lib/src/lib.rs b/shared/comm-lib/src/lib.rs --- a/shared/comm-lib/src/lib.rs +++ b/shared/comm-lib/src/lib.rs @@ -11,6 +11,7 @@ pub mod shared; pub mod tools; +#[allow(unused_imports)] mod reexports { #[cfg(feature = "blob-client")] pub use {bytes, reqwest};