From 167f2304e9ab82b34aeeca773ffe2caeb6aac389 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 16 Mar 2020 16:17:47 -0700 Subject: [PATCH] pagekite: Don't allow non-unique custom services - Change in any of the following is treated as unique: protocol, frontend port, subdomains. - Change in any of the following is not treated as unique: backend port. Issue reported in https://salsa.debian.org/freedombox-team/plinth/-/merge_requests/1742#note_147960 Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- actions/pagekite | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/actions/pagekite b/actions/pagekite index ae170d2e4..fc3987514 100755 --- a/actions/pagekite +++ b/actions/pagekite @@ -172,19 +172,19 @@ def subcommand_remove_service(arguments): action_utils.service_restart('pagekite') -def _get_existing_service_paths(service): +def _get_existing_service_paths(service, keys=None): """Return paths of existing services that match the given service params""" # construct an augeas query path with patterns like: # */service_on/*[protocol='http'] path = PATHS['service_on'] - for param, value in service.items(): - path += "[%s='%s']" % (param, value) + for param in (keys or service.keys()): + path += "[%s='%s']" % (param, service[param]) return aug.match(path) def _add_service(service): """Add a new service into configuration.""" - if _get_existing_service_paths(service): + if _get_existing_service_paths(service, ['protocol', 'kitename']): msg = "Service with the parameters %s already exists" raise RuntimeError(msg % service)