feature: added a method for 'SSHKeyCollection' that outputs its data in an Ansible-friendly data structure
This commit is contained in:
@@ -582,6 +582,42 @@ class SSHKeyCollection(Sequence):
|
|||||||
|
|
||||||
return prefix + content + postfix
|
return prefix + content + postfix
|
||||||
|
|
||||||
|
def publish(self, pref: int | None = None, datatype = dict):
|
||||||
|
privkey = list()
|
||||||
|
pubkey = list()
|
||||||
|
self.__current = self.__first
|
||||||
|
|
||||||
|
if datatype == list:
|
||||||
|
while self.__current is not None:
|
||||||
|
if self.__current.category == SSHKeyType.privkey.name:
|
||||||
|
privkey.append(str(self.__current._SSHKey__value))
|
||||||
|
elif self.__current.category == SSHKeyType.pubkey.name:
|
||||||
|
pubkey.append(self.__current._SSHKey__value.read_text())
|
||||||
|
elif self.__current.category == SSHKeyType.dual.name:
|
||||||
|
privkey.append(str(self.__current._SSHKey__value[0]))
|
||||||
|
pubkey.append(self.__current._SSHKey__value[1].read_text())
|
||||||
|
self.__current = next(self.__first)
|
||||||
|
|
||||||
|
return (privkey, pubkey, gamble(range(len(privkey))))
|
||||||
|
elif datatype == dict:
|
||||||
|
result = dict()
|
||||||
|
|
||||||
|
while self.__current is not None:
|
||||||
|
if self.__current.category == SSHKeyType.privkey.name:
|
||||||
|
privkey.append(str(self.__current._SSHKey__value))
|
||||||
|
elif self.__current.category == SSHKeyType.pubkey.name:
|
||||||
|
pubkey.append(self.__current._SSHKey__value.read_text())
|
||||||
|
elif self.__current.category == SSHKeyType.dual.name:
|
||||||
|
privkey.append(str(self.__current._SSHKey__value[0]))
|
||||||
|
pubkey.append(self.__current._SSHKey__value[1].read_text())
|
||||||
|
self.__current = next(self.__first)
|
||||||
|
|
||||||
|
result["ssh_authorized_keys"]: list[str] = pubkey
|
||||||
|
result["ssh_private_key_paths"]: list[str] = privkey
|
||||||
|
result["ssh_private_key_path_pref"]: int = pref if pref is not None else gamble(range(len(privkey)))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
# @TODO maybe move to separate module for classes for handling users and groups
|
# @TODO maybe move to separate module for classes for handling users and groups
|
||||||
class UserSSH:
|
class UserSSH:
|
||||||
def __init__(self, username: str = "root", paths: Apps | None = None, keys: dict = dict(), password: str = "password123", fate: RootFate = RootFate.disposal.name):
|
def __init__(self, username: str = "root", paths: Apps | None = None, keys: dict = dict(), password: str = "password123", fate: RootFate = RootFate.disposal.name):
|
||||||
|
|||||||
Reference in New Issue
Block a user