Skip to content

Commit

Permalink
CLI: require stdin.isatty before using cli.input
Browse files Browse the repository at this point in the history
The cli.input method currently blindly calls either
raw_input or getpass both of which hang if stdin is
piped into the bin/omero command. A further fix here
would be to teach the input method itself how to check
stdin, but this require a more further review.

See
https://trello.com/c/mUAfr6kf/200-bin-omero-should-fail-if-not-logged-in-and-no-stdin

Former-commit-id: bc59894
  • Loading branch information
joshmoore committed Jul 5, 2017
1 parent c7986db commit 1657d14
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/omero/plugins/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ def login(self, args):
action = "Reconnected to"

if not rv:

self._require_tty("cannot request password")

tries = 3
while True:
try:
Expand Down Expand Up @@ -883,6 +886,7 @@ def _get_server(self, store, name, port):
defserver = store.last_host()
if not port:
port = str(omero.constants.GLACIER2PORT)
self._require_tty("cannot request server")
rv = self.ctx.input("Server: [%s:%s]" % (defserver, port))
if not rv:
return defserver, name, port
Expand All @@ -892,12 +896,18 @@ def _get_server(self, store, name, port):
def _get_username(self, defuser):
if defuser is None:
defuser = get_user("root")
self._require_tty("cannot request username")
rv = self.ctx.input("Username: [%s]" % defuser)
if not rv:
return defuser
else:
return rv

def _require_tty(self, msg):
if sys.stdin.isatty():
return
self.ctx.die(564, "stdin is not a terminal: %s" % msg)


try:
register("sessions", SessionsControl, HELP)
Expand Down

0 comments on commit 1657d14

Please sign in to comment.