Repository: simphony/simphony-remote

Issue:
FileConfig with tls=True or tls_verify=False only, leads to docker TLSParameterError 
On Linux, if my file config for the `remoteappmanager_config.py` ONLY contains the following:
```
$ cat remoteappmanager_config.py
tls = True
```

or
```
$ cat remoteappmanager_config.py
tls_verify = True
```

Then starting remoteappmanager gives this error
```
$ remoteappmanager --user=kit --port=45707 --cookie-name=jupyter-hub-token-kit --base-urlpath=/user/kit --hub-host= --hub-prefix=/hub/ --hub-api-url=http://172.16.253.129:8081/hub/api --ip=127.0.0.1 --proxy-api-url=http://127.0.0.1:8001/api/routes/ --config-file=remoteappmanager_config.py
...
[E 160720 14:33:43 web:1548] Uncaught exception GET /user/kit/ (127.0.0.1)
    HTTPServerRequest(protocol='http', host='127.0.0.1:8000', method='GET', uri='/user/kit/', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'X-Forwarded-Proto': 'https', 'Accept-Language': 'en-US,en;q=0.5', 'X-Forwarded-For': '127.0.0.1', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'If-None-Match': '"dfba4089bef9b2e40bbd2a75ba5413bb8edbdd83"', 'Host': '127.0.0.1:8000', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0', 'Referer': 'https://127.0.0.1:8000/hub/login', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'X-Forwarded-Port': '8000', 'Cookie': 'jupyter-hub-token-kit="2|1:0|10:1469021623|21:jupyter-hub-token-kit|44:M2UzMjRlOGNhNDBjNGQ5ZWEwYjg3Njk0N2U0ODY4MmE=|1ec021fdad25b335a6b11b22ff198ce0860a0742a4d95c46a33a6d659d5f4e2d"'})
    Traceback (most recent call last):
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/traitlets/traitlets.py", line 501, in get
        value = obj._trait_values[self.name]
    KeyError: 'container_manager'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/tornado/web.py", line 1469, in _execute
        result = yield result
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/tornado/gen.py", line 1015, in run
        value = future.result()
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/tornado/concurrent.py", line 237, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/tornado/gen.py", line 1021, in run
        yielded = self.gen.throw(*exc_info)
      File "/mnt/hgfs/VM_shared/SimPhoNy/simphony-remote/remoteappmanager/handlers/home_handler.py", line 21, in get
        images_info = yield self._get_images_info()
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/tornado/gen.py", line 1015, in run
        value = future.result()
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/tornado/concurrent.py", line 237, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/tornado/gen.py", line 285, in wrapper
        yielded = next(result)
      File "/mnt/hgfs/VM_shared/SimPhoNy/simphony-remote/remoteappmanager/handlers/home_handler.py", line 184, in _get_images_info
        container_manager = self.application.container_manager
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/traitlets/traitlets.py", line 529, in __get__
        return self.get(obj, cls)
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/traitlets/traitlets.py", line 508, in get
        value = self._validate(obj, dynamic_default())
      File "/mnt/hgfs/VM_shared/SimPhoNy/simphony-remote/remoteappmanager/application.py", line 81, in _container_manager_default
        docker_config=self.file_config.docker_config()
      File "/mnt/hgfs/VM_shared/SimPhoNy/simphony-remote/remoteappmanager/file_config.py", line 155, in docker_config
        assert_hostname=True,
      File "/home/kit/.virtualenv/simremote/lib/python3.4/site-packages/docker/tls.py", line 47, in __init__
        'Path to a certificate and key files must be provided'
    docker.errors.TLSParameterError: Path to a certificate and key files must be provided through the client_config param. TLS configurations should map the Docker CLI client configurations. See https://docs.docker.com/engine/articles/https/ for API details.
```


Discussion:

Patch:
diff --git a/remoteappmanager/file_config.py b/remoteappmanager/file_config.py
index 2f93478..8966ed8 100644
--- a/remoteappmanager/file_config.py
+++ b/remoteappmanager/file_config.py
@@ -3,7 +3,6 @@ import os
 import tornado.options
 from docker import tls
 from traitlets import HasTraits, Int, Unicode, Bool, Dict
-from traitlets.utils.sentinel import Sentinel
 
 from remoteappmanager import paths
 from remoteappmanager.traitlets import set_traits_from_dict
@@ -110,12 +109,7 @@ class FileConfig(HasTraits):
         for traitlet_name, traitlet in self.traits().items():
             # tornado.OptionParser defines an option with a Python type
             # and performs type validation.
-            # traitlet.default_value may be a Sentinel value (e.g. Tuple,
-            # Dict, Instance), in which case we use the repr
-            default_value = traitlet.default_value
-
-            if type(default_value) is Sentinel:
-                default_value = eval(traitlet.default_value_repr())
+            default_value = getattr(self, traitlet_name)
 
             file_line_parser.define(
                 traitlet_name,


Test patch:
diff --git a/tests/test_file_config.py b/tests/test_file_config.py
index 22ce879..484d1b9 100644
--- a/tests/test_file_config.py
+++ b/tests/test_file_config.py
@@ -151,3 +151,15 @@ class TestFileConfig(TempMixin, unittest.TestCase):
         config = FileConfig(tls=True)
         self.assertNotEqual(config.tls_key, '')
         self.assertNotEqual(config.tls_cert, '')
+
+    def test_file_parsing_not_overriding_bug_131(self):
+        docker_config = textwrap.dedent('''
+            tls = True
+            ''')
+        with open(self.config_file, 'w') as fhandle:
+            print(docker_config, file=fhandle)
+
+        config = FileConfig()
+        config.parse_config(self.config_file)
+        self.assertNotEqual(config.tls_key, '')
+        self.assertNotEqual(config.tls_cert, '')