Hotfix: user and ssh key creation when no were defined

pull/6/head
Inex Code 2021-11-18 20:54:45 +02:00
parent 1432671cbe
commit e00aaf7118
2 changed files with 5 additions and 2 deletions

View File

@ -97,6 +97,8 @@ class WriteSSHKey(Resource):
data = json.load(userdata_file)
if "ssh" not in data:
data["ssh"] = {}
if "rootKeys" not in data["ssh"]:
data["ssh"]["rootKeys"] = []
# Return 409 if key already in array
for key in data["ssh"]["rootKeys"]:
if key == public_key:

View File

@ -104,13 +104,14 @@ class Users(Resource):
try:
data = json.load(userdata_file)
if "users" not in data:
data["users"] = []
# Return 400 if user already exists
for user in data["users"]:
if user["username"] == args["username"]:
return {"error": "User already exists"}, 409
if "users" not in data:
data["users"] = []
data["users"].append(
{
"username": args["username"],