Skip to content

Commit

Permalink
Handle no tty pwinput (#8296)
Browse files Browse the repository at this point in the history
* Handle no tty pwinput

Pwinput : When terminal / tty is not available, read from stdin

* update version

* fix lint issue
  • Loading branch information
nascarsayan authored Jan 7, 2025
1 parent 8d5bfbd commit 28ae98d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/connectedvmware/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Release History
===============
1.2.1
++++++
* For pwinput, read input from stdin when tty is not available

1.2.0
++++++
* Add support to enable a VM using managed object name (moName).
Expand Down
2 changes: 1 addition & 1 deletion src/connectedvmware/azext_connectedvmware/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ def create_from_machines(
for vm in vm_list:
biosId2VM[vm["biosId"]].append(vm)
for i, vm in enumerate(vm_list):
prefix = f"[{i+1}/{len(vm_list)}]"
prefix = f"[{i + 1}/{len(vm_list)}]"
machineId = vm["machineId"]
machineName = vm["name"]
machineRG = vm["resourceGroup"]
Expand Down
5 changes: 4 additions & 1 deletion src/connectedvmware/azext_connectedvmware/pwinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
except ImportError:
pass # There is no typing module on Python 2, but that's fine because we use the comment-style of type hints.

if sys.platform == 'win32':
if not sys.stdin.isatty():
def pwinput(prompt='Password: ', mask='*'):
return sys.stdin.readline().rstrip()
elif sys.platform == 'win32':
# For some reason, mypy reports that msvcrt doesn't have getch, ignore this warning:
from msvcrt import getch # type: ignore

Expand Down
2 changes: 1 addition & 1 deletion src/connectedvmware/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.

VERSION = '1.2.0'
VERSION = '1.2.1'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down

0 comments on commit 28ae98d

Please sign in to comment.