diff --git a/sshkey_man.py b/sshkey_man.py index f103b96..8f74426 100644 --- a/sshkey_man.py +++ b/sshkey_man.py @@ -582,6 +582,42 @@ class SSHKeyCollection(Sequence): 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 class UserSSH: def __init__(self, username: str = "root", paths: Apps | None = None, keys: dict = dict(), password: str = "password123", fate: RootFate = RootFate.disposal.name):