Commit cedff074 authored by James Valleroy's avatar James Valleroy

backups: Validate backup manifests

Signed-off-by: James Valleroy's avatarJames Valleroy <jvalleroy@mailbox.org>
parent 496e4c86
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Utility methods for providing backup information.
"""
def validate(backup):
"""Validate the backup' information schema."""
assert isinstance(backup, dict)
assert 'config' in backup
assert isinstance(backup['config'], dict)
_validate_directories_and_files(backup['config'])
assert 'data' in backup
assert isinstance(backup['data'], dict)
_validate_directories_and_files(backup['data'])
assert 'secrets' in backup
assert isinstance(backup['secrets'], dict)
_validate_directories_and_files(backup['secrets'])
assert 'services' in backup
assert isinstance(backup['services'], list)
return backup
def _validate_directories_and_files(df):
"""Validate directories and files structure."""
assert 'directories' in df
assert isinstance(df['directories'], list)
assert 'files' in df
assert isinstance(df['files'], list)
......@@ -15,7 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
backup = {
from plinth.backup import validate as validate_backup
backup = validate_backup({
'config': {
'directories': ['/etc/ez-ipupdate/'],
'files': [],
......@@ -29,4 +31,4 @@ backup = {
'files': [],
},
'services': []
}
})
......@@ -17,6 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.clients import store_url, validate
from plinth.modules.jsxc import manifest as jsxc_manifest
......@@ -121,7 +122,7 @@ _clients.extend(jsxc_manifest.clients)
clients = _clients
backup = {
backup = validate_backup({
'config': {
'directories': [],
'files': ['/etc/ejabberd/ejabberd.yml'],
......@@ -135,4 +136,4 @@ backup = {
'files': ['/etc/ejabberd/ejabberd.pem'],
},
'services': ['ejabberd']
}
})
......@@ -17,6 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.clients import validate
clients = validate([{
......@@ -27,7 +28,7 @@ clients = validate([{
}]
}])
backup = {
backup = validate_backup({
'config': {
'directories': [],
'files': [],
......@@ -41,4 +42,4 @@ backup = {
'files': [],
},
'services': []
}
})
......@@ -18,6 +18,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth import cfg
from plinth.backup import validate as validate_backup
from plinth.clients import validate
from plinth.utils import format_lazy
......@@ -46,7 +47,7 @@ clients = validate([{
}]
}])
backup = {
backup = validate_backup({
'config': {
'directories': [],
'files': [],
......@@ -63,4 +64,4 @@ backup = {
],
},
'services': ['infinoted']
}
})
......@@ -17,6 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.clients import store_url, validate
_android_package_id = 'im.vector.alpha'
......@@ -53,7 +54,7 @@ clients = validate([{
}]
}])
backup = {
backup = validate_backup({
'config': {
'directories': ['/etc/matrix-synapse/conf.d/'],
'files': [
......@@ -78,4 +79,4 @@ backup = {
],
},
'services': ['matrix-synapse']
}
})
......@@ -17,6 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.clients import validate
clients = validate([{
......@@ -27,7 +28,7 @@ clients = validate([{
}]
}])
backup = {
backup = validate_backup({
'config': {
'directories': [],
'files': [],
......@@ -41,4 +42,4 @@ backup = {
'files': [],
},
'services': []
}
})
......@@ -17,6 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.clients import store_url, validate
clients = validate([{
......@@ -51,7 +52,7 @@ clients = validate([{
}]
}])
backup = {
backup = validate_backup({
'config': {
'directories': [],
'files': ['/etc/minetest/minetest.conf'],
......@@ -65,4 +66,4 @@ backup = {
'files': [],
},
'services': ['minetest-server']
}
})
......@@ -17,6 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.clients import store_url, validate
clients = validate([{
......@@ -86,7 +87,7 @@ clients = validate([{
}]
}])
backup = {
backup = validate_backup({
'config': {
'directories': [],
'files': [],
......@@ -100,4 +101,4 @@ backup = {
'files': [],
},
'services': ['radicale']
}
})
......@@ -17,6 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.clients import store_url, validate
_jitsi_package_id = 'org.jitsi.meet'
......@@ -74,7 +75,7 @@ clients = validate([{
}]
}])
backup = {
backup = validate_backup({
'config': {
'directories': [],
'files': ['/etc/repro/repro.config', '/etc/repro/users.txt'],
......@@ -88,4 +89,4 @@ backup = {
'files': ['/etc/repro/dh2048.pem'],
},
'services': ['repro']
}
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment