From 1657d142d3349f0f7e2d7a107a36373bf76cbe68 Mon Sep 17 00:00:00 2001 From: jmoore Date: Wed, 5 Jul 2017 10:07:55 +0200 Subject: [PATCH] CLI: require stdin.isatty before using cli.input 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: bc598940d3de3edd3c8fd2de2bdce6c42a9dda04 --- src/omero/plugins/sessions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/omero/plugins/sessions.py b/src/omero/plugins/sessions.py index 75ac0d0b8..aaa408600 100644 --- a/src/omero/plugins/sessions.py +++ b/src/omero/plugins/sessions.py @@ -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: @@ -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 @@ -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)