mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-09 17:39:31 +00:00
Implemented logging for user creation endpoint
This commit is contained in:
parent
ff13321154
commit
a4987210ac
16
main.py
16
main.py
|
@ -66,10 +66,13 @@ def upgradeSystem():
|
||||||
|
|
||||||
@app.route("/createUser", methods=["POST"])
|
@app.route("/createUser", methods=["POST"])
|
||||||
def createUser():
|
def createUser():
|
||||||
|
print("[INFO] Opening /etc/nixos/users.nix...", sep="")
|
||||||
readOnlyFileDescriptor = open("/etc/nixos/users.nix", "r")
|
readOnlyFileDescriptor = open("/etc/nixos/users.nix", "r")
|
||||||
|
print("done")
|
||||||
fileContent = list()
|
fileContent = list()
|
||||||
index = int(0)
|
index = int(0)
|
||||||
|
|
||||||
|
print("[INFO] Reading file content...", sep="")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = readOnlyFileDescriptor.readline()
|
line = readOnlyFileDescriptor.readline()
|
||||||
|
@ -78,6 +81,7 @@ def createUser():
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
fileContent.append(line)
|
fileContent.append(line)
|
||||||
|
print("[DEBUG] Read line!")
|
||||||
|
|
||||||
|
|
||||||
userTemplate = """
|
userTemplate = """
|
||||||
|
@ -88,13 +92,19 @@ def createUser():
|
||||||
}};
|
}};
|
||||||
#end""".format(request.headers.get("X-User"), request.headers.get("X-Password"))
|
#end""".format(request.headers.get("X-User"), request.headers.get("X-Password"))
|
||||||
|
|
||||||
|
print("[TRACE] {0}".format(userTemplate))
|
||||||
|
|
||||||
for line in fileContent:
|
for line in fileContent:
|
||||||
index += 1
|
index -= 1
|
||||||
if line.startswith(" #begin"):
|
if line.startswith(" #begin"):
|
||||||
fileContent.insert(index-1, userTemplate)
|
print("[DEBUG] Found user configuration snippet match!")
|
||||||
|
print("[INFO] Writing new user configuration snippet to memory...", sep="")
|
||||||
|
fileContent.insert(index, userTemplate)
|
||||||
|
print("done")
|
||||||
|
|
||||||
|
print("[INFO] Writing data from memory to file...", sep="")
|
||||||
readWriteFileDescriptor = open("/etc/nixos/users.nix", "w")
|
readWriteFileDescriptor = open("/etc/nixos/users.nix", "w")
|
||||||
|
print("done")
|
||||||
operationResult = readWriteFileDescriptor.writelines(fileContent)
|
operationResult = readWriteFileDescriptor.writelines(fileContent)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue