Repository: Kinto/kinto

Issue:
Enabling the flush endpoint through env vars does not seem to work
I'm running Kinto + postgres with docker-compose (using the example docker-compose.yml in the repo). 

Adding `KINTO_FLUSH_ENDPOINT_ENABLED` to the environment section in docker-compose.yml does not enable the flush endpoint for me. I instead had to add `kinto.flush_endpoint_enabled = true` to a custom ini file, that worked.

Can the flush endpoint be enabled through an env var like this?



Discussion:
Let me try :)

I can confirm that adding `KINTO_FLUSH_ENDPOINT_ENABLED` env variable doesn't work.

Refs #515 


Resolving patch:
diff --git a/kinto/__init__.py b/kinto/__init__.py
--- a/kinto/__init__.py
+++ b/kinto/__init__.py
@@ -19,6 +19,7 @@
 
 
 DEFAULT_SETTINGS = {
+    'flush_endpoint_enabled': False,
     'retry_after_seconds': 3,
     'cache_backend': 'kinto.core.cache.memory',
     'permission_backend': 'kinto.core.permission.memory',
@@ -58,18 +59,18 @@ def main(global_config, config=None, **settings):
 
     # Scan Kinto views.
     kwargs = {}
-    flush_enabled = asbool(settings.get('flush_endpoint_enabled'))
 
+    flush_enabled = asbool(settings.get('flush_endpoint_enabled'))
     if flush_enabled:
         config.add_api_capability(
             "flush_endpoint",
             description="The __flush__ endpoint can be used to remove all "
                         "data from all backends.",
             url="http://kinto.readthedocs.io/en/latest/configuration/"
-                "settings.html#activating-the-flush-endpoint"
-        )
+                "settings.html#activating-the-flush-endpoint")
     else:
         kwargs['ignore'] = 'kinto.views.flush'
+
     config.scan("kinto.views", **kwargs)
 
     app = config.make_wsgi_app()


Test patch:
diff --git a/kinto/tests/test_views_flush.py b/kinto/tests/test_views_flush.py
--- a/kinto/tests/test_views_flush.py
+++ b/kinto/tests/test_views_flush.py
@@ -1,3 +1,4 @@
+import os
 import webtest
 from pyramid.config import Configurator
 
@@ -61,7 +62,7 @@ def _get_test_app(self, settings=None):
     def get_app_settings(self, extra=None):
         if extra is None:
             extra = {}
-        extra.setdefault('kinto.flush_endpoint_enabled', True)
+        extra.setdefault('flush_endpoint_enabled', True)
         settings = super(FlushViewTest, self).get_app_settings(extra)
         return settings
 
@@ -69,7 +70,7 @@ def listener(self, event):
         self.events.append(event)
 
     def test_returns_404_if_not_enabled_in_configuration(self):
-        extra = {'kinto.flush_endpoint_enabled': False}
+        extra = {'flush_endpoint_enabled': False}
         app = self._get_test_app(settings=extra)
         app.post('/__flush__', headers=self.headers, status=404)
 
@@ -90,3 +91,10 @@ def test_event_triggered_post(self):
         self.app.post('/__flush__', headers=self.headers, status=202)
         self.assertEqual(len(self.events), 1)
         self.assertTrue(isinstance(self.events[0], ServerFlushed))
+
+    def test_can_be_enabled_via_environment(self):
+        os.environ['KINTO_FLUSH_ENDPOINT_ENABLED'] = 'true'
+        extra = {'flush_endpoint_enabled': False}
+        app = self._get_test_app(settings=extra)
+        app.post('/__flush__', headers=self.headers)
+        os.environ.pop('KINTO_FLUSH_ENDPOINT_ENABLED')