mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 21:41:27 +00:00
feat(backups): local secret generation and storage
This commit is contained in:
parent
60dcde458c
commit
0847e16089
|
@ -2,29 +2,40 @@
|
||||||
Separated out for circular dependency reasons
|
Separated out for circular dependency reasons
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import secrets
|
||||||
|
|
||||||
|
from selfprivacy_api.utils.redis_pool import RedisPool
|
||||||
|
|
||||||
|
|
||||||
REDIS_KEY = "backup:local_secret"
|
REDIS_KEY = "backup:local_secret"
|
||||||
|
|
||||||
|
redis = RedisPool().get_connection()
|
||||||
|
|
||||||
|
|
||||||
class LocalBackupSecret:
|
class LocalBackupSecret:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get():
|
def get():
|
||||||
"""A secret string which backblaze/other clouds do not know.
|
"""A secret string which backblaze/other clouds do not know.
|
||||||
Serves as encryption key.
|
Serves as encryption key.
|
||||||
TODO: generate and save in redis
|
|
||||||
"""
|
"""
|
||||||
return "TEMPORARY_SECRET"
|
if not LocalBackupSecret.exists():
|
||||||
|
LocalBackupSecret.reset()
|
||||||
|
return redis.get(REDIS_KEY)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reset():
|
def reset():
|
||||||
pass
|
new_secret = LocalBackupSecret._generate()
|
||||||
|
LocalBackupSecret._store(new_secret)
|
||||||
def exists():
|
|
||||||
pass
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _generate():
|
def exists() -> bool:
|
||||||
pass
|
return redis.exists(REDIS_KEY)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _generate() -> str:
|
||||||
|
return secrets.token_urlsafe(256)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _store(secret: str):
|
def _store(secret: str):
|
||||||
pass
|
redis.set(REDIS_KEY, secret)
|
||||||
|
|
Loading…
Reference in a new issue