Skip to content

Commit

Permalink
Tighten privacy on read-only session fields
Browse files Browse the repository at this point in the history
  • Loading branch information
aturon committed Dec 1, 2021
1 parent 2ce48c7 commit 90bf9b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
25 changes: 20 additions & 5 deletions lib/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ pub struct Session {
/// The backends configured for this execution.
///
/// Populated prior to guest execution, and never modified.
pub(crate) backends: Arc<Backends>,
backends: Arc<Backends>,
/// The TLS configuration for this execution.
///
/// Populated prior to guest execution, and never modified.
pub(crate) tls_config: Arc<rustls::ClientConfig>,
tls_config: Arc<rustls::ClientConfig>,
/// The dictionaries configured for this execution.
///
/// Populated prior to guest execution, and never modified.
pub(crate) dictionaries: Arc<Dictionaries>,
dictionaries: Arc<Dictionaries>,
/// The dictionaries configured for this execution.
///
/// Populated prior to guest execution, and never modified.
dictionaries_by_name: PrimaryMap<DictionaryHandle, DictionaryName>,
/// 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<Option<PathBuf>>,
config_path: Arc<Option<PathBuf>>,
/// The ID for the client request being processed.
req_id: u64,
}
Expand Down Expand Up @@ -520,9 +520,14 @@ impl Session {
self.backends.get(name).map(std::ops::Deref::deref)
}

/// Access the backend map.
pub fn backends(&self) -> &Arc<Backends> {
&self.backends
}

// ----- TLS config -----

/// Reference the TLS configuration.
/// Access the TLS configuration.
pub fn tls_config(&self) -> &Arc<rustls::ClientConfig> {
&self.tls_config
}
Expand All @@ -543,6 +548,11 @@ impl Session {
.ok_or(HandleError::InvalidDictionaryHandle(handle))
}

/// Access the dictionary map.
pub fn dictionaries(&self) -> &Arc<Dictionaries> {
&self.dictionaries
}

// ----- Pending Requests API -----

/// Insert a [`PendingRequest`] into the session.
Expand Down Expand Up @@ -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<Option<PathBuf>> {
&self.config_path
}
}

#[derive(Clone, Copy, Eq, Hash, PartialEq)]
Expand Down
6 changes: 3 additions & 3 deletions lib/src/wiggle_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ impl UserErrorConversion for Session {
fn fastly_status_from_error(&mut self, e: Error) -> Result<FastlyStatus, wiggle::Trap> {
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!(
Expand Down

0 comments on commit 90bf9b6

Please sign in to comment.