mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-23 09:16:51 +00:00
BREAKING CHANGE(backups): support only individual service backup requests(combinable)
This commit is contained in:
parent
0b8f77e6f7
commit
44e45a5124
|
@ -12,6 +12,10 @@ def backup_job_type(service: Service) -> str:
|
||||||
return f"{job_type_prefix(service)}.backup"
|
return f"{job_type_prefix(service)}.backup"
|
||||||
|
|
||||||
|
|
||||||
|
def restore_job_type(service: Service) -> str:
|
||||||
|
return f"{job_type_prefix(service)}.restore"
|
||||||
|
|
||||||
|
|
||||||
def get_jobs_by_service(service: Service) -> List[Job]:
|
def get_jobs_by_service(service: Service) -> List[Job]:
|
||||||
result = []
|
result = []
|
||||||
for job in Jobs.get_jobs():
|
for job in Jobs.get_jobs():
|
||||||
|
@ -54,3 +58,7 @@ def get_job_by_type(type_id: str) -> Optional[Job]:
|
||||||
|
|
||||||
def get_backup_job(service: Service) -> Optional[Job]:
|
def get_backup_job(service: Service) -> Optional[Job]:
|
||||||
return get_job_by_type(backup_job_type(service))
|
return get_job_by_type(backup_job_type(service))
|
||||||
|
|
||||||
|
|
||||||
|
def get_restore_job(service: Service) -> Optional[Job]:
|
||||||
|
return get_job_by_type(restore_job_type(service))
|
||||||
|
|
|
@ -6,15 +6,18 @@ from strawberry.types import Info
|
||||||
from selfprivacy_api.graphql import IsAuthenticated
|
from selfprivacy_api.graphql import IsAuthenticated
|
||||||
from selfprivacy_api.graphql.mutations.mutation_interface import (
|
from selfprivacy_api.graphql.mutations.mutation_interface import (
|
||||||
GenericMutationReturn,
|
GenericMutationReturn,
|
||||||
|
GenericJobButationReturn,
|
||||||
MutationReturnInterface,
|
MutationReturnInterface,
|
||||||
)
|
)
|
||||||
from selfprivacy_api.graphql.queries.backup import BackupConfiguration
|
from selfprivacy_api.graphql.queries.backup import BackupConfiguration
|
||||||
from selfprivacy_api.graphql.queries.backup import Backup
|
from selfprivacy_api.graphql.queries.backup import Backup
|
||||||
from selfprivacy_api.graphql.queries.providers import BackupProvider
|
from selfprivacy_api.graphql.queries.providers import BackupProvider
|
||||||
|
from selfprivacy_api.graphql.common_types.jobs import job_to_api_job
|
||||||
|
|
||||||
from selfprivacy_api.backup import Backups
|
from selfprivacy_api.backup import Backups
|
||||||
from selfprivacy_api.services import get_all_services, get_service_by_id
|
from selfprivacy_api.services import get_all_services, get_service_by_id
|
||||||
from selfprivacy_api.backup.tasks import start_backup, restore_snapshot
|
from selfprivacy_api.backup.tasks import start_backup, restore_snapshot
|
||||||
|
from selfprivacy_api.backup.jobs import get_backup_job, get_restore_job
|
||||||
|
|
||||||
|
|
||||||
@strawberry.input
|
@strawberry.input
|
||||||
|
@ -38,10 +41,6 @@ class GenericBackupConfigReturn(MutationReturnInterface):
|
||||||
configuration: typing.Optional[BackupConfiguration]
|
configuration: typing.Optional[BackupConfiguration]
|
||||||
|
|
||||||
|
|
||||||
class GenericJobMutationReturn:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class BackupMutations:
|
class BackupMutations:
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
|
@ -76,28 +75,45 @@ class BackupMutations:
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def start_backup(
|
def start_backup(
|
||||||
self, service_id: typing.Optional[str] = None
|
self, service_id: typing.Optional[str] = None
|
||||||
) -> GenericJobMutationReturn:
|
) -> GenericJobButationReturn:
|
||||||
"""Start backup. If service not provided, backup all services"""
|
"""Start backup"""
|
||||||
if service_id is None:
|
|
||||||
for service in get_all_services():
|
|
||||||
start_backup(service)
|
|
||||||
else:
|
|
||||||
service = get_service_by_id(service_id)
|
service = get_service_by_id(service_id)
|
||||||
if service is None:
|
if service is None:
|
||||||
raise ValueError(f"nonexistent service: {service_id}")
|
return GenericJobButationReturn(
|
||||||
|
success=False,
|
||||||
|
code=300,
|
||||||
|
message=f"nonexistent service: {service_id}",
|
||||||
|
job=None,
|
||||||
|
)
|
||||||
start_backup(service)
|
start_backup(service)
|
||||||
|
job = get_backup_job(service)
|
||||||
|
|
||||||
return GenericJobMutationReturn()
|
return GenericJobButationReturn(
|
||||||
|
success=True, code=200, message="Backup job queued", job=job_to_api_job(job)
|
||||||
|
)
|
||||||
|
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def restore_backup(self, snapshot_id: str) -> GenericJobMutationReturn:
|
def restore_backup(self, snapshot_id: str) -> GenericJobButationReturn:
|
||||||
"""Restore backup"""
|
"""Restore backup"""
|
||||||
snap = Backups.get_snapshot_by_id(snapshot_id)
|
snap = Backups.get_snapshot_by_id(snapshot_id)
|
||||||
if snap in None:
|
service = get_service_by_id(snap.service_name)
|
||||||
raise ValueError(f"No such snapshot: {snapshot_id}")
|
if snap is None:
|
||||||
|
return GenericJobButationReturn(
|
||||||
|
success=False,
|
||||||
|
code=300,
|
||||||
|
message=f"No such snapshot: {snapshot_id}",
|
||||||
|
job=None,
|
||||||
|
)
|
||||||
|
|
||||||
restore_snapshot(snap)
|
restore_snapshot(snap)
|
||||||
|
|
||||||
return GenericJobMutationReturn()
|
return GenericJobButationReturn(
|
||||||
|
success=True,
|
||||||
|
code=200,
|
||||||
|
message="restore job created",
|
||||||
|
jobs=[get_restore_job(service)],
|
||||||
|
)
|
||||||
|
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def force_snapshots_reload(self) -> GenericMutationReturn:
|
def force_snapshots_reload(self) -> GenericMutationReturn:
|
||||||
|
|
Loading…
Reference in a new issue