summaryrefslogtreecommitdiffstats
path: root/src/commands/endpoint.rs
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-03-11 11:14:41 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-03-11 11:18:08 +0100
commit5c51a9bdafda4987ab7da52b816e01ea6b56502d (patch)
treea3df26957e60bd627961e59a18e27445cd9b303a /src/commands/endpoint.rs
parentd8cc10deecb954613c1a7a6465fd4de3efbbc9c4 (diff)
Endpoint configuration as Map
This patch rewrites the endpoint configuration format to be a map. The problem here is, that a list of endpoints cannot easily be used with layered configuration, where a part of the configuration lives in the XDG config home of the user and the rest lives in the repository. With this patch, the endpoints are configured with a map instead of an array, which makes it less complicated to overwrite. The name of an endpoint is now the key in the map. A type `EndpointName` was introduced to take advantage of strong typing. Thus, the patch touches a bit more code to adapt to the new type in use. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net> Tested-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/commands/endpoint.rs')
-rw-r--r--src/commands/endpoint.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/commands/endpoint.rs b/src/commands/endpoint.rs
index c1632e6..5338978 100644
--- a/src/commands/endpoint.rs
+++ b/src/commands/endpoint.rs
@@ -20,6 +20,7 @@ use itertools::Itertools;
use tokio_stream::StreamExt;
use crate::config::Configuration;
+use crate::config::EndpointName;
use crate::util::progress::ProgressBars;
use crate::endpoint::Endpoint;
@@ -27,12 +28,13 @@ pub async fn endpoint(matches: &ArgMatches, config: &Configuration, progress_gen
let endpoint_names = matches
.value_of("endpoint_name")
.map(String::from)
+ .map(EndpointName::from)
.map(|ep| vec![ep])
.unwrap_or_else(|| {
config.docker()
.endpoints()
.iter()
- .map(|ep| ep.name())
+ .map(|(ep_name, _)| ep_name)
.cloned()
.collect()
});
@@ -47,7 +49,7 @@ pub async fn endpoint(matches: &ArgMatches, config: &Configuration, progress_gen
}
}
-async fn ping(endpoint_names: Vec<String>,
+async fn ping(endpoint_names: Vec<EndpointName>,
matches: &ArgMatches,
config: &Configuration,
progress_generator: ProgressBars
@@ -94,7 +96,7 @@ async fn ping(endpoint_names: Vec<String>,
tokio::join!(ping_process, multibar_block).0
}
-async fn stats(endpoint_names: Vec<String>,
+async fn stats(endpoint_names: Vec<EndpointName>,
matches: &ArgMatches,
config: &Configuration,
progress_generator: ProgressBars
@@ -155,7 +157,7 @@ async fn stats(endpoint_names: Vec<String>,
}
-async fn containers(endpoint_names: Vec<String>,
+async fn containers(endpoint_names: Vec<EndpointName>,
matches: &ArgMatches,
config: &Configuration,
) -> Result<()> {
@@ -167,7 +169,7 @@ async fn containers(endpoint_names: Vec<String>,
}
}
-async fn containers_list(endpoint_names: Vec<String>,
+async fn containers_list(endpoint_names: Vec<EndpointName>,
matches: &ArgMatches,
config: &Configuration,
) -> Result<()> {
@@ -204,7 +206,7 @@ async fn containers_list(endpoint_names: Vec<String>,
.filter(|stat| newer_than_filter.as_ref().map(|time| time < &stat.created).unwrap_or(true))
.map(|stat| {
vec![
- endpoint_name.clone(),
+ endpoint_name.as_ref().to_owned(),
stat.id,
stat.image,
stat.created.to_string(),
@@ -219,7 +221,7 @@ async fn containers_list(endpoint_names: Vec<String>,
crate::commands::util::display_data(hdr, data, csv)
}
-async fn containers_prune(endpoint_names: Vec<String>,
+async fn containers_prune(endpoint_names: Vec<EndpointName>,
matches: &ArgMatches,
config: &Configuration,
) -> Result<()> {
@@ -274,16 +276,16 @@ fn get_date_filter(name: &str, matches: &ArgMatches) -> Result<Option<chrono::Da
/// Helper function to connect to all endpoints from the configuration, that appear (by name) in
/// the `endpoint_names` list
-pub(super) async fn connect_to_endpoints(config: &Configuration, endpoint_names: &[String]) -> Result<Vec<Arc<Endpoint>>> {
+pub(super) async fn connect_to_endpoints(config: &Configuration, endpoint_names: &[EndpointName]) -> Result<Vec<Arc<Endpoint>>> {
let endpoint_configurations = config
.docker()
.endpoints()
.iter()
- .filter(|ep| endpoint_names.contains(ep.name()))
- .cloned()
- .map(|ep_cfg| {
+ .filter(|(ep_name, _)| endpoint_names.contains(ep_name))
+ .map(|(ep_name, ep_cfg)| {
crate::endpoint::EndpointConfiguration::builder()
- .endpoint(ep_cfg)
+ .endpoint_name(ep_name.clone())
+ .endpoint(ep_cfg.clone())
.required_images(config.docker().images().clone())
.required_docker_versions(config.docker().docker_versions().clone())
.required_docker_api_versions(config.docker().docker_api_versions().clone())
@@ -294,7 +296,7 @@ pub(super) async fn connect_to_endpoints(config: &Configuration, endpoint_names:
info!("Endpoint config build");
info!("Connecting to {n} endpoints: {eps}",
n = endpoint_configurations.len(),
- eps = endpoint_configurations.iter().map(|epc| epc.endpoint().name()).join(", "));
+ eps = endpoint_configurations.iter().map(|epc| epc.endpoint_name()).join(", "));
crate::endpoint::util::setup_endpoints(endpoint_configurations).await
}