From fc0486dd4a00ebc0c7d56fa552cf04adfea78c4e Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 11 Sep 2022 16:14:07 +0100 Subject: [PATCH] remove lazy_static --- Cargo.lock | 2 +- auth/simple-auth-server/Cargo.toml | 2 +- auth/simple-auth-server/src/email_service.rs | 6 +++--- auth/simple-auth-server/src/utils.rs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec12bb5..10709bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5779,7 +5779,7 @@ dependencies = [ "diesel", "dotenv", "env_logger 0.9.0", - "lazy_static", + "once_cell", "r2d2", "rust-argon2", "serde", diff --git a/auth/simple-auth-server/Cargo.toml b/auth/simple-auth-server/Cargo.toml index b795d31..1251a80 100644 --- a/auth/simple-auth-server/Cargo.toml +++ b/auth/simple-auth-server/Cargo.toml @@ -12,9 +12,9 @@ derive_more = "0.99.5" diesel = { version = "2", features = ["postgres", "r2d2", "uuid", "chrono"] } dotenv = "0.15" env_logger = "0.9" +once_cell = "1" r2d2 = "0.8" rust-argon2 = "1" -lazy_static = "1.4" serde = { version = "1", features = ["derive"] } serde_json = "1" sparkpost = "0.5" diff --git a/auth/simple-auth-server/src/email_service.rs b/auth/simple-auth-server/src/email_service.rs index ffaca52..9a0afa1 100644 --- a/auth/simple-auth-server/src/email_service.rs +++ b/auth/simple-auth-server/src/email_service.rs @@ -1,12 +1,12 @@ +use once_cell::sync::Lazy; use sparkpost::transmission::{ EmailAddress, Message, Options, Recipient, Transmission, TransmissionResponse, }; use crate::{errors::ServiceError, models::Invitation}; -lazy_static::lazy_static! { -static ref API_KEY: String = std::env::var("SPARKPOST_API_KEY").expect("SPARKPOST_API_KEY must be set"); -} +static API_KEY: Lazy = + Lazy::new(|| std::env::var("SPARKPOST_API_KEY").expect("SPARKPOST_API_KEY must be set")); pub fn send_invitation(invitation: &Invitation) -> Result<(), ServiceError> { let tm = Transmission::new_eu(API_KEY.as_str()); diff --git a/auth/simple-auth-server/src/utils.rs b/auth/simple-auth-server/src/utils.rs index f285681..07cc025 100644 --- a/auth/simple-auth-server/src/utils.rs +++ b/auth/simple-auth-server/src/utils.rs @@ -1,10 +1,10 @@ use argon2::{self, Config}; +use once_cell::sync::Lazy; use crate::errors::ServiceError; -lazy_static::lazy_static! { - pub static ref SECRET_KEY: String = std::env::var("SECRET_KEY").unwrap_or_else(|_| "0123".repeat(8)); -} +pub static SECRET_KEY: Lazy = + Lazy::new(|| std::env::var("SECRET_KEY").unwrap_or_else(|_| "0123".repeat(8))); const SALT: &[u8] = b"supersecuresalt";