From e09131771c6dbd535cd2f98a1830fb3d9a1bc427 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 5 Mar 2021 20:06:28 +0100 Subject: Add Endpoint::get_container_by_id() This function returns a shiplift::Container rather than an own type, which is more convenient at this point, but might be rewritten if we provide more endpoints (something else than docker). Signed-off-by: Matthias Beyer --- src/endpoint/configured.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/endpoint') diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index ae54dfb..b703a5f 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -283,6 +283,19 @@ impl Endpoint { .map(|o| o.is_some()) } + pub async fn get_container_by_id<'a>(&'a self, id: &str) -> Result>> { + self.container_stats() + .await? + .iter() + .find(|st| st.id == id) + .map(|_| { + self.docker + .containers() + .get(id) + }) + .map(Ok) + .transpose() + } } /// Helper type to store endpoint statistics -- cgit v1.2.3