First commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.venv
|
||||
11
README.md
Normal file
11
README.md
Normal file
@@ -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
|
||||
|
||||
BIN
src/__pycache__/collection.cpython-312.pyc
Normal file
BIN
src/__pycache__/collection.cpython-312.pyc
Normal file
Binary file not shown.
62
src/collection.py
Normal file
62
src/collection.py
Normal file
@@ -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())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
38
src/collections.py
Normal file
38
src/collections.py
Normal file
@@ -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"
|
||||
0
src/main.py
Normal file
0
src/main.py
Normal file
0
src/ssh.py
Normal file
0
src/ssh.py
Normal file
Reference in New Issue
Block a user