diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-03-11 11:14:41 +0100 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-03-11 11:18:08 +0100 |
commit | 5c51a9bdafda4987ab7da52b816e01ea6b56502d (patch) | |
tree | a3df26957e60bd627961e59a18e27445cd9b303a /src/endpoint | |
parent | d8cc10deecb954613c1a7a6465fd4de3efbbc9c4 (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/endpoint')
-rw-r--r-- | src/endpoint/configuration.rs | 3 | ||||
-rw-r--r-- | src/endpoint/configured.rs | 19 |
2 files changed, 13 insertions, 9 deletions
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 @@ -16,6 +16,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, #[getset(get = "pub")] 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<Self> { - 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<Endpoint> { + fn setup_endpoint(ep_name: &EndpointName, ep: &crate::config::Endpoint) -> Result<Endpoint> { 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()) |