fix: disallow commands to be sent so an oxker container, closes #19

This commit is contained in:
Jack Wills
2022-12-05 03:52:41 +00:00
parent 43fe902bae
commit 160b8021b1
5 changed files with 31 additions and 8 deletions
+6 -3
View File
@@ -370,17 +370,19 @@ pub struct ContainerItem {
pub state: State,
pub status: String,
pub tx: ByteStats,
pub is_oxker: bool
}
impl ContainerItem {
/// Create a new container item
pub fn new(
created: u64,
id: ContainerId,
status: String,
image: String,
state: State,
is_oxker: bool,
name: String,
created: u64,
state: State,
status: String,
) -> Self {
let mut docker_controls = StatefulList::new(DockerControls::gen_vec(state));
docker_controls.start();
@@ -392,6 +394,7 @@ impl ContainerItem {
docker_controls,
id,
image,
is_oxker,
last_updated: 0,
logs,
mem_limit: ByteStats::default(),
+17 -3
View File
@@ -5,7 +5,7 @@ use tui::widgets::ListItem;
mod container_state;
use crate::{app_error::AppError, parse_args::CliArgs, ui::log_sanitizer};
use crate::{app_error::AppError, parse_args::CliArgs, ui::log_sanitizer, ENTRY_POINT};
pub use container_state::*;
/// Global app_state, stored in an Arc<Mutex>
@@ -171,6 +171,18 @@ impl AppData {
output
}
/// Check if the selected container is a dockerised version of oxker
/// So that can disallow commands to be send
/// Is a poor way of implementing this
pub fn selected_container_is_oxker(&self) -> bool {
if let Some(index) = self.containers.state.selected() {
if let Some(x) = self.containers.items.get(index) {
return x.is_oxker
}
}
false
}
/// Sort the containers vec, based on a heading, either ascending or descending,
/// If not sort set, then sort by created time
fn sort_containers(&mut self) {
@@ -242,7 +254,7 @@ impl AppData {
} else {
self.containers
.items
.sort_by(|a, b| a.created.cmp(&b.created))
.sort_by(|a, b| a.created.cmp(&b.created));
}
}
@@ -471,6 +483,8 @@ impl AppData {
})
});
let is_oxker = i.command.as_ref().map_or(false, |i|i.starts_with(ENTRY_POINT));
let state = State::from(i.state.as_ref().map_or("dead".to_owned(), trim_owned));
let status = i.status.as_ref().map_or(String::new(), trim_owned);
@@ -506,7 +520,7 @@ impl AppData {
};
// else container not known, so make new ContainerItem and push into containers Vec
} else {
let container = ContainerItem::new(id, status, image, state, name, created);
let container = ContainerItem::new(created, id, image, is_oxker, name, state, status);
self.containers.items.push(container);
}
}
+2 -2
View File
@@ -19,7 +19,7 @@ use crate::{
app_data::{AppData, ContainerId, DockerControls},
app_error::AppError,
parse_args::CliArgs,
ui::{GuiState, Status},
ui::{GuiState, Status}, ENTRY_POINT,
};
mod message;
pub use message::DockerMessage;
@@ -190,7 +190,7 @@ impl DockerData {
Some(_) => {
if f.command
.as_ref()
.map_or(false, |c| c.starts_with("./start_oxker.sh"))
.map_or(false, |c| c.starts_with(ENTRY_POINT))
&& self.args.show_self
{
None
+4
View File
@@ -250,6 +250,10 @@ impl InputHandler {
if let Some(command) = option_command {
let option_id = self.app_data.lock().get_selected_container_id();
// Poor way of disallowing commands to be sent to a containerised okxer
if self.app_data.lock().selected_container_is_oxker() {
return
};
if let Some(id) = option_id {
match command {
DockerControls::Pause => self
+2
View File
@@ -26,6 +26,8 @@ mod ui;
use ui::{create_ui, GuiState, Status};
const ENTRY_POINT: &str = "./start_oxker.sh";
fn setup_tracing() {
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
// TODO write to file?