forked from 3wordchant/capsul-flask
first crack at adding ssh host key display to the capsul detail page
This commit is contained in:
@ -104,7 +104,17 @@ class DBModel:
|
||||
self.cursor.execute("UPDATE vms SET last_seen_ipv4 = %s WHERE email = %s AND id = %s", (ipv4, email, id))
|
||||
self.connection.commit()
|
||||
|
||||
def create_vm(self, email, id, size, os, ssh_public_keys):
|
||||
def update_vm_ssh_host_keys(self, email, id, ssh_host_keys):
|
||||
for key in ssh_host_keys:
|
||||
self.cursor.execute("""
|
||||
INSERT INTO vm_ssh_host_key (email, vm_id, key_type, content, sha256)
|
||||
VALUES (%s, %s, %s, %s, %s)
|
||||
""",
|
||||
(email, id, key['key_type'], key['content'], key['sha256'])
|
||||
)
|
||||
self.connection.commit()
|
||||
|
||||
def create_vm(self, email, id, size, os, ssh_authorized_keys):
|
||||
self.cursor.execute("""
|
||||
INSERT INTO vms (email, id, size, os)
|
||||
VALUES (%s, %s, %s, %s)
|
||||
@ -112,14 +122,14 @@ class DBModel:
|
||||
(email, id, size, os)
|
||||
)
|
||||
|
||||
for ssh_public_key in ssh_public_keys:
|
||||
current_app.logger.info(f"INSERT INTO vm_ssh_public_key (email, vm_id, ssh_public_key_name) VALUES (\"{email}\", \"{id}\", \"{ssh_public_key}\")")
|
||||
for ssh_authorized_key in ssh_authorized_keys:
|
||||
current_app.logger.info(f"INSERT INTO vm_ssh_authorized_key (email, vm_id, ssh_public_key_name) VALUES (\"{email}\", \"{id}\", \"{ssh_authorized_key}\")")
|
||||
|
||||
self.cursor.execute("""
|
||||
INSERT INTO vm_ssh_public_key (email, vm_id, ssh_public_key_name)
|
||||
INSERT INTO vm_ssh_authorized_key (email, vm_id, ssh_public_key_name)
|
||||
VALUES (%s, %s, %s)
|
||||
""",
|
||||
(email, id, ssh_public_key)
|
||||
(email, id, ssh_authorized_key)
|
||||
)
|
||||
self.connection.commit()
|
||||
|
||||
@ -147,11 +157,19 @@ class DBModel:
|
||||
)
|
||||
|
||||
self.cursor.execute("""
|
||||
SELECT ssh_public_key_name FROM vm_ssh_public_key
|
||||
WHERE vm_ssh_public_key.email = %s AND vm_ssh_public_key.vm_id = %s""",
|
||||
SELECT ssh_public_key_name FROM vm_ssh_authorized_key
|
||||
WHERE vm_ssh_authorized_key.email = %s AND vm_ssh_authorized_key.vm_id = %s""",
|
||||
(email, id)
|
||||
)
|
||||
vm["ssh_public_keys"] = list(map( lambda x: x[0], self.cursor.fetchall() ))
|
||||
vm["ssh_authorized_keys"] = list(map( lambda x: x[0], self.cursor.fetchall() ))
|
||||
|
||||
|
||||
self.cursor.execute("""
|
||||
SELECT key_type, content, sha256 FROM vm_ssh_host_key
|
||||
WHERE vm_ssh_host_key.email = %s AND vm_ssh_host_key.vm_id = %s""",
|
||||
(email, id)
|
||||
)
|
||||
vm["ssh_host_keys"] = list(map( lambda x: dict(key_type=x[0], content=x[1], sha256=x[2]), self.cursor.fetchall() ))
|
||||
|
||||
return vm
|
||||
|
||||
|
Reference in New Issue
Block a user