(bugfix) Validate Django-managed SSH private keys
Validate uploaded SSH private keys with ssh-keygen before saving them so invalid, malformed, or unsupported key material is rejected in the control panel instead of failing later during rsync. Auto-populate the public key when it is omitted, add an edit flow for existing SSH credentials, and cover create, update, and invalid-key paths with view tests.
This commit is contained in:
@@ -82,6 +82,29 @@ def create_ssh_credential(request):
|
||||
"pobsync_backend/ssh_credential_form.html",
|
||||
{
|
||||
"form": form,
|
||||
"credential": None,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@staff_member_required
|
||||
def edit_ssh_credential(request, credential_id: int):
|
||||
credential = get_object_or_404(SshCredential, id=credential_id)
|
||||
if request.method == "POST":
|
||||
form = SshCredentialForm(request.POST, instance=credential)
|
||||
if form.is_valid():
|
||||
saved_credential = form.save()
|
||||
messages.success(request, f"SSH credential saved for {saved_credential.name}.")
|
||||
return redirect("ssh_credentials")
|
||||
else:
|
||||
form = SshCredentialForm(instance=credential)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"pobsync_backend/ssh_credential_form.html",
|
||||
{
|
||||
"form": form,
|
||||
"credential": credential,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user