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] = [
RotationBucket(
quotas.last,
quotas.last, # type: ignore
-1,
lambda _, index: index,
),
RotationBucket(
quotas.daily,
quotas.daily, # type: ignore
-1,
lambda date, _: date.year * 10000 + date.month * 100 + date.day,
),
RotationBucket(
quotas.weekly,
quotas.weekly, # type: ignore
-1,
lambda date, _: date.year * 100 + date.isocalendar()[1],
),
RotationBucket(
quotas.monthly,
quotas.monthly, # type: ignore
-1,
lambda date, _: date.year * 100 + date.month,
),
RotationBucket(
quotas.yearly,
quotas.yearly, # type: ignore
-1,
lambda date, _: date.year,
),
@ -409,11 +409,11 @@ class Backups:
Storage.set_autobackup_quotas(
AutobackupQuotas(
last=Backups._standardize_quotas(quotas.last),
daily=Backups._standardize_quotas(quotas.daily),
weekly=Backups._standardize_quotas(quotas.weekly),
monthly=Backups._standardize_quotas(quotas.monthly),
yearly=Backups._standardize_quotas(quotas.yearly),
last=Backups._standardize_quotas(quotas.last), # type: ignore
daily=Backups._standardize_quotas(quotas.daily), # type: ignore
weekly=Backups._standardize_quotas(quotas.weekly), # type: ignore
monthly=Backups._standardize_quotas(quotas.monthly), # type: ignore
yearly=Backups._standardize_quotas(quotas.yearly), # type: ignore
)
)
@ -438,7 +438,7 @@ class Backups:
job: Job,
) -> None:
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)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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