mirror of
https://github.com/devproje/balance-application.git
synced 2024-10-20 15:11:21 +00:00
feat: add generate secret token
This commit is contained in:
parent
0b4c55284d
commit
6f8fef42ac
3 changed files with 28 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,6 +6,8 @@ __pycache__/
|
|||
.env
|
||||
!.env.example
|
||||
|
||||
secret_token.txt
|
||||
|
||||
load.txt
|
||||
|
||||
.DS_Store
|
||||
|
|
19
generate.py
19
generate.py
|
@ -1,4 +1,4 @@
|
|||
import psycopg2, os
|
||||
import psycopg2
|
||||
import random, string
|
||||
from getpass import getpass
|
||||
from util.auth_lib import hash
|
||||
|
@ -6,8 +6,17 @@ from util.config import conn_param
|
|||
from service.auth_service import AuthData, AuthService
|
||||
|
||||
def gen_salt(length = 20):
|
||||
letters = string.ascii_lowercase + string.digits + string.punctuation
|
||||
return ''.join(random.choice(letters) for i in range(length))
|
||||
letters = string.ascii_lowercase + string.digits + string.punctuation
|
||||
return "".join(random.choice(letters) for i in range(length))
|
||||
|
||||
def _gen_token():
|
||||
deps = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation
|
||||
token = "".join(random.choice(deps) for i in range(20))
|
||||
|
||||
sec = open("./secret_token.txt", "w")
|
||||
sec.write(token)
|
||||
|
||||
sec.close()
|
||||
|
||||
def __main__():
|
||||
conn = psycopg2.connect(conn_param)
|
||||
|
@ -15,10 +24,12 @@ def __main__():
|
|||
|
||||
try:
|
||||
f = open("./load.txt", "r")
|
||||
_gen_token()
|
||||
if f.read().split("=")[1] == "false":
|
||||
raise ValueError("value not true")
|
||||
|
||||
print("server already initialized")
|
||||
f.close()
|
||||
except:
|
||||
cur.execute(
|
||||
"""
|
||||
|
@ -78,4 +89,6 @@ def __main__():
|
|||
f = open("load.txt", "w")
|
||||
f.write("init=true")
|
||||
|
||||
f.close()
|
||||
|
||||
__main__()
|
||||
|
|
|
@ -3,6 +3,14 @@ from dotenv import load_dotenv
|
|||
|
||||
load_dotenv()
|
||||
|
||||
def _load_secret():
|
||||
try:
|
||||
tok = open("./secret_token.txt", "r").read()
|
||||
except:
|
||||
return ""
|
||||
|
||||
return tok
|
||||
|
||||
conn_param = "host=%s port=%s dbname=%s user=%s password=%s" % (
|
||||
os.getenv("DB_URL"),
|
||||
os.getenv("DB_PORT"),
|
||||
|
@ -10,3 +18,5 @@ conn_param = "host=%s port=%s dbname=%s user=%s password=%s" % (
|
|||
os.getenv("DB_USERNAME"),
|
||||
os.getenv("DB_PASSWORD")
|
||||
)
|
||||
|
||||
secret = _load_secret()
|
||||
|
|
Loading…
Reference in a new issue