Skip to content

Commit 75fb2ac

Browse files
committed
refactor: make writes more safe by hiding rendering function
The function `FileSystem::rendered` was public before, which could cause access to the internal `HashMap<PathBuf, String>`. If bound as mutable, it could be modified to write to unintended locations. Now the creation of `RenderedFileSystemEntries` is safer and doesn't provide visibility to the paths, only to write.
1 parent 8383858 commit 75fb2ac

File tree

6 files changed

+6
-5
lines changed

6 files changed

+6
-5
lines changed

agent-control/src/agent_type/runtime_config/on_host/filesystem.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use crate::agent_type::{
2424
};
2525
use serde::Deserialize;
2626

27+
pub mod rendered;
28+
2729
/// Represents the file system configuration for the deployment of a host agent. Consisting of
2830
/// a set of directories (map keys) which in turn contain a set of files (nested map keys) with
2931
/// their respective content (map values).
@@ -54,7 +56,7 @@ impl FileSystem {
5456
///
5557
/// **WARNING**: This must be called **after** the rendering process has finished
5658
/// or else AC might crash!
57-
pub fn rendered(self) -> HashMap<PathBuf, String> {
59+
fn rendered(self) -> HashMap<PathBuf, String> {
5860
self.0
5961
.into_iter()
6062
.flat_map(|(dir_path, dir_entries)| dir_entries.rendered_with(&dir_path))

agent-control/src/sub_agent/on_host/command/filesystem_entries.rs renamed to agent-control/src/agent_type/runtime_config/on_host/filesystem/rendered.rs

File renamed without changes.

agent-control/src/sub_agent/on_host/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::agent_control::defaults::{HOST_NAME_ATTRIBUTE_KEY, OPAMP_SERVICE_VERSION};
22
use crate::agent_control::run::Environment;
3+
use crate::agent_type::runtime_config::on_host::filesystem::rendered::RenderedFileSystemEntries;
34
use crate::context::Context;
45
use crate::event::SubAgentEvent;
56
use crate::event::broadcaster::unbounded::UnboundedBroadcast;
@@ -10,7 +11,6 @@ use crate::sub_agent::SubAgent;
1011
use crate::sub_agent::effective_agents_assembler::{EffectiveAgent, EffectiveAgentsAssembler};
1112
use crate::sub_agent::identity::AgentIdentity;
1213
use crate::sub_agent::on_host::command::executable_data::ExecutableData;
13-
use crate::sub_agent::on_host::command::filesystem_entries::RenderedFileSystemEntries;
1414
use crate::sub_agent::on_host::supervisor::NotStartedSupervisorOnHost;
1515
use crate::sub_agent::remote_config_parser::RemoteConfigParser;
1616
use crate::sub_agent::supervisor::builder::SupervisorBuilder;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub mod command_os;
22
pub mod error;
33
pub mod executable_data;
4-
pub mod filesystem_entries;
54
pub mod logging;
65
pub mod restart_policy;
76
pub mod shutdown;

agent-control/src/sub_agent/on_host/supervisor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::agent_control::agent_id::AgentID;
22
use crate::agent_type::runtime_config::health_config::OnHostHealthConfig;
3+
use crate::agent_type::runtime_config::on_host::filesystem::rendered::RenderedFileSystemEntries;
34
use crate::agent_type::runtime_config::version_config::OnHostVersionConfig;
45
use crate::context::Context;
56
use crate::event::SubAgentInternalEvent;
@@ -14,7 +15,6 @@ use crate::sub_agent::identity::{AgentIdentity, ID_ATTRIBUTE_NAME};
1415
use crate::sub_agent::on_host::command::command_os::CommandOSNotStarted;
1516
use crate::sub_agent::on_host::command::error::CommandError;
1617
use crate::sub_agent::on_host::command::executable_data::ExecutableData;
17-
use crate::sub_agent::on_host::command::filesystem_entries::RenderedFileSystemEntries;
1818
use crate::sub_agent::on_host::command::shutdown::{
1919
ProcessTerminator, wait_exit_timeout, wait_exit_timeout_default,
2020
};

agent-control/src/sub_agent/supervisor/starter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use crate::agent_type::runtime_config::on_host::filesystem::rendered::FileSystemEntriesError;
12
use crate::event::SubAgentInternalEvent;
23
use crate::event::channel::EventPublisher;
34
use crate::health::health_checker::HealthCheckerError;
45
use crate::sub_agent::error::SubAgentBuilderError;
5-
use crate::sub_agent::on_host::command::filesystem_entries::FileSystemEntriesError;
66
use crate::sub_agent::supervisor::stopper::SupervisorStopper;
77
use thiserror::Error;
88

0 commit comments

Comments
 (0)