mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-03-18 20:39:46 +00:00
Fix ssh key add
This commit is contained in:
parent
09f319d683
commit
2f03cb0756
1 changed files with 8 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from flask import Blueprint, request
|
from flask import Blueprint, request
|
||||||
from flask_restful import Resource
|
from flask_restful import Resource, reqparse
|
||||||
|
|
||||||
from selfprivacy_api.resources.services import api
|
from selfprivacy_api.resources.services import api
|
||||||
|
|
||||||
|
@ -25,9 +25,13 @@ class EnableSSH(Resource):
|
||||||
# Write new SSH key
|
# Write new SSH key
|
||||||
class WriteSSHKey(Resource):
|
class WriteSSHKey(Resource):
|
||||||
def put(self):
|
def put(self):
|
||||||
requestBody = request.get_json()
|
parser = reqparse.RequestParser()
|
||||||
|
parser.add_argument(
|
||||||
|
"public_key", type=str, required=True, help="Key cannot be blank!"
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
publicKey = requestBody.data(["public_key"])
|
publicKey = args["public_key"]
|
||||||
|
|
||||||
print("[INFO] Opening /etc/nixos/configuration.nix...", sep="")
|
print("[INFO] Opening /etc/nixos/configuration.nix...", sep="")
|
||||||
readOnlyFileDescriptor = open("/etc/nixos/configuration.nix", "r")
|
readOnlyFileDescriptor = open("/etc/nixos/configuration.nix", "r")
|
||||||
|
@ -51,7 +55,7 @@ class WriteSSHKey(Resource):
|
||||||
if "openssh.authorizedKeys.keys = [" in line:
|
if "openssh.authorizedKeys.keys = [" in line:
|
||||||
print("[DEBUG] Found SSH key configuration snippet match!")
|
print("[DEBUG] Found SSH key configuration snippet match!")
|
||||||
print("[INFO] Writing new SSH key", sep="")
|
print("[INFO] Writing new SSH key", sep="")
|
||||||
fileContent.append(index, '\n "' + publicKey + '"')
|
fileContent.append('\n "' + publicKey + '"')
|
||||||
print("done")
|
print("done")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue