Skip to content
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

feat: adding import functionality #13

Merged
merged 28 commits into from
Jul 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1cad64e
feat: adding import functionality
johnson2427 Jun 24, 2024
736142f
feat: working import
johnson2427 Jun 25, 2024
638e7d8
feat: adding functionality to allow for export of keys
johnson2427 Jun 25, 2024
0cc8bb9
feat: adding private key to cache
johnson2427 Jun 26, 2024
a4a83cd
feat: add purge to delete key from hidden ape folder
johnson2427 Jun 27, 2024
c0e7788
feat: add ability to add your own private key
johnson2427 Jun 27, 2024
9b7ef46
fix: remove breakpoint
johnson2427 Jun 27, 2024
ce1a88e
refactor: linting issues
johnson2427 Jun 27, 2024
2ca6074
fix: add cryptography to requirements
johnson2427 Jun 27, 2024
87d6879
refactor: remove unused imports
johnson2427 Jun 27, 2024
7bc9b25
refactor: isort
johnson2427 Jun 27, 2024
881612d
fix: create_key expected inputs
johnson2427 Jun 27, 2024
5062fe4
fix: remove mypy errors
johnson2427 Jun 27, 2024
a97c8ae
feat: add ability to input file
johnson2427 Jun 28, 2024
d816088
feat: add ability to use mnemonic
johnson2427 Jun 28, 2024
01b00ff
refactor: remove unused imports and clean up code
johnson2427 Jun 28, 2024
4ef628e
feat: clean up cli interface
johnson2427 Jun 28, 2024
d003195
fix: isort issue
johnson2427 Jun 28, 2024
9e26c0a
fix: use click prompt to hide password
johnson2427 Jul 1, 2024
335640c
fix: remove breakpoint
johnson2427 Jul 1, 2024
862a5e5
feat: add docs to README and remove colon from input request
johnson2427 Jul 1, 2024
b549274
fix: update README for create
johnson2427 Jul 1, 2024
5cf67b1
fix: update README
johnson2427 Jul 1, 2024
a29c4d7
fix: update README again
johnson2427 Jul 1, 2024
5635751
fix: update metavar for admins
johnson2427 Jul 1, 2024
c6b1a2d
feat: add some cleanup for import and README
johnson2427 Jul 1, 2024
9850fca
fix: add error handling
johnson2427 Jul 1, 2024
83cfc81
fix: black issue
johnson2427 Jul 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions ape_aws/kms/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def create_key(
@click.option(
"-p",
"--private-key",
"private_key",
"private_key_path",
type=click.Path(),
help="The private key you intend to import",
metavar="str",
metavar="Path",
johnson2427 marked this conversation as resolved.
Show resolved Hide resolved
)
@click.option(
"-a",
Expand All @@ -96,18 +97,6 @@ def create_key(
help="The description of the key you intend to create.",
metavar="str",
)
@click.option(
"--from-file",
"import_from_file",
help="Import a key from a file",
is_flag=True,
)
@click.option(
"--file-path",
"file_path",
help="The path to the file containing the private key",
metavar="str | Path",
)
@click.option(
"--use-mnemonic",
"import_from_mnemonic",
Expand All @@ -124,30 +113,31 @@ def create_key(
def import_key(
cli_ctx,
alias_name: str,
private_key: bytes | str,
private_key_path: Path,
administrators: list[str],
users: list[str],
description: str,
import_from_file: bool,
file_path: str | Path,
import_from_mnemonic: bool,
hd_path: str,
):
if import_from_file:
if isinstance(file_path, str):
path = Path(private_key)
if path.exists() and path.is_file():
cli_ctx.logger.info(f"Reading private key from {path}")
private_key = path.read_text().strip()

if import_from_mnemonic:
if private_key_path:
if isinstance(private_key_path, str):
private_key_path = Path(private_key_path)
if private_key_path.exists() and private_key_path.is_file():
cli_ctx.logger.info(f"Reading private key from {private_key_path}")
private_key = private_key_path.read_text().strip()

elif import_from_mnemonic:
if not hd_path:
hd_path = ETHEREUM_DEFAULT_PATH
mnemonic = click.prompt("Enter your mnemonic phrase", hide_input=True)
EthAccount.enable_unaudited_hdwallet_features()
account = EthAccount.from_mnemonic(mnemonic, account_path=hd_path)
private_key = account.key.hex()

else:
private_key = input("Enter your private key: ")
johnson2427 marked this conversation as resolved.
Show resolved Hide resolved

key_spec = ImportKeyRequest(
alias=alias_name,
description=description, # type: ignore
Expand Down
Loading