[fix] Be able to call some repositories actions

This commit is contained in:
ljf 2019-08-16 19:44:19 +02:00
parent f46160da64
commit 3ec43be650
3 changed files with 49 additions and 13 deletions

View file

@ -1039,19 +1039,20 @@ backup:
add:
action_help: Add a backup repository
api: POST /backup/repository/<name>
configuration:
authenticate: all
authenticator: ldap-anonymous
arguments:
path:
help: Path eventually on another server
location:
help: Location on this server or on an other
extra:
pattern: *pattern_backup_repository_path
pattern: &pattern_backup_repository_location
- !!str ^((ssh://)?[a-z_]\w*@\[\w\-\.]+:)?(~?/)?[\w/]*$
- "pattern_backup_repository_location"
-n:
full: --name
help: Name of the repository
extra:
pattern: *pattern_backup_repository_name
pattern: &pattern_backup_repository_name
- !!str ^\w+$
- "pattern_backup_repository_name"
-d:
full: --description
help: Short description of the repository
@ -1061,7 +1062,7 @@ backup:
-q:
full: --quota
help: Quota to configure with this repository
--e:
-e:
full: --encryption
help: Type of encryption

View file

@ -2571,6 +2571,39 @@ def backup_delete(name):
logger.success(m18n.n('backup_deleted'))
#
# Repository subcategory
#
import yunohost.repository
def backup_repository_list(full):
return yunohost.repository.backup_repository_list(full)
def backup_repository_info(name, human_readable, space_used):
return yunohost.repository.backup_repository_info(name, human_readable, space_used)
def backup_repository_add(location, name, description, methods, quota, encryption):
return yunohost.repository.backup_repository_add(location, name, description, methods, quota, encryption)
def backup_repository_update(name, description, quota, password):
return yunohost.repository.backup_repository_update(name, description, quota, password)
def backup_repository_remove(name, purge):
return yunohost.repository.backup_repository_remove(name, purge)
#
# End Repository subcategory
#
#
# Misc helpers #
#

View file

@ -32,13 +32,12 @@ from moulinette import msignals, m18n
from moulinette.core import MoulinetteError
from moulinette.utils import filesystem
from moulinette.utils.log import getActionLogger
from moulinette.utils.filesystem import read_file, read_json, write_to_json
from moulinette.utils.filesystem import read_file, read_yaml, write_to_json
from yunohost.utils.error import YunohostError
from yunohost.monitor import binary_to_human
from yunohost.log import OperationLogger, is_unit_operation
from yunohost.backup import BackupMethod
logger = getActionLogger('yunohost.repository')
REPOSITORIES_PATH = '/etc/yunohost/repositories.yml'
@ -75,7 +74,7 @@ class BackupRepository(object):
if os.path.exists(REPOSITORIES_PATH):
try:
cls.repositories = read_json(REPOSITORIES_PATH)
cls.repositories = read_yaml(REPOSITORIES_PATH)['repositories']
except MoulinetteError as e:
raise YunohostError(
'backup_cant_open_repositories_file', reason=e)
@ -94,6 +93,7 @@ class BackupRepository(object):
def __init__(self, created, location, name=None, description=None, method=None,
encryption=None, quota=None):
from yunohost.backup import BackupMethod
self.location = location
self._split_location()
@ -154,7 +154,8 @@ class BackupRepository(object):
self.domain = location_match.group('domain')
self.path = location_match.group('path')
def backup_repository_list(name, full=False):
def backup_repository_list(full=False):
"""
List available repositories where put archives
"""
@ -165,6 +166,7 @@ def backup_repository_list(name, full=False):
else:
return repositories.keys()
def backup_repository_info(name, human_readable=True, space_used=False):
"""
Show info about a repository
@ -189,7 +191,7 @@ def backup_repository_info(name, human_readable=True, space_used=False):
@is_unit_operation()
def backup_repository_add(operation_logger, location, name, description=None,
methods=None, quota=None, encryption="passphrase"):
methods=None, quota=None, encryption="passphrase"):
"""
Add a backup repository