Repository: Netflix/lemur

Issue:
allow lemur init to use alternate config
When installing we can define an alternate path for the `lemur create_config` with the -c arg. Can we get `lemur init` to accept an alternate path? Or is it always expected to have configuration items (config, keys, etc) under ~/.lemur/ ?

thanks


Discussion:
That seems reasonable. 
thanks
Looking into this it seems we already support this. For any given command you should be able to pass '-c' and point to the configuration for which you want use.

In your case something like:
  
    lemur -c <path-to_config> init

Should use the configuration as passed.

Can you try that out and let me know how it goes?
So having already performed init, it appears to work. Though when I run `lemur -c /path/to/config start` it tries to use the ~/.lemur/ path.

Starting from scratch in a temp dir and fresh database all seems well until I try to start. Renaming the config found in ~/.lemur and trying to start I get the following

> : mv ~/.lemur/lemur.conf.py ~/.lemur/lemur.conf.py.bak
(lemur) jguarini-ld1:/tmp/lemur: lemur -c /tmp/lemur/config/lemur.conf.py start -b 0.0.0.0:8001
/tmp/lemur/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.
  warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.')
Plugin 'DigiCertIssuerPlugin' may not work correctly. Required variable 'DIGICERT_API_KEY' is not set in Lemur's conf.
Plugin 'DigiCertCISIssuerPlugin' may not work correctly. Required variable 'DIGICERT_CIS_API_KEY' is not set in Lemur's conf.
/tmp/lemur/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.
  warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.')
Plugin 'DigiCertIssuerPlugin' may not work correctly. Required variable 'DIGICERT_API_KEY' is not set in Lemur's conf.
Plugin 'DigiCertCISIssuerPlugin' may not work correctly. Required variable 'DIGICERT_CIS_API_KEY' is not set in Lemur's conf.
Traceback (most recent call last):
  File "/tmp/lemur/bin/lemur", line 11, in <module>
    load_entry_point('lemur', 'console_scripts', 'lemur')()
  File "/tmp/lemur/lemur/manage.py", line 636, in main
    manager.run()
  File "/tmp/lemur/lib/python3.5/site-packages/flask_script/__init__.py", line 412, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/tmp/lemur/lib/python3.5/site-packages/flask_script/__init__.py", line 383, in handle
    res = handle(*args, **config)
  File "/tmp/lemur/lib/python3.5/site-packages/flask_script/commands.py", line 216, in __call__
    return self.run(*args, **kwargs)
  File "/tmp/lemur/lemur/manage.py", line 377, in run
    validate_conf(pre_app, REQUIRED_VARIABLES)
  File "/tmp/lemur/lemur/common/utils.py", line 99, in validate_conf
    raise InvalidConfiguration("Required variable '{var}' is not set in Lemur's conf.".format(var=var))
lemur.exceptions.InvalidConfiguration: Required variable 'LEMUR_SECURITY_TEAM_EMAIL' is not set in Lemur's conf.


thanks for looking into this
Ugh, That is an ugly amount of output for a simple command. Let me see if I can clean that up.

Resolving patch:
diff --git a/lemur/common/managers.py b/lemur/common/managers.py
--- a/lemur/common/managers.py
+++ b/lemur/common/managers.py
@@ -60,11 +60,14 @@ def all(self):
                     results.append(cls())
                 else:
                     results.append(cls)
+
             except InvalidConfiguration as e:
                 current_app.logger.warning("Plugin '{0}' may not work correctly. {1}".format(class_name, e))
+
             except Exception as e:
                 current_app.logger.exception("Unable to import {0}. Reason: {1}".format(cls_path, e))
                 continue
+
         self.cache = results
 
         return results
diff --git a/lemur/factory.py b/lemur/factory.py
--- a/lemur/factory.py
+++ b/lemur/factory.py
@@ -92,6 +92,7 @@ def configure_app(app, config=None):
     """
     # respect the config first
     if config and config != 'None':
+        app.config['CONFIG_PATH'] = config
         app.config.from_object(from_file(config))
     else:
         try:
@@ -103,6 +104,9 @@ def configure_app(app, config=None):
             else:
                 app.config.from_object(from_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'default.conf.py')))
 
+    # we don't use this
+    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
+
 
 def configure_extensions(app):
     """
diff --git a/lemur/manage.py b/lemur/manage.py
--- a/lemur/manage.py
+++ b/lemur/manage.py
@@ -119,7 +119,6 @@
 # modify this if you are not using a local database
 SQLALCHEMY_DATABASE_URI = 'postgresql://lemur:lemur@localhost:5432/lemur'
 
-
 # AWS
 
 #LEMUR_INSTANCE_PROFILE = 'Lemur'
@@ -372,11 +371,10 @@ def run(self, *args, **kwargs):
 
         app = WSGIApplication()
 
-        # run startup tasks on an app like object
-        pre_app = create_app(kwargs.get('config'))
-        validate_conf(pre_app, REQUIRED_VARIABLES)
+        # run startup tasks on a app like object
+        validate_conf(current_app, REQUIRED_VARIABLES)
 
-        app.app_uri = 'lemur:create_app(config="{0}")'.format(kwargs.get('config'))
+        app.app_uri = 'lemur:create_app(config="{0}")'.format(current_app.config.get('CONFIG_PATH'))
 
         return app.run()
 


Test patch: