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 <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2020-03-16 16:17:47 -07:00 committed by Veiko Aasa
parent 146db8344a
commit 167f2304e9
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -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)