Repository: typesafehub/conductr-cli

Issue:
load-license message not needed?
Encountered this while upgrading conductr cluster from alpha1 to alpha3:
```
conduct load-license -f <<< '...'

An access token is required. Please visit https://www.lightbend.com/account/access-token to
obtain one, and a free license or your commercial one.

Please enter your access token: Loading license into ConductR at 172.31.60.175

Licensed To: 1d1400b6-3e12-45fe-b0cc-15790b5a9b73
Expires In: 364 days (Fri 04 May 2018 01:21AM)
Grants: akka-sbr, cinnamon, conductr

License successfully loaded
```

The initial message is confusing. 
1) I'm loading a new access token so the message is out of place to begin with. 
2) What does " and a free license or your commercial one" mean? Perhaps just omit that?


Discussion:
longshorej: Here's a manual test showing that we no longer show the prompt when providing a token:

```
$ conduct load-license <<< 1235
Error: Your credentials are no longer valid. Please visit https://www.lightbend.com/account/access-token to renew them.
-> 1
```

Patch:
diff --git a/conductr_cli/license_auth.py b/conductr_cli/license_auth.py
index b1d2128..1ab3c67 100644
--- a/conductr_cli/license_auth.py
+++ b/conductr_cli/license_auth.py
@@ -1,5 +1,6 @@
 from conductr_cli.constants import DEFAULT_AUTH_TOKEN_FILE
 import os
+import sys
 try:
     import readline
 except ImportError:
@@ -7,7 +8,7 @@ except ImportError:
 
 
 AUTH_TOKEN_PROMPT = '\nAn access token is required. Please visit https://www.lightbend.com/account/access-token to \n' \
-                    'obtain one, and a free license or your commercial one.\n' \
+                    'obtain one for free and commercial licenses.\n' \
                     '\n' \
                     'Please enter your access token: '
 
@@ -34,7 +35,10 @@ def prompt_for_auth_token():
     readline.clear_history()
 
     try:
-        return input(AUTH_TOKEN_PROMPT).strip()
+        if sys.stdin.isatty():
+            return input(AUTH_TOKEN_PROMPT).strip()
+        else:
+            return input().strip()
     except EOFError:
         return ''
 


Test patch:
diff --git a/conductr_cli/test/test_license_auth.py b/conductr_cli/test/test_license_auth.py
index 727cf24..0c7b5b1 100644
--- a/conductr_cli/test/test_license_auth.py
+++ b/conductr_cli/test/test_license_auth.py
@@ -39,11 +39,25 @@ class TestPromptForAuthToken(TestCase):
         mock_input = MagicMock(return_value=auth_token)
 
         with patch('builtins.print', mock_print), \
-                patch('builtins.input', mock_input):
+                patch('builtins.input', mock_input), \
+                patch('sys.stdin.isatty', lambda: True):
             self.assertEqual(auth_token, license_auth.prompt_for_auth_token())
 
         mock_input.assert_called_once_with(license_auth.AUTH_TOKEN_PROMPT)
 
+    def test_no_tty_dont_prompt_for_auth_token(self):
+        auth_token = 'test auth token'
+
+        mock_print = MagicMock()
+        mock_input = MagicMock(return_value=auth_token)
+
+        with patch('builtins.print', mock_print), \
+                patch('builtins.input', mock_input), \
+                patch('sys.stdin.isatty', lambda: False):
+            self.assertEqual(auth_token, license_auth.prompt_for_auth_token())
+
+        mock_input.assert_called_once_with()
+
 
 class TestRemoveCachedAuthToken(TestCase):
     def test_cached_token_exists(self):