mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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:
parent
146db8344a
commit
167f2304e9
@ -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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user