From 5c51a9bdafda4987ab7da52b816e01ea6b56502d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 11 Mar 2021 11:14:41 +0100 Subject: 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 Tested-by: Matthias Beyer --- src/endpoint/configuration.rs | 3 +++ src/endpoint/configured.rs | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/endpoint') diff --git a/src/endpoint/configuration.rs b/src/endpoint/configuration.rs index a9b4688..bdabd08 100644 --- a/src/endpoint/configuration.rs +++ b/src/endpoint/configuration.rs @@ -15,6 +15,9 @@ use crate::util::docker::ImageName; #[derive(Getters, TypedBuilder)] pub struct EndpointConfiguration { + #[getset(get = "pub")] + endpoint_name: crate::config::EndpointName, + #[getset(get = "pub")] endpoint: crate::config::Endpoint, diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index 7265dd6..f850ff6 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -28,6 +28,7 @@ use tokio::sync::RwLock; use tokio_stream::StreamExt; use typed_builder::TypedBuilder; +use crate::config::EndpointName; use crate::endpoint::EndpointConfiguration; use crate::filestore::ReleaseStore; use crate::filestore::StagingStore; @@ -43,7 +44,7 @@ use crate::util::docker::ImageName; #[derive(Getters, CopyGetters, TypedBuilder)] pub struct Endpoint { #[getset(get = "pub")] - name: String, + name: EndpointName, #[getset(get = "pub")] docker: Docker, @@ -69,10 +70,10 @@ impl Debug for Endpoint { impl Endpoint { pub(super) async fn setup(epc: EndpointConfiguration) -> Result { - let ep = Endpoint::setup_endpoint(epc.endpoint()).with_context(|| { + let ep = Endpoint::setup_endpoint(epc.endpoint_name(), epc.endpoint()).with_context(|| { anyhow!( "Setting up endpoint: {} -> {}", - epc.endpoint().name(), + epc.endpoint_name(), epc.endpoint().uri() ) })?; @@ -89,21 +90,21 @@ impl Endpoint { let _ = versions_compat.with_context(|| { anyhow!( "Checking version compatibility for {} -> {}", - epc.endpoint().name(), + epc.endpoint_name(), epc.endpoint().uri() ) })?; let _ = api_versions_compat.with_context(|| { anyhow!( "Checking API version compatibility for {} -> {}", - epc.endpoint().name(), + epc.endpoint_name(), epc.endpoint().uri() ) })?; let _ = imgs_avail.with_context(|| { anyhow!( "Checking for available images on {} -> {}", - epc.endpoint().name(), + epc.endpoint_name(), epc.endpoint().uri() ) })?; @@ -111,7 +112,7 @@ impl Endpoint { Ok(ep) } - fn setup_endpoint(ep: &crate::config::Endpoint) -> Result { + fn setup_endpoint(ep_name: &EndpointName, ep: &crate::config::Endpoint) -> Result { match ep.endpoint_type() { crate::config::EndpointType::Http => shiplift::Uri::from_str(ep.uri()) .map(shiplift::Docker::host) @@ -119,7 +120,7 @@ impl Endpoint { .map_err(Error::from) .map(|docker| { Endpoint::builder() - .name(ep.name().clone()) + .name(ep_name.clone()) .uri(ep.uri().clone()) .docker(docker) .num_max_jobs(ep.maxjobs()) @@ -129,7 +130,7 @@ impl Endpoint { crate::config::EndpointType::Socket => Ok({ Endpoint::builder() - .name(ep.name().clone()) + .name(ep_name.clone()) .uri(ep.uri().clone()) .num_max_jobs(ep.maxjobs()) .network_mode(ep.network_mode().clone()) -- cgit v1.2.3