mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-25 09:21:04 +00:00
Persistent secrets
This commit is contained in:
parent
683d155b1e
commit
3fe629f8cf
2 changed files with 15 additions and 2 deletions
|
@ -24,5 +24,9 @@ def get_current_secret():
|
|||
def setup(args):
|
||||
if args.api_keys and args.require_api_key_secret:
|
||||
s = get_storage()
|
||||
s.set_str("secret_0", generate_secret())
|
||||
s.set_str("secret_1", generate_secret())
|
||||
|
||||
if not s.exists("secret_0"):
|
||||
s.set_str("secret_0", generate_secret())
|
||||
|
||||
if not s.exists("secret_1"):
|
||||
s.set_str("secret_1", generate_secret())
|
||||
|
|
|
@ -5,6 +5,9 @@ def get_storage():
|
|||
return storage
|
||||
|
||||
class Storage:
|
||||
def exists(self, key):
|
||||
raise Exception("not implemented")
|
||||
|
||||
def set_bool(self, key, value):
|
||||
raise Exception("not implemented")
|
||||
def get_bool(self, key):
|
||||
|
@ -38,6 +41,9 @@ class MemoryStorage(Storage):
|
|||
def __init__(self):
|
||||
self.store = {}
|
||||
|
||||
def exists(self, key):
|
||||
return key in self.store
|
||||
|
||||
def set_bool(self, key, value):
|
||||
self.store[key] = bool(value)
|
||||
|
||||
|
@ -98,6 +104,9 @@ class RedisStorage(Storage):
|
|||
self.conn = redis.from_url(redis_uri)
|
||||
self.conn.ping()
|
||||
|
||||
def exists(self, key):
|
||||
return bool(self.conn.exists(key))
|
||||
|
||||
def set_bool(self, key, value):
|
||||
self.conn.set(key, "1" if value else "0")
|
||||
|
||||
|
|
Loading…
Reference in a new issue