Skip to content

Commit

Permalink
feat(serverless,runtime,cli,wpt-runner): upgrade to Rust 1.70 (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz authored Jun 7, 2023
1 parent 0a64b68 commit a8a02dd
Show file tree
Hide file tree
Showing 27 changed files with 135 additions and 164 deletions.
8 changes: 8 additions & 0 deletions .changeset/early-points-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@lagon/cli': patch
'@lagon/runtime': patch
'@lagon/serverless': patch
'@lagon/wpt-runner': patch
---

Replace once_cell with std's OnceLock
5 changes: 5 additions & 0 deletions .changeset/neat-taxis-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/serverless': patch
---

Set region label for prometheus exporter globally
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ notify = "6.0.0"
envfile = "0.2.1"
anyhow = "1.0.71"
urlencoding = "2.1.2"
once_cell = "1.17.1"
12 changes: 7 additions & 5 deletions crates/cli/src/commands/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::utils::{create_deployment, print_progress, resolve_path, Config, TrpcClient, THEME};
use crate::utils::{
create_deployment, get_theme, print_progress, resolve_path, Config, TrpcClient,
};
use anyhow::{anyhow, Result};
use dialoguer::{console::style, Confirm, Input, Select};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -77,14 +79,14 @@ pub async fn deploy(
.await?;
let organizations = response.result.data;

let index = Select::with_theme(&*THEME)
let index = Select::with_theme(get_theme())
.items(&organizations)
.default(0)
.with_prompt("Which Organization would you like to deploy to?")
.interact()?;
let organization = &organizations[index];

match Confirm::with_theme(&*THEME)
match Confirm::with_theme(get_theme())
.with_prompt("Link to an existing Function?")
.default(false)
.interact()?
Expand All @@ -95,7 +97,7 @@ pub async fn deploy(
.await?;
let functions = response.result.data;

let index = Select::with_theme(&*THEME)
let index = Select::with_theme(get_theme())
.items(&functions)
.default(0)
.with_prompt("Which Function would you like to link?")
Expand All @@ -110,7 +112,7 @@ pub async fn deploy(
create_deployment(config, &function_config, is_production, &root, true).await?;
}
false => {
let name = Input::<String>::with_theme(&*THEME)
let name = Input::<String>::with_theme(get_theme())
.with_prompt("What's the name of this new Function?")
.interact_text()?;

Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/commands/link.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
commands::deploy::{FunctionsResponse, OrganizationsResponse},
utils::{get_root, Config, FunctionConfig, TrpcClient, THEME},
utils::{get_root, get_theme, Config, FunctionConfig, TrpcClient},
};
use anyhow::{anyhow, Result};
use dialoguer::{console::style, Select};
Expand All @@ -27,7 +27,7 @@ pub async fn link(directory: Option<PathBuf>) -> Result<()> {
.await?;
let organizations = response.result.data;

let index = Select::with_theme(&*THEME)
let index = Select::with_theme(get_theme())
.items(&organizations)
.default(0)
.with_prompt("Which Organization would you like to link from?")
Expand All @@ -39,7 +39,7 @@ pub async fn link(directory: Option<PathBuf>) -> Result<()> {
.await?;
let functions = response.result.data;

let index = Select::with_theme(&*THEME)
let index = Select::with_theme(get_theme())
.items(&functions)
.default(0)
.with_prompt("Which Function would you like to link?")
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/commands/login.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{print_progress, Config, TrpcClient, THEME};
use crate::utils::{get_theme, print_progress, Config, TrpcClient};
use anyhow::{anyhow, Result};
use dialoguer::{console::style, Confirm, Password};
use serde::{Deserialize, Serialize};
Expand All @@ -17,7 +17,7 @@ pub async fn login() -> Result<()> {
let mut config = Config::new()?;

if config.token.is_some()
&& !Confirm::with_theme(&*THEME)
&& !Confirm::with_theme(get_theme())
.with_prompt("You are already logged in. Do you want to log out and log in again?")
.default(true)
.interact()?
Expand Down Expand Up @@ -45,7 +45,7 @@ pub async fn login() -> Result<()> {
);
println!();

let code = Password::with_theme(&*THEME)
let code = Password::with_theme(get_theme())
.with_prompt("Paste the verification code from your browser here")
.interact()?;

Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/commands/logout.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{Config, THEME};
use crate::utils::{get_theme, Config};
use anyhow::{anyhow, Result};
use dialoguer::{console::style, Confirm};

Expand All @@ -9,7 +9,7 @@ pub fn logout() -> Result<()> {
return Err(anyhow!("You are not logged in."));
}

match Confirm::with_theme(&*THEME)
match Confirm::with_theme(get_theme())
.with_prompt("Do you really want to log out?")
.default(true)
.interact()?
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/commands/promote.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{get_root, print_progress, Config, FunctionConfig, TrpcClient, THEME};
use crate::utils::{get_root, get_theme, print_progress, Config, FunctionConfig, TrpcClient};
use anyhow::{anyhow, Result};
use dialoguer::{console::style, Confirm};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -29,7 +29,7 @@ pub async fn promote(deployment_id: String, directory: Option<PathBuf>) -> Resul
let root = get_root(directory);
let function_config = FunctionConfig::load(&root, None, None)?;

match Confirm::with_theme(&*THEME)
match Confirm::with_theme(get_theme())
.with_prompt("Do you really want to promote this Deployment to production?")
.default(true)
.interact()?
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/commands/rm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{get_root, print_progress, Config, FunctionConfig, TrpcClient, THEME};
use crate::utils::{get_root, get_theme, print_progress, Config, FunctionConfig, TrpcClient};
use anyhow::{anyhow, Result};
use dialoguer::{console::style, Confirm};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -28,7 +28,7 @@ pub async fn rm(directory: Option<PathBuf>) -> Result<()> {
let root = get_root(directory);
let function_config = FunctionConfig::load(&root, None, None)?;

match Confirm::with_theme(&*THEME)
match Confirm::with_theme(get_theme())
.with_prompt(
"Do you really want to completely delete this Function, its Deployments, statistics and logs?",
)
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/commands/undeploy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{get_root, print_progress, Config, FunctionConfig, TrpcClient, THEME};
use crate::utils::{get_root, get_theme, print_progress, Config, FunctionConfig, TrpcClient};
use anyhow::{anyhow, Result};
use dialoguer::{console::style, Confirm};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -29,7 +29,7 @@ pub async fn undeploy(deployment_id: String, directory: Option<PathBuf>) -> Resu
let root = get_root(directory);
let function_config = FunctionConfig::load(&root, None, None)?;

match Confirm::with_theme(&*THEME)
match Confirm::with_theme(get_theme())
.with_prompt("Do you really want to delete this Deployment?")
.default(false)
.interact()?
Expand Down
51 changes: 27 additions & 24 deletions crates/cli/src/utils/console.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use dialoguer::{
console::{style, Style},
theme::ColorfulTheme,
theme::{ColorfulTheme, Theme},
};
use indicatif::{ProgressBar, ProgressStyle};
use once_cell::sync::Lazy;
use std::time::Duration;
use std::{sync::OnceLock, time::Duration};

pub fn print_progress(message: &str) -> impl Fn() + '_ {
let index_progress = ProgressBar::new_spinner();
Expand Down Expand Up @@ -36,24 +35,28 @@ pub fn print_progress(message: &str) -> impl Fn() + '_ {
}
}

pub static THEME: Lazy<ColorfulTheme> = Lazy::new(|| ColorfulTheme {
defaults_style: Style::new().for_stderr().blue(),
prompt_style: Style::new().for_stderr().bold(),
prompt_prefix: style(" ○".to_string()).for_stderr().magenta(),
prompt_suffix: style("›".to_string()).for_stderr().black().bright(),
success_prefix: style(" ●".to_string()).for_stderr().magenta(),
success_suffix: style("›".to_string()).for_stderr().black().bright(),
error_prefix: style("✕".to_string()).for_stderr().red(),
error_style: Style::new().for_stderr(),
hint_style: Style::new().for_stderr().black().bright(),
values_style: Style::new().for_stderr().blue(),
active_item_style: Style::new().for_stderr().blue(),
inactive_item_style: Style::new().for_stderr(),
active_item_prefix: style("›".to_string()).for_stderr().blue(),
inactive_item_prefix: style(" ".to_string()).for_stderr(),
checked_item_prefix: style("✔".to_string()).for_stderr().green(),
unchecked_item_prefix: style("✔".to_string()).for_stderr().black(),
picked_item_prefix: style("❯".to_string()).for_stderr().green(),
unpicked_item_prefix: style(" ".to_string()).for_stderr(),
inline_selections: true,
});
static THEME: OnceLock<ColorfulTheme> = OnceLock::new();

pub fn get_theme() -> &'static dyn Theme {
THEME.get_or_init(|| ColorfulTheme {
defaults_style: Style::new().for_stderr().blue(),
prompt_style: Style::new().for_stderr().bold(),
prompt_prefix: style(" ○".to_string()).for_stderr().magenta(),
prompt_suffix: style("›".to_string()).for_stderr().black().bright(),
success_prefix: style(" ●".to_string()).for_stderr().magenta(),
success_suffix: style("›".to_string()).for_stderr().black().bright(),
error_prefix: style("✕".to_string()).for_stderr().red(),
error_style: Style::new().for_stderr(),
hint_style: Style::new().for_stderr().black().bright(),
values_style: Style::new().for_stderr().blue(),
active_item_style: Style::new().for_stderr().blue(),
inactive_item_style: Style::new().for_stderr(),
active_item_prefix: style("›".to_string()).for_stderr().blue(),
inactive_item_prefix: style(" ".to_string()).for_stderr(),
checked_item_prefix: style("✔".to_string()).for_stderr().green(),
unchecked_item_prefix: style("✔".to_string()).for_stderr().black(),
picked_item_prefix: style("❯".to_string()).for_stderr().green(),
unpicked_item_prefix: style(" ".to_string()).for_stderr(),
inline_selections: true,
})
}
8 changes: 4 additions & 4 deletions crates/cli/src/utils/deployments.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
validate_assets_dir, validate_code_file, Config, MAX_ASSET_SIZE_MB, MAX_FUNCTION_SIZE_MB,
};
use crate::utils::{print_progress, TrpcClient, THEME};
use crate::utils::{get_theme, print_progress, TrpcClient};
use anyhow::{anyhow, Result};
use dialoguer::console::style;
use dialoguer::{Confirm, Input};
Expand Down Expand Up @@ -58,7 +58,7 @@ impl FunctionConfig {
index
}
None => {
let index = Input::<String>::with_theme(&*THEME)
let index = Input::<String>::with_theme(get_theme())
.with_prompt(format!(
"Path to your Function's entrypoint? {}",
style(format!("(relative to {:?})", root.canonicalize()?))
Expand All @@ -83,13 +83,13 @@ impl FunctionConfig {
);
Some(assets)
}
None => match Confirm::with_theme(&*THEME)
None => match Confirm::with_theme(get_theme())
.with_prompt("Do you have a public directory to serve assets from?")
.default(false)
.interact()?
{
true => {
let assets = Input::<String>::with_theme(&*THEME)
let assets = Input::<String>::with_theme(get_theme())
.with_prompt(format!(
"Path to your Function's public directory? {}",
style(format!("(relative to {:?})", root.canonicalize()?))
Expand Down
1 change: 0 additions & 1 deletion crates/runtime_crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ aes = "0.8.2"
aes-gcm = "0.10.2"
cbc = { version = "0.1.2", features = ["std"] }
ring = { version = "0.16.20", features = ["std"] }
once_cell = "1.17.1"
num-traits = "0.2.15"
rsa = { version = "=0.9.2", default-features = false, features = ["std", "sha2"] }
p256 = { version = "0.13.2", features = ["ecdh"] }
Expand Down
10 changes: 6 additions & 4 deletions crates/runtime_crypto/src/methods/generate_key.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use anyhow::{anyhow, Ok, Result};
use num_traits::FromPrimitive;
use once_cell::sync::Lazy;
use ring::rand::{SecureRandom, SystemRandom};
use ring::signature::EcdsaKeyPair;
use rsa::pkcs1::EncodeRsaPrivateKey;
use rsa::rand_core::OsRng;
use rsa::{BigUint, RsaPrivateKey};
use std::sync::OnceLock;

use crate::{CryptoNamedCurve, KeyGenAlgorithm, Sha};

static PUB_EXPONENT_1: Lazy<BigUint> = Lazy::new(|| BigUint::from_u64(3).unwrap());
static PUB_EXPONENT_2: Lazy<BigUint> = Lazy::new(|| BigUint::from_u64(65537).unwrap());
static PUB_EXPONENT_1: OnceLock<BigUint> = OnceLock::new();
static PUB_EXPONENT_2: OnceLock<BigUint> = OnceLock::new();

pub fn generate_key(algorithm: KeyGenAlgorithm) -> Result<Vec<u8>> {
match algorithm {
Expand All @@ -20,7 +20,9 @@ pub fn generate_key(algorithm: KeyGenAlgorithm) -> Result<Vec<u8>> {
} => {
let exponent = BigUint::from_bytes_be(public_exponent);

if exponent != *PUB_EXPONENT_1 && exponent != *PUB_EXPONENT_2 {
if exponent != *PUB_EXPONENT_1.get_or_init(|| BigUint::from_u64(3).unwrap())
&& exponent != *PUB_EXPONENT_2.get_or_init(|| BigUint::from_u64(65537).unwrap())
{
return Err(anyhow!("Bad public exponent"));
}

Expand Down
1 change: 0 additions & 1 deletion crates/runtime_isolate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ hyper-tls = { version = "0.5.0", features = ["vendored"] }
flume = "0.10.14"
anyhow = "1.0.71"
log = { version = "0.4.18", features = ["std", "kv_unstable"] }
once_cell = "1.17.1"
async-recursion = "1.0.4"
linked-hash-map = "0.5.6"
lagon-runtime-v8-utils = { path = "../runtime_v8_utils" }
Expand Down
8 changes: 4 additions & 4 deletions crates/runtime_isolate/src/bindings/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use async_recursion::async_recursion;
use hyper::{client::HttpConnector, header::LOCATION, http::Uri, Body, Client, Request, Response};
use hyper_tls::HttpsConnector;
use lagon_runtime_http::request_from_v8;
use once_cell::sync::Lazy;
use std::sync::OnceLock;

use crate::{bindings::PromiseResult, Isolate};

use super::BindingResult;

static CLIENT: Lazy<Client<HttpsConnector<HttpConnector>>> =
Lazy::new(|| Client::builder().build::<_, Body>(HttpsConnector::new()));
static CLIENT: OnceLock<Client<HttpsConnector<HttpConnector>>> = OnceLock::new();

type Arg = Request<Body>;

Expand Down Expand Up @@ -84,7 +83,8 @@ async fn make_request(
let uri = request.uri().clone();

let (request_a, request_b) = clone_response(request).await?;
let response = CLIENT.request(request_a).await?;
let client = CLIENT.get_or_init(|| Client::builder().build::<_, Body>(HttpsConnector::new()));
let response = client.request(request_a).await?;

if response.status().is_redirection() {
let mut redirect_url = match response.headers().get(LOCATION) {
Expand Down
1 change: 0 additions & 1 deletion crates/serverless/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ serde_json = "1.0"
metrics = "0.21.0"
metrics-exporter-prometheus = { version = "0.12.1", default-features = false, features = ["http-listener"] }
log = { version = "0.4.18", features = ["std", "kv_unstable", "kv_unstable_serde"] }
once_cell = "1.17.1"
anyhow = "1.0.71"
tokio-cron-scheduler = "0.9.4"
dashmap = "5.4.0"
Expand Down
Loading

0 comments on commit a8a02dd

Please sign in to comment.