Skip to content

Commit f6737c7

Browse files
committed
fix: import boto3/hvac/keyring lazily so the CLI runs without them (v1.2.1)
Closes #1. The integrations module imported `boto3`, `hvac`, `keyring` and `botocore.exceptions` at module load time, and the CLI imports that module at startup. As a result, any problem in those packages crashed every command, including plain password generation that never touches AWS, Vault or the OS keychain. This is what issue #1 hit: a broken `boto3` in the user's environment (`boto.vendored.six.moves`) brought down the whole tool. Fixed - Move the `boto3`, `hvac`, `keyring` and `botocore.exceptions` imports inside the methods that use them (AWS Secrets Manager, HashiCorp Vault, OS keychain). Password generation and all non-integration features now run with no dependency on those packages being importable. - When an integration is used and its package is missing or broken, only that feature fails, with a clear error, instead of taking down the entire CLI. Bumps version to 1.2.1.
1 parent 4f8ac9e commit f6737c7

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

cryptex/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A production-ready CLI tool for generating secure passwords with advanced features.
44
"""
55

6-
__version__ = "1.2.0"
6+
__version__ = "1.2.1"
77
__author__ = "Tarek CHEIKH"
88
__email__ = "tarek@tocconsulting.fr"
99
__description__ = "Enhanced random password generator with advanced security features"

cryptex/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
help='Save generated password(s)/TOTP details to a file '
237237
'instead of printing to the terminal.'
238238
)
239-
@click.version_option(version='1.2.0', prog_name='cryptex')
239+
@click.version_option(version='1.2.1', prog_name='cryptex')
240240
def main(
241241
length: int,
242242
count: int,

cryptex/integrations.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
import sys
77
from typing import Dict, List, Optional
88

9-
import boto3
10-
import click
11-
import hvac
12-
import keyring
13-
from botocore.exceptions import ClientError, NoCredentialsError
9+
# boto3, hvac and keyring are imported lazily inside the methods that use
10+
# them. They pull in heavy/native dependencies, and importing them at module
11+
# load time would crash the entire CLI (even plain password generation) if
12+
# any of them is broken or missing in the user's environment.
1413

1514

1615
class AWSSecretsManager:
1716
"""AWS Secrets Manager integration."""
1817

1918
def __init__(self, region_name: str = 'us-east-1', profile_name: Optional[str] = None):
19+
import boto3
20+
from botocore.exceptions import NoCredentialsError
2021
try:
2122
# Create session with optional profile
2223
if profile_name:
@@ -37,6 +38,7 @@ def __init__(self, region_name: str = 'us-east-1', profile_name: Optional[str] =
3738

3839
def save_secret(self, secret_name: str, secret_value: str, description: str = "") -> bool:
3940
"""Save a secret to AWS Secrets Manager."""
41+
from botocore.exceptions import ClientError
4042
try:
4143
# Try to create new secret
4244
self.client.create_secret(
@@ -72,6 +74,7 @@ class HashiCorpVault:
7274
"""HashiCorp Vault integration."""
7375

7476
def __init__(self, url: str = 'http://localhost:8200', token: Optional[str] = None):
77+
import hvac
7578
self.client = hvac.Client(url=url, token=token)
7679

7780
if not self.client.is_authenticated():
@@ -110,6 +113,7 @@ def __init__(self):
110113

111114
def save_secret(self, service: str, username: str, password: str) -> bool:
112115
"""Save a secret to OS keychain."""
116+
import keyring
113117
try:
114118
keyring.set_password(service, username, password)
115119
return True

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "cryptex-cli"
7-
version = "1.2.0"
7+
version = "1.2.1"
88
description = "Enhanced random password generator with advanced security features"
99
authors = [
1010
{name = "Tarek CHEIKH", email = "tarek@tocconsulting.fr"},

0 commit comments

Comments
 (0)