fix(backups): expose snapshot reason and set the default value

This commit is contained in:
Inex Code 2023-09-09 09:52:20 +03:00
parent 6b106cbcf3
commit 8b840d4c2c
7 changed files with 18 additions and 14 deletions

View file

@ -335,27 +335,27 @@ class Backups:
buckets: list[RotationBucket] = [ buckets: list[RotationBucket] = [
RotationBucket( RotationBucket(
quotas.last, quotas.last, # type: ignore
-1, -1,
lambda _, index: index, lambda _, index: index,
), ),
RotationBucket( RotationBucket(
quotas.daily, quotas.daily, # type: ignore
-1, -1,
lambda date, _: date.year * 10000 + date.month * 100 + date.day, lambda date, _: date.year * 10000 + date.month * 100 + date.day,
), ),
RotationBucket( RotationBucket(
quotas.weekly, quotas.weekly, # type: ignore
-1, -1,
lambda date, _: date.year * 100 + date.isocalendar()[1], lambda date, _: date.year * 100 + date.isocalendar()[1],
), ),
RotationBucket( RotationBucket(
quotas.monthly, quotas.monthly, # type: ignore
-1, -1,
lambda date, _: date.year * 100 + date.month, lambda date, _: date.year * 100 + date.month,
), ),
RotationBucket( RotationBucket(
quotas.yearly, quotas.yearly, # type: ignore
-1, -1,
lambda date, _: date.year, lambda date, _: date.year,
), ),
@ -409,11 +409,11 @@ class Backups:
Storage.set_autobackup_quotas( Storage.set_autobackup_quotas(
AutobackupQuotas( AutobackupQuotas(
last=Backups._standardize_quotas(quotas.last), last=Backups._standardize_quotas(quotas.last), # type: ignore
daily=Backups._standardize_quotas(quotas.daily), daily=Backups._standardize_quotas(quotas.daily), # type: ignore
weekly=Backups._standardize_quotas(quotas.weekly), weekly=Backups._standardize_quotas(quotas.weekly), # type: ignore
monthly=Backups._standardize_quotas(quotas.monthly), monthly=Backups._standardize_quotas(quotas.monthly), # type: ignore
yearly=Backups._standardize_quotas(quotas.yearly), yearly=Backups._standardize_quotas(quotas.yearly), # type: ignore
) )
) )
@ -438,7 +438,7 @@ class Backups:
job: Job, job: Job,
) -> None: ) -> None:
Jobs.update( Jobs.update(
job, status=JobStatus.CREATED, status_text=f"Waiting for pre-restore backup" job, status=JobStatus.CREATED, status_text="Waiting for pre-restore backup"
) )
failsafe_snapshot = Backups.back_up(service, BackupReason.PRE_RESTORE) failsafe_snapshot = Backups.back_up(service, BackupReason.PRE_RESTORE)

View file

@ -27,4 +27,4 @@ async def get_token_header(
def get_api_version() -> str: def get_api_version() -> str:
"""Get API version""" """Get API version"""
return "2.4.0" return "2.4.1"

View file

@ -2,6 +2,7 @@ from enum import Enum
import typing import typing
import strawberry import strawberry
import datetime import datetime
from selfprivacy_api.graphql.common_types.backup import BackupReason
from selfprivacy_api.graphql.common_types.dns import DnsRecord from selfprivacy_api.graphql.common_types.dns import DnsRecord
from selfprivacy_api.services import get_service_by_id, get_services_by_location from selfprivacy_api.services import get_service_by_id, get_services_by_location
@ -114,6 +115,7 @@ class SnapshotInfo:
id: str id: str
service: Service service: Service
created_at: datetime.datetime created_at: datetime.datetime
reason: BackupReason
def service_to_graphql_service(service: ServiceInterface) -> Service: def service_to_graphql_service(service: ServiceInterface) -> Service:

View file

@ -77,6 +77,7 @@ class Backup:
id=snap.id, id=snap.id,
service=service, service=service,
created_at=snap.created_at, created_at=snap.created_at,
reason=snap.reason,
) )
result.append(graphql_snap) result.append(graphql_snap)
return result return result

View file

@ -8,4 +8,4 @@ class Snapshot(BaseModel):
id: str id: str
service_name: str service_name: str
created_at: datetime.datetime created_at: datetime.datetime
reason: BackupReason reason: BackupReason = BackupReason.EXPLICIT

View file

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name="selfprivacy_api", name="selfprivacy_api",
version="2.4.0", version="2.4.1",
packages=find_packages(), packages=find_packages(),
scripts=[ scripts=[
"selfprivacy_api/app.py", "selfprivacy_api/app.py",

View file

@ -145,6 +145,7 @@ allSnapshots {
id id
} }
createdAt createdAt
reason
} }
""" """