fix: disallow commands to be sent so an oxker container, closes #19
This commit is contained in:
@@ -370,17 +370,19 @@ pub struct ContainerItem {
|
|||||||
pub state: State,
|
pub state: State,
|
||||||
pub status: String,
|
pub status: String,
|
||||||
pub tx: ByteStats,
|
pub tx: ByteStats,
|
||||||
|
pub is_oxker: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContainerItem {
|
impl ContainerItem {
|
||||||
/// Create a new container item
|
/// Create a new container item
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
created: u64,
|
||||||
id: ContainerId,
|
id: ContainerId,
|
||||||
status: String,
|
|
||||||
image: String,
|
image: String,
|
||||||
state: State,
|
is_oxker: bool,
|
||||||
name: String,
|
name: String,
|
||||||
created: u64,
|
state: State,
|
||||||
|
status: String,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut docker_controls = StatefulList::new(DockerControls::gen_vec(state));
|
let mut docker_controls = StatefulList::new(DockerControls::gen_vec(state));
|
||||||
docker_controls.start();
|
docker_controls.start();
|
||||||
@@ -392,6 +394,7 @@ impl ContainerItem {
|
|||||||
docker_controls,
|
docker_controls,
|
||||||
id,
|
id,
|
||||||
image,
|
image,
|
||||||
|
is_oxker,
|
||||||
last_updated: 0,
|
last_updated: 0,
|
||||||
logs,
|
logs,
|
||||||
mem_limit: ByteStats::default(),
|
mem_limit: ByteStats::default(),
|
||||||
|
|||||||
+17
-3
@@ -5,7 +5,7 @@ use tui::widgets::ListItem;
|
|||||||
|
|
||||||
mod container_state;
|
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::*;
|
pub use container_state::*;
|
||||||
|
|
||||||
/// Global app_state, stored in an Arc<Mutex>
|
/// Global app_state, stored in an Arc<Mutex>
|
||||||
@@ -171,6 +171,18 @@ impl AppData {
|
|||||||
output
|
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,
|
/// Sort the containers vec, based on a heading, either ascending or descending,
|
||||||
/// If not sort set, then sort by created time
|
/// If not sort set, then sort by created time
|
||||||
fn sort_containers(&mut self) {
|
fn sort_containers(&mut self) {
|
||||||
@@ -242,7 +254,7 @@ impl AppData {
|
|||||||
} else {
|
} else {
|
||||||
self.containers
|
self.containers
|
||||||
.items
|
.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 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);
|
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 container not known, so make new ContainerItem and push into containers Vec
|
||||||
} else {
|
} 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);
|
self.containers.items.push(container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use crate::{
|
|||||||
app_data::{AppData, ContainerId, DockerControls},
|
app_data::{AppData, ContainerId, DockerControls},
|
||||||
app_error::AppError,
|
app_error::AppError,
|
||||||
parse_args::CliArgs,
|
parse_args::CliArgs,
|
||||||
ui::{GuiState, Status},
|
ui::{GuiState, Status}, ENTRY_POINT,
|
||||||
};
|
};
|
||||||
mod message;
|
mod message;
|
||||||
pub use message::DockerMessage;
|
pub use message::DockerMessage;
|
||||||
@@ -190,7 +190,7 @@ impl DockerData {
|
|||||||
Some(_) => {
|
Some(_) => {
|
||||||
if f.command
|
if f.command
|
||||||
.as_ref()
|
.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
|
&& self.args.show_self
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -250,6 +250,10 @@ impl InputHandler {
|
|||||||
|
|
||||||
if let Some(command) = option_command {
|
if let Some(command) = option_command {
|
||||||
let option_id = self.app_data.lock().get_selected_container_id();
|
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 {
|
if let Some(id) = option_id {
|
||||||
match command {
|
match command {
|
||||||
DockerControls::Pause => self
|
DockerControls::Pause => self
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ mod ui;
|
|||||||
|
|
||||||
use ui::{create_ui, GuiState, Status};
|
use ui::{create_ui, GuiState, Status};
|
||||||
|
|
||||||
|
const ENTRY_POINT: &str = "./start_oxker.sh";
|
||||||
|
|
||||||
fn setup_tracing() {
|
fn setup_tracing() {
|
||||||
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
|
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
|
||||||
// TODO write to file?
|
// TODO write to file?
|
||||||
|
|||||||
Reference in New Issue
Block a user