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/config | |
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/config')
-rw-r--r-- | src/config/docker_config.rs | 5 | ||||
-rw-r--r-- | src/config/endpoint_config.rs | 27 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/config/docker_config.rs b/src/config/docker_config.rs index 1cef561..f7cd1db 100644 --- a/src/config/docker_config.rs +++ b/src/config/docker_config.rs @@ -8,10 +8,13 @@ // SPDX-License-Identifier: EPL-2.0 // +use std::collections::HashMap; + use getset::{CopyGetters, Getters}; use serde::Deserialize; use crate::config::Endpoint; +use crate::config::EndpointName; use crate::util::docker::ImageName; /// Configuration of the docker daemon interfacing functionality @@ -48,5 +51,5 @@ pub struct DockerConfig { images: Vec<ImageName>, #[getset(get = "pub")] - endpoints: Vec<Endpoint>, + endpoints: HashMap<EndpointName, Endpoint>, } diff --git a/src/config/endpoint_config.rs b/src/config/endpoint_config.rs index 13db137..69405dc 100644 --- a/src/config/endpoint_config.rs +++ b/src/config/endpoint_config.rs @@ -11,13 +11,31 @@ use getset::{CopyGetters, Getters}; use serde::Deserialize; +#[derive(Debug, Clone, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[serde(transparent)] +pub struct EndpointName(String); + +impl From<String> for EndpointName { + fn from(s: String) -> Self { + EndpointName(s) + } +} + +impl std::fmt::Display for EndpointName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { + self.0.fmt(f) + } +} + +impl AsRef<str> for EndpointName { + fn as_ref(&self) -> &str { + self.0.as_ref() + } +} + /// Configuration of a single endpoint #[derive(Clone, Debug, Getters, CopyGetters, Deserialize)] pub struct Endpoint { - /// A human-readable name of the endpoint - #[getset(get = "pub")] - name: String, - /// The URI where the endpoint is reachable #[getset(get = "pub")] uri: String, @@ -42,3 +60,4 @@ pub enum EndpointType { #[serde(rename = "http")] Http, } + |