Commit c0cfc591 authored by James Valleroy's avatar James Valleroy

backups: Move manifest validation into backups app

Signed-off-by: James Valleroy's avatarJames Valleroy <jvalleroy@mailbox.org>
parent cedff074
#
# 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)
......@@ -30,6 +30,36 @@ import collections
from plinth import actions, action_utils, module_loader
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)
class Packet:
"""Information passed to a handlers for backup/restore operations."""
......
......@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from plinth.backup import validate as validate_backup
from plinth.modules.backups.backups import validate as validate_backup
backup = validate_backup({
'config': {
......
......@@ -17,7 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.modules.backups.backups import validate as validate_backup
from plinth.clients import store_url, validate
from plinth.modules.jsxc import manifest as jsxc_manifest
......
......@@ -17,7 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.modules.backups.backups import validate as validate_backup
from plinth.clients import validate
clients = validate([{
......
......@@ -18,7 +18,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth import cfg
from plinth.backup import validate as validate_backup
from plinth.modules.backups.backups import validate as validate_backup
from plinth.clients import validate
from plinth.utils import format_lazy
......
......@@ -17,7 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.modules.backups.backups import validate as validate_backup
from plinth.clients import store_url, validate
_android_package_id = 'im.vector.alpha'
......
......@@ -17,7 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.modules.backups.backups import validate as validate_backup
from plinth.clients import validate
clients = validate([{
......
......@@ -17,7 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.modules.backups.backups import validate as validate_backup
from plinth.clients import store_url, validate
clients = validate([{
......
......@@ -17,7 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.modules.backups.backups import validate as validate_backup
from plinth.clients import store_url, validate
clients = validate([{
......
......@@ -17,7 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from plinth.backup import validate as validate_backup
from plinth.modules.backups.backups import validate as validate_backup
from plinth.clients import store_url, validate
_jitsi_package_id = 'org.jitsi.meet'
......
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