From 90bf9b690258d496b03c4e86580afa1dd6ea7784 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Wed, 1 Dec 2021 10:15:29 -0800 Subject: [PATCH] Tighten privacy on read-only session fields --- lib/src/session.rs | 25 ++++++++++++++++++++----- lib/src/wiggle_abi.rs | 6 +++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/src/session.rs b/lib/src/session.rs index 397b6a9a..8a90b89a 100644 --- a/lib/src/session.rs +++ b/lib/src/session.rs @@ -64,15 +64,15 @@ pub struct Session { /// The backends configured for this execution. /// /// Populated prior to guest execution, and never modified. - pub(crate) backends: Arc, + backends: Arc, /// The TLS configuration for this execution. /// /// Populated prior to guest execution, and never modified. - pub(crate) tls_config: Arc, + tls_config: Arc, /// The dictionaries configured for this execution. /// /// Populated prior to guest execution, and never modified. - pub(crate) dictionaries: Arc, + dictionaries: Arc, /// The dictionaries configured for this execution. /// /// Populated prior to guest execution, and never modified. @@ -80,7 +80,7 @@ pub struct Session { /// The path to the configuration file used for this invocation of Viceroy. /// /// Created prior to guest execution, and never modified. - pub(crate) config_path: Arc>, + config_path: Arc>, /// The ID for the client request being processed. req_id: u64, } @@ -520,9 +520,14 @@ impl Session { self.backends.get(name).map(std::ops::Deref::deref) } + /// Access the backend map. + pub fn backends(&self) -> &Arc { + &self.backends + } + // ----- TLS config ----- - /// Reference the TLS configuration. + /// Access the TLS configuration. pub fn tls_config(&self) -> &Arc { &self.tls_config } @@ -543,6 +548,11 @@ impl Session { .ok_or(HandleError::InvalidDictionaryHandle(handle)) } + /// Access the dictionary map. + pub fn dictionaries(&self) -> &Arc { + &self.dictionaries + } + // ----- Pending Requests API ----- /// Insert a [`PendingRequest`] into the session. @@ -641,6 +651,11 @@ impl Session { pub fn req_id(&self) -> u64 { self.req_id } + + /// Access the path to the configuration file for this invocation. + pub fn config_path(&self) -> &Arc> { + &self.config_path + } } #[derive(Clone, Copy, Eq, Hash, PartialEq)] diff --git a/lib/src/wiggle_abi.rs b/lib/src/wiggle_abi.rs index 6d000460..4cda6cff 100644 --- a/lib/src/wiggle_abi.rs +++ b/lib/src/wiggle_abi.rs @@ -107,9 +107,9 @@ impl UserErrorConversion for Session { fn fastly_status_from_error(&mut self, e: Error) -> Result { match e { Error::UnknownBackend(ref backend) => { - let config_path = &self.config_path; - let backends_buffer = itertools::join(self.backends.keys(), ","); - let backends_len = self.backends.len(); + let config_path = &self.config_path(); + let backends_buffer = itertools::join(self.backends().keys(), ","); + let backends_len = self.backends().len(); match (backends_len, (**config_path).as_ref()) { (_, None) => event!(