Clearer error handling on read_keys().
This commit is contained in:
parent
8800275ed5
commit
c02ea2849a
@ -11,6 +11,7 @@ import math
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import binascii
|
import binascii
|
||||||
import threading
|
import threading
|
||||||
@ -54,6 +55,11 @@ def read_keys():
|
|||||||
Reads the declared KEYSFILE and returns "user_publickeys" from it.
|
Reads the declared KEYSFILE and returns "user_publickeys" from it.
|
||||||
Returns: json object
|
Returns: json object
|
||||||
"""
|
"""
|
||||||
|
empty_userkeys = {
|
||||||
|
"user_publickeys": {
|
||||||
|
"user_name": "user_ecdsa_public key"
|
||||||
|
}
|
||||||
|
}
|
||||||
# test if the file is there, we could make one if there is non
|
# test if the file is there, we could make one if there is non
|
||||||
try:
|
try:
|
||||||
# ascii is subset of UTF-8, this should be quite safe...
|
# ascii is subset of UTF-8, this should be quite safe...
|
||||||
@ -61,20 +67,18 @@ def read_keys():
|
|||||||
user_keys = json.load(cfile)
|
user_keys = json.load(cfile)
|
||||||
|
|
||||||
if 'user_publickeys' not in user_keys:
|
if 'user_publickeys' not in user_keys:
|
||||||
raise ValueError('Missing required property "user_publickeys" in config file')
|
print('Missing required property "user_publickeys" in config file')
|
||||||
|
sys.exit(1)
|
||||||
|
if user_keys == empty_userkeys:
|
||||||
|
print('Your userkeys.json file seems to not filled. Please insert your key there.')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
return user_keys["user_publickeys"]
|
return user_keys["user_publickeys"]
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
empty_userkeys = {
|
|
||||||
"user_publickeys": {
|
|
||||||
"user_name": "user_ecdsa_public key"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
with open(KEYSFILE, "w", encoding='utf-8') as nfile:
|
with open(KEYSFILE, "w", encoding='utf-8') as nfile:
|
||||||
print('You seem be lacking the users key file, created example for you. Exiting')
|
print('You seem be lacking the users key file, created example for you. Exiting')
|
||||||
json.dump(empty_userkeys, nfile, indent=2)
|
json.dump(empty_userkeys, nfile, indent=2)
|
||||||
raise FileNotFoundError
|
sys.exit(1)
|
||||||
return {}
|
|
||||||
|
|
||||||
def check_database():
|
def check_database():
|
||||||
"""
|
"""
|
||||||
@ -421,11 +425,7 @@ if __name__ == "__main__":
|
|||||||
database_lock = threading.Lock()
|
database_lock = threading.Lock()
|
||||||
|
|
||||||
# Get the users public keys
|
# Get the users public keys
|
||||||
try:
|
user_publickeys = read_keys()
|
||||||
user_publickeys = read_keys()
|
|
||||||
except FileNotFoundError:
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
# 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)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"user_publickeys": {
|
"user_publickeys": {
|
||||||
"user_name": "user_ecdsa_public key"
|
"user1": "f1debc13fb21fe0eee54525aa4f8aae5733b201c755edaa55f8893c90aa375b261a62eaa3110651ac5d7705d402581256a37508b0a1ca28bd919ea44710d9c88"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"user_publickeys": {
|
|
||||||
"user1": "f1debc13fb21fe0eee54525aa4f8aae5733b201c755edaa55f8893c90aa375b261a62eaa3110651ac5d7705d402581256a37508b0a1ca28bd919ea44710d9c88"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user