mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
backups: Move manifest validation into backups app
Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
623dbb4cbf
commit
539c6ca99e
@ -1,49 +0,0 @@
|
|||||||
#
|
|
||||||
# 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
|
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:
|
class Packet:
|
||||||
"""Information passed to a handlers for backup/restore operations."""
|
"""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/>.
|
# 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({
|
backup = validate_backup({
|
||||||
'config': {
|
'config': {
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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.clients import store_url, validate
|
||||||
from plinth.modules.jsxc import manifest as jsxc_manifest
|
from plinth.modules.jsxc import manifest as jsxc_manifest
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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
|
from plinth.clients import validate
|
||||||
|
|
||||||
clients = validate([{
|
clients = validate([{
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from plinth import cfg
|
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.clients import validate
|
||||||
from plinth.utils import format_lazy
|
from plinth.utils import format_lazy
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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.clients import store_url, validate
|
||||||
|
|
||||||
_android_package_id = 'im.vector.alpha'
|
_android_package_id = 'im.vector.alpha'
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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
|
from plinth.clients import validate
|
||||||
|
|
||||||
clients = validate([{
|
clients = validate([{
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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.clients import store_url, validate
|
||||||
|
|
||||||
clients = validate([{
|
clients = validate([{
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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.clients import store_url, validate
|
||||||
|
|
||||||
clients = validate([{
|
clients = validate([{
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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.clients import store_url, validate
|
||||||
|
|
||||||
_jitsi_package_id = 'org.jitsi.meet'
|
_jitsi_package_id = 'org.jitsi.meet'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user