Repository: voxpupuli/puppetboard

Issue:
Allow to force the protocol to connect to PuppetDB
When the `PUPPETDB_CERT` and `PUPPETDB_KEY` are not set, the Pypuppetdb library will automatically choose 'http' as the protocol to be used for the connection to PuppetDB.

It seems to me that as of now is not possible to configure PuppetBoard to connect to PuppetDB via HTTPS without a key/cert pair.
I think it's a quick and easy feature to add, so I'm sending a PR for it, if you'll deem acceptable.

Discussion:

Patch:
diff --git a/README.rst b/README.rst
index c0e7921..ac4dee0 100644
--- a/README.rst
+++ b/README.rst
@@ -190,7 +190,8 @@ connect. Therefor you'll also have to supply the following settings:
 * ``PUPPETDB_CERT = /path/to/public/keyfile.crt``
 
 For information about how to generate the correct keys please refer to the
-`pypuppetdb documentation`_.
+`pypuppetdb documentation`_. Alternatively is possible to explicitly specify
+the protocol to be used setting the ``PUPPETDB_PROTO`` variable.
 
 Other settings that might be interesting in no particular order:
 
diff --git a/puppetboard/core.py b/puppetboard/core.py
index 203c373..77f8453 100644
--- a/puppetboard/core.py
+++ b/puppetboard/core.py
@@ -47,7 +47,8 @@ def get_puppetdb():
                            ssl_verify=app.config['PUPPETDB_SSL_VERIFY'],
                            ssl_key=app.config['PUPPETDB_KEY'],
                            ssl_cert=app.config['PUPPETDB_CERT'],
-                           timeout=app.config['PUPPETDB_TIMEOUT'],)
+                           timeout=app.config['PUPPETDB_TIMEOUT'],
+                           protocol=app.config['PUPPETDB_PROTO'],)
         PUPPETDB = puppetdb
 
     return PUPPETDB
diff --git a/puppetboard/default_settings.py b/puppetboard/default_settings.py
index d33126c..e8f3a40 100644
--- a/puppetboard/default_settings.py
+++ b/puppetboard/default_settings.py
@@ -2,6 +2,7 @@ import os
 
 PUPPETDB_HOST = 'localhost'
 PUPPETDB_PORT = 8080
+PUPPETDB_PROTO = None
 PUPPETDB_SSL_VERIFY = True
 PUPPETDB_KEY = None
 PUPPETDB_CERT = None
diff --git a/puppetboard/docker_settings.py b/puppetboard/docker_settings.py
index b797906..f137c6a 100644
--- a/puppetboard/docker_settings.py
+++ b/puppetboard/docker_settings.py
@@ -2,7 +2,7 @@ import os
 
 PUPPETDB_HOST = os.getenv('PUPPETDB_HOST', 'puppetdb')
 PUPPETDB_PORT = int(os.getenv('PUPPETDB_PORT', '8080'))
-# Since this is an env it will alwas be a string, we need
+# Since this is an env it will always be a string, we need
 # to conver that string to a bool
 SSL_VERIFY = os.getenv('PUPPETDB_SSL_VERIFY', 'True')
 if SSL_VERIFY.upper() == 'TRUE':
@@ -14,6 +14,7 @@ else:
 
 PUPPETDB_KEY = os.getenv('PUPPETDB_KEY', None)
 PUPPETDB_CERT = os.getenv('PUPPETDB_CERT', None)
+PUPPETDB_PROTO = os.getenv('PUPPETDB_PROTO', None)
 PUPPETDB_TIMEOUT = int(os.getenv('PUPPETDB_TIMEOUT', '20'))
 DEFAULT_ENVIRONMENT = os.getenv('DEFAULT_ENVIRONMENT', 'production')
 SECRET_KEY = os.getenv('SECRET_KEY', os.urandom(24))


Test patch:
diff --git a/test/test_docker_settings.py b/test/test_docker_settings.py
index fe18a48..02ce89a 100644
--- a/test/test_docker_settings.py
+++ b/test/test_docker_settings.py
@@ -40,6 +40,12 @@ def test_set_host_port(cleanUpEnv):
     assert docker_settings.PUPPETDB_PORT == 9081
 
 
+def test_set_proto(cleanUpEnv):
+    os.environ['PUPPETDB_PROTO'] = 'https'
+    reload(docker_settings)
+    assert docker_settings.PUPPETDB_PROTO == 'https'
+
+
 def test_cert_true_test(cleanUpEnv):
     os.environ['PUPPETDB_SSL_VERIFY'] = 'True'
     reload(docker_settings)