commit c9fd97f8ad946ecac93f4535358965f3b9a2da3b Author: jrenaud Date: Fri Oct 17 18:31:20 2025 +0200 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d17dae --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv diff --git a/README.md b/README.md new file mode 100644 index 0000000..107c265 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +#### explication #### + - Manage ssh config file through several computer + - Manage ssh key through several computer + +#### Schema applicatif #### + - Création d'un workspace + - Création de clé ssh au sein d'un workspace + - Créer la clé ssh + - Encrypter la clé ssh avec le password du workspace + - Stocker la clé sur un repo git définit dans le workspace + diff --git a/src/__pycache__/collection.cpython-312.pyc b/src/__pycache__/collection.cpython-312.pyc new file mode 100644 index 0000000..c89a705 Binary files /dev/null and b/src/__pycache__/collection.cpython-312.pyc differ diff --git a/src/collection.py b/src/collection.py new file mode 100644 index 0000000..603163f --- /dev/null +++ b/src/collection.py @@ -0,0 +1,62 @@ +from pathlib import Path +from os import walk, chmod +from Crypto.PublicKey import RSA + +class ssh_key: + """ + Object class for a ssh key + """ + def __init__(self, name, key_type, public, private): + self.name = name + self.type = key_type + self.public = public + self.private = private + + def get_name(self): + """Getter for name""" + return self.name + def get_type(self): + """Getter for type""" + return self.type + def get_private(self): + """Getter for private key""" + return self.private + def get_public(self): + """Getter for public key""" + return self.public + +class Collection: + """ + Object class of Collection type + """ + def __init__(self, collection_name): + self.collection_name = collection_name + self.collection_path = Path.home().joinpath(".sshkeymanager", self.collection_name) + + def generate_ssh_key(self, name: str, key_type: str): + """ + public class to generate a ssh key + """ + key = RSA.generate(2048) + sshKey = ssh_key(name=name, key_type=key_type, private=key.exportKey('PEM'), public=key.publickey().exportKey('OpenSSH')) + self.save_ssh_key(sshKey=sshKey) + + def save_ssh_key(self, sshKey: ssh_key): + """ + Function to save the sshkey + """ + key_file_path = self.collection_path.joinpath(sshKey.get_name()) + with open(f"{key_file_path}.txt", "w+", encoding="utf-8") as info_file: + info_file.write(f"name: {sshKey.get_name()}\nKey_type: {sshKey.get_type()}") + with open(key_file_path, "wb") as private_file: + private_file.write(sshKey.get_private()) + with open(f"{key_file_path}.pub", "wb") as public_file: + public_file.write(sshKey.get_public()) + + + + + + + + diff --git a/src/collections.py b/src/collections.py new file mode 100644 index 0000000..c7bd406 --- /dev/null +++ b/src/collections.py @@ -0,0 +1,38 @@ +from pathlib import Path + + +class Collections: + """ + collections manager in sshkey-manager project + """ + def __init__(self): + self.user_path = Path.home() + self.collection_path = self.user_path.joinpath(".sshkeymanager") + self.collection_path.mkdir(exist_ok=True) + self.set_collection_list() + + def set_collection_list(self): + """ + Setter for collection_list variable + """ + self.collection_list = [ + d.name for d in self.collection_path.iterdir() if d.is_dir() + ] + + def get_collection_list(self) -> list: + """ + Getter for collection_list variable + """ + return self.collection_list + + def add_collection(self, collection_name: str) -> str: + """ + Function to add a collection + """ + if collection_name not in self.collection_list: + new_path = self.collection_path.joinpath(collection_name) + new_path.mkdir() + self.set_collection_list() + return "Collection created" + else: + return "Collection already exists" \ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..e69de29 diff --git a/src/ssh.py b/src/ssh.py new file mode 100644 index 0000000..e69de29