From a5d3355ef835192be229745bbee32c527128f6ba Mon Sep 17 00:00:00 2001 From: Ravi Shankar Date: Tue, 2 Apr 2024 23:27:31 +0530 Subject: [PATCH] Remove twilio support --- server/Cargo.lock | 251 ++-------------------------------------------- server/Cargo.toml | 5 +- server/Dockerfile | 3 +- server/src/sms.rs | 64 ------------ 4 files changed, 11 insertions(+), 312 deletions(-) diff --git a/server/Cargo.lock b/server/Cargo.lock index ac2f4a2..3d66157 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -470,12 +470,6 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "bincode" version = "1.3.3" @@ -765,15 +759,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" -[[package]] -name = "encoding_rs" -version = "0.8.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "env_filter" version = "0.1.0" @@ -1185,25 +1170,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "h2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ee2dd2e4f378392eeff5d51618cd9a63166a2513846bbc55f21cfacd9199d4" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 1.1.0", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "hashbrown" version = "0.14.3" @@ -1295,29 +1261,6 @@ dependencies = [ "pin-project-lite 0.2.14", ] -[[package]] -name = "http-body" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" -dependencies = [ - "bytes", - "http 1.1.0", -] - -[[package]] -name = "http-body-util" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" -dependencies = [ - "bytes", - "futures-core", - "http 1.1.0", - "http-body 1.0.0", - "pin-project-lite 0.2.14", -] - [[package]] name = "http-client" version = "6.5.3" @@ -1380,9 +1323,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2 0.3.25", + "h2", "http 0.2.12", - "http-body 0.4.6", + "http-body", "httparse", "httpdate", "itoa", @@ -1394,26 +1337,6 @@ dependencies = [ "want", ] -[[package]] -name = "hyper" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "h2 0.4.3", - "http 1.1.0", - "http-body 1.0.0", - "httparse", - "itoa", - "pin-project-lite 0.2.14", - "smallvec", - "tokio", - "want", -] - [[package]] name = "hyper-tls" version = "0.5.0" @@ -1421,48 +1344,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper 0.14.28", + "hyper", "native-tls", "tokio", "tokio-native-tls", ] -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper 1.2.0", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - -[[package]] -name = "hyper-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http 1.1.0", - "http-body 1.0.0", - "hyper 1.2.0", - "pin-project-lite 0.2.14", - "socket2 0.5.6", - "tokio", - "tower", - "tower-service", - "tracing", -] - [[package]] name = "iana-time-zone" version = "0.1.60" @@ -1561,12 +1448,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ipnet" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" - [[package]] name = "itoa" version = "1.0.11" @@ -2137,48 +2018,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" -[[package]] -name = "reqwest" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d66674f2b6fb864665eea7a3c1ac4e3dfacd2fda83cf6f935a612e01b0e3338" -dependencies = [ - "base64 0.21.7", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2 0.4.3", - "http 1.1.0", - "http-body 1.0.0", - "http-body-util", - "hyper 1.2.0", - "hyper-tls 0.6.0", - "hyper-util", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite 0.2.14", - "rustls-pemfile", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "system-configuration", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "route-recognizer" version = "0.2.0" @@ -2197,8 +2036,8 @@ dependencies = [ "crc32fast", "futures", "http 0.2.12", - "hyper 0.14.28", - "hyper-tls 0.5.0", + "hyper", + "hyper-tls", "lazy_static", "log", "rusoto_credential", @@ -2220,7 +2059,7 @@ dependencies = [ "chrono", "dirs-next", "futures", - "hyper 0.14.28", + "hyper", "serde", "serde_json", "shlex", @@ -2242,7 +2081,7 @@ dependencies = [ "hex", "hmac 0.11.0", "http 0.2.12", - "hyper 0.14.28", + "hyper", "log", "md-5", "percent-encoding", @@ -2319,15 +2158,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rustls-pemfile" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" -dependencies = [ - "base64 0.21.7", -] - [[package]] name = "ryu" version = "1.0.17" @@ -2478,7 +2308,6 @@ dependencies = [ "mime_guess", "notify", "percent-encoding", - "reqwest", "rusoto_core", "rusoto_credential", "rusoto_sns", @@ -2541,12 +2370,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - [[package]] name = "socket2" version = "0.4.10" @@ -2731,33 +2554,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "tempfile" version = "3.10.1" @@ -2919,28 +2715,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite 0.2.14", - "tokio", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - [[package]] name = "tower-service" version = "0.3.2" @@ -2953,7 +2727,6 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "log", "pin-project-lite 0.2.14", "tracing-core", ] @@ -3394,16 +3167,6 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if 1.0.0", - "windows-sys 0.48.0", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/server/Cargo.toml b/server/Cargo.toml index e882f53..5f3c0ab 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -2,12 +2,12 @@ name = "server" version = "0.1.0" authors = ["Ravi Shankar "] -edition = "2018" +edition = "2021" [dependencies] async-std = { version = "1.6", features = ["attributes"] } async-trait = "0.1" -chrono = { version = "0.4.30", features = ["serde"] } +chrono = "0.4" crossbeam-channel = "0.5" env_logger = "0.11" futures = "0.3" @@ -20,7 +20,6 @@ mime = "0.3" mime_guess = "2.0" notify = "4" percent-encoding = "2.3" -reqwest = { version = "0.12", features = ["json"] } rusoto_core = "0.48" rusoto_credential = "0.48" rusoto_sns = "0.48" diff --git a/server/Dockerfile b/server/Dockerfile index 3f5d493..9e68fb6 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,4 +1,5 @@ -FROM ekidd/rust-musl-builder:stable +FROM rust:alpine +RUN apk add --update musl-dev openssl-dev COPY . /home/rust/src WORKDIR /home/rust/src RUN cargo build --release diff --git a/server/src/sms.rs b/server/src/sms.rs index 0b00d63..1b4f65d 100644 --- a/server/src/sms.rs +++ b/server/src/sms.rs @@ -1,5 +1,3 @@ -use http::header; -use reqwest::Client; use rusoto_core::{request::HttpClient, Region, RusotoError}; use rusoto_credential::EnvironmentProvider; use rusoto_sns::{MessageAttributeValue, PublishError, PublishInput, Sns, SnsClient}; @@ -12,19 +10,6 @@ lazy_static! { static ref SMS_RECEIVER: Option = env::var("SMS_RECEIVER").ok(); - /* Twilio */ - /// Twilio account ID set in environment. - static ref TWILIO_ACCOUNT: Option - = env::var("TWILIO_ACCOUNT").ok(); - /// Twilio access token set in environment. - static ref TWILIO_TOKEN: Option - = env::var("TWILIO_TOKEN").ok(); - /// Twilio sender number. - static ref TWILIO_SENDER: Option - = env::var("TWILIO_SENDER").ok(); - static ref TWILIO_API_ENDPOINT: Option - = TWILIO_ACCOUNT.as_ref().and_then(|a| Some(format!("https://api.twilio.com/2010-04-01/Accounts/{}/Messages.json", a))); - /* AWS */ // Uses `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` @@ -45,10 +30,6 @@ lazy_static! { }); Some(h) }; - - /* Other */ - - static ref HTTP_CLIENT: Client = Client::new(); } /// Sends the message to the given number. @@ -64,12 +45,6 @@ pub async fn send(message: &str) { Err(e) => error!("Error sending message using AWS: {:?}", e), } - match send_using_twilio(message).await { - Ok(true) => return, - Ok(false) => (), - Err(e) => error!("Error sending message using Twilio: {:?}", e), - } - error!("No supported SMS providers have been configured."); } @@ -94,42 +69,3 @@ async fn send_using_aws(message: &str) -> Result info!("AWS response: {:?}", resp); Ok(true) } - -/// Send a message using Twilio API. -async fn send_using_twilio(message: &str) -> Result { - info!("Sending message using Twilio."); - let (sender, receiver, endpoint, account, token) = match ( - TWILIO_SENDER.as_ref(), - SMS_RECEIVER.as_ref(), - TWILIO_API_ENDPOINT.as_ref(), - TWILIO_ACCOUNT.as_ref(), - TWILIO_TOKEN.as_ref(), - ) { - (Some(s), Some(r), Some(e), Some(a), Some(t)) => (s, r, e, a, t), - _ => { - info!("Missing environment variables for Twilio API."); - return Ok(false); - } - }; - - let mut params = HashMap::new(); - params.insert("From", sender.as_str()); - params.insert("To", receiver.as_str()); - params.insert("Body", message); - - let response = HTTP_CLIENT - .post(endpoint) - .header( - header::CONTENT_TYPE, - mime::APPLICATION_WWW_FORM_URLENCODED.as_ref(), - ) - .basic_auth(account, Some(token)) - .form(¶ms) - .send().await?; - - let status = response.status(); - let json: serde_json::Value = response.json().await?; - info!("{}: {}", status, json); - - Ok(true) -}