-
Notifications
You must be signed in to change notification settings - Fork 6
Additional SSH key pair Algorithms #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
74e1cb5
bf3e535
2969a58
789cb86
9c8eb63
cd629fe
f662ecd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = '0.5.2' | ||
__version__ = '0.5.3' | ||
|
||
|
||
from battenberg.core import Battenberg | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes are conversions to |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes are conversions to |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes are conversions to |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
import os | ||
import logging | ||
import re | ||
import subprocess | ||
from typing import Optional | ||
from pygit2 import discover_repository, init_repository, Keypair, Repository | ||
from battenberg.errors import InvalidRepositoryException | ||
|
||
from battenberg.errors import InvalidRepositoryException, KeypairException | ||
from pathlib import Path | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def open_repository(path: str) -> Repository: | ||
def open_repository(path: Path) -> Repository: | ||
try: | ||
repo_path = discover_repository(path) | ||
except Exception as e: | ||
|
@@ -26,7 +25,7 @@ def open_repository(path: str) -> Repository: | |
return Repository(repo_path) | ||
|
||
|
||
def open_or_init_repository(path: str, template: str, initial_branch: Optional[str] = None): | ||
def open_or_init_repository(path: Path, template: str, initial_branch: Optional[str] = None): | ||
try: | ||
return open_repository(path) | ||
except InvalidRepositoryException: | ||
|
@@ -64,11 +63,38 @@ def set_initial_branch(repo: Repository, template: str): | |
repo.references['HEAD'].set_target(initial_branch) | ||
|
||
|
||
def construct_keypair(public_key_path: str = None, private_key_path: str = None, | ||
passphrase: str = '') -> Keypair: | ||
ssh_path = os.path.join(os.path.expanduser('~'), '.ssh') | ||
if not public_key_path: | ||
public_key_path = os.path.join(ssh_path, 'id_rsa.pub') | ||
if not private_key_path: | ||
private_key_path = os.path.join(ssh_path, 'id_rsa') | ||
ALGORITHMS = { | ||
"ED25519": { | ||
"public": "id_ed25519.pub", | ||
"private": "id_ed25519" | ||
}, | ||
"ED25519_SK": { | ||
"public": "id_ed25519_sk.pub", | ||
"private": "id_ed25519_sk" | ||
}, | ||
"ECDSA_SK": { | ||
"public": "id_ecdsa_sk.pub", | ||
"private": "id_ecdsa_sk" | ||
}, | ||
"RSA": { | ||
"public": "id_rsa.pub", | ||
"private": "id_rsa" | ||
} | ||
} | ||
|
||
|
||
def find_key_paths(ssh_path: Path): | ||
for algorithm in ALGORITHMS.values(): | ||
public_key_path = ssh_path / algorithm['public'] | ||
private_key_path = ssh_path / algorithm['private'] | ||
if public_key_path.exists() and private_key_path.exists(): | ||
return public_key_path, private_key_path | ||
|
||
raise KeypairException(f'Could not find keypair in {ssh_path}', | ||
f'Possible options include: {ALGORITHMS}') | ||
|
||
|
||
def construct_keypair(ssh_path: Path = None, passphrase: str = '') -> Keypair: | ||
ssh_path = ssh_path or Path('~/.ssh').expanduser() | ||
public_key_path, private_key_path = find_key_paths(ssh_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core Issue being solved, Gitlab accepts more than just RSA key pairs. A new exception type was added for when none of the possibilities can be located. The original |
||
return Keypair("git", public_key_path, private_key_path, passphrase) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes are conversions to |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes are conversions to
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes are conversions to |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes are due to applying linting rules to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint's
tests
as well asbattenberg
This is where many changes likely came from.