Some testing with raise -calls.
This commit is contained in:
parent
21f0d0c229
commit
52d380a4ee
@ -33,7 +33,6 @@ server_public_key = server_private_key.get_verifying_key()
|
|||||||
# We need the hexadecimal form for sharing over http/json
|
# We need the hexadecimal form for sharing over http/json
|
||||||
server_public_key_hex = binascii.hexlify(server_public_key.to_string()).decode("utf-8")
|
server_public_key_hex = binascii.hexlify(server_public_key.to_string()).decode("utf-8")
|
||||||
|
|
||||||
database_lock = threading.Lock()
|
|
||||||
|
|
||||||
# Empty response json
|
# Empty response json
|
||||||
empty_dict = {
|
empty_dict = {
|
||||||
@ -51,10 +50,32 @@ empty_json = json.dumps(empty_dict)
|
|||||||
|
|
||||||
|
|
||||||
def read_keys():
|
def read_keys():
|
||||||
with open(KEYSFILE, "r") as cfile:
|
"""
|
||||||
|
Reads the declared KEYSFILE and returns "user_publickeys" from it.
|
||||||
|
Returns: json object
|
||||||
|
"""
|
||||||
|
# test if the file is there, we could make one if there is non
|
||||||
|
try:
|
||||||
|
# ascii is subset of UTF-8, this should be quite safe...
|
||||||
|
with open(KEYSFILE, "r", encoding='utf-8') as cfile:
|
||||||
user_keys = json.load(cfile)
|
user_keys = json.load(cfile)
|
||||||
return user_keys["user_publickeys"]
|
|
||||||
|
|
||||||
|
if 'user_publickeys' not in user_keys:
|
||||||
|
raise ValueError('Missing required property "user_publickeys" in config file')
|
||||||
|
|
||||||
|
return user_keys["user_publickeys"]
|
||||||
|
except FileNotFoundError:
|
||||||
|
empty_userkeys = {
|
||||||
|
"user_publickeys": {
|
||||||
|
"user_name": "user_ecdsa_public key"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
empty_userkeys_json = json.dumps(empty_userkeys)
|
||||||
|
with open(KEYSFILE, "w", encoding='utf-8') as nfile:
|
||||||
|
print('You seem be lacking the users key file, created example for you. Exiting')
|
||||||
|
json.dump(empty_userkeys_json, nfile)
|
||||||
|
raise EmptyUsersFile('Error')
|
||||||
|
return {}
|
||||||
|
|
||||||
def check_database():
|
def check_database():
|
||||||
"""
|
"""
|
||||||
@ -398,10 +419,13 @@ def give_serverkey():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Make sanity checks for the database
|
# Make sanity checks for the database
|
||||||
check_database()
|
check_database()
|
||||||
|
database_lock = threading.Lock()
|
||||||
|
|
||||||
# Get the users public keys
|
# Get the users public keys
|
||||||
|
try:
|
||||||
user_publickeys = read_keys()
|
user_publickeys = read_keys()
|
||||||
|
|
||||||
|
|
||||||
# Start the data fetching backend process§
|
# Start the data fetching backend process§
|
||||||
fetch_thread = threading.Thread(target=get_the_data)
|
fetch_thread = threading.Thread(target=get_the_data)
|
||||||
fetch_thread.daemon = True
|
fetch_thread.daemon = True
|
||||||
|
Loading…
Reference in New Issue
Block a user