From 69ec45eac76c63ea973c68479ea4f0bbf58b29e9 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Tue, 17 Jan 2023 16:18:24 -0800 Subject: refactor(cli): Integrate standalone mode cert handling into `Flags` (#17419) The way the standalone mode handles the `--cert` flag is different to all other modes. This is because `--cert` takes a path to the certificate file, which is directly added to the root cert store; except for compile mode, where its byte contents are stored in the standalone metadata, and they are added to the root cert store after the `ProcState` is created. This change instead changes `Flags::ca_file` (an `Option`) into `Flags::ca_data`, which can represent a `String` file path or a `Vec` with the certificate contents. That way, standalone mode can create a `ProcState` whose root cert store alreay contains the certificate. This change also adds a tests for certificates in standalone mode, since there weren't any before. This refactor will help with implementing web workers in standalone mode in the future. --- cli/tools/installer.rs | 3 ++- cli/tools/standalone.rs | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'cli/tools') diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index 344758590..2d2584f54 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -1,6 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use crate::args::resolve_no_prompt; +use crate::args::CaData; use crate::args::ConfigFlag; use crate::args::Flags; use crate::args::InstallFlags; @@ -325,7 +326,7 @@ fn resolve_shim_data( executable_args.push("--location".to_string()); executable_args.push(url.to_string()); } - if let Some(ca_file) = &flags.ca_file { + if let Some(CaData::File(ca_file)) = &flags.ca_data { executable_args.push("--cert".to_string()); executable_args.push(ca_file.to_owned()) } diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs index b5738654a..8b99b8874 100644 --- a/cli/tools/standalone.rs +++ b/cli/tools/standalone.rs @@ -1,5 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use crate::args::CaData; use crate::args::CompileFlags; use crate::args::Flags; use crate::cache::DenoDir; @@ -158,10 +159,11 @@ async fn create_standalone_binary( ) -> Result, AnyError> { let mut eszip_archive = eszip.into_bytes(); - let ca_data = match ps.options.ca_file() { - Some(ca_file) => { + let ca_data = match ps.options.ca_data() { + Some(CaData::File(ca_file)) => { Some(fs::read(ca_file).with_context(|| format!("Reading: {}", ca_file))?) } + Some(CaData::Bytes(bytes)) => Some(bytes.clone()), None => None, }; let maybe_import_map: Option<(Url, String)> = -- cgit v1.2.3