fix: add TTY handling for password prompts and config get alias
Some checks failed
CLI Tests / test-cli (push) Has been cancelled
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
Some checks failed
CLI Tests / test-cli (push) Has been cancelled
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
- Fixed getpass TTY error by checking sys.stdin.isatty() before prompting - Added environment variable fallback for non-interactive environments (AITBC_WALLET_PASSWORD) - Added config get command as alias for show command - Wrapped getpass calls in try/except for better error handling - Fixes termios.error in non-interactive environments like CI/scripts
This commit is contained in:
@@ -34,6 +34,13 @@ def show(ctx):
|
||||
output(config_dict, ctx.obj['output_format'])
|
||||
|
||||
|
||||
@config.command(name="get")
|
||||
@click.pass_context
|
||||
def get(ctx):
|
||||
"""Get current configuration (alias for show)"""
|
||||
return ctx.invoke(show)
|
||||
|
||||
|
||||
@config.command()
|
||||
@click.argument("key")
|
||||
@click.argument("value")
|
||||
|
||||
@@ -43,9 +43,28 @@ def _get_wallet_password(wallet_name: str) -> str:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Check if we're in a TTY environment
|
||||
import sys
|
||||
if not sys.stdin.isatty():
|
||||
# Non-interactive: try environment variable
|
||||
password = os.environ.get(f"AITBC_WALLET_PASSWORD_{wallet_name.upper()}")
|
||||
if password:
|
||||
return password
|
||||
# Try generic password env var
|
||||
password = os.environ.get("AITBC_WALLET_PASSWORD")
|
||||
if password:
|
||||
return password
|
||||
error("No TTY available for password prompt. Set AITBC_WALLET_PASSWORD environment variable.")
|
||||
raise click.Abort()
|
||||
|
||||
# Prompt for password
|
||||
while True:
|
||||
try:
|
||||
password = getpass.getpass(f"Enter password for wallet '{wallet_name}': ")
|
||||
except Exception as e:
|
||||
error(f"Password prompt failed: {e}")
|
||||
raise click.Abort()
|
||||
|
||||
if not password:
|
||||
error("Password cannot be empty")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user